From 2feb9632f61bc68d83c86e28fc2e3830e7e5e2fa Mon Sep 17 00:00:00 2001 From: baseballyama Date: Sun, 1 Dec 2024 12:47:00 +0900 Subject: [PATCH 1/2] fix: recognize script as module for Typescript type checking --- .changeset/purple-otters-hammer.md | 5 + package.json | 1 - src/parser/typescript/analyze/index.ts | 20 +- .../docs/runes/08-$props-ts-output.json | 21 + .../docs/runes/08-4-$bindable-ts-output.json | 21 + .../docs/runes/11-3-$inspect-ts-output.json | 21 + .../10-typing-snippets-type-output.svelte | 2 +- .../11-typing-snippets-type-output.svelte | 2 +- .../generics01-snippets-type-output.svelte | 2 +- .../svelte5/ts-$props01-type-output.svelte | 2 +- .../ast/svelte5/ts-$props02-input.svelte | 5 + .../ast/svelte5/ts-$props02-output.json | 1021 +++++++++++++++++ .../ts-$props02-prefer-const-result.json | 8 + .../ast/svelte5/ts-$props02-requirements.json | 8 + .../ast/svelte5/ts-$props02-scope-output.json | 593 ++++++++++ .../svelte5/ts-$props02-type-output.svelte | 5 + .../ast/svelte5/ts-event03-type-output.svelte | 2 +- .../parser/ast/ts-$$props01-output.json | 21 + .../parser/ast/ts-$$slots01-output.json | 21 + .../ast/ts-$$slots02-no-slot-output.json | 21 + .../parser/ast/ts-$$slots03-named-output.json | 21 + .../parser/ast/ts-$$slots04-named-output.json | 21 + .../parser/ast/ts-issue226-output.json | 21 + 23 files changed, 1858 insertions(+), 7 deletions(-) create mode 100644 .changeset/purple-otters-hammer.md create mode 100644 tests/fixtures/parser/ast/svelte5/ts-$props02-input.svelte create mode 100644 tests/fixtures/parser/ast/svelte5/ts-$props02-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-$props02-prefer-const-result.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-$props02-requirements.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-$props02-scope-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-$props02-type-output.svelte diff --git a/.changeset/purple-otters-hammer.md b/.changeset/purple-otters-hammer.md new file mode 100644 index 00000000..6f1a7496 --- /dev/null +++ b/.changeset/purple-otters-hammer.md @@ -0,0 +1,5 @@ +--- +"svelte-eslint-parser": patch +--- + +fix: recognize script as module for Typescript type checking diff --git a/package.json b/package.json index a2cf3f8a..e48dc2b1 100644 --- a/package.json +++ b/package.json @@ -95,7 +95,6 @@ "eslint-plugin-regexp": "^2.7.0", "eslint-plugin-svelte": "^2.46.1", "eslint-plugin-yml": "^1.15.0", - "estree-walker": "^3.0.3", "globals": "^15.12.0", "locate-character": "^3.0.0", "magic-string": "^0.30.14", diff --git a/src/parser/typescript/analyze/index.ts b/src/parser/typescript/analyze/index.ts index 09c014f9..001305e7 100644 --- a/src/parser/typescript/analyze/index.ts +++ b/src/parser/typescript/analyze/index.ts @@ -80,6 +80,12 @@ export function analyzeTypeScriptInSvelte( analyzeRenderScopes(code, ctx); + // When performing type checking on TypeScript code that is not a module, the error `Cannot redeclare block-scoped variable 'xxx'`. occurs. To fix this, add an `export`. + // see: https://github.com/sveltejs/svelte-eslint-parser/issues/557 + if (!hasExportDeclaration(result.ast)) { + ctx.appendVirtualScript("export {};"); + } + ctx.appendOriginalToEnd(); return ctx; @@ -118,6 +124,18 @@ export function analyzeTypeScript( return ctx; } +function hasExportDeclaration(ast: TSESParseForESLintResult["ast"]): boolean { + for (const node of ast.body) { + if ( + node.type === "ExportNamedDeclaration" || + node.type === "ExportDefaultDeclaration" + ) { + return true; + } + } + return false; +} + /** * Analyze the store reference names. * Insert type definitions code to provide correct type information for variables that begin with `$`. @@ -380,7 +398,7 @@ function analyzeRuneVariables( // See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16/packages/svelte/types/index.d.ts#L2615 case "$props": { // Use type parameters to avoid `@typescript-eslint/no-unsafe-assignment` errors. - appendDeclareFunctionVirtualScripts(globalName, ["(): T"]); + appendDeclareFunctionVirtualScripts(globalName, ["(): any"]); break; } // See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16/packages/svelte/types/index.d.ts#L2626 diff --git a/tests/fixtures/parser/ast/svelte5/docs/runes/08-$props-ts-output.json b/tests/fixtures/parser/ast/svelte5/docs/runes/08-$props-ts-output.json index d2f3206c..aab3a233 100644 --- a/tests/fixtures/parser/ast/svelte5/docs/runes/08-$props-ts-output.json +++ b/tests/fixtures/parser/ast/svelte5/docs/runes/08-$props-ts-output.json @@ -502,6 +502,27 @@ "column": 57 } } + }, + { + "type": "ExportNamedDeclaration", + "declaration": null, + "exportKind": "value", + "source": null, + "specifiers": [], + "range": [ + 108, + 108 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 0 + } + } } ], "endTag": { diff --git a/tests/fixtures/parser/ast/svelte5/docs/runes/08-4-$bindable-ts-output.json b/tests/fixtures/parser/ast/svelte5/docs/runes/08-4-$bindable-ts-output.json index 909c38d4..f0553447 100644 --- a/tests/fixtures/parser/ast/svelte5/docs/runes/08-4-$bindable-ts-output.json +++ b/tests/fixtures/parser/ast/svelte5/docs/runes/08-4-$bindable-ts-output.json @@ -427,6 +427,27 @@ "column": 75 } } + }, + { + "type": "ExportNamedDeclaration", + "declaration": null, + "exportKind": "value", + "source": null, + "specifiers": [], + "range": [ + 105, + 105 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 0 + } + } } ], "endTag": { diff --git a/tests/fixtures/parser/ast/svelte5/docs/runes/11-3-$inspect-ts-output.json b/tests/fixtures/parser/ast/svelte5/docs/runes/11-3-$inspect-ts-output.json index 3a146be6..a6d0ca6d 100644 --- a/tests/fixtures/parser/ast/svelte5/docs/runes/11-3-$inspect-ts-output.json +++ b/tests/fixtures/parser/ast/svelte5/docs/runes/11-3-$inspect-ts-output.json @@ -394,6 +394,27 @@ "column": 38 } } + }, + { + "type": "ExportNamedDeclaration", + "declaration": null, + "exportKind": "value", + "source": null, + "specifiers": [], + "range": [ + 94, + 94 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 0 + } + } } ], "endTag": { diff --git a/tests/fixtures/parser/ast/svelte5/docs/snippets/10-typing-snippets-type-output.svelte b/tests/fixtures/parser/ast/svelte5/docs/snippets/10-typing-snippets-type-output.svelte index 0db3e719..2009d36a 100644 --- a/tests/fixtures/parser/ast/svelte5/docs/snippets/10-typing-snippets-type-output.svelte +++ b/tests/fixtures/parser/ast/svelte5/docs/snippets/10-typing-snippets-type-output.svelte @@ -5,7 +5,7 @@ data: any[]; // data: any[] children: Snippet; // Snippet: Snippet, children: Snippet<[]> row: Snippet<[any]>; // Snippet: Snippet, row: Snippet<[any]> - } = $props(); // $props(): { data: any[]; children: Snippet<[]>; row: Snippet<[any]>; } + } = $props(); // $props(): any diff --git a/tests/fixtures/parser/ast/svelte5/docs/snippets/11-typing-snippets-type-output.svelte b/tests/fixtures/parser/ast/svelte5/docs/snippets/11-typing-snippets-type-output.svelte index 3396ed9b..204db6f5 100644 --- a/tests/fixtures/parser/ast/svelte5/docs/snippets/11-typing-snippets-type-output.svelte +++ b/tests/fixtures/parser/ast/svelte5/docs/snippets/11-typing-snippets-type-output.svelte @@ -5,7 +5,7 @@ data: T[]; // T: unknown, data: unknown[] children: Snippet; // Snippet: Snippet, children: Snippet<[]> row: Snippet<[T]>; // Snippet: Snippet, T: unknown, row: Snippet<[unknown]> - } = $props(); // $props(): { data: unknown[]; children: Snippet<[]>; row: Snippet<[unknown]>; } + } = $props(); // $props(): any
diff --git a/tests/fixtures/parser/ast/svelte5/generics01-snippets-type-output.svelte b/tests/fixtures/parser/ast/svelte5/generics01-snippets-type-output.svelte index 73fb2bc4..9511f75b 100644 --- a/tests/fixtures/parser/ast/svelte5/generics01-snippets-type-output.svelte +++ b/tests/fixtures/parser/ast/svelte5/generics01-snippets-type-output.svelte @@ -6,7 +6,7 @@ data: A[]; // A: unknown, data: unknown[] children: Snippet; // Snippet: Snippet, children: Snippet<[]> row: Snippet<[A]>; // Snippet: Snippet, A: unknown, row: Snippet<[unknown]> - } = $props(); // $props(): { data: unknown[]; children: Snippet<[]>; row: Snippet<[unknown]>; } + } = $props(); // $props(): any
diff --git a/tests/fixtures/parser/ast/svelte5/ts-$props01-type-output.svelte b/tests/fixtures/parser/ast/svelte5/ts-$props01-type-output.svelte index ff36a150..5bccb22f 100644 --- a/tests/fixtures/parser/ast/svelte5/ts-$props01-type-output.svelte +++ b/tests/fixtures/parser/ast/svelte5/ts-$props01-type-output.svelte @@ -5,7 +5,7 @@ c: boolean; // c: boolean d: number; // d: number } - let { a, b, c, ...everythingElse }: MyProps = $props(); // a: number, a: number, b: string, b: string, c: boolean, c: boolean, everythingElse: { d: number; }, MyProps: MyProps, $props(): MyProps + let { a, b, c, ...everythingElse }: MyProps = $props(); // a: number, a: number, b: string, b: string, c: boolean, c: boolean, everythingElse: { d: number; }, MyProps: MyProps, $props(): any {a} diff --git a/tests/fixtures/parser/ast/svelte5/ts-$props02-input.svelte b/tests/fixtures/parser/ast/svelte5/ts-$props02-input.svelte new file mode 100644 index 00000000..5ba2e0a0 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-$props02-input.svelte @@ -0,0 +1,5 @@ + + +{name} diff --git a/tests/fixtures/parser/ast/svelte5/ts-$props02-output.json b/tests/fixtures/parser/ast/svelte5/ts-$props02-output.json new file mode 100644 index 00000000..c84ba774 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-$props02-output.json @@ -0,0 +1,1021 @@ +{ + "type": "Program", + "body": [ + { + "type": "SvelteScriptElement", + "name": { + "type": "SvelteName", + "name": "script", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "lang", + "range": [ + 8, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteLiteral", + "value": "ts", + "range": [ + 14, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + } + } + ], + "range": [ + 8, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 17 + } + } + } + ], + "selfClosing": false, + "range": [ + 0, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + } + }, + "body": [ + { + "type": "VariableDeclaration", + "kind": "let", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "ObjectPattern", + "properties": [ + { + "type": "Property", + "kind": "init", + "computed": false, + "key": { + "type": "Identifier", + "name": "name", + "range": [ + 27, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "method": false, + "shorthand": true, + "value": { + "type": "Identifier", + "name": "name", + "range": [ + 27, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "range": [ + 27, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + ], + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSTypeLiteral", + "members": [ + { + "type": "TSPropertySignature", + "computed": false, + "key": { + "type": "Identifier", + "name": "name", + "range": [ + 37, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 43, + 49 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 30 + } + } + }, + "range": [ + 41, + 49 + ], + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 30 + } + } + }, + "range": [ + 37, + 49 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 30 + } + } + } + ], + "range": [ + 35, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 32 + } + } + }, + "range": [ + 33, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 32 + } + } + }, + "range": [ + 25, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 32 + } + } + }, + "init": { + "type": "CallExpression", + "arguments": [], + "callee": { + "type": "Identifier", + "name": "$props", + "range": [ + 54, + 60 + ], + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 41 + } + } + }, + "optional": false, + "range": [ + 54, + 62 + ], + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 43 + } + } + }, + "range": [ + 25, + 62 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 43 + } + } + } + ], + "range": [ + 21, + 63 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 44 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 64, + 73 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + "range": [ + 0, + 73 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 73, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "Identifier", + "name": "name", + "range": [ + 76, + 80 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 5 + } + } + }, + "range": [ + 75, + 81 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 6 + } + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "value": "<", + "range": [ + 0, + 1 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "lang", + "range": [ + 8, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 12, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + } + }, + { + "type": "HTMLText", + "value": "ts", + "range": [ + 14, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 16, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + } + }, + { + "type": "Keyword", + "value": "let", + "range": [ + 21, + 24 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 25, + 26 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + } + }, + { + "type": "Identifier", + "value": "name", + "range": [ + 27, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 33, + 34 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + { + "type": "Identifier", + "value": "name", + "range": [ + 37, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 41, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + { + "type": "Identifier", + "value": "string", + "range": [ + 43, + 49 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 30 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 50, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 31 + }, + "end": { + "line": 2, + "column": 32 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 52, + 53 + ], + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 34 + } + } + }, + { + "type": "Identifier", + "value": "$props", + "range": [ + 54, + 60 + ], + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 41 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 60, + 61 + ], + "loc": { + "start": { + "line": 2, + "column": 41 + }, + "end": { + "line": 2, + "column": 42 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 61, + 62 + ], + "loc": { + "start": { + "line": 2, + "column": 42 + }, + "end": { + "line": 2, + "column": 43 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 62, + 63 + ], + "loc": { + "start": { + "line": 2, + "column": 43 + }, + "end": { + "line": 2, + "column": 44 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 64, + 65 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 65, + 66 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 66, + 72 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 72, + 73 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 73, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 75, + 76 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + } + }, + { + "type": "Identifier", + "value": "name", + "range": [ + 76, + 80 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 80, + 81 + ], + "loc": { + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 6 + } + } + } + ], + "range": [ + 0, + 82 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-$props02-prefer-const-result.json b/tests/fixtures/parser/ast/svelte5/ts-$props02-prefer-const-result.json new file mode 100644 index 00000000..9f2b37ad --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-$props02-prefer-const-result.json @@ -0,0 +1,8 @@ +[ + { + "ruleId": "prefer-const", + "code": "name", + "line": 2, + "column": 9 + } +] \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-$props02-requirements.json b/tests/fixtures/parser/ast/svelte5/ts-$props02-requirements.json new file mode 100644 index 00000000..14189c9d --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-$props02-requirements.json @@ -0,0 +1,8 @@ +{ + "test": { + "@typescript-eslint/parser": ">=6.5.0" + }, + "scope": { + "@typescript-eslint/parser": ">=6.5.0" + } +} diff --git a/tests/fixtures/parser/ast/svelte5/ts-$props02-scope-output.json b/tests/fixtures/parser/ast/svelte5/ts-$props02-scope-output.json new file mode 100644 index 00000000..e158999e --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-$props02-scope-output.json @@ -0,0 +1,593 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$state", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$derived", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$effect", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$props", + "identifiers": [], + "defs": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "$props", + "range": [ + 54, + 60 + ], + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 41 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] + }, + { + "name": "$bindable", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$inspect", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$host", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "name", + "identifiers": [ + { + "type": "Identifier", + "name": "name", + "range": [ + 27, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "name", + "range": [ + 27, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "ObjectPattern", + "properties": [ + { + "type": "Property", + "kind": "init", + "computed": false, + "key": { + "type": "Identifier", + "name": "name", + "range": [ + 27, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "method": false, + "shorthand": true, + "value": { + "type": "Identifier", + "name": "name", + "range": [ + 27, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "range": [ + 27, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + ], + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSTypeLiteral", + "members": [ + { + "type": "TSPropertySignature", + "computed": false, + "key": { + "type": "Identifier", + "name": "name", + "range": [ + 37, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 43, + 49 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 30 + } + } + }, + "range": [ + 41, + 49 + ], + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 30 + } + } + }, + "range": [ + 37, + 49 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 30 + } + } + } + ], + "range": [ + 35, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 32 + } + } + }, + "range": [ + 33, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 32 + } + } + }, + "range": [ + 25, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 32 + } + } + }, + "init": { + "type": "CallExpression", + "arguments": [], + "callee": { + "type": "Identifier", + "name": "$props", + "range": [ + 54, + 60 + ], + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 41 + } + } + }, + "optional": false, + "range": [ + 54, + 62 + ], + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 43 + } + } + }, + "range": [ + 25, + 62 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 43 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "name", + "range": [ + 27, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "name", + "range": [ + 27, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "name", + "range": [ + 76, + 80 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 5 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "name", + "range": [ + 27, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "name", + "range": [ + 27, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "name", + "range": [ + 27, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "$props", + "range": [ + 54, + 60 + ], + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 41 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "name", + "range": [ + 76, + 80 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 5 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "name", + "range": [ + 27, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "$props", + "range": [ + 54, + 60 + ], + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 41 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] + } + ], + "through": [] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-$props02-type-output.svelte b/tests/fixtures/parser/ast/svelte5/ts-$props02-type-output.svelte new file mode 100644 index 00000000..018fe64f --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-$props02-type-output.svelte @@ -0,0 +1,5 @@ + + +{name} diff --git a/tests/fixtures/parser/ast/svelte5/ts-event03-type-output.svelte b/tests/fixtures/parser/ast/svelte5/ts-event03-type-output.svelte index 72c2a943..e56a63cf 100644 --- a/tests/fixtures/parser/ast/svelte5/ts-event03-type-output.svelte +++ b/tests/fixtures/parser/ast/svelte5/ts-event03-type-output.svelte @@ -1,7 +1,7 @@ diff --git a/tests/fixtures/parser/ast/ts-$$props01-output.json b/tests/fixtures/parser/ast/ts-$$props01-output.json index 958c6abc..6a9ef749 100644 --- a/tests/fixtures/parser/ast/ts-$$props01-output.json +++ b/tests/fixtures/parser/ast/ts-$$props01-output.json @@ -167,6 +167,27 @@ "column": 15 } } + }, + { + "type": "ExportNamedDeclaration", + "declaration": null, + "exportKind": "value", + "source": null, + "specifiers": [], + "range": [ + 58, + 58 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 0 + } + } } ], "endTag": { diff --git a/tests/fixtures/parser/ast/ts-$$slots01-output.json b/tests/fixtures/parser/ast/ts-$$slots01-output.json index 5689b674..d03a7d92 100644 --- a/tests/fixtures/parser/ast/ts-$$slots01-output.json +++ b/tests/fixtures/parser/ast/ts-$$slots01-output.json @@ -132,6 +132,27 @@ "column": 11 } } + }, + { + "type": "ExportNamedDeclaration", + "declaration": null, + "exportKind": "value", + "source": null, + "specifiers": [], + "range": [ + 56, + 56 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 0 + } + } } ], "endTag": { diff --git a/tests/fixtures/parser/ast/ts-$$slots02-no-slot-output.json b/tests/fixtures/parser/ast/ts-$$slots02-no-slot-output.json index 24dbb472..40447797 100644 --- a/tests/fixtures/parser/ast/ts-$$slots02-no-slot-output.json +++ b/tests/fixtures/parser/ast/ts-$$slots02-no-slot-output.json @@ -132,6 +132,27 @@ "column": 11 } } + }, + { + "type": "ExportNamedDeclaration", + "declaration": null, + "exportKind": "value", + "source": null, + "specifiers": [], + "range": [ + 41, + 41 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 0 + } + } } ], "endTag": { diff --git a/tests/fixtures/parser/ast/ts-$$slots03-named-output.json b/tests/fixtures/parser/ast/ts-$$slots03-named-output.json index a47054d7..7c9193a9 100644 --- a/tests/fixtures/parser/ast/ts-$$slots03-named-output.json +++ b/tests/fixtures/parser/ast/ts-$$slots03-named-output.json @@ -132,6 +132,27 @@ "column": 11 } } + }, + { + "type": "ExportNamedDeclaration", + "declaration": null, + "exportKind": "value", + "source": null, + "specifiers": [], + "range": [ + 67, + 67 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 0 + } + } } ], "endTag": { diff --git a/tests/fixtures/parser/ast/ts-$$slots04-named-output.json b/tests/fixtures/parser/ast/ts-$$slots04-named-output.json index 270a43df..0ecafcd5 100644 --- a/tests/fixtures/parser/ast/ts-$$slots04-named-output.json +++ b/tests/fixtures/parser/ast/ts-$$slots04-named-output.json @@ -132,6 +132,27 @@ "column": 11 } } + }, + { + "type": "ExportNamedDeclaration", + "declaration": null, + "exportKind": "value", + "source": null, + "specifiers": [], + "range": [ + 92, + 92 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 0 + } + } } ], "endTag": { diff --git a/tests/fixtures/parser/ast/ts-issue226-output.json b/tests/fixtures/parser/ast/ts-issue226-output.json index 918e5895..0c822a08 100644 --- a/tests/fixtures/parser/ast/ts-issue226-output.json +++ b/tests/fixtures/parser/ast/ts-issue226-output.json @@ -1622,6 +1622,27 @@ "column": 74 } } + }, + { + "type": "ExportNamedDeclaration", + "declaration": null, + "exportKind": "value", + "source": null, + "specifiers": [], + "range": [ + 411, + 411 + ], + "loc": { + "start": { + "line": 16, + "column": 0 + }, + "end": { + "line": 16, + "column": 0 + } + } } ], "endTag": { From 605581178125d4d51587001acc33f90e26161363 Mon Sep 17 00:00:00 2001 From: baseballyama Date: Sun, 1 Dec 2024 15:05:04 +0900 Subject: [PATCH 2/2] fix --- src/parser/typescript/analyze/index.ts | 61 +++++++++++++++---- .../docs/runes/08-$props-ts-output.json | 21 ------- .../docs/runes/08-4-$bindable-ts-output.json | 21 ------- .../docs/runes/11-3-$inspect-ts-output.json | 21 ------- .../10-typing-snippets-type-output.svelte | 2 +- .../11-typing-snippets-type-output.svelte | 2 +- .../generics01-snippets-type-output.svelte | 2 +- .../svelte5/ts-$props01-type-output.svelte | 2 +- .../svelte5/ts-$props02-type-output.svelte | 2 +- .../ast/svelte5/ts-event03-type-output.svelte | 2 +- .../parser/ast/ts-$$props01-output.json | 21 ------- .../parser/ast/ts-$$slots01-output.json | 21 ------- .../ast/ts-$$slots02-no-slot-output.json | 21 ------- .../parser/ast/ts-$$slots03-named-output.json | 21 ------- .../parser/ast/ts-$$slots04-named-output.json | 21 ------- .../parser/ast/ts-issue226-output.json | 21 ------- 16 files changed, 55 insertions(+), 207 deletions(-) diff --git a/src/parser/typescript/analyze/index.ts b/src/parser/typescript/analyze/index.ts index 001305e7..6530e396 100644 --- a/src/parser/typescript/analyze/index.ts +++ b/src/parser/typescript/analyze/index.ts @@ -83,7 +83,7 @@ export function analyzeTypeScriptInSvelte( // When performing type checking on TypeScript code that is not a module, the error `Cannot redeclare block-scoped variable 'xxx'`. occurs. To fix this, add an `export`. // see: https://github.com/sveltejs/svelte-eslint-parser/issues/557 if (!hasExportDeclaration(result.ast)) { - ctx.appendVirtualScript("export {};"); + appendDummyExport(ctx); } ctx.appendOriginalToEnd(); @@ -337,6 +337,34 @@ function analyzeDollarDollarVariables( } } +/** Append dummy export */ +function appendDummyExport(ctx: VirtualTypeScriptContext) { + ctx.appendVirtualScript(`export namespace SvelteEslintParserModuleMarker {}`); + ctx.restoreContext.addRestoreStatementProcess((node, result) => { + if ( + node.type !== "ExportNamedDeclaration" || + node.declaration?.type !== "TSModuleDeclaration" || + node.declaration.kind !== "namespace" || + node.declaration.id.type !== "Identifier" || + node.declaration.id.name !== "SvelteEslintParserModuleMarker" + ) { + return false; + } + const program = result.ast; + program.body.splice(program.body.indexOf(node), 1); + + const scopeManager = result.scopeManager as ScopeManager; + + // Remove `declare` variable + removeAllScopeAndVariableAndReference(node, { + visitorKeys: result.visitorKeys, + scopeManager, + }); + + return true; + }); +} + /** * Analyze Runes. * Insert type definitions code to provide correct type information for Runes. @@ -398,7 +426,7 @@ function analyzeRuneVariables( // See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16/packages/svelte/types/index.d.ts#L2615 case "$props": { // Use type parameters to avoid `@typescript-eslint/no-unsafe-assignment` errors. - appendDeclareFunctionVirtualScripts(globalName, ["(): any"]); + appendDeclareFunctionVirtualScripts(globalName, ["(): T"]); break; } // See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16/packages/svelte/types/index.d.ts#L2626 @@ -587,24 +615,29 @@ function analyzeRenderScopes( ) { ctx.appendOriginal(code.script.length); const renderFunctionName = ctx.generateUniqueId("render"); - ctx.appendVirtualScript(`function ${renderFunctionName}(){`); + ctx.appendVirtualScript(`export function ${renderFunctionName}(){`); ctx.appendOriginal(code.script.length + code.render.length); ctx.appendVirtualScript(`}`); ctx.restoreContext.addRestoreStatementProcess((node, result) => { if ( - node.type !== "FunctionDeclaration" || - node.id.name !== renderFunctionName + node.type !== "ExportNamedDeclaration" || + node.declaration?.type !== "FunctionDeclaration" || + node.declaration?.id?.name !== renderFunctionName ) { return false; } const program = result.ast; - program.body.splice(program.body.indexOf(node), 1, ...node.body.body); - for (const body of node.body.body) { + program.body.splice( + program.body.indexOf(node), + 1, + ...node.declaration.body.body, + ); + for (const body of node.declaration.body.body) { body.parent = program; } const scopeManager = result.scopeManager as ScopeManager; - removeFunctionScope(node, scopeManager); + removeFunctionScope(node.declaration, scopeManager); return true; }); } @@ -861,7 +894,7 @@ function transformForReactiveStatement( const functionId = ctx.generateUniqueId("reactiveStatementScopeFunction"); const originalBody = statement.body; ctx.appendOriginal(originalBody.range[0]); - ctx.appendVirtualScript(`function ${functionId}(){`); + ctx.appendVirtualScript(`export function ${functionId}(){`); ctx.appendOriginal(originalBody.range[1]); ctx.appendVirtualScript(`}`); ctx.appendOriginal(statement.range[1]); @@ -872,14 +905,18 @@ function transformForReactiveStatement( } const reactiveStatement = node as TSESTree.LabeledStatement; const body = reactiveStatement.body; - if (body.type !== "FunctionDeclaration" || body.id.name !== functionId) { + if ( + body.type !== "ExportNamedDeclaration" || + body.declaration?.type !== "FunctionDeclaration" || + body.declaration?.id?.name !== functionId + ) { return false; } - reactiveStatement.body = body.body.body[0]; + reactiveStatement.body = body.declaration.body.body[0]; reactiveStatement.body.parent = reactiveStatement; const scopeManager = result.scopeManager as ScopeManager; - removeFunctionScope(body, scopeManager); + removeFunctionScope(body.declaration, scopeManager); return true; }); } diff --git a/tests/fixtures/parser/ast/svelte5/docs/runes/08-$props-ts-output.json b/tests/fixtures/parser/ast/svelte5/docs/runes/08-$props-ts-output.json index aab3a233..d2f3206c 100644 --- a/tests/fixtures/parser/ast/svelte5/docs/runes/08-$props-ts-output.json +++ b/tests/fixtures/parser/ast/svelte5/docs/runes/08-$props-ts-output.json @@ -502,27 +502,6 @@ "column": 57 } } - }, - { - "type": "ExportNamedDeclaration", - "declaration": null, - "exportKind": "value", - "source": null, - "specifiers": [], - "range": [ - 108, - 108 - ], - "loc": { - "start": { - "line": 5, - "column": 0 - }, - "end": { - "line": 5, - "column": 0 - } - } } ], "endTag": { diff --git a/tests/fixtures/parser/ast/svelte5/docs/runes/08-4-$bindable-ts-output.json b/tests/fixtures/parser/ast/svelte5/docs/runes/08-4-$bindable-ts-output.json index f0553447..909c38d4 100644 --- a/tests/fixtures/parser/ast/svelte5/docs/runes/08-4-$bindable-ts-output.json +++ b/tests/fixtures/parser/ast/svelte5/docs/runes/08-4-$bindable-ts-output.json @@ -427,27 +427,6 @@ "column": 75 } } - }, - { - "type": "ExportNamedDeclaration", - "declaration": null, - "exportKind": "value", - "source": null, - "specifiers": [], - "range": [ - 105, - 105 - ], - "loc": { - "start": { - "line": 4, - "column": 0 - }, - "end": { - "line": 4, - "column": 0 - } - } } ], "endTag": { diff --git a/tests/fixtures/parser/ast/svelte5/docs/runes/11-3-$inspect-ts-output.json b/tests/fixtures/parser/ast/svelte5/docs/runes/11-3-$inspect-ts-output.json index a6d0ca6d..3a146be6 100644 --- a/tests/fixtures/parser/ast/svelte5/docs/runes/11-3-$inspect-ts-output.json +++ b/tests/fixtures/parser/ast/svelte5/docs/runes/11-3-$inspect-ts-output.json @@ -394,27 +394,6 @@ "column": 38 } } - }, - { - "type": "ExportNamedDeclaration", - "declaration": null, - "exportKind": "value", - "source": null, - "specifiers": [], - "range": [ - 94, - 94 - ], - "loc": { - "start": { - "line": 6, - "column": 0 - }, - "end": { - "line": 6, - "column": 0 - } - } } ], "endTag": { diff --git a/tests/fixtures/parser/ast/svelte5/docs/snippets/10-typing-snippets-type-output.svelte b/tests/fixtures/parser/ast/svelte5/docs/snippets/10-typing-snippets-type-output.svelte index 2009d36a..0db3e719 100644 --- a/tests/fixtures/parser/ast/svelte5/docs/snippets/10-typing-snippets-type-output.svelte +++ b/tests/fixtures/parser/ast/svelte5/docs/snippets/10-typing-snippets-type-output.svelte @@ -5,7 +5,7 @@ data: any[]; // data: any[] children: Snippet; // Snippet: Snippet, children: Snippet<[]> row: Snippet<[any]>; // Snippet: Snippet, row: Snippet<[any]> - } = $props(); // $props(): any + } = $props(); // $props(): { data: any[]; children: Snippet<[]>; row: Snippet<[any]>; }
diff --git a/tests/fixtures/parser/ast/svelte5/docs/snippets/11-typing-snippets-type-output.svelte b/tests/fixtures/parser/ast/svelte5/docs/snippets/11-typing-snippets-type-output.svelte index 204db6f5..3396ed9b 100644 --- a/tests/fixtures/parser/ast/svelte5/docs/snippets/11-typing-snippets-type-output.svelte +++ b/tests/fixtures/parser/ast/svelte5/docs/snippets/11-typing-snippets-type-output.svelte @@ -5,7 +5,7 @@ data: T[]; // T: unknown, data: unknown[] children: Snippet; // Snippet: Snippet, children: Snippet<[]> row: Snippet<[T]>; // Snippet: Snippet, T: unknown, row: Snippet<[unknown]> - } = $props(); // $props(): any + } = $props(); // $props(): { data: unknown[]; children: Snippet<[]>; row: Snippet<[unknown]>; }
diff --git a/tests/fixtures/parser/ast/svelte5/generics01-snippets-type-output.svelte b/tests/fixtures/parser/ast/svelte5/generics01-snippets-type-output.svelte index 9511f75b..73fb2bc4 100644 --- a/tests/fixtures/parser/ast/svelte5/generics01-snippets-type-output.svelte +++ b/tests/fixtures/parser/ast/svelte5/generics01-snippets-type-output.svelte @@ -6,7 +6,7 @@ data: A[]; // A: unknown, data: unknown[] children: Snippet; // Snippet: Snippet, children: Snippet<[]> row: Snippet<[A]>; // Snippet: Snippet, A: unknown, row: Snippet<[unknown]> - } = $props(); // $props(): any + } = $props(); // $props(): { data: unknown[]; children: Snippet<[]>; row: Snippet<[unknown]>; }
diff --git a/tests/fixtures/parser/ast/svelte5/ts-$props01-type-output.svelte b/tests/fixtures/parser/ast/svelte5/ts-$props01-type-output.svelte index 5bccb22f..ff36a150 100644 --- a/tests/fixtures/parser/ast/svelte5/ts-$props01-type-output.svelte +++ b/tests/fixtures/parser/ast/svelte5/ts-$props01-type-output.svelte @@ -5,7 +5,7 @@ c: boolean; // c: boolean d: number; // d: number } - let { a, b, c, ...everythingElse }: MyProps = $props(); // a: number, a: number, b: string, b: string, c: boolean, c: boolean, everythingElse: { d: number; }, MyProps: MyProps, $props(): any + let { a, b, c, ...everythingElse }: MyProps = $props(); // a: number, a: number, b: string, b: string, c: boolean, c: boolean, everythingElse: { d: number; }, MyProps: MyProps, $props(): MyProps {a} diff --git a/tests/fixtures/parser/ast/svelte5/ts-$props02-type-output.svelte b/tests/fixtures/parser/ast/svelte5/ts-$props02-type-output.svelte index 018fe64f..82485298 100644 --- a/tests/fixtures/parser/ast/svelte5/ts-$props02-type-output.svelte +++ b/tests/fixtures/parser/ast/svelte5/ts-$props02-type-output.svelte @@ -1,5 +1,5 @@ {name} diff --git a/tests/fixtures/parser/ast/svelte5/ts-event03-type-output.svelte b/tests/fixtures/parser/ast/svelte5/ts-event03-type-output.svelte index e56a63cf..72c2a943 100644 --- a/tests/fixtures/parser/ast/svelte5/ts-event03-type-output.svelte +++ b/tests/fixtures/parser/ast/svelte5/ts-event03-type-output.svelte @@ -1,7 +1,7 @@ diff --git a/tests/fixtures/parser/ast/ts-$$props01-output.json b/tests/fixtures/parser/ast/ts-$$props01-output.json index 6a9ef749..958c6abc 100644 --- a/tests/fixtures/parser/ast/ts-$$props01-output.json +++ b/tests/fixtures/parser/ast/ts-$$props01-output.json @@ -167,27 +167,6 @@ "column": 15 } } - }, - { - "type": "ExportNamedDeclaration", - "declaration": null, - "exportKind": "value", - "source": null, - "specifiers": [], - "range": [ - 58, - 58 - ], - "loc": { - "start": { - "line": 6, - "column": 0 - }, - "end": { - "line": 6, - "column": 0 - } - } } ], "endTag": { diff --git a/tests/fixtures/parser/ast/ts-$$slots01-output.json b/tests/fixtures/parser/ast/ts-$$slots01-output.json index d03a7d92..5689b674 100644 --- a/tests/fixtures/parser/ast/ts-$$slots01-output.json +++ b/tests/fixtures/parser/ast/ts-$$slots01-output.json @@ -132,27 +132,6 @@ "column": 11 } } - }, - { - "type": "ExportNamedDeclaration", - "declaration": null, - "exportKind": "value", - "source": null, - "specifiers": [], - "range": [ - 56, - 56 - ], - "loc": { - "start": { - "line": 6, - "column": 0 - }, - "end": { - "line": 6, - "column": 0 - } - } } ], "endTag": { diff --git a/tests/fixtures/parser/ast/ts-$$slots02-no-slot-output.json b/tests/fixtures/parser/ast/ts-$$slots02-no-slot-output.json index 40447797..24dbb472 100644 --- a/tests/fixtures/parser/ast/ts-$$slots02-no-slot-output.json +++ b/tests/fixtures/parser/ast/ts-$$slots02-no-slot-output.json @@ -132,27 +132,6 @@ "column": 11 } } - }, - { - "type": "ExportNamedDeclaration", - "declaration": null, - "exportKind": "value", - "source": null, - "specifiers": [], - "range": [ - 41, - 41 - ], - "loc": { - "start": { - "line": 4, - "column": 0 - }, - "end": { - "line": 4, - "column": 0 - } - } } ], "endTag": { diff --git a/tests/fixtures/parser/ast/ts-$$slots03-named-output.json b/tests/fixtures/parser/ast/ts-$$slots03-named-output.json index 7c9193a9..a47054d7 100644 --- a/tests/fixtures/parser/ast/ts-$$slots03-named-output.json +++ b/tests/fixtures/parser/ast/ts-$$slots03-named-output.json @@ -132,27 +132,6 @@ "column": 11 } } - }, - { - "type": "ExportNamedDeclaration", - "declaration": null, - "exportKind": "value", - "source": null, - "specifiers": [], - "range": [ - 67, - 67 - ], - "loc": { - "start": { - "line": 6, - "column": 0 - }, - "end": { - "line": 6, - "column": 0 - } - } } ], "endTag": { diff --git a/tests/fixtures/parser/ast/ts-$$slots04-named-output.json b/tests/fixtures/parser/ast/ts-$$slots04-named-output.json index 0ecafcd5..270a43df 100644 --- a/tests/fixtures/parser/ast/ts-$$slots04-named-output.json +++ b/tests/fixtures/parser/ast/ts-$$slots04-named-output.json @@ -132,27 +132,6 @@ "column": 11 } } - }, - { - "type": "ExportNamedDeclaration", - "declaration": null, - "exportKind": "value", - "source": null, - "specifiers": [], - "range": [ - 92, - 92 - ], - "loc": { - "start": { - "line": 7, - "column": 0 - }, - "end": { - "line": 7, - "column": 0 - } - } } ], "endTag": { diff --git a/tests/fixtures/parser/ast/ts-issue226-output.json b/tests/fixtures/parser/ast/ts-issue226-output.json index 0c822a08..918e5895 100644 --- a/tests/fixtures/parser/ast/ts-issue226-output.json +++ b/tests/fixtures/parser/ast/ts-issue226-output.json @@ -1622,27 +1622,6 @@ "column": 74 } } - }, - { - "type": "ExportNamedDeclaration", - "declaration": null, - "exportKind": "value", - "source": null, - "specifiers": [], - "range": [ - 411, - 411 - ], - "loc": { - "start": { - "line": 16, - "column": 0 - }, - "end": { - "line": 16, - "column": 0 - } - } } ], "endTag": {