From 07a42d9767a2ed4fd84524ab6a499d2a30d6e385 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath <2+defunkt@users.noreply.github.com> Date: Wed, 3 Dec 2025 15:52:20 -0800 Subject: [PATCH] ignore trailing whitespace in dict key name --- src/compiler/compiler.ts | 2 +- src/compiler/tests/literals.test.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/compiler/compiler.ts b/src/compiler/compiler.ts index 73db0f5..11105cd 100644 --- a/src/compiler/compiler.ts +++ b/src/compiler/compiler.ts @@ -807,7 +807,7 @@ export class Compiler { const valueNode = node.firstChild!.nextSibling // 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(...this.#compileNode(valueNode!, input)) diff --git a/src/compiler/tests/literals.test.ts b/src/compiler/tests/literals.test.ts index 1783830..c398fae 100644 --- a/src/compiler/tests/literals.test.ts +++ b/src/compiler/tests/literals.test.ts @@ -151,18 +151,22 @@ describe('array literals', () => { describe('dict literals', () => { 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 }) }) 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' }) }) 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' }) }) 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' }] }) }) test('can span multiple lines', () => { @@ -171,6 +175,12 @@ describe('dict literals', () => { 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', () => { @@ -190,10 +200,12 @@ describe('dict literals', () => { 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 }) }) 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 }) }) test('empty lines within dicts', () => {