Skip to content

Commit

Permalink
Frontend changes
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Cameron <[email protected]>
  • Loading branch information
nrc committed Jan 15, 2025
1 parent 522cbba commit 98f608d
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 73 deletions.
10 changes: 8 additions & 2 deletions src/lang/abstractSyntaxTree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,21 @@ describe('testing AST', () => {
type: 'Literal',
start: 0,
end: 1,
value: 5,
value: {
suffix: 'None',
value: 5,
},
raw: '5',
},
operator: '+',
right: {
type: 'Literal',
start: 3,
end: 4,
value: 6,
value: {
suffix: 'None',
value: 6,
},
raw: '6',
},
},
Expand Down
12 changes: 6 additions & 6 deletions src/lang/modifyAst.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Testing createLiteral', () => {
it('should create a literal', () => {
const result = createLiteral(5)
expect(result.type).toBe('Literal')
expect(result.value).toBe(5)
expect((result as any).value.value).toBe(5)
})
})
describe('Testing createIdentifier', () => {
Expand All @@ -49,7 +49,7 @@ describe('Testing createCallExpression', () => {
expect(result.callee.type).toBe('Identifier')
expect(result.callee.name).toBe('myFunc')
expect(result.arguments[0].type).toBe('Literal')
expect((result.arguments[0] as any).value).toBe(5)
expect((result.arguments[0] as any).value.value).toBe(5)
})
})
describe('Testing createObjectExpression', () => {
Expand All @@ -61,15 +61,15 @@ describe('Testing createObjectExpression', () => {
expect(result.properties[0].type).toBe('ObjectProperty')
expect(result.properties[0].key.name).toBe('myProp')
expect(result.properties[0].value.type).toBe('Literal')
expect((result.properties[0].value as any).value).toBe(5)
expect((result.properties[0].value as any).value.value).toBe(5)
})
})
describe('Testing createArrayExpression', () => {
it('should create an array expression', () => {
const result = createArrayExpression([createLiteral(5)])
expect(result.type).toBe('ArrayExpression')
expect(result.elements[0].type).toBe('Literal')
expect((result.elements[0] as any).value).toBe(5)
expect((result.elements[0] as any).value.value).toBe(5)
})
})
describe('Testing createPipeSubstitution', () => {
Expand All @@ -86,15 +86,15 @@ describe('Testing createVariableDeclaration', () => {
expect(result.declaration.id.type).toBe('Identifier')
expect(result.declaration.id.name).toBe('myVar')
expect(result.declaration.init.type).toBe('Literal')
expect((result.declaration.init as any).value).toBe(5)
expect((result.declaration.init as any).value.value).toBe(5)
})
})
describe('Testing createPipeExpression', () => {
it('should create a pipe expression', () => {
const result = createPipeExpression([createLiteral(5)])
expect(result.type).toBe('PipeExpression')
expect(result.body[0].type).toBe('Literal')
expect((result.body[0] as any).value).toBe(5)
expect((result.body[0] as any).value.value).toBe(5)
})
})

Expand Down
8 changes: 6 additions & 2 deletions src/lang/modifyAst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -743,14 +743,18 @@ export function splitPathAtPipeExpression(pathToNode: PathToNode): {
return splitPathAtPipeExpression(pathToNode.slice(0, -1))
}

export function createLiteral(value: LiteralValue): Node<Literal> {
export function createLiteral(value: LiteralValue | number): Node<Literal> {
const raw = `${value}`
if (typeof value === 'number') {
value = { value, suffix: 'None' }
}
return {
type: 'Literal',
start: 0,
end: 0,
moduleId: 0,
value,
raw: `${value}`,
raw,
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lang/queryAst.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ myNestedVar = [
enter: (node, path) => {
if (
node.type === 'Literal' &&
String(node.value) === literalOfInterest
String((node as any).value.value) === literalOfInterest
) {
pathToNode = path
} else if (
Expand Down
Loading

0 comments on commit 98f608d

Please sign in to comment.