From 261d937059bc69254b70b1834202a1392bc44002 Mon Sep 17 00:00:00 2001 From: wrapperup Date: Sun, 12 Jan 2025 17:09:06 -0500 Subject: [PATCH 1/2] fix property destruct --- src/transformer.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/transformer.ts b/src/transformer.ts index a166bb7..0b6a5a4 100644 --- a/src/transformer.ts +++ b/src/transformer.ts @@ -228,11 +228,13 @@ export function transformTemplateCode( break; case "Property": - if (node.shorthand && node.key.type === "Identifier") { + // Value is implicitly the same as the key if it's just an + // identifier, so we only transform the value (not the key) + if (node.shorthand && node.value.type === "Identifier") { this.replace({ type: "Property", key: node.key, - value: transformIdentifier(node.key), + value: transformIdentifier(node.value), kind: "init", computed: false, method: false, From b4788278887a2675d0dab795017192266c2b53ec Mon Sep 17 00:00:00 2001 From: wrapperup Date: Sun, 12 Jan 2025 17:09:21 -0500 Subject: [PATCH 2/2] add js test for property destruct --- test/js.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/js.test.ts b/test/js.test.ts index 028aab3..956b340 100644 --- a/test/js.test.ts +++ b/test/js.test.ts @@ -79,4 +79,12 @@ Deno.test("> tag", async () => { `, expected: "Hello s", }); + + await test({ + template: ` + {{> const { a = 2 } = {}; }} + {{ JSON.stringify(a) }} + `, + expected: "2", + }); });