Skip to content

Commit fc33a39

Browse files
committed
fix
1 parent 3f56275 commit fc33a39

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,24 @@ export function client_component(analysis, options) {
360360

361361
let component_block = b.block([...legacy_reactive_declarations, ...group_binding_declarations]);
362362

363+
const should_inject_context =
364+
dev ||
365+
analysis.needs_context ||
366+
analysis.reactive_statements.size > 0 ||
367+
component_returned_object.length > 0;
368+
363369
if (analysis.instance.has_await) {
370+
if (should_inject_context && component_returned_object.length > 0) {
371+
component_block.body.push(b.var('$$exports'));
372+
}
364373
const body = b.block([
365374
store_init,
366375
...store_setup,
367376
...state.instance_level_snippets,
368377
.../** @type {ESTree.Statement[]} */ (instance.body),
378+
...(should_inject_context && component_returned_object.length > 0
379+
? [b.stmt(b.assignment('=', b.id('$$exports'), b.object(component_returned_object)))]
380+
: []),
369381
b.if(b.call('$.aborted'), b.return()),
370382
.../** @type {ESTree.Statement[]} */ (template.body)
371383
]);
@@ -380,6 +392,9 @@ export function client_component(analysis, options) {
380392
...state.instance_level_snippets,
381393
.../** @type {ESTree.Statement[]} */ (instance.body)
382394
);
395+
if (should_inject_context && component_returned_object.length > 0) {
396+
component_block.body.push(b.var('$$exports', b.object(component_returned_object)));
397+
}
383398
component_block.body.unshift(store_init, ...store_setup);
384399

385400
if (!analysis.runes && analysis.needs_context) {
@@ -395,12 +410,6 @@ export function client_component(analysis, options) {
395410
);
396411
}
397412

398-
const should_inject_context =
399-
dev ||
400-
analysis.needs_context ||
401-
analysis.reactive_statements.size > 0 ||
402-
component_returned_object.length > 0;
403-
404413
let should_inject_props =
405414
should_inject_context ||
406415
analysis.needs_props ||
@@ -447,7 +456,7 @@ export function client_component(analysis, options) {
447456
let to_push;
448457

449458
if (component_returned_object.length > 0) {
450-
let pop_call = b.call('$.pop', b.object(component_returned_object));
459+
let pop_call = b.call('$.pop', b.id('$$exports'));
451460
to_push = needs_store_cleanup ? b.var('$$pop', pop_call) : b.return(pop_call);
452461
} else {
453462
to_push = b.stmt(b.call('$.pop'));

0 commit comments

Comments
 (0)