Skip to content

Commit b6fccdb

Browse files
fix: properly migrate imports types prefixed with $ (#14007)
1 parent 3876b30 commit b6fccdb

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

.changeset/wild-oranges-promise.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: properly migrate imports types prefixed with $

packages/svelte/src/compiler/phases/2-analyze/visitors/shared/utils.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,16 @@ export function validate_identifier_name(binding, function_depth) {
220220

221221
if (node.name === '$') {
222222
e.dollar_binding_invalid(node);
223-
} else if (node.name.startsWith('$')) {
223+
} else if (
224+
node.name.startsWith('$') &&
225+
// import type { $Type } from "" - these are normally already filtered out,
226+
// but for the migration they aren't, and throwing here is preventing the migration to complete
227+
// TODO -> once migration script is gone we can remove this check
228+
!(
229+
binding.initial?.type === 'ImportDeclaration' &&
230+
/** @type {any} */ (binding.initial).importKind === 'type'
231+
)
232+
) {
224233
e.dollar_prefix_invalid(node);
225234
}
226235
}

packages/svelte/src/compiler/phases/scope.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
348348
is_reference(node, /** @type {Node} */ (parent)) &&
349349
// TSTypeAnnotation, TSInterfaceDeclaration etc - these are normally already filtered out,
350350
// but for the migration they aren't, so we need to filter them out here
351-
// -> once migration script is gone we can remove this check
351+
// TODO -> once migration script is gone we can remove this check
352352
!parent.type.startsWith('TS')
353353
) {
354354
references.push([state.scope, { node, path: path.slice() }]);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script lang="ts">
2+
import type { $Test } from './types';
3+
4+
export let data: $Test;
5+
</script>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script lang="ts">
2+
import type { $Test } from './types';
3+
4+
interface Props {
5+
data: $Test;
6+
}
7+
8+
let { data }: Props = $props();
9+
</script>

0 commit comments

Comments
 (0)