fmt
This commit is contained in:
@ -155,7 +155,12 @@ function App() {
|
||||
<OrbitControls
|
||||
enableDamping={false}
|
||||
enablePan
|
||||
enableRotate={!(guiMode.mode === 'canEditSketch' || guiMode.mode === 'sketch')}
|
||||
enableRotate={
|
||||
!(
|
||||
guiMode.mode === 'canEditSketch' ||
|
||||
guiMode.mode === 'sketch'
|
||||
)
|
||||
}
|
||||
enableZoom
|
||||
reverseOrbit={false}
|
||||
/>
|
||||
|
@ -1219,27 +1219,33 @@ export function changeArguments(
|
||||
node: Program,
|
||||
pathToNode: (string | number)[],
|
||||
args: [number, number]
|
||||
): { modifiedAst: Program; pathToNode: (string | number)[] }{
|
||||
): { modifiedAst: Program; pathToNode: (string | number)[] } {
|
||||
const _node = { ...node }
|
||||
const dumbyStartend = { start: 0, end: 0 }
|
||||
// const thePath = getNodePathFromSourceRange(_node, sourceRange)
|
||||
const callExpression = getNodeFromPath(_node, pathToNode) as CallExpression
|
||||
const newXArg: CallExpression['arguments'][number] = callExpression.arguments[0].type === 'Literal' ? {
|
||||
type: 'Literal',
|
||||
...dumbyStartend,
|
||||
value: args[0],
|
||||
raw: `${args[0]}`,
|
||||
} : {
|
||||
...callExpression.arguments[0]
|
||||
}
|
||||
const newYArg: CallExpression['arguments'][number] = callExpression.arguments[1].type === 'Literal' ? {
|
||||
type: 'Literal',
|
||||
...dumbyStartend,
|
||||
value: args[1],
|
||||
raw: `${args[1]}`,
|
||||
} : {
|
||||
...callExpression.arguments[1]
|
||||
}
|
||||
const newXArg: CallExpression['arguments'][number] =
|
||||
callExpression.arguments[0].type === 'Literal'
|
||||
? {
|
||||
type: 'Literal',
|
||||
...dumbyStartend,
|
||||
value: args[0],
|
||||
raw: `${args[0]}`,
|
||||
}
|
||||
: {
|
||||
...callExpression.arguments[0],
|
||||
}
|
||||
const newYArg: CallExpression['arguments'][number] =
|
||||
callExpression.arguments[1].type === 'Literal'
|
||||
? {
|
||||
type: 'Literal',
|
||||
...dumbyStartend,
|
||||
value: args[1],
|
||||
raw: `${args[1]}`,
|
||||
}
|
||||
: {
|
||||
...callExpression.arguments[1],
|
||||
}
|
||||
callExpression.arguments = [newXArg, newYArg]
|
||||
return {
|
||||
modifiedAst: _node,
|
||||
|
@ -300,10 +300,10 @@ export type ViewerArtifact =
|
||||
geo: LineGeos
|
||||
}
|
||||
| {
|
||||
type: 'sketchBase',
|
||||
sourceRange: SourceRange,
|
||||
type: 'sketchBase'
|
||||
sourceRange: SourceRange
|
||||
geo: BufferGeometry
|
||||
}
|
||||
}
|
||||
| {
|
||||
type: 'parent'
|
||||
sourceRange: SourceRange
|
||||
@ -322,12 +322,12 @@ export const processShownObjects = (
|
||||
): ViewerArtifact[] => {
|
||||
if (geoMeta?.type === 'sketchGeo') {
|
||||
return geoMeta.sketch.map(({ geo, sourceRange, type }) => {
|
||||
if(type === 'toPoint') {
|
||||
if (type === 'toPoint') {
|
||||
// const newGeo = geo.clone()
|
||||
const newGeo: LineGeos = {
|
||||
line: geo.line.clone(),
|
||||
tip: geo.tip.clone(),
|
||||
centre: geo.centre.clone(),
|
||||
line: geo.line.clone(),
|
||||
tip: geo.tip.clone(),
|
||||
centre: geo.centre.clone(),
|
||||
}
|
||||
previousTransforms.forEach(({ rotation, transform }) => {
|
||||
Object.values(newGeo).forEach((geoItem) => {
|
||||
@ -342,7 +342,7 @@ export const processShownObjects = (
|
||||
geo: newGeo,
|
||||
sourceRange,
|
||||
}
|
||||
} else if(type === 'base') {
|
||||
} else if (type === 'base') {
|
||||
const newGeo = geo.clone()
|
||||
previousTransforms.forEach(({ rotation, transform }) => {
|
||||
newGeo.rotateX(rotation[0])
|
||||
@ -356,8 +356,6 @@ export const processShownObjects = (
|
||||
sourceRange,
|
||||
}
|
||||
}
|
||||
console.log('type',type)
|
||||
|
||||
throw new Error('Unknown geo type')
|
||||
})
|
||||
} else if (geoMeta.type === 'transform') {
|
||||
|
@ -3,8 +3,8 @@ import { lexer } from './tokeniser'
|
||||
import { abstractSyntaxTree, getNodeFromPath } from './abstractSyntaxTree'
|
||||
|
||||
describe('testing getNodePathFromSourceRange', () => {
|
||||
it('test it gets the right path for a `lineTo` CallExpression within a SketchExpression', () => {
|
||||
const code = `
|
||||
it('test it gets the right path for a `lineTo` CallExpression within a SketchExpression', () => {
|
||||
const code = `
|
||||
const myVar = 5
|
||||
sketch sk3 {
|
||||
lineTo(1, 2)
|
||||
@ -12,16 +12,18 @@ describe('testing getNodePathFromSourceRange', () => {
|
||||
close()
|
||||
}
|
||||
`
|
||||
const subStr = 'lineTo(3, 4)'
|
||||
const lineToSubstringIndex = code.indexOf(subStr)
|
||||
const sourceRange: [number, number] = [lineToSubstringIndex, lineToSubstringIndex + subStr.length]
|
||||
const subStr = 'lineTo(3, 4)'
|
||||
const lineToSubstringIndex = code.indexOf(subStr)
|
||||
const sourceRange: [number, number] = [
|
||||
lineToSubstringIndex,
|
||||
lineToSubstringIndex + subStr.length,
|
||||
]
|
||||
|
||||
const ast = abstractSyntaxTree(lexer(code))
|
||||
const nodePath = getNodePathFromSourceRange(ast, sourceRange)
|
||||
const node = getNodeFromPath(ast, nodePath)
|
||||
const ast = abstractSyntaxTree(lexer(code))
|
||||
const nodePath = getNodePathFromSourceRange(ast, sourceRange)
|
||||
const node = getNodeFromPath(ast, nodePath)
|
||||
|
||||
expect([node.start, node.end]).toEqual(sourceRange)
|
||||
expect(node.type).toBe('CallExpression')
|
||||
|
||||
})
|
||||
expect([node.start, node.end]).toEqual(sourceRange)
|
||||
expect(node.type).toBe('CallExpression')
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user