|
|
|
|
@ -2351,12 +2351,17 @@ export function server_component(analysis, options) {
|
|
|
|
|
if (options.dev) push_args.push(b.id(analysis.name));
|
|
|
|
|
|
|
|
|
|
const component_block = b.block([
|
|
|
|
|
b.stmt(b.call('$.push', ...push_args)),
|
|
|
|
|
.../** @type {import('estree').Statement[]} */ (instance.body),
|
|
|
|
|
.../** @type {import('estree').Statement[]} */ (template.body),
|
|
|
|
|
b.stmt(b.call('$.pop'))
|
|
|
|
|
.../** @type {import('estree').Statement[]} */ (template.body)
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
let should_inject_context = analysis.needs_context || options.dev;
|
|
|
|
|
|
|
|
|
|
if (should_inject_context) {
|
|
|
|
|
component_block.body.unshift(b.stmt(b.call('$.push', ...push_args)));
|
|
|
|
|
component_block.body.push(b.stmt(b.call('$.pop')));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (analysis.uses_rest_props) {
|
|
|
|
|
/** @type {string[]} */
|
|
|
|
|
const named_props = analysis.exports.map(({ name, alias }) => alias ?? name);
|
|
|
|
|
@ -2388,9 +2393,18 @@ export function server_component(analysis, options) {
|
|
|
|
|
|
|
|
|
|
const body = [...state.hoisted, ...module.body];
|
|
|
|
|
|
|
|
|
|
let should_inject_props =
|
|
|
|
|
should_inject_context ||
|
|
|
|
|
props.length > 0 ||
|
|
|
|
|
analysis.needs_props ||
|
|
|
|
|
analysis.uses_props ||
|
|
|
|
|
analysis.uses_rest_props ||
|
|
|
|
|
analysis.uses_slots ||
|
|
|
|
|
analysis.slot_names.size > 0;
|
|
|
|
|
|
|
|
|
|
const component_function = b.function_declaration(
|
|
|
|
|
b.id(analysis.name),
|
|
|
|
|
[b.id('$$payload'), b.id('$$props')],
|
|
|
|
|
should_inject_props ? [b.id('$$payload'), b.id('$$props')] : [b.id('$$payload')],
|
|
|
|
|
component_block
|
|
|
|
|
);
|
|
|
|
|
if (options.legacy.componentApi) {
|
|
|
|
|
|