Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/funny-houses-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: migrate `$$Props` without creating non existent props
7 changes: 5 additions & 2 deletions packages/svelte/src/compiler/migrate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export function migrate(source) {
props = `...${state.names.props}`;
} else {
props = state.props
.filter((prop) => !prop.type_only)
.map((prop) => {
let prop_str =
prop.local === prop.exported ? prop.local : `${prop.exported}: ${prop.local}`;
Expand Down Expand Up @@ -282,7 +283,7 @@ export function migrate(source) {
* str: MagicString;
* analysis: ComponentAnalysis;
* 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;
* has_props_rune: boolean;
* end: number;
Expand Down Expand Up @@ -419,6 +420,7 @@ const instance_script = {
: '';
prop.bindable = binding.updated;
prop.exported = binding.prop_alias || name;
prop.type_only = false;
} else {
state.props.push({
local: name,
Expand Down Expand Up @@ -989,7 +991,8 @@ function handle_identifier(node, state, path) {
bindable: false,
optional: member.optional,
type,
comment
comment,
type_only: true
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/** foo */
foo: string;
bar: boolean;
/** should not create a prop */
type_only: boolean;
}

export let foo: $$Props['foo'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
/** foo */
foo: string;
bar: boolean;
/** should not create a prop */
type_only: boolean;
}

let { foo = $bindable(), bar = true }: Props = $props();
Expand Down