Parse units on numeric literals and keep them in the AST (#5061)
* Code changes Signed-off-by: Nick Cameron <nrc@ncameron.org> * test changes Signed-off-by: Nick Cameron <nrc@ncameron.org> * Frontend changes Signed-off-by: Nick Cameron <nrc@ncameron.org> * Refactor asNum Co-authored-by: Jonathan Tran <jonnytran@gmail.com> --------- Signed-off-by: Nick Cameron <nrc@ncameron.org> Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
This commit is contained in:
@ -39,7 +39,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', () => {
|
||||
@ -56,7 +56,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', () => {
|
||||
@ -68,7 +68,7 @@ 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', () => {
|
||||
@ -76,7 +76,7 @@ describe('Testing createArrayExpression', () => {
|
||||
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', () => {
|
||||
@ -93,7 +93,7 @@ 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', () => {
|
||||
@ -101,7 +101,7 @@ describe('Testing createPipeExpression', () => {
|
||||
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)
|
||||
})
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user