Skip to content

Commit 943b810

Browse files
committed
fix: use analysis.name when migrating <svelte:self>
1 parent 2f6d84a commit 943b810

File tree

5 files changed

+36
-30
lines changed

5 files changed

+36
-30
lines changed

.changeset/soft-stingrays-attend.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: use `analysis.name` when migrating `<svelte:self>`

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function migrate(source, { filename } = {}) {
4242
});
4343

4444
reset_warning_filter(() => false);
45-
reset(source, { filename: filename ?? 'migrate.svelte' });
45+
reset(source, { filename: filename ?? '(unknown)' });
4646

4747
let parsed = parse(source);
4848

@@ -52,7 +52,8 @@ export function migrate(source, { filename } = {}) {
5252
const combined_options = {
5353
...validate_component_options({}, ''),
5454
...parsed_options,
55-
customElementOptions
55+
customElementOptions,
56+
filename: filename ?? '(unknown)'
5657
};
5758

5859
const str = new MagicString(source);
@@ -93,7 +94,7 @@ export function migrate(source, { filename } = {}) {
9394
bubble: analysis.root.unique('bubble').name,
9495
passive: analysis.root.unique('passive').name,
9596
nonpassive: analysis.root.unique('nonpassive').name,
96-
svelte_self: analysis.root.unique('SvelteSelf').name
97+
svelte_self: analysis.name
9798
},
9899
legacy_imports: new Set(),
99100
script_insertions: new Set(),

packages/svelte/tests/migrate/samples/svelte-self-name-conflict/input.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
let SvelteSelf;
2+
let Output;
33
</script>
44

55
{#if false}
@@ -16,4 +16,4 @@
1616
child
1717
</svelte:self>
1818
<svelte:self></svelte:self>
19-
{/if}
19+
{/if}
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
<script>
2-
import SvelteSelf_1 from './output.svelte';
2+
import Output_1 from './output.svelte';
33
/** @type {Record<string, any>} */
44
let { ...props } = $props();
5-
let SvelteSelf;
5+
let Output;
66
</script>
77

88
{#if false}
9-
<SvelteSelf_1 />
10-
<SvelteSelf_1 with_attributes/>
11-
<SvelteSelf_1 count={count+1}/>
12-
<SvelteSelf_1>
9+
<Output_1 />
10+
<Output_1 with_attributes/>
11+
<Output_1 count={count+1}/>
12+
<Output_1>
1313
child
14-
</SvelteSelf_1>
15-
<SvelteSelf_1 count={count+1}>
14+
</Output_1>
15+
<Output_1 count={count+1}>
1616
child
17-
</SvelteSelf_1>
18-
<SvelteSelf_1 count={props.count} >
17+
</Output_1>
18+
<Output_1 count={props.count} >
1919
child
20-
</SvelteSelf_1>
21-
<SvelteSelf_1></SvelteSelf_1>
22-
{/if}
20+
</Output_1>
21+
<Output_1></Output_1>
22+
{/if}
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
<script>
2-
import SvelteSelf from './output.svelte';
2+
import Output from './output.svelte';
33
/** @type {Record<string, any>} */
44
let { ...props } = $props();
55
</script>
66

77
{#if false}
8-
<SvelteSelf />
9-
<SvelteSelf with_attributes/>
10-
<SvelteSelf count={count+1}/>
11-
<SvelteSelf>
8+
<Output />
9+
<Output with_attributes/>
10+
<Output count={count+1}/>
11+
<Output>
1212
child
13-
</SvelteSelf>
14-
<SvelteSelf count={count+1}>
13+
</Output>
14+
<Output count={count+1}>
1515
child
16-
</SvelteSelf>
17-
<SvelteSelf count={props.count} >
16+
</Output>
17+
<Output count={props.count} >
1818
child
19-
</SvelteSelf>
20-
<SvelteSelf></SvelteSelf>
21-
{/if}
19+
</Output>
20+
<Output></Output>
21+
{/if}

0 commit comments

Comments
 (0)