only inject $$props when necessary

pull/11319/head
Rich Harris 2 years ago
parent e4ca8eb8ff
commit 9aa5449844

@ -392,12 +392,13 @@ export function client_component(source, analysis, options) {
append_styles();
if (
const should_inject_context =
analysis.needs_context ||
analysis.reactive_statements.size > 0 ||
component_returned_object.length > 0 ||
options.dev
) {
options.dev;
if (should_inject_context) {
component_block.body.unshift(b.stmt(b.call('$.push', ...push_args)));
component_block.body.push(
@ -439,12 +440,32 @@ export function client_component(source, analysis, options) {
component_block.body.unshift(b.const('$$slots', b.call('$.sanitize_slots', b.id('$$props'))));
}
let should_inject_props =
should_inject_context ||
analysis.uses_props ||
analysis.uses_rest_props ||
analysis.uses_slots ||
analysis.slot_names.size > 0;
if (!should_inject_props) {
for (const declaration of analysis.instance.scope.declarations.values()) {
if (
declaration.kind === 'prop' ||
declaration.kind === 'bindable_prop' ||
declaration.kind === 'rest_prop'
) {
should_inject_props = true;
break;
}
}
}
const body = [
...state.hoisted,
...module.body,
b.function_declaration(
b.id(analysis.name),
[b.id('$$anchor'), b.id('$$props')],
should_inject_props ? [b.id('$$anchor'), b.id('$$props')] : [b.id('$$anchor')],
component_block
)
];

@ -7,7 +7,7 @@ import TextInput from './Child.svelte';
var root_1 = $.template(`Something`, 1);
var root = $.template(`<!> `, 1);
function Bind_component_snippet($$anchor, $$props) {
function Bind_component_snippet($$anchor) {
let value = $.source('');
const _snippet = snippet;
var fragment_1 = root();

@ -5,7 +5,7 @@ import * as $ from "svelte/internal/client";
var root = $.template(`<div></div> <svg></svg> <custom-element></custom-element> <div></div> <svg></svg> <custom-element></custom-element>`, 3);
function Main($$anchor, $$props) {
function Main($$anchor) {
// needs to be a snapshot test because jsdom does auto-correct the attribute casing
let x = 'test';
let y = () => 'test';

@ -3,7 +3,7 @@
import "svelte/internal/disclose-version";
import * as $ from "svelte/internal/client";
function Function_prop_no_getter($$anchor, $$props) {
function Function_prop_no_getter($$anchor) {
let count = $.source(0);
function onmouseup() {

@ -12,7 +12,7 @@ function reset(_, str, tpl) {
var root = $.template(`<input> <input> <button>reset</button>`, 1);
function State_proxy_literal($$anchor, $$props) {
function State_proxy_literal($$anchor) {
let str = $.source('');
let tpl = $.source(``);
var fragment = root();

Loading…
Cancel
Save