pull/16197/head
Rich Harris 6 months ago
parent 0f5b3cd89b
commit 32f753daed

@ -369,10 +369,24 @@ export function client_component(analysis, options) {
: b.stmt(b.call('$.init', analysis.immutable ? b.true : undefined))
]);
const should_inject_context =
dev ||
analysis.needs_context ||
analysis.reactive_statements.size > 0 ||
component_returned_object.length > 0;
let should_inject_props =
should_inject_context ||
analysis.needs_props ||
analysis.uses_props ||
analysis.uses_rest_props ||
analysis.uses_slots ||
analysis.slot_names.size > 0;
if (analysis.instance.has_await) {
const body = b.function_declaration(
b.id('$$body'),
[b.id('$$anchor'), b.id('$$props')],
should_inject_props ? [b.id('$$anchor'), b.id('$$props')] : [b.id('$$anchor')],
b.block([
b.var('$$unsuspend', b.call('$.suspend')),
...component_block.body,
@ -388,7 +402,7 @@ export function client_component(analysis, options) {
component_block = b.block([
b.var('fragment', b.call('$.comment')),
b.var('node', b.call('$.first_child', b.id('fragment'))),
b.stmt(b.call(body.id, b.id('node'), b.id('$$props'))),
b.stmt(b.call(body.id, b.id('node'), should_inject_props && b.id('$$props'))),
b.stmt(b.call('$.append', b.id('$$anchor'), b.id('fragment')))
]);
} else {
@ -428,12 +442,6 @@ export function client_component(analysis, options) {
);
}
const should_inject_context =
dev ||
analysis.needs_context ||
analysis.reactive_statements.size > 0 ||
component_returned_object.length > 0;
// we want the cleanup function for the stores to run as the very last thing
// so that it can effectively clean up the store subscription even after the user effects runs
if (should_inject_context) {
@ -499,14 +507,6 @@ export function client_component(analysis, options) {
component_block.body.unshift(b.const('$$slots', b.call('$.sanitize_slots', b.id('$$props'))));
}
let should_inject_props =
should_inject_context ||
analysis.needs_props ||
analysis.uses_props ||
analysis.uses_rest_props ||
analysis.uses_slots ||
analysis.slot_names.size > 0;
// Merge hoisted statements into module body.
// Ensure imports are on top, with the order preserved, then module body, then hoisted statements
/** @type {ESTree.ImportDeclaration[]} */

Loading…
Cancel
Save