Skip to content

Commit bf436c6

Browse files
committed
Merge branch 'hmr' of github.com:sveltejs/svelte into hmr
2 parents b5d44af + ce20ddb commit bf436c6

File tree

23 files changed

+377
-390
lines changed

23 files changed

+377
-390
lines changed

.changeset/early-months-whisper.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
fix: loosen proxy signal creation heuristics

.changeset/gold-tools-nail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
fix: ensure top level snippets are defined when binding to component prop

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

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,44 +2315,29 @@ export const template_visitors = {
23152315
)
23162316
: /** @type {import('estree').Expression} */ (context.visit(node.key))
23172317
)
2318-
: b.literal(null);
2318+
: b.id('$.index');
23192319

23202320
if (node.index && each_node_meta.contains_group_binding) {
23212321
// We needed to create a unique identifier for the index above, but we want to use the
23222322
// original index name in the template, therefore create another binding
23232323
declarations.push(b.let(node.index, index));
23242324
}
23252325

2326-
let callee = '$.each_indexed';
2327-
2328-
/** @type {import('estree').Expression[]} */
2329-
const args = [];
2330-
2331-
if ((each_type & EACH_KEYED) !== 0) {
2332-
if (context.state.options.dev && key_function.type !== 'Literal') {
2333-
context.state.init.push(
2334-
b.stmt(b.call('$.validate_each_keys', b.thunk(collection), key_function))
2335-
);
2336-
}
2337-
2338-
callee = '$.each_keyed';
2339-
2340-
args.push(
2341-
context.state.node,
2342-
b.literal(each_type),
2343-
each_node_meta.array_name ? each_node_meta.array_name : b.thunk(collection),
2344-
key_function,
2345-
b.arrow([b.id('$$anchor'), item, index], b.block(declarations.concat(children)))
2346-
);
2347-
} else {
2348-
args.push(
2349-
context.state.node,
2350-
b.literal(each_type),
2351-
each_node_meta.array_name ? each_node_meta.array_name : b.thunk(collection),
2352-
b.arrow([b.id('$$anchor'), item, index], b.block(declarations.concat(children)))
2326+
if (context.state.options.dev && (each_type & EACH_KEYED) !== 0) {
2327+
context.state.init.push(
2328+
b.stmt(b.call('$.validate_each_keys', b.thunk(collection), key_function))
23532329
);
23542330
}
23552331

2332+
/** @type {import('estree').Expression[]} */
2333+
const args = [
2334+
context.state.node,
2335+
b.literal(each_type),
2336+
each_node_meta.array_name ? each_node_meta.array_name : b.thunk(collection),
2337+
key_function,
2338+
b.arrow([b.id('$$anchor'), item, index], b.block(declarations.concat(children)))
2339+
];
2340+
23562341
if (node.fallback) {
23572342
args.push(
23582343
b.arrow(
@@ -2362,7 +2347,7 @@ export const template_visitors = {
23622347
);
23632348
}
23642349

2365-
context.state.init.push(b.stmt(b.call(callee, ...args)));
2350+
context.state.init.push(b.stmt(b.call('$.each', ...args)));
23662351
},
23672352
IfBlock(node, context) {
23682353
context.state.template.push('<!>');

packages/svelte/src/compiler/phases/3-transform/server/transform-server.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,14 +1614,15 @@ const template_visitors = {
16141614
state.template.push(block_close);
16151615
},
16161616
SnippetBlock(node, context) {
1617-
// TODO hoist where possible
1618-
context.state.init.push(
1619-
b.function_declaration(
1620-
node.expression,
1621-
[b.id('$$payload'), ...node.parameters],
1622-
/** @type {import('estree').BlockStatement} */ (context.visit(node.body))
1623-
)
1617+
const fn = b.function_declaration(
1618+
node.expression,
1619+
[b.id('$$payload'), ...node.parameters],
1620+
/** @type {import('estree').BlockStatement} */ (context.visit(node.body))
16241621
);
1622+
// @ts-expect-error - TODO remove this hack once $$render_inner for legacy bindings is gone
1623+
fn.___snippet = true;
1624+
// TODO hoist where possible
1625+
context.state.init.push(fn);
16251626

16261627
if (context.state.options.dev) {
16271628
context.state.init.push(b.stmt(b.call('$.add_snippet_symbol', node.expression)));
@@ -2221,14 +2222,27 @@ export function server_component(analysis, options) {
22212222
// If the component binds to a child, we need to put the template in a loop and repeat until legacy bindings are stable.
22222223
// We can remove this once the legacy syntax is gone.
22232224
if (analysis.uses_component_bindings) {
2225+
const snippets = template.body.filter(
2226+
(node) =>
2227+
node.type === 'FunctionDeclaration' &&
2228+
// @ts-expect-error
2229+
node.___snippet
2230+
);
2231+
const rest = template.body.filter(
2232+
(node) =>
2233+
node.type !== 'FunctionDeclaration' ||
2234+
// @ts-expect-error
2235+
!node.___snippet
2236+
);
22242237
template.body = [
2238+
...snippets,
22252239
b.let('$$settled', b.true),
22262240
b.let('$$inner_payload'),
22272241
b.stmt(
22282242
b.function(
22292243
b.id('$$render_inner'),
22302244
[b.id('$$payload')],
2231-
b.block(/** @type {import('estree').Statement[]} */ (template.body))
2245+
b.block(/** @type {import('estree').Statement[]} */ (rest))
22322246
)
22332247
),
22342248
b.do_while(

0 commit comments

Comments
 (0)