ignore trailing whitespace in dict key name
This commit is contained in:
parent
ef20c67e61
commit
07a42d9767
|
|
@ -807,7 +807,7 @@ export class Compiler {
|
||||||
const valueNode = node.firstChild!.nextSibling
|
const valueNode = node.firstChild!.nextSibling
|
||||||
|
|
||||||
// name= -> name
|
// name= -> name
|
||||||
const key = input.slice(keyNode!.from, keyNode!.to).slice(0, -1)
|
const key = input.slice(keyNode!.from, keyNode!.to).replace(/\s*=$/, '')
|
||||||
instructions.push(['PUSH', key])
|
instructions.push(['PUSH', key])
|
||||||
|
|
||||||
instructions.push(...this.#compileNode(valueNode!, input))
|
instructions.push(...this.#compileNode(valueNode!, input))
|
||||||
|
|
|
||||||
|
|
@ -151,18 +151,22 @@ describe('array literals', () => {
|
||||||
describe('dict literals', () => {
|
describe('dict literals', () => {
|
||||||
test('work with numbers', () => {
|
test('work with numbers', () => {
|
||||||
expect('[a=1 b=2 c=3]').toEvaluateTo({ a: 1, b: 2, c: 3 })
|
expect('[a=1 b=2 c=3]').toEvaluateTo({ a: 1, b: 2, c: 3 })
|
||||||
|
expect('[a = 1 b = 2 c = 3]').toEvaluateTo({ a: 1, b: 2, c: 3 })
|
||||||
})
|
})
|
||||||
|
|
||||||
test('work with strings', () => {
|
test('work with strings', () => {
|
||||||
expect("[a='one' b='two' c='three']").toEvaluateTo({ a: 'one', b: 'two', c: 'three' })
|
expect("[a='one' b='two' c='three']").toEvaluateTo({ a: 'one', b: 'two', c: 'three' })
|
||||||
|
expect("[a = 'one' b = 'two' c = 'three']").toEvaluateTo({ a: 'one', b: 'two', c: 'three' })
|
||||||
})
|
})
|
||||||
|
|
||||||
test('work with identifiers', () => {
|
test('work with identifiers', () => {
|
||||||
expect('[a=one b=two c=three]').toEvaluateTo({ a: 'one', b: 'two', c: 'three' })
|
expect('[a=one b=two c=three]').toEvaluateTo({ a: 'one', b: 'two', c: 'three' })
|
||||||
|
expect('[a = one b = two c = three]').toEvaluateTo({ a: 'one', b: 'two', c: 'three' })
|
||||||
})
|
})
|
||||||
|
|
||||||
test('can be nested', () => {
|
test('can be nested', () => {
|
||||||
expect('[a=one b=[two [c=three]]]').toEvaluateTo({ a: 'one', b: ['two', { c: 'three' }] })
|
expect('[a=one b=[two [c=three]]]').toEvaluateTo({ a: 'one', b: ['two', { c: 'three' }] })
|
||||||
|
expect('[a = one b = [two [c = three]]]').toEvaluateTo({ a: 'one', b: ['two', { c: 'three' }] })
|
||||||
})
|
})
|
||||||
|
|
||||||
test('can span multiple lines', () => {
|
test('can span multiple lines', () => {
|
||||||
|
|
@ -171,6 +175,12 @@ describe('dict literals', () => {
|
||||||
b=2
|
b=2
|
||||||
c=3
|
c=3
|
||||||
]`).toEvaluateTo({ a: 1, b: 2, c: 3 })
|
]`).toEvaluateTo({ a: 1, b: 2, c: 3 })
|
||||||
|
|
||||||
|
expect(`[
|
||||||
|
a = 1
|
||||||
|
b = 2
|
||||||
|
c = 3
|
||||||
|
]`).toEvaluateTo({ a: 1, b: 2, c: 3 })
|
||||||
})
|
})
|
||||||
|
|
||||||
test('empty dict', () => {
|
test('empty dict', () => {
|
||||||
|
|
@ -190,10 +200,12 @@ describe('dict literals', () => {
|
||||||
|
|
||||||
test('semicolons as separators', () => {
|
test('semicolons as separators', () => {
|
||||||
expect('[a=1; b=2; c=3]').toEvaluateTo({ a: 1, b: 2, c: 3 })
|
expect('[a=1; b=2; c=3]').toEvaluateTo({ a: 1, b: 2, c: 3 })
|
||||||
|
expect('[a = 1; b = 2; c = 3]').toEvaluateTo({ a: 1, b: 2, c: 3 })
|
||||||
})
|
})
|
||||||
|
|
||||||
test('expressions in dicts', () => {
|
test('expressions in dicts', () => {
|
||||||
expect('[a=(1 + 2) b=(3 * 4)]').toEvaluateTo({ a: 3, b: 12 })
|
expect('[a=(1 + 2) b=(3 * 4)]').toEvaluateTo({ a: 3, b: 12 })
|
||||||
|
expect('[a = (1 + 2) b = (3 * 4)]').toEvaluateTo({ a: 3, b: 12 })
|
||||||
})
|
})
|
||||||
|
|
||||||
test('empty lines within dicts', () => {
|
test('empty lines within dicts', () => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user