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 <rich.harris@vercel.com>
pull/11646/head
Dominic Gannaway 7 months ago committed by GitHub
parent c00d8245ee
commit 053159bf0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: avoid state_referenced_locally warning within type annotations

@ -53,6 +53,24 @@ const visitors = {
},
TSTypeAliasDeclaration() {
return b.empty;
},
TSTypeParameterDeclaration() {
return b.empty;
},
TSTypeParameterInstantiation() {
return b.empty;
},
TSEnumDeclaration() {
return b.empty;
},
Identifier(node) {
if (node.typeAnnotation) {
return {
...node,
typeAnnotation: null
};
}
return node;
}
};

@ -676,14 +676,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
TransitionDirective: SvelteDirective,
AnimateDirective: SvelteDirective,
UseDirective: SvelteDirective,
// @ts-ignore
TSTypeAnnotation: skip,
TSInterfaceDeclaration: skip,
TSTypeAliasDeclaration: skip,
TSTypeParameterDeclaration: skip,
TSEnumDeclaration: skip
UseDirective: SvelteDirective
// TODO others
});

@ -1,4 +1,4 @@
<script>
<script lang="ts">
let obj = $state({ a: 0 });
let count = $state(0);
let doubled = $derived(count * 2);
@ -11,6 +11,8 @@
count = 1;
obj.a++;
obj.a = 1;
// @ts-ignore
let typed: {count: number} | null = null;
</script>
<button onclick={() => count += 1}>

Loading…
Cancel
Save