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
pull/13198/head
Paolo Ricciuti 1 week ago committed by GitHub
parent 3808935f51
commit 941f83b5a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: don't show `state_referenced_locally` warning on types

@ -73,6 +73,11 @@ const visitors = {
TSNonNullExpression(node, context) {
return context.visit(node.expression);
},
TSTypeAnnotation() {
// This isn't correct, strictly speaking, and could result in invalid ASTs (like an empty statement within function parameters),
// but esrap, our printing tool, just ignores these AST nodes at invalid positions, so it's fine
return b.empty;
},
TSInterfaceDeclaration() {
return b.empty;
},
@ -94,15 +99,6 @@ const visitors = {
}
return node.parameter;
},
Identifier(node) {
if (node.typeAnnotation) {
return {
...node,
typeAnnotation: null
};
}
return node;
},
FunctionExpression: remove_this_param,
FunctionDeclaration: remove_this_param,
TSDeclareFunction() {

@ -0,0 +1,6 @@
<script lang="ts">
let { a }: { a: string } = $state({});
let { b }: { b: string } = $derived(a);
</script>
<button onclick={()=>a++}></button>
Loading…
Cancel
Save