Skip to content

Commit 75eb2bb

Browse files
authored
fix: key block can have its own block scope (#2768)
#2762
1 parent 1301e80 commit 75eb2bb

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ import { BaseNode } from '../../interfaces';
33
import { isImplicitlyClosedBlock, withTrailingPropertyAccess } from '../utils/node-utils';
44

55
/**
6-
* {#key expr}content{/key} ---> expr; content
6+
* {#key expr}content{/key} ---> expr; {content}
77
*/
88
export function handleKey(str: MagicString, keyBlock: BaseNode): void {
9-
// {#key expr} -> expr;
9+
// {#key expr} -> expr;{
1010
str.overwrite(keyBlock.start, keyBlock.expression.start, '', { contentOnly: true });
1111
const expressionEnd = withTrailingPropertyAccess(str.original, keyBlock.expression.end);
1212
const end = str.original.indexOf('}', expressionEnd);
13-
str.overwrite(expressionEnd, end + 1, '; ');
13+
str.overwrite(expressionEnd, end + 1, '; {');
1414

15-
// {/key} ->
15+
// {/key} -> }
1616
const endKey = str.original.lastIndexOf('{', keyBlock.end - 1);
1717
if (!isImplicitlyClosedBlock(endKey, keyBlock)) {
18-
str.overwrite(endKey, keyBlock.end, '', { contentOnly: true });
18+
str.overwrite(endKey, keyBlock.end, '}', { contentOnly: true });
1919
}
2020
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
''.;
1+
''.; {
2+
3+
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
value;
1+
value; {
22
{ svelteHTML.createElement("p", {}); }
3-
4-
$store;
3+
}
4+
$store; {
55
{ svelteHTML.createElement("p", {}); }
6-
7-
expr.obj;
8-
{ svelteHTML.createElement("p", {}); }
6+
}
7+
expr.obj; {
8+
{ svelteHTML.createElement("p", {}); }
9+
}

packages/svelte2tsx/test/htmlx2jsx/samples/nested-snippet.v5/expectedv2.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ if(true){
88

99
}
1010

11-
key;
11+
key; {
1212
const foo/*Ωignore_positionΩ*/ = ()/*Ωignore_startΩ*/: ReturnType<import('svelte').Snippet>/*Ωignore_endΩ*/ => { async ()/*Ωignore_positionΩ*/ => {};return __sveltets_2_any(0)};;__sveltets_2_ensureSnippet(foo());
1313

14-
14+
}
1515

1616
const snippetBlock/*Ωignore_positionΩ*/ = ()/*Ωignore_startΩ*/: ReturnType<import('svelte').Snippet>/*Ωignore_endΩ*/ => { async ()/*Ωignore_positionΩ*/ => {
1717
const foo/*Ωignore_positionΩ*/ = ()/*Ωignore_startΩ*/: ReturnType<import('svelte').Snippet>/*Ωignore_endΩ*/ => { async ()/*Ωignore_positionΩ*/ => {};return __sveltets_2_any(0)}; const foo2/*Ωignore_positionΩ*/ = ()/*Ωignore_startΩ*/: ReturnType<import('svelte').Snippet>/*Ωignore_endΩ*/ => { async ()/*Ωignore_positionΩ*/ => {};return __sveltets_2_any(0)};;__sveltets_2_ensureSnippet(foo());

packages/svelte2tsx/test/htmlx2jsx/samples/ts-in-template.v5/expectedv2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ try { const $$_value = await (foo as Promise<void>);{ const result: any = $$_val
1414

1515
}}
1616

17-
item as string;
17+
item as string; { }
1818

1919
const foo/*Ωignore_positionΩ*/ = (bar: string)/*Ωignore_startΩ*/: ReturnType<import('svelte').Snippet>/*Ωignore_endΩ*/ => { async ()/*Ωignore_positionΩ*/ => { };return __sveltets_2_any(0)};
2020

0 commit comments

Comments
 (0)