Skip to content
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/yellow-pumas-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: migrate multiple declarations with only some exported correctly
41 changes: 34 additions & 7 deletions packages/svelte/src/compiler/migrate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,8 @@ const instance_script = {

let nr_of_props = 0;

for (const declarator of node.declarations) {
for (let i = 0; i < node.declarations.length; i++) {
const declarator = node.declarations[i];
if (state.analysis.runes) {
if (get_rune(declarator.init, state.scope) === '$props') {
state.props_insertion_point = /** @type {number} */ (declarator.id.start) + 1;
Expand Down Expand Up @@ -605,12 +606,38 @@ const instance_script = {
});
}

state.props_insertion_point = /** @type {number} */ (declarator.end);
state.str.update(
/** @type {number} */ (declarator.start),
/** @type {number} */ (declarator.end),
''
);
let start = /** @type {number} */ (declarator.start);
let end = /** @type {number} */ (declarator.end);

// handle cases like let a,b,c; where only some are exported
if (node.declarations.length > 1) {
// move the insertion point after the node itself;
state.props_insertion_point = /** @type {number} */ (node.end);
// if it's not the first declaration remove from the , of the previous declaration
if (i !== 0) {
start = state.str.original.indexOf(
',',
/** @type {number} */ (node.declarations[i - 1].end)
);
}
// if it's not the last declaration remove either from up until the
// start of the next declaration (if it's the first declaration) or
// up until the last index of , from the next declaration
if (i !== node.declarations.length - 1) {
if (i === 0) {
end = /** @type {number} */ (node.declarations[i + 1].start);
} else {
end = state.str.original.lastIndexOf(
',',
/** @type {number} */ (node.declarations[i + 1].start)
);
}
}
} else {
state.props_insertion_point = /** @type {number} */ (declarator.end);
}

state.str.update(start, end, '');

continue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script>
let a, b, c, d;
let e, f, g, h;

export {a, c , f, h}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script>
let b, d;
let e, g;
let {
a,
c,
f,
h
} = $props();


</script>