Fix up tests

This commit is contained in:
Adam Chalmers
2023-11-17 17:12:22 -06:00
parent 4eeb41ba06
commit 5a0043c959
3 changed files with 37 additions and 20 deletions

View File

@ -169,16 +169,24 @@ describe('testing function declaration', () => {
end: 39, end: 39,
params: [ params: [
{ {
type: 'Identifier', type: 'Parameter',
start: 12, identifier: {
end: 13, type: 'Identifier',
name: 'a', start: 12,
end: 13,
name: 'a',
},
optional: false,
}, },
{ {
type: 'Identifier', type: 'Parameter',
start: 15, identifier: {
end: 16, type: 'Identifier',
name: 'b', start: 15,
end: 16,
name: 'b',
},
optional: false,
}, },
], ],
body: { body: {
@ -244,16 +252,24 @@ const myVar = funcN(1, 2)`
end: 37, end: 37,
params: [ params: [
{ {
type: 'Identifier', type: 'Parameter',
start: 12, identifier: {
end: 13, type: 'Identifier',
name: 'a', start: 12,
end: 13,
name: 'a',
},
optional: false,
}, },
{ {
type: 'Identifier', type: 'Parameter',
start: 15, identifier: {
end: 16, type: 'Identifier',
name: 'b', start: 15,
end: 16,
name: 'b',
},
optional: false,
}, },
], ],
body: { body: {

View File

@ -1,5 +1,5 @@
import { getNodePathFromSourceRange, getNodeFromPath } from './queryAst' import { getNodePathFromSourceRange, getNodeFromPath } from './queryAst'
import { Identifier, parse, initPromise } from './wasm' import { Identifier, parse, initPromise, Parameter } from './wasm'
beforeAll(() => initPromise) beforeAll(() => initPromise)
@ -46,7 +46,7 @@ const b1 = cube([0,0], 10)`
const ast = parse(code) const ast = parse(code)
const nodePath = getNodePathFromSourceRange(ast, sourceRange) const nodePath = getNodePathFromSourceRange(ast, sourceRange)
const node = getNodeFromPath<Identifier>(ast, nodePath).node const node = getNodeFromPath<Parameter>(ast, nodePath).node
expect(nodePath).toEqual([ expect(nodePath).toEqual([
['body', ''], ['body', ''],
@ -57,8 +57,8 @@ const b1 = cube([0,0], 10)`
['params', 'FunctionExpression'], ['params', 'FunctionExpression'],
[0, 'index'], [0, 'index'],
]) ])
expect(node.type).toBe('Identifier') expect(node.type).toBe('Parameter')
expect(node.name).toBe('pos') expect(node.identifier.name).toBe('pos')
}) })
it('gets path right for deep within function definition body', () => { it('gets path right for deep within function definition body', () => {
const code = `fn cube = (pos, scale) => { const code = `fn cube = (pos, scale) => {

View File

@ -20,6 +20,7 @@ export type { ObjectExpression } from '../wasm-lib/kcl/bindings/ObjectExpression
export type { MemberExpression } from '../wasm-lib/kcl/bindings/MemberExpression' export type { MemberExpression } from '../wasm-lib/kcl/bindings/MemberExpression'
export type { PipeExpression } from '../wasm-lib/kcl/bindings/PipeExpression' export type { PipeExpression } from '../wasm-lib/kcl/bindings/PipeExpression'
export type { VariableDeclaration } from '../wasm-lib/kcl/bindings/VariableDeclaration' 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 { PipeSubstitution } from '../wasm-lib/kcl/bindings/PipeSubstitution'
export type { Identifier } from '../wasm-lib/kcl/bindings/Identifier' export type { Identifier } from '../wasm-lib/kcl/bindings/Identifier'
export type { UnaryExpression } from '../wasm-lib/kcl/bindings/UnaryExpression' export type { UnaryExpression } from '../wasm-lib/kcl/bindings/UnaryExpression'