From 5a0043c959467bca90173cc13531e1a93b5d78ec Mon Sep 17 00:00:00 2001 From: Adam Chalmers Date: Fri, 17 Nov 2023 17:12:22 -0600 Subject: [PATCH] Fix up tests --- src/lang/abstractSyntaxTree.test.ts | 48 ++++++++++++++------- src/lang/getNodePathFromSourceRange.test.ts | 8 ++-- src/lang/wasm.ts | 1 + 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/lang/abstractSyntaxTree.test.ts b/src/lang/abstractSyntaxTree.test.ts index d48633c42..911846137 100644 --- a/src/lang/abstractSyntaxTree.test.ts +++ b/src/lang/abstractSyntaxTree.test.ts @@ -169,16 +169,24 @@ describe('testing function declaration', () => { end: 39, params: [ { - type: 'Identifier', - start: 12, - end: 13, - name: 'a', + type: 'Parameter', + identifier: { + type: 'Identifier', + start: 12, + end: 13, + name: 'a', + }, + optional: false, }, { - type: 'Identifier', - start: 15, - end: 16, - name: 'b', + type: 'Parameter', + identifier: { + type: 'Identifier', + start: 15, + end: 16, + name: 'b', + }, + optional: false, }, ], body: { @@ -244,16 +252,24 @@ const myVar = funcN(1, 2)` end: 37, params: [ { - type: 'Identifier', - start: 12, - end: 13, - name: 'a', + type: 'Parameter', + identifier: { + type: 'Identifier', + start: 12, + end: 13, + name: 'a', + }, + optional: false, }, { - type: 'Identifier', - start: 15, - end: 16, - name: 'b', + type: 'Parameter', + identifier: { + type: 'Identifier', + start: 15, + end: 16, + name: 'b', + }, + optional: false, }, ], body: { diff --git a/src/lang/getNodePathFromSourceRange.test.ts b/src/lang/getNodePathFromSourceRange.test.ts index c240e5998..c37cf3004 100644 --- a/src/lang/getNodePathFromSourceRange.test.ts +++ b/src/lang/getNodePathFromSourceRange.test.ts @@ -1,5 +1,5 @@ import { getNodePathFromSourceRange, getNodeFromPath } from './queryAst' -import { Identifier, parse, initPromise } from './wasm' +import { Identifier, parse, initPromise, Parameter } from './wasm' beforeAll(() => initPromise) @@ -46,7 +46,7 @@ const b1 = cube([0,0], 10)` const ast = parse(code) const nodePath = getNodePathFromSourceRange(ast, sourceRange) - const node = getNodeFromPath(ast, nodePath).node + const node = getNodeFromPath(ast, nodePath).node expect(nodePath).toEqual([ ['body', ''], @@ -57,8 +57,8 @@ const b1 = cube([0,0], 10)` ['params', 'FunctionExpression'], [0, 'index'], ]) - expect(node.type).toBe('Identifier') - expect(node.name).toBe('pos') + expect(node.type).toBe('Parameter') + expect(node.identifier.name).toBe('pos') }) it('gets path right for deep within function definition body', () => { const code = `fn cube = (pos, scale) => { diff --git a/src/lang/wasm.ts b/src/lang/wasm.ts index e95718292..220de6d9c 100644 --- a/src/lang/wasm.ts +++ b/src/lang/wasm.ts @@ -20,6 +20,7 @@ export type { ObjectExpression } from '../wasm-lib/kcl/bindings/ObjectExpression export type { MemberExpression } from '../wasm-lib/kcl/bindings/MemberExpression' export type { PipeExpression } from '../wasm-lib/kcl/bindings/PipeExpression' export type { VariableDeclaration } from '../wasm-lib/kcl/bindings/VariableDeclaration' +export type { Parameter } from '../wasm-lib/kcl/bindings/Parameter' export type { PipeSubstitution } from '../wasm-lib/kcl/bindings/PipeSubstitution' export type { Identifier } from '../wasm-lib/kcl/bindings/Identifier' export type { UnaryExpression } from '../wasm-lib/kcl/bindings/UnaryExpression'