diff --git a/.changeset/five-suns-roll.md b/.changeset/five-suns-roll.md new file mode 100644 index 0000000000..ffd0ca44cf --- /dev/null +++ b/.changeset/five-suns-roll.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: don't show `state_referenced_locally` warning on types diff --git a/packages/svelte/src/compiler/phases/1-parse/remove_typescript_nodes.js b/packages/svelte/src/compiler/phases/1-parse/remove_typescript_nodes.js index 872b71a4df..edbb673bd5 100644 --- a/packages/svelte/src/compiler/phases/1-parse/remove_typescript_nodes.js +++ b/packages/svelte/src/compiler/phases/1-parse/remove_typescript_nodes.js @@ -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() { diff --git a/packages/svelte/tests/validator/samples/state-referenced-locally-types/input.svelte b/packages/svelte/tests/validator/samples/state-referenced-locally-types/input.svelte new file mode 100644 index 0000000000..30d282d7e4 --- /dev/null +++ b/packages/svelte/tests/validator/samples/state-referenced-locally-types/input.svelte @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/packages/svelte/tests/validator/samples/state-referenced-locally-types/warnings.json b/packages/svelte/tests/validator/samples/state-referenced-locally-types/warnings.json new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/packages/svelte/tests/validator/samples/state-referenced-locally-types/warnings.json @@ -0,0 +1 @@ +[]