Skip to content

Commit a33b766

Browse files
committed
merge
2 parents 41f0a12 + efd9dbb commit a33b766

File tree

4 files changed

+53
-9
lines changed

4 files changed

+53
-9
lines changed

packages/svelte/src/compiler/phases/3-transform/client/visitors/IfBlock.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,17 @@ export function IfBlock(node, context) {
1616

1717
// compile to if rather than $.if for non-reactive if statements
1818
// NOTE: doesn't handle else/elseif yet or mismatches. also, this probably breaks transition locality
19-
if (!node.metadata.expression.has_state && !(node.alternate || node.elseif)) {
19+
if (!node.metadata.expression.has_state && !node.elseif) {
2020
state.init.push(
21-
b.stmt(b.call('$.next')),
22-
b.if(node.test, b.block([b.let(b.id('$$anchor'), state.node), ...consequent.body]))
21+
b.block([
22+
b.let(b.id('$$anchor'), state.node),
23+
b.stmt(b.call('$.next')),
24+
b.if(
25+
node.test,
26+
consequent,
27+
node.alternate ? /** @type {BlockStatement} */ (context.visit(node.alternate)) : undefined
28+
)
29+
])
2330
);
2431

2532
return;
Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
import "svelte/internal/disclose-version";
22
import * as $ from "svelte/internal/client";
33

4-
var root = $.template(`<!> <!>`, 1);
4+
var root = $.template(`<!> <!> <!>`, 1);
55

66
export default function Non_reactive_control_structures($$anchor) {
77
const a = true;
88
let b = true;
99
var fragment = root();
1010
var node = $.first_child(fragment);
1111

12-
$.next();
13-
14-
if (a) {
12+
{
1513
let $$anchor = node;
16-
var text = $.text("hello");
1714

18-
$.append($$anchor, text);
15+
$.next();
16+
17+
if (a) {
18+
var text = $.text("hello");
19+
20+
$.append($$anchor, text);
21+
}
1922
}
2023

2124
var node_1 = $.sibling(node, 2);
@@ -26,5 +29,23 @@ export default function Non_reactive_control_structures($$anchor) {
2629
$.append($$anchor, text_1);
2730
});
2831

32+
var node_2 = $.sibling(node_1, 2);
33+
34+
{
35+
let $$anchor = node_2;
36+
37+
$.next();
38+
39+
if (a) {
40+
var text_2 = $.text("hi");
41+
42+
$.append($$anchor, text_2);
43+
} else {
44+
var text_3 = $.text("earth");
45+
46+
$.append($$anchor, text_3);
47+
}
48+
}
49+
2950
$.append($$anchor, fragment);
3051
}

packages/svelte/tests/snapshot/samples/non-reactive-control-structures/_expected/server/index.svelte.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,15 @@ export default function Non_reactive_control_structures($$payload) {
2020
$$payload.out += "<!--[!-->";
2121
}
2222

23+
$$payload.out += `<!--]--> `;
24+
25+
if (a) {
26+
$$payload.out += "<!--[-->";
27+
$$payload.out += `hi`;
28+
} else {
29+
$$payload.out += "<!--[!-->";
30+
$$payload.out += `earth`;
31+
}
32+
2333
$$payload.out += `<!--]-->`;
2434
}

packages/svelte/tests/snapshot/samples/non-reactive-control-structures/index.svelte

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@
1212
{#if b}
1313
world
1414
{/if}
15+
16+
{#if a}
17+
hi
18+
{:else}
19+
earth
20+
{/if}

0 commit comments

Comments
 (0)