Skip to content

Commit 941f83b

Browse files
fix: don't show state_referenced_locally warning on types (#13177)
Add a new visitor to the "strip TS AST" logic. Strictly speaking this results in incorrect ASTs but esrap, our printer, just ignores them at those positions, so we can do that. An alternative would be to adjust zimmerframe to be able to return something to say "delete this node" Fixes #13173
1 parent 3808935 commit 941f83b

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

.changeset/five-suns-roll.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: don't show `state_referenced_locally` warning on types

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ const visitors = {
7373
TSNonNullExpression(node, context) {
7474
return context.visit(node.expression);
7575
},
76+
TSTypeAnnotation() {
77+
// This isn't correct, strictly speaking, and could result in invalid ASTs (like an empty statement within function parameters),
78+
// but esrap, our printing tool, just ignores these AST nodes at invalid positions, so it's fine
79+
return b.empty;
80+
},
7681
TSInterfaceDeclaration() {
7782
return b.empty;
7883
},
@@ -94,15 +99,6 @@ const visitors = {
9499
}
95100
return node.parameter;
96101
},
97-
Identifier(node) {
98-
if (node.typeAnnotation) {
99-
return {
100-
...node,
101-
typeAnnotation: null
102-
};
103-
}
104-
return node;
105-
},
106102
FunctionExpression: remove_this_param,
107103
FunctionDeclaration: remove_this_param,
108104
TSDeclareFunction() {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script lang="ts">
2+
let { a }: { a: string } = $state({});
3+
let { b }: { b: string } = $derived(a);
4+
</script>
5+
6+
<button onclick={()=>a++}></button>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

0 commit comments

Comments
 (0)