Skip to content

Commit

Permalink
same but for $$props
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed May 24, 2024
1 parent 8160831 commit ac5a803
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2355,7 +2355,9 @@ export function server_component(analysis, options) {
.../** @type {import('estree').Statement[]} */ (template.body)
]);

if (analysis.needs_context || options.dev) {
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')));
}
Expand Down Expand Up @@ -2391,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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as $ from "svelte/internal/server";
import TextInput from './Child.svelte';

export default function Bind_component_snippet($$payload, $$props) {
export default function Bind_component_snippet($$payload) {
let value = '';
const _snippet = snippet;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as $ from "svelte/internal/server";

export default function Bind_this($$payload, $$props) {
export default function Bind_this($$payload) {
$$payload.out += `<!--[-->`;
Foo($$payload, {});
$$payload.out += `<!--]-->`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as $ from "svelte/internal/server";

export default function Main($$payload, $$props) {
export default function Main($$payload) {
// needs to be a snapshot test because jsdom does auto-correct the attribute casing
let x = 'test';
let y = () => 'test';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as $ from "svelte/internal/server";

export default function Each_string_template($$payload, $$props) {
export default function Each_string_template($$payload) {
const each_array = $.ensure_array_like(['foo', 'bar', 'baz']);

$$payload.out += `<!--[-->`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as $ from "svelte/internal/server";

export default function Function_prop_no_getter($$payload, $$props) {
export default function Function_prop_no_getter($$payload) {
let count = 0;

function onmouseup() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as $ from "svelte/internal/server";

export default function Hello_world($$payload, $$props) {
export default function Hello_world($$payload) {
$$payload.out += `<h1>hello world</h1>`;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as $ from "svelte/internal/server";

export default function Hmr($$payload, $$props) {
export default function Hmr($$payload) {
$$payload.out += `<h1>hello world</h1>`;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as $ from "svelte/internal/server";

export default function State_proxy_literal($$payload, $$props) {
export default function State_proxy_literal($$payload) {
let str = '';
let tpl = ``;

Expand Down

0 comments on commit ac5a803

Please sign in to comment.