Skip to content

Commit 053159b

Browse files
trueadmRich-Harris
andauthored
fix: avoid state_referenced_locally warning within type annotations (#11638)
* fix: avoid state_referenced_locally warning within type annotations * better fix * prettier * better fix * fix * fix * fix --------- Co-authored-by: Rich Harris <[email protected]>
1 parent c00d824 commit 053159b

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

.changeset/popular-games-hug.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: avoid state_referenced_locally warning within type annotations

packages/svelte/src/compiler/phases/1-parse/remove_typescript_nodes.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ const visitors = {
5353
},
5454
TSTypeAliasDeclaration() {
5555
return b.empty;
56+
},
57+
TSTypeParameterDeclaration() {
58+
return b.empty;
59+
},
60+
TSTypeParameterInstantiation() {
61+
return b.empty;
62+
},
63+
TSEnumDeclaration() {
64+
return b.empty;
65+
},
66+
Identifier(node) {
67+
if (node.typeAnnotation) {
68+
return {
69+
...node,
70+
typeAnnotation: null
71+
};
72+
}
73+
return node;
5674
}
5775
};
5876

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -676,14 +676,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
676676

677677
TransitionDirective: SvelteDirective,
678678
AnimateDirective: SvelteDirective,
679-
UseDirective: SvelteDirective,
680-
681-
// @ts-ignore
682-
TSTypeAnnotation: skip,
683-
TSInterfaceDeclaration: skip,
684-
TSTypeAliasDeclaration: skip,
685-
TSTypeParameterDeclaration: skip,
686-
TSEnumDeclaration: skip
679+
UseDirective: SvelteDirective
687680

688681
// TODO others
689682
});

packages/svelte/tests/validator/samples/static-state-reference/input.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<script>
1+
<script lang="ts">
22
let obj = $state({ a: 0 });
33
let count = $state(0);
44
let doubled = $derived(count * 2);
@@ -11,6 +11,8 @@
1111
count = 1;
1212
obj.a++;
1313
obj.a = 1;
14+
// @ts-ignore
15+
let typed: {count: number} | null = null;
1416
</script>
1517

1618
<button onclick={() => count += 1}>

0 commit comments

Comments
 (0)