fix: migrate `$$Props` without creating non existent props (#13484)

pull/13485/head
Paolo Ricciuti 3 months ago committed by GitHub
parent b665425e5d
commit 344808a719
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: migrate `$$Props` without creating non existent props

@ -150,6 +150,7 @@ export function migrate(source) {
props = `...${state.names.props}`; props = `...${state.names.props}`;
} else { } else {
props = state.props props = state.props
.filter((prop) => !prop.type_only)
.map((prop) => { .map((prop) => {
let prop_str = let prop_str =
prop.local === prop.exported ? prop.local : `${prop.exported}: ${prop.local}`; prop.local === prop.exported ? prop.local : `${prop.exported}: ${prop.local}`;
@ -282,7 +283,7 @@ export function migrate(source) {
* str: MagicString; * str: MagicString;
* analysis: ComponentAnalysis; * analysis: ComponentAnalysis;
* indent: string; * indent: string;
* props: Array<{ local: string; exported: string; init: string; bindable: boolean; slot_name?: string; optional: boolean; type: string; comment?: string }>; * props: Array<{ local: string; exported: string; init: string; bindable: boolean; slot_name?: string; optional: boolean; type: string; comment?: string, type_only?: boolean }>;
* props_insertion_point: number; * props_insertion_point: number;
* has_props_rune: boolean; * has_props_rune: boolean;
* end: number; * end: number;
@ -419,6 +420,7 @@ const instance_script = {
: ''; : '';
prop.bindable = binding.updated; prop.bindable = binding.updated;
prop.exported = binding.prop_alias || name; prop.exported = binding.prop_alias || name;
prop.type_only = false;
} else { } else {
state.props.push({ state.props.push({
local: name, local: name,
@ -989,7 +991,8 @@ function handle_identifier(node, state, path) {
bindable: false, bindable: false,
optional: member.optional, optional: member.optional,
type, type,
comment comment,
type_only: true
}); });
} }
} }

@ -3,6 +3,8 @@
/** foo */ /** foo */
foo: string; foo: string;
bar: boolean; bar: boolean;
/** should not create a prop */
type_only: boolean;
} }
export let foo: $$Props['foo']; export let foo: $$Props['foo'];

@ -5,6 +5,8 @@
/** foo */ /** foo */
foo: string; foo: string;
bar: boolean; bar: boolean;
/** should not create a prop */
type_only: boolean;
} }
let { foo = $bindable(), bar = true }: Props = $props(); let { foo = $bindable(), bar = true }: Props = $props();

Loading…
Cancel
Save