Skip to content

Commit 5229f02

Browse files
committed
fix
1 parent b9c7f86 commit 5229f02

File tree

4 files changed

+9
-17
lines changed

4 files changed

+9
-17
lines changed

packages/svelte/src/compiler/phases/2-analyze/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ export function analyze_component(root, source, options) {
371371
uses_component_bindings: false,
372372
uses_render_tags: false,
373373
needs_context: false,
374+
needs_props: false,
374375
custom_element: options.customElementOptions ?? options.customElement,
375376
inject_styles: options.css === 'injected' || options.customElement,
376377
accessors: options.customElement
@@ -818,6 +819,8 @@ const legacy_scope_tweaker = {
818819
return next();
819820
}
820821

822+
state.analysis.needs_props = true;
823+
821824
if (!node.declaration) {
822825
for (const specifier of node.specifiers) {
823826
const binding = /** @type {import('#compiler').Binding} */ (
@@ -946,6 +949,8 @@ const runes_scope_tweaker = {
946949
}
947950

948951
if (rune === '$props') {
952+
state.analysis.needs_props = true;
953+
949954
for (const property of /** @type {import('estree').ObjectPattern} */ (node.id).properties) {
950955
if (property.type !== 'Property') continue;
951956

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -442,28 +442,12 @@ export function client_component(source, analysis, options) {
442442

443443
let should_inject_props =
444444
should_inject_context ||
445+
analysis.needs_props ||
445446
analysis.uses_props ||
446447
analysis.uses_rest_props ||
447448
analysis.uses_slots ||
448449
analysis.slot_names.size > 0;
449450

450-
if (!should_inject_props) {
451-
for (const declaration of analysis.instance.scope.declarations.values()) {
452-
if (declaration.declaration_kind === 'synthetic') {
453-
continue;
454-
}
455-
456-
if (
457-
declaration.kind === 'prop' ||
458-
declaration.kind === 'bindable_prop' ||
459-
declaration.kind === 'rest_prop'
460-
) {
461-
should_inject_props = true;
462-
break;
463-
}
464-
}
465-
}
466-
467451
const body = [
468452
...state.hoisted,
469453
...module.body,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,8 @@ function serialize_event_handler(node, { state, visit }) {
12281228

12291229
return handler;
12301230
} else {
1231+
state.analysis.needs_props = true;
1232+
12311233
// Function + .call to preserve "this" context as much as possible
12321234
return b.function(
12331235
null,

packages/svelte/src/compiler/phases/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export interface ComponentAnalysis extends Analysis {
5858
uses_component_bindings: boolean;
5959
uses_render_tags: boolean;
6060
needs_context: boolean;
61+
needs_props: boolean;
6162
custom_element: boolean | SvelteOptions['customElement'];
6263
/** If `true`, should append styles through JavaScript */
6364
inject_styles: boolean;

0 commit comments

Comments
 (0)