Skip to content

Commit

Permalink
fix: properly migrate imports types prefixed with $ (#14007)
Browse files Browse the repository at this point in the history
  • Loading branch information
paoloricciuti authored Oct 28, 2024
1 parent 3876b30 commit b6fccdb
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/wild-oranges-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: properly migrate imports types prefixed with $
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,16 @@ export function validate_identifier_name(binding, function_depth) {

if (node.name === '$') {
e.dollar_binding_invalid(node);
} else if (node.name.startsWith('$')) {
} else if (
node.name.startsWith('$') &&
// import type { $Type } from "" - these are normally already filtered out,
// but for the migration they aren't, and throwing here is preventing the migration to complete
// TODO -> once migration script is gone we can remove this check
!(
binding.initial?.type === 'ImportDeclaration' &&
/** @type {any} */ (binding.initial).importKind === 'type'
)
) {
e.dollar_prefix_invalid(node);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/compiler/phases/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
is_reference(node, /** @type {Node} */ (parent)) &&
// TSTypeAnnotation, TSInterfaceDeclaration etc - these are normally already filtered out,
// but for the migration they aren't, so we need to filter them out here
// -> once migration script is gone we can remove this check
// TODO -> once migration script is gone we can remove this check
!parent.type.startsWith('TS')
) {
references.push([state.scope, { node, path: path.slice() }]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script lang="ts">
import type { $Test } from './types';
export let data: $Test;
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script lang="ts">
import type { $Test } from './types';
interface Props {
data: $Test;
}
let { data }: Props = $props();
</script>

0 comments on commit b6fccdb

Please sign in to comment.