Skip to content

Commit 23db5a4

Browse files
authored
fix: handle object literal in MustacheTag (#2805)
1 parent b73d807 commit 23db5a4

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

packages/svelte2tsx/src/htmlxtojsx_v2/nodes/MustacheTag.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ export function handleMustacheTag(str: MagicString, node: BaseNode, parent: Base
1010
// handled inside Attribute.ts / StyleDirective.ts
1111
return;
1212
}
13+
const text = str.original.slice(node.start + 1, node.end - 1);
14+
if (text.trimStart().startsWith('{')) {
15+
// possibly an object literal, wrapping it in parentheses so it's treated as an expression
16+
str.overwrite(node.start, node.start + 1, ';(', { contentOnly: true });
17+
str.overwrite(node.end - 1, node.end, ');', { contentOnly: true });
18+
return;
19+
}
1320
str.overwrite(node.start, node.start + 1, '', { contentOnly: true });
1421
str.overwrite(node.end - 1, node.end, ';', { contentOnly: true });
1522
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
;({
2+
toString() { return "Hello World" }
3+
});
4+
5+
;({ a: '' }['a']);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{{
2+
toString() { return "Hello World" }
3+
}}
4+
5+
{{ a: '' }['a']}

0 commit comments

Comments
 (0)