Skip to content

Commit 9a575e6

Browse files
committed
add actionable advice
1 parent 377d89d commit 9a575e6

File tree

9 files changed

+19
-12
lines changed

9 files changed

+19
-12
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ export function migrate(source, { filename, use_ts } = {}) {
246246
const has_rune_binding = !!state.scope.get(rune);
247247
if (has_rune_binding) {
248248
throw new MigrationError(
249-
`migrating this component would require adding a \`$${rune}\` but there's already a variable named ${rune}`
249+
`migrating this component would require adding a \`$${rune}\` rune but there's already a variable named ${rune}.\n Rename the variable and try again or migrate by hand.`
250250
);
251251
}
252252
}
@@ -670,14 +670,13 @@ const instance_script = {
670670
}
671671

672672
/**
673-
*
674673
* @param {"state"|"derived"} rune
675674
*/
676675
function check_rune_binding(rune) {
677676
const has_rune_binding = !!state.scope.get(rune);
678677
if (has_rune_binding) {
679678
throw new MigrationError(
680-
`can't migrate \`${state.str.original.substring(/** @type {number} */ (node.start), node.end)}\` to \`$${rune}\` because there's a variable named ${rune}`
679+
`can't migrate \`${state.str.original.substring(/** @type {number} */ (node.start), node.end)}\` to \`$${rune}\` because there's a variable named ${rune}.\n Rename the variable and try again or migrate by hand.`
681680
);
682681
}
683682
}
@@ -901,7 +900,7 @@ const instance_script = {
901900
const has_rune_binding = state.scope.get(rune);
902901
if (has_rune_binding) {
903902
throw new MigrationError(
904-
`can't migrate \`$: ${state.str.original.substring(/** @type {number} */ (node.body.start), node.body.end)}\` to \`$${rune}\` because there's a variable named ${rune}`
903+
`can't migrate \`$: ${state.str.original.substring(/** @type {number} */ (node.body.start), node.body.end)}\` to \`$${rune}\` because there's a variable named ${rune}.\n Rename the variable and try again or migrate by hand.`
905904
);
906905
}
907906
}

packages/svelte/tests/migrate/samples/impossible-migrate-$bindable-bindable-var-1/output.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<!-- @migration-task Error while migrating Svelte code: migrating this component would require adding a `$bindable` but there's already a variable named bindable -->
1+
<!-- @migration-task Error while migrating Svelte code: migrating this component would require adding a `$bindable` rune but there's already a variable named bindable.
2+
Rename the variable and try again or migrate by hand. -->
23
<script>
34
let bindable;
45
export let something;

packages/svelte/tests/migrate/samples/impossible-migrate-$derived-derived-var-1/output.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<!-- @migration-task Error while migrating Svelte code: can't migrate `$: other = name;` to `$derived` because there's a variable named derived -->
1+
<!-- @migration-task Error while migrating Svelte code: can't migrate `$: other = name;` to `$derived` because there's a variable named derived.
2+
Rename the variable and try again or migrate by hand. -->
23
<script>
34
let name = 'world';
45

packages/svelte/tests/migrate/samples/impossible-migrate-$derived-derived-var-2/output.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<!-- @migration-task Error while migrating Svelte code: migrating this component would require adding a `$derived` but there's already a variable named derived -->
1+
<!-- @migration-task Error while migrating Svelte code: migrating this component would require adding a `$derived` rune but there's already a variable named derived.
2+
Rename the variable and try again or migrate by hand. -->
23
<script>
34
let derived;
45
</script>

packages/svelte/tests/migrate/samples/impossible-migrate-$derived-derived-var-4/output.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<!-- @migration-task Error while migrating Svelte code: can't migrate `let other;` to `$derived` because there's a variable named derived -->
1+
<!-- @migration-task Error while migrating Svelte code: can't migrate `let other;` to `$derived` because there's a variable named derived.
2+
Rename the variable and try again or migrate by hand. -->
23
<script>
34
let name = 'world';
45

packages/svelte/tests/migrate/samples/impossible-migrate-$props-props-var-1/output.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<!-- @migration-task Error while migrating Svelte code: migrating this component would require adding a `$props` but there's already a variable named props -->
1+
<!-- @migration-task Error while migrating Svelte code: migrating this component would require adding a `$props` rune but there's already a variable named props.
2+
Rename the variable and try again or migrate by hand. -->
23
<script>
34
let props;
45
export let something;

packages/svelte/tests/migrate/samples/impossible-migrate-$state-state-var-1/output.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<!-- @migration-task Error while migrating Svelte code: can't migrate `let other;` to `$state` because there's a variable named state -->
1+
<!-- @migration-task Error while migrating Svelte code: can't migrate `let other;` to `$state` because there's a variable named state.
2+
Rename the variable and try again or migrate by hand. -->
23
<script>
34
let state = 'world';
45

packages/svelte/tests/migrate/samples/impossible-migrate-$state-state-var-2/output.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<!-- @migration-task Error while migrating Svelte code: can't migrate `let other = 42;` to `$state` because there's a variable named state -->
1+
<!-- @migration-task Error while migrating Svelte code: can't migrate `let other = 42;` to `$state` because there's a variable named state.
2+
Rename the variable and try again or migrate by hand. -->
23
<script>
34
let state = 'world';
45

packages/svelte/tests/migrate/samples/impossible-migrate-$state-state-var-3/output.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<!-- @migration-task Error while migrating Svelte code: can't migrate `$: other = 42;` to `$state` because there's a variable named state -->
1+
<!-- @migration-task Error while migrating Svelte code: can't migrate `$: other = 42;` to `$state` because there's a variable named state.
2+
Rename the variable and try again or migrate by hand. -->
23
<script>
34
let state = 'world';
45

0 commit comments

Comments
 (0)