Skip to content

Commit 32bb628

Browse files
committed
fix: migrate $$Props without creating non existent props
1 parent b665425 commit 32bb628

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

.changeset/funny-houses-kick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: migrate `$$Props` without creating non existent props

packages/svelte/src/compiler/migrate/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export function migrate(source) {
150150
props = `...${state.names.props}`;
151151
} else {
152152
props = state.props
153+
.filter((prop) => !prop.type_only)
153154
.map((prop) => {
154155
let prop_str =
155156
prop.local === prop.exported ? prop.local : `${prop.exported}: ${prop.local}`;
@@ -282,7 +283,7 @@ export function migrate(source) {
282283
* str: MagicString;
283284
* analysis: ComponentAnalysis;
284285
* indent: string;
285-
* props: Array<{ local: string; exported: string; init: string; bindable: boolean; slot_name?: string; optional: boolean; type: string; comment?: string }>;
286+
* props: Array<{ local: string; exported: string; init: string; bindable: boolean; slot_name?: string; optional: boolean; type: string; comment?: string, type_only?: boolean }>;
286287
* props_insertion_point: number;
287288
* has_props_rune: boolean;
288289
* end: number;
@@ -419,6 +420,7 @@ const instance_script = {
419420
: '';
420421
prop.bindable = binding.updated;
421422
prop.exported = binding.prop_alias || name;
423+
prop.type_only = false;
422424
} else {
423425
state.props.push({
424426
local: name,
@@ -989,7 +991,8 @@ function handle_identifier(node, state, path) {
989991
bindable: false,
990992
optional: member.optional,
991993
type,
992-
comment
994+
comment,
995+
type_only: true
993996
});
994997
}
995998
}

packages/svelte/tests/migrate/samples/props-interface/input.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
/** foo */
44
foo: string;
55
bar: boolean;
6+
/** should not create a prop */
7+
type_only: boolean;
68
}
79
810
export let foo: $$Props['foo'];

packages/svelte/tests/migrate/samples/props-interface/output.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
/** foo */
66
foo: string;
77
bar: boolean;
8+
/** should not create a prop */
9+
type_only: boolean;
810
}
911
1012
let { foo = $bindable(), bar = true }: Props = $props();

0 commit comments

Comments
 (0)