diff --git a/src/lang/executor.ts b/src/lang/executor.ts index 8252d256d..e9454fe66 100644 --- a/src/lang/executor.ts +++ b/src/lang/executor.ts @@ -108,7 +108,11 @@ export const executor = ( return _programMemory.root[arg.name] } }) - if ('lineTo' === functionName || 'close' === functionName || 'base' === functionName) { + if ( + 'lineTo' === functionName || + 'close' === functionName || + 'base' === functionName + ) { if (options.bodyType !== 'sketch') { throw new Error( `Cannot call ${functionName} outside of a sketch declaration` diff --git a/src/lang/recast.test.ts b/src/lang/recast.test.ts index c093b0335..65d66f666 100644 --- a/src/lang/recast.test.ts +++ b/src/lang/recast.test.ts @@ -50,14 +50,13 @@ log(5, myVar)` expect(recasted).toBe(code.trim()) }) it('function declaration with call', () => { - const code = - [ - 'fn funcN = (a, b) => {', - ' return a + b', - '}', - 'const theVar = 60', - 'const magicNum = funcN(9, theVar)', - ].join('\n') + const code = [ + 'fn funcN = (a, b) => {', + ' return a + b', + '}', + 'const theVar = 60', + 'const magicNum = funcN(9, theVar)', + ].join('\n') const { ast } = code2ast(code) const recasted = recast(ast) expect(recasted).toBe(code.trim()) diff --git a/src/lang/recast.ts b/src/lang/recast.ts index f88f9f613..f56877b70 100644 --- a/src/lang/recast.ts +++ b/src/lang/recast.ts @@ -113,6 +113,6 @@ function recastSketchExpression( indentation: string ): string { return `{ -${recast(expression.body, '', indentation + ' ')} +${recast(expression.body, '', indentation + ' ')} }` } diff --git a/src/lang/sketch.ts b/src/lang/sketch.ts index 72662eacd..6fc9efc23 100644 --- a/src/lang/sketch.ts +++ b/src/lang/sketch.ts @@ -92,28 +92,29 @@ function getCoordsFromPaths(paths: Path[], index = 0): Coords2d { } export const sketchFns = { - base: (programMemory: ProgramMemory, + base: ( + programMemory: ProgramMemory, name: string = '', sourceRange: SourceRange, ...args: any[] - ): PathReturn => { - if(programMemory._sketch?.length > 0) { - throw new Error('Base can only be called once') - } - const [x, y] = args as [number, number] - let from: [number, number] = [x, y] - const newPath: Path = { - type: 'base', - from, - sourceRange, - } - return { - programMemory: { - ...programMemory, - _sketch: [...(programMemory?._sketch || []), newPath], - }, - currentPath: newPath, - } + ): PathReturn => { + if (programMemory._sketch?.length > 0) { + throw new Error('Base can only be called once') + } + const [x, y] = args as [number, number] + let from: [number, number] = [x, y] + const newPath: Path = { + type: 'base', + from, + sourceRange, + } + return { + programMemory: { + ...programMemory, + _sketch: [...(programMemory?._sketch || []), newPath], + }, + currentPath: newPath, + } }, close: ( programMemory: ProgramMemory, diff --git a/src/lang/tokeniser.test.ts b/src/lang/tokeniser.test.ts index 402f6edc3..fba09b5bf 100644 --- a/src/lang/tokeniser.test.ts +++ b/src/lang/tokeniser.test.ts @@ -21,7 +21,7 @@ describe('testing helpers', () => { expect(isNumber('-5')).toBe(true) expect(isNumber('5.5')).toBe(true) expect(isNumber('-5.5')).toBe(true) - + expect(isNumber('a')).toBe(false) expect(isNumber('?')).toBe(false) expect(isNumber('?5')).toBe(false) @@ -299,7 +299,6 @@ describe('testing lexer', () => { "whitespace ' ' from 6 to 7", "number '2.5' from 7 to 10", ]) - }) })