Skip to content

Commit

Permalink
Merge pull request #93 from wrapperup/fix-property-pattern-matching
Browse files Browse the repository at this point in the history
Fix property destruct codegen
  • Loading branch information
oscarotero authored Jan 13, 2025
2 parents 93ac07c + b478827 commit 7afcfb9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions test/js.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,12 @@ Deno.test("> tag", async () => {
`,
expected: "Hello s",
});

await test({
template: `
{{> const { a = 2 } = {}; }}
{{ JSON.stringify(a) }}
`,
expected: "2",
});
});

0 comments on commit 7afcfb9

Please sign in to comment.