From 4a3e3a2135c8ef3887b4d7b0c40608aac5414308 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 20 Mar 2025 06:28:46 +0000 Subject: [PATCH 01/23] chore(deps): update typescript-eslint monorepo to ~8.27.0 (#688) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7d0c438a..3881e5b0 100644 --- a/package.json +++ b/package.json @@ -78,8 +78,8 @@ "@types/node": "^22.10.1", "@types/semver": "^7.5.8", "@typescript-eslint/eslint-plugin": "^8.16.0", - "@typescript-eslint/parser": "~8.26.0", - "@typescript-eslint/types": "~8.26.0", + "@typescript-eslint/parser": "~8.27.0", + "@typescript-eslint/types": "~8.27.0", "benchmark": "^2.1.4", "c8": "^10.1.2", "chai": "^5.0.0", From 883ba2ab98a2f634e17e4890e91bf1159b6eb916 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 24 Mar 2025 22:24:19 +0000 Subject: [PATCH 02/23] chore(deps): update typescript-eslint monorepo to ~8.28.0 (#690) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 3881e5b0..31b8ff0c 100644 --- a/package.json +++ b/package.json @@ -78,8 +78,8 @@ "@types/node": "^22.10.1", "@types/semver": "^7.5.8", "@typescript-eslint/eslint-plugin": "^8.16.0", - "@typescript-eslint/parser": "~8.27.0", - "@typescript-eslint/types": "~8.27.0", + "@typescript-eslint/parser": "~8.28.0", + "@typescript-eslint/types": "~8.28.0", "benchmark": "^2.1.4", "c8": "^10.1.2", "chai": "^5.0.0", From c5fe76965b1152a0a146830a796ff59f0ad1803f Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 25 Mar 2025 02:42:27 +0000 Subject: [PATCH 03/23] chore(deps): update dependency eslint to ~9.23.0 (#689) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 31b8ff0c..30675f3b 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "chai": "^5.0.0", "env-cmd": "^10.1.0", "esbuild": "^0.25.0", - "eslint": "~9.22.0", + "eslint": "~9.23.0", "eslint-config-prettier": "^10.0.0", "eslint-plugin-eslint-comments": "^3.2.0", "eslint-plugin-jsdoc": "^50.6.0", From 1c533d8929c57f3bba5e97bc4d1aee06ddd9cdd0 Mon Sep 17 00:00:00 2001 From: Yuichiro Yamashita Date: Thu, 27 Mar 2025 10:46:36 +0900 Subject: [PATCH 04/23] fix: resolved issue of `$props` incorrectly detected as store when using variables named after runes like `$props` and `props` (#692) --- .changeset/icy-pianos-film.md | 5 + src/parser/analyze-scope.ts | 13 +- src/parser/index.ts | 4 +- ...ps-without-destructuring-runes-config.json | 7 + ...s-without-destructuring-runes-input.svelte | 6 + ...ps-without-destructuring-runes-output.json | 785 ++++++++++++++++++ ...hout-destructuring-runes-scope-output.json | 429 ++++++++++ ...ut-destructuring-without-runes-config.json | 7 + ...t-destructuring-without-runes-input.svelte | 6 + ...ut-destructuring-without-runes-output.json | 785 ++++++++++++++++++ ...tructuring-without-runes-scope-output.json | 396 +++++++++ 11 files changed, 2439 insertions(+), 4 deletions(-) create mode 100644 .changeset/icy-pianos-film.md create mode 100644 tests/fixtures/parser/ast/svelte5/$props-without-destructuring-runes-config.json create mode 100644 tests/fixtures/parser/ast/svelte5/$props-without-destructuring-runes-input.svelte create mode 100644 tests/fixtures/parser/ast/svelte5/$props-without-destructuring-runes-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/$props-without-destructuring-runes-scope-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/$props-without-destructuring-without-runes-config.json create mode 100644 tests/fixtures/parser/ast/svelte5/$props-without-destructuring-without-runes-input.svelte create mode 100644 tests/fixtures/parser/ast/svelte5/$props-without-destructuring-without-runes-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/$props-without-destructuring-without-runes-scope-output.json diff --git a/.changeset/icy-pianos-film.md b/.changeset/icy-pianos-film.md new file mode 100644 index 00000000..90fbe471 --- /dev/null +++ b/.changeset/icy-pianos-film.md @@ -0,0 +1,5 @@ +--- +"svelte-eslint-parser": patch +--- + +fix: resolved issue of `$props` incorrectly detected as store when using variables named after runes like `$props` and `props` diff --git a/src/parser/analyze-scope.ts b/src/parser/analyze-scope.ts index 01fc9ab4..2182f0b0 100644 --- a/src/parser/analyze-scope.ts +++ b/src/parser/analyze-scope.ts @@ -16,6 +16,7 @@ import { import { addElementToSortedArray } from "../utils/index.js"; import type { NormalizedParserOptions } from "./parser-options.js"; import type { SvelteParseContext } from "./svelte-parse-context.js"; +import { getGlobalsForSvelte } from "./globals.js"; /** * Analyze scope */ @@ -105,7 +106,10 @@ export function analyzeReactiveScope(scopeManager: ScopeManager): void { /** * Analyze store scope. e.g. $count */ -export function analyzeStoreScope(scopeManager: ScopeManager): void { +export function analyzeStoreScope( + scopeManager: ScopeManager, + svelteParseContext: SvelteParseContext, +): void { const moduleScope = scopeManager.scopes.find( (scope) => scope.type === "module", ); @@ -114,8 +118,13 @@ export function analyzeStoreScope(scopeManager: ScopeManager): void { } const toBeMarkAsUsedReferences: Reference[] = []; + const globals = getGlobalsForSvelte(svelteParseContext); + for (const reference of [...scopeManager.globalScope.through]) { - if (reference.identifier.name.startsWith("$")) { + if ( + reference.identifier.name.startsWith("$") && + !globals.includes(reference.identifier.name as never) + ) { const realName = reference.identifier.name.slice(1); const variable = moduleScope.set.get(realName); if (variable) { diff --git a/src/parser/index.ts b/src/parser/index.ts index 641468cf..601e2914 100644 --- a/src/parser/index.ts +++ b/src/parser/index.ts @@ -170,9 +170,9 @@ function parseAsSvelte( sortNodes(ctx.comments); sortNodes(ctx.tokens); extractTokens(ctx); - analyzeStoreScope(resultScript.scopeManager!); + analyzeStoreScope(resultScript.scopeManager!, svelteParseContext); analyzeReactiveScope(resultScript.scopeManager!); - analyzeStoreScope(resultScript.scopeManager!); // for reactive vars + analyzeStoreScope(resultScript.scopeManager!, svelteParseContext); // for reactive vars analyzeSnippetsScope(ctx.snippets, resultScript.scopeManager!); // Add $$xxx variable diff --git a/tests/fixtures/parser/ast/svelte5/$props-without-destructuring-runes-config.json b/tests/fixtures/parser/ast/svelte5/$props-without-destructuring-runes-config.json new file mode 100644 index 00000000..623877c3 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/$props-without-destructuring-runes-config.json @@ -0,0 +1,7 @@ +{ + "svelteConfig": { + "compilerOptions": { + "runes": true + } + } +} diff --git a/tests/fixtures/parser/ast/svelte5/$props-without-destructuring-runes-input.svelte b/tests/fixtures/parser/ast/svelte5/$props-without-destructuring-runes-input.svelte new file mode 100644 index 00000000..ee5502fb --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/$props-without-destructuring-runes-input.svelte @@ -0,0 +1,6 @@ + + +{props} diff --git a/tests/fixtures/parser/ast/svelte5/$props-without-destructuring-runes-output.json b/tests/fixtures/parser/ast/svelte5/$props-without-destructuring-runes-output.json new file mode 100644 index 00000000..7d51d648 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/$props-without-destructuring-runes-output.json @@ -0,0 +1,785 @@ +{ + "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": [], + "selfClosing": false, + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + "body": [ + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "props", + "range": [ + 60, + 65 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + "init": { + "type": "CallExpression", + "arguments": [], + "callee": { + "type": "Identifier", + "name": "$props", + "range": [ + 68, + 74 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 21 + } + } + }, + "optional": false, + "range": [ + 68, + 76 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + "range": [ + 60, + 76 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 23 + } + } + } + ], + "range": [ + 54, + 77 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 24 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 78, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 9 + } + } + }, + "range": [ + 0, + 87 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 87, + 89 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 6, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "span", + "range": [ + 90, + 94 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 5 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [], + "selfClosing": false, + "range": [ + 89, + 95 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 6 + } + } + }, + "children": [ + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "Identifier", + "name": "props", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 12 + } + } + }, + "range": [ + 95, + 102 + ], + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 13 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 102, + 109 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 20 + } + } + }, + "range": [ + 89, + 109 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 20 + } + } + } + ], + "sourceType": "module", + "comments": [ + { + "type": "Line", + "value": " It should not be recognized as a store.", + "range": [ + 10, + 52 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 43 + } + } + } + ], + "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": "Punctuator", + "value": ">", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + { + "type": "Keyword", + "value": "const", + "range": [ + 54, + 59 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 6 + } + } + }, + { + "type": "Identifier", + "value": "props", + "range": [ + 60, + 65 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 66, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "$props", + "range": [ + 68, + 74 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 22 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 75, + 76 + ], + "loc": { + "start": { + "line": 3, + "column": 22 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 76, + 77 + ], + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 78, + 79 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 79, + 80 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 80, + 86 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 86, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 87, + 89 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 6, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 89, + 90 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "span", + "range": [ + 90, + 94 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 94, + 95 + ], + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 95, + 96 + ], + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 7 + } + } + }, + { + "type": "Identifier", + "value": "props", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 101, + 102 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 103, + 104 + ], + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 15 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "span", + "range": [ + 104, + 108 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 108, + 109 + ], + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 6, + "column": 20 + } + } + } + ], + "range": [ + 0, + 110 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/$props-without-destructuring-runes-scope-output.json b/tests/fixtures/parser/ast/svelte5/$props-without-destructuring-runes-scope-output.json new file mode 100644 index 00000000..0c95113b --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/$props-without-destructuring-runes-scope-output.json @@ -0,0 +1,429 @@ +{ + "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": [ + 68, + 74 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 21 + } + } + }, + "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": "props", + "identifiers": [ + { + "type": "Identifier", + "name": "props", + "range": [ + 60, + 65 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "props", + "range": [ + 60, + 65 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "props", + "range": [ + 60, + 65 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + "init": { + "type": "CallExpression", + "arguments": [], + "callee": { + "type": "Identifier", + "name": "$props", + "range": [ + 68, + 74 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 21 + } + } + }, + "optional": false, + "range": [ + 68, + 76 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + "range": [ + 60, + 76 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 23 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "props", + "range": [ + 60, + 65 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "props", + "range": [ + 60, + 65 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "props", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 12 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "props", + "range": [ + 60, + 65 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "props", + "range": [ + 60, + 65 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "props", + "range": [ + 60, + 65 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "$props", + "range": [ + 68, + 74 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 21 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "props", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 12 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "props", + "range": [ + 60, + 65 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + } + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "$props", + "range": [ + 68, + 74 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 21 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] + } + ], + "through": [] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/$props-without-destructuring-without-runes-config.json b/tests/fixtures/parser/ast/svelte5/$props-without-destructuring-without-runes-config.json new file mode 100644 index 00000000..f5145143 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/$props-without-destructuring-without-runes-config.json @@ -0,0 +1,7 @@ +{ + "svelteConfig": { + "compilerOptions": { + "runes": false + } + } +} diff --git a/tests/fixtures/parser/ast/svelte5/$props-without-destructuring-without-runes-input.svelte b/tests/fixtures/parser/ast/svelte5/$props-without-destructuring-without-runes-input.svelte new file mode 100644 index 00000000..0ef437b2 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/$props-without-destructuring-without-runes-input.svelte @@ -0,0 +1,6 @@ + + +{props} diff --git a/tests/fixtures/parser/ast/svelte5/$props-without-destructuring-without-runes-output.json b/tests/fixtures/parser/ast/svelte5/$props-without-destructuring-without-runes-output.json new file mode 100644 index 00000000..ef78b834 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/$props-without-destructuring-without-runes-output.json @@ -0,0 +1,785 @@ +{ + "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": [], + "selfClosing": false, + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + "body": [ + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "props", + "range": [ + 56, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + "init": { + "type": "CallExpression", + "arguments": [], + "callee": { + "type": "Identifier", + "name": "$props", + "range": [ + 64, + 70 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 21 + } + } + }, + "optional": false, + "range": [ + 64, + 72 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + "range": [ + 56, + 72 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 23 + } + } + } + ], + "range": [ + 50, + 73 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 24 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 74, + 83 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 9 + } + } + }, + "range": [ + 0, + 83 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 83, + 85 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 6, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "span", + "range": [ + 86, + 90 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 5 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [], + "selfClosing": false, + "range": [ + 85, + 91 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 6 + } + } + }, + "children": [ + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "Identifier", + "name": "props", + "range": [ + 92, + 97 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 12 + } + } + }, + "range": [ + 91, + 98 + ], + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 13 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 98, + 105 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 20 + } + } + }, + "range": [ + 85, + 105 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 20 + } + } + } + ], + "sourceType": "module", + "comments": [ + { + "type": "Line", + "value": " It should be recognized as a store.", + "range": [ + 10, + 48 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 39 + } + } + } + ], + "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": "Punctuator", + "value": ">", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + { + "type": "Keyword", + "value": "const", + "range": [ + 50, + 55 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 6 + } + } + }, + { + "type": "Identifier", + "value": "props", + "range": [ + 56, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 62, + 63 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "$props", + "range": [ + 64, + 70 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 70, + 71 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 22 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 71, + 72 + ], + "loc": { + "start": { + "line": 3, + "column": 22 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 72, + 73 + ], + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 75, + 76 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 76, + 82 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 82, + 83 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 83, + 85 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 6, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 85, + 86 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "span", + "range": [ + 86, + 90 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 90, + 91 + ], + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 91, + 92 + ], + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 7 + } + } + }, + { + "type": "Identifier", + "value": "props", + "range": [ + 92, + 97 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 97, + 98 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 98, + 99 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 99, + 100 + ], + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 15 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "span", + "range": [ + 100, + 104 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 6, + "column": 20 + } + } + } + ], + "range": [ + 0, + 106 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/$props-without-destructuring-without-runes-scope-output.json b/tests/fixtures/parser/ast/svelte5/$props-without-destructuring-without-runes-scope-output.json new file mode 100644 index 00000000..dffec93b --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/$props-without-destructuring-without-runes-scope-output.json @@ -0,0 +1,396 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "props", + "identifiers": [ + { + "type": "Identifier", + "name": "props", + "range": [ + 56, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "props", + "range": [ + 56, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "props", + "range": [ + 56, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + "init": { + "type": "CallExpression", + "arguments": [], + "callee": { + "type": "Identifier", + "name": "$props", + "range": [ + 64, + 70 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 21 + } + } + }, + "optional": false, + "range": [ + 64, + 72 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + "range": [ + 56, + 72 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 23 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "props", + "range": [ + 56, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "props", + "range": [ + 56, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "$props", + "range": [ + 64, + 70 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 21 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "props", + "range": [ + 56, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "props", + "range": [ + 92, + 97 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 12 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "props", + "range": [ + 56, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "props", + "range": [ + 56, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "props", + "range": [ + 56, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "$props", + "range": [ + 64, + 70 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 21 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "props", + "range": [ + 56, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "props", + "range": [ + 92, + 97 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 12 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "props", + "range": [ + 56, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + } + } + ], + "childScopes": [], + "through": [] + } + ], + "through": [] +} \ No newline at end of file From 49b9c80dc347262f4c49cfa136cbbc74178805cd Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 27 Mar 2025 10:47:51 +0900 Subject: [PATCH 05/23] chore(deps): update pnpm/action-setup action to v4 (#691) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .github/workflows/GHPages.yml | 2 +- .github/workflows/NodeCI.yml | 14 +++++++------- .github/workflows/Release.yml | 2 +- .github/workflows/format.yml | 2 +- .github/workflows/pkg.pr.new.yml | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/GHPages.yml b/.github/workflows/GHPages.yml index c0a73137..a326867e 100644 --- a/.github/workflows/GHPages.yml +++ b/.github/workflows/GHPages.yml @@ -25,7 +25,7 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 - uses: actions/setup-node@v4 - name: Install And Build run: |+ diff --git a/.github/workflows/NodeCI.yml b/.github/workflows/NodeCI.yml index 8eb55fc1..70490c12 100644 --- a/.github/workflows/NodeCI.yml +++ b/.github/workflows/NodeCI.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 - uses: actions/setup-node@v4 - name: Install Packages run: pnpm install @@ -26,7 +26,7 @@ jobs: node-version: [18.x, 20.x, 22.x, latest] steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 with: @@ -39,7 +39,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 - name: Use Node.js uses: actions/setup-node@v4 - name: Install Packages @@ -51,7 +51,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 - name: Use Node.js uses: actions/setup-node@v4 - name: Install Svelte v4 @@ -70,7 +70,7 @@ jobs: node-version: [18.x] steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 with: @@ -87,7 +87,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 - uses: actions/setup-node@v4 - name: Install Packages run: pnpm install @@ -101,7 +101,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 - uses: actions/setup-node@v4 - name: Install Packages run: pnpm install diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index 5c8fefa8..5aa84503 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -22,7 +22,7 @@ jobs: fetch-depth: 0 - name: Setup pnpm - uses: pnpm/action-setup@v2 + uses: pnpm/action-setup@v4 - name: Setup Node.js uses: actions/setup-node@v4 diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index c0b82e21..1e60d6a8 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 - uses: actions/setup-node@v4 - name: Install Packages run: pnpm install diff --git a/.github/workflows/pkg.pr.new.yml b/.github/workflows/pkg.pr.new.yml index 20d5d4aa..27864d31 100644 --- a/.github/workflows/pkg.pr.new.yml +++ b/.github/workflows/pkg.pr.new.yml @@ -13,7 +13,7 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 - uses: actions/setup-node@v4 - name: Install Packages run: pnpm install From 0df76be11c474c7c239648519f07dd07ba7afb5d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 27 Mar 2025 10:48:43 +0900 Subject: [PATCH 06/23] chore: release svelte-eslint-parser (#693) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .changeset/icy-pianos-film.md | 5 ----- CHANGELOG.md | 6 ++++++ package.json | 2 +- src/meta.ts | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) delete mode 100644 .changeset/icy-pianos-film.md diff --git a/.changeset/icy-pianos-film.md b/.changeset/icy-pianos-film.md deleted file mode 100644 index 90fbe471..00000000 --- a/.changeset/icy-pianos-film.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"svelte-eslint-parser": patch ---- - -fix: resolved issue of `$props` incorrectly detected as store when using variables named after runes like `$props` and `props` diff --git a/CHANGELOG.md b/CHANGELOG.md index d0640c7b..06414798 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # svelte-eslint-parser +## 1.1.1 + +### Patch Changes + +- [#692](https://github.com/sveltejs/svelte-eslint-parser/pull/692) [`1c533d8`](https://github.com/sveltejs/svelte-eslint-parser/commit/1c533d8929c57f3bba5e97bc4d1aee06ddd9cdd0) Thanks [@baseballyama](https://github.com/baseballyama)! - fix: resolved issue of `$props` incorrectly detected as store when using variables named after runes like `$props` and `props` + ## 1.1.0 ### Minor Changes diff --git a/package.json b/package.json index 30675f3b..7d9ffddc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svelte-eslint-parser", - "version": "1.1.0", + "version": "1.1.1", "description": "Svelte parser for ESLint", "repository": "git+https://github.com/sveltejs/svelte-eslint-parser.git", "homepage": "https://github.com/sveltejs/svelte-eslint-parser#readme", diff --git a/src/meta.ts b/src/meta.ts index 9628bc65..cb4ca736 100644 --- a/src/meta.ts +++ b/src/meta.ts @@ -2,4 +2,4 @@ // This file has been automatically generated, // in order to update its content execute "pnpm run build:meta" export const name = "svelte-eslint-parser"; -export const version = "1.1.0"; +export const version = "1.1.1"; From 73479f9dd3ca7c27cd0ce9a65f4885b13c0132de Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 27 Mar 2025 10:59:43 +0900 Subject: [PATCH 07/23] chore(deps): update dependency eslint-plugin-svelte to v3 (#678) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: yosuke ota --- explorer-v2/src/lib/AstExplorer.svelte | 23 ++++---- explorer-v2/src/lib/ESLintPlayground.svelte | 23 ++++---- explorer-v2/src/lib/MonacoEditor.svelte | 33 ++++++------ explorer-v2/src/lib/ScopeExplorer.svelte | 23 ++++---- package.json | 58 ++++++++++----------- 5 files changed, 82 insertions(+), 78 deletions(-) diff --git a/explorer-v2/src/lib/AstExplorer.svelte b/explorer-v2/src/lib/AstExplorer.svelte index 66ff7746..53191731 100644 --- a/explorer-v2/src/lib/AstExplorer.svelte +++ b/explorer-v2/src/lib/AstExplorer.svelte @@ -29,19 +29,20 @@ ); let tsParser = undefined; + function setTSParser(parser) { + if (typeof window !== 'undefined') { + if (!window.process) { + window.process = { + cwd: () => '', + env: {} + }; + } + } + tsParser = parser; + } $: { if (hasLangTs && !tsParser) { - import('@typescript-eslint/parser').then((parser) => { - if (typeof window !== 'undefined') { - if (!window.process) { - window.process = { - cwd: () => '', - env: {} - }; - } - } - tsParser = parser; - }); + import('@typescript-eslint/parser').then(setTSParser); } } diff --git a/explorer-v2/src/lib/ESLintPlayground.svelte b/explorer-v2/src/lib/ESLintPlayground.svelte index 6905ab06..dacaa2d3 100644 --- a/explorer-v2/src/lib/ESLintPlayground.svelte +++ b/explorer-v2/src/lib/ESLintPlayground.svelte @@ -34,19 +34,20 @@ $: hasLangTs = /lang\s*=\s*(?:"ts"|ts|'ts'|"typescript"|typescript|'typescript')/u.test(code); let tsParser = undefined; + function setTSParser(parser) { + if (typeof window !== 'undefined') { + if (!window.process) { + window.process = { + cwd: () => '', + env: {} + }; + } + } + tsParser = parser; + } $: { if (hasLangTs && !tsParser) { - import('@typescript-eslint/parser').then((parser) => { - if (typeof window !== 'undefined') { - if (!window.process) { - window.process = { - cwd: () => '', - env: {} - }; - } - } - tsParser = parser; - }); + import('@typescript-eslint/parser').then(setTSParser); } } diff --git a/explorer-v2/src/lib/MonacoEditor.svelte b/explorer-v2/src/lib/MonacoEditor.svelte index 97246e99..3db6ffa5 100644 --- a/explorer-v2/src/lib/MonacoEditor.svelte +++ b/explorer-v2/src/lib/MonacoEditor.svelte @@ -54,22 +54,7 @@ $: { disposeCodeActionProvider(); if (provideCodeActions) { - loadingMonaco.then((monaco) => { - codeActionProviderDisposable = monaco.languages.registerCodeActionProvider(language, { - provideCodeActions(model, range, context) { - const editor = getLeftEditor?.(); - if (editor?.getModel().url !== model.url) { - return { - actions: [], - dispose() { - /* nop */ - } - }; - } - return provideCodeActions(model, range, context); - } - }); - }); + loadingMonaco.then((monaco) => setupCodeActionProvider(monaco, provideCodeActions)); } } @@ -216,6 +201,22 @@ } } + function setupCodeActionProvider(monaco, provideCodeActions) { + codeActionProviderDisposable = monaco.languages.registerCodeActionProvider(language, { + provideCodeActions(model, range, context) { + const editor = getLeftEditor?.(); + if (editor?.getModel().url !== model.url) { + return { + actions: [], + dispose() { + /* nop */ + } + }; + } + return provideCodeActions(model, range, context); + } + }); + } function disposeCodeActionProvider() { if (codeActionProviderDisposable) { codeActionProviderDisposable.dispose(); diff --git a/explorer-v2/src/lib/ScopeExplorer.svelte b/explorer-v2/src/lib/ScopeExplorer.svelte index ecf361f8..263661a9 100644 --- a/explorer-v2/src/lib/ScopeExplorer.svelte +++ b/explorer-v2/src/lib/ScopeExplorer.svelte @@ -28,19 +28,20 @@ svelteValue ); let tsParser = undefined; + function setTSParser(parser) { + if (typeof window !== 'undefined') { + if (!window.process) { + window.process = { + cwd: () => '', + env: {} + }; + } + } + tsParser = parser; + } $: { if (hasLangTs && !tsParser) { - import('@typescript-eslint/parser').then((parser) => { - if (typeof window !== 'undefined') { - if (!window.process) { - window.process = { - cwd: () => '', - env: {} - }; - } - } - tsParser = parser; - }); + import('@typescript-eslint/parser').then(setTSParser); } } $: { diff --git a/package.json b/package.json index 7d9ffddc..190eed0e 100644 --- a/package.json +++ b/package.json @@ -63,54 +63,54 @@ "postcss-selector-parser": "^7.0.0" }, "devDependencies": { - "@changesets/changelog-github": "^0.5.0", - "@changesets/cli": "^2.27.10", - "@changesets/get-release-plan": "^4.0.5", + "@changesets/changelog-github": "^0.5.1", + "@changesets/cli": "^2.28.1", + "@changesets/get-release-plan": "^4.0.8", "@ota-meshi/eslint-plugin": "^0.17.6", "@ota-meshi/test-snapshot": "^1.1.0", "@types/benchmark": "^2.1.5", - "@types/chai": "^5.0.0", + "@types/chai": "^5.2.1", "@types/eslint": "^9.6.1", "@types/eslint-scope": "^3.7.7", "@types/eslint-visitor-keys": "^3.3.2", - "@types/estree": "^1.0.6", + "@types/estree": "^1.0.7", "@types/mocha": "^10.0.10", - "@types/node": "^22.10.1", - "@types/semver": "^7.5.8", - "@typescript-eslint/eslint-plugin": "^8.16.0", + "@types/node": "^22.13.13", + "@types/semver": "^7.7.0", + "@typescript-eslint/eslint-plugin": "^8.28.0", "@typescript-eslint/parser": "~8.28.0", "@typescript-eslint/types": "~8.28.0", "benchmark": "^2.1.4", - "c8": "^10.1.2", - "chai": "^5.0.0", + "c8": "^10.1.3", + "chai": "^5.2.0", "env-cmd": "^10.1.0", - "esbuild": "^0.25.0", + "esbuild": "^0.25.1", "eslint": "~9.23.0", - "eslint-config-prettier": "^10.0.0", + "eslint-config-prettier": "^10.1.1", "eslint-plugin-eslint-comments": "^3.2.0", - "eslint-plugin-jsdoc": "^50.6.0", - "eslint-plugin-json-schema-validator": "^5.2.0", - "eslint-plugin-jsonc": "^2.18.2", - "eslint-plugin-n": "^17.14.0", + "eslint-plugin-jsdoc": "^50.6.9", + "eslint-plugin-json-schema-validator": "^5.3.1", + "eslint-plugin-jsonc": "^2.20.0", + "eslint-plugin-n": "^17.17.0", "eslint-plugin-node-dependencies": "^0.12.0", - "eslint-plugin-prettier": "^5.2.1", + "eslint-plugin-prettier": "^5.2.5", "eslint-plugin-regexp": "^2.7.0", - "eslint-plugin-svelte": "^2.46.1", - "eslint-plugin-yml": "^1.16.0", + "eslint-plugin-svelte": "^3.3.3", + "eslint-plugin-yml": "^1.17.0", "globals": "^16.0.0", "locate-character": "^3.0.0", - "magic-string": "^0.30.14", - "mocha": "^11.0.0", - "prettier": "~3.5.0", + "magic-string": "^0.30.17", + "mocha": "^11.1.0", + "prettier": "~3.5.3", "prettier-plugin-pkg": "^0.18.1", - "prettier-plugin-svelte": "^3.3.2", + "prettier-plugin-svelte": "^3.3.3", "rimraf": "^6.0.1", - "semver": "^7.6.3", - "svelte": "^5.9.0", - "svelte2tsx": "^0.7.28", - "tsx": "^4.19.2", - "typescript": "~5.8.0", - "typescript-eslint": "^8.16.0", + "semver": "^7.7.1", + "svelte": "^5.25.3", + "svelte2tsx": "^0.7.35", + "tsx": "^4.19.3", + "typescript": "~5.8.2", + "typescript-eslint": "^8.28.0", "typescript-eslint-parser-for-extra-files": "^0.7.0" }, "publishConfig": { From 00549ff7bf5f670534c7ea5e60856e68afcfe8bd Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Sat, 29 Mar 2025 15:39:02 +0000 Subject: [PATCH 08/23] perf: iterate children using a for loop (#694) --- src/parser/converts/block.ts | 44 ++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/parser/converts/block.ts b/src/parser/converts/block.ts index 1d9709da..fc9f3f92 100644 --- a/src/parser/converts/block.ts +++ b/src/parser/converts/block.ts @@ -147,17 +147,17 @@ export function convertIfBlock( }); const consequent = getConsequentFromIfBlock(node); - ifBlock.children.push( - ...convertChildren( - { - nodes: - // Adjust for Svelte v5 - trimChildren(getChildren(consequent)), - }, - ifBlock, - ctx, - ), - ); + for (const child of convertChildren( + { + nodes: + // Adjust for Svelte v5 + trimChildren(getChildren(consequent)), + }, + ifBlock, + ctx, + )) { + ifBlock.children.push(child); + } ctx.scriptLet.closeScope(); if (elseif) { @@ -218,17 +218,17 @@ export function convertIfBlock( ifBlock.else = elseBlock; ctx.scriptLet.nestBlock(elseBlock); - elseBlock.children.push( - ...convertChildren( - { - nodes: - // Adjust for Svelte v5 - trimChildren(elseChildren), - }, - elseBlock, - ctx, - ), - ); + for (const child of convertChildren( + { + nodes: + // Adjust for Svelte v5 + trimChildren(elseChildren), + }, + elseBlock, + ctx, + )) { + elseBlock.children.push(child); + } ctx.scriptLet.closeScope(); extractMustacheBlockTokens(elseBlock, ctx, { startOnly: true }); From 157d486e84262cbf1051a530ee8561c98d2ba077 Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Sat, 29 Mar 2025 17:13:02 +0000 Subject: [PATCH 09/23] chore: drop require in benchmark (#695) --- benchmark/index.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/benchmark/index.ts b/benchmark/index.ts index 6e23c845..38ff0001 100644 --- a/benchmark/index.ts +++ b/benchmark/index.ts @@ -1,12 +1,15 @@ // eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair -- ignore /* eslint-disable no-console -- ignore */ -import * as Benchmark from "benchmark"; -import fs from "fs"; -import { parseForESLint } from "../src/index.js"; +import Benchmark from "benchmark"; +import fs from "node:fs"; +import { fileURLToPath } from "node:url"; import { parseForESLint as parseOld } from "../node_modules/svelte-eslint-parser/lib/index.js"; +import { parseForESLint } from "../src/index.js"; const contents = `${fs.readFileSync( - require.resolve("../explorer-v2/src/lib/RulesSettings.svelte"), + fileURLToPath( + import.meta.resolve("../explorer-v2/src/lib/RulesSettings.svelte"), + ), "utf-8", )}// comments`; From e82b5174976d8f8726f3e43da064af085ee856e2 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 31 Mar 2025 23:43:43 +0000 Subject: [PATCH 10/23] chore(deps): update typescript-eslint monorepo to ~8.29.0 (#696) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 190eed0e..31843489 100644 --- a/package.json +++ b/package.json @@ -78,8 +78,8 @@ "@types/node": "^22.13.13", "@types/semver": "^7.7.0", "@typescript-eslint/eslint-plugin": "^8.28.0", - "@typescript-eslint/parser": "~8.28.0", - "@typescript-eslint/types": "~8.28.0", + "@typescript-eslint/parser": "~8.29.0", + "@typescript-eslint/types": "~8.29.0", "benchmark": "^2.1.4", "c8": "^10.1.3", "chai": "^5.2.0", From 81883020381ddef27490ddc27ea719135abee89e Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Thu, 3 Apr 2025 18:06:42 +0900 Subject: [PATCH 11/23] fix: crash with `$derived()` in template using ts (#698) --- .changeset/gold-planes-retire.md | 5 + src/parser/typescript/analyze/index.ts | 29 +- ...derived-in-template-with-ts01-input.svelte | 5 + ...$derived-in-template-with-ts01-output.json | 1032 +++++++++++++++++ ...ed-in-template-with-ts01-scope-output.json | 345 ++++++ ...ived-in-template-without-ts01-input.svelte | 5 + ...rived-in-template-without-ts01-output.json | 884 ++++++++++++++ ...in-template-without-ts01-scope-output.json | 345 ++++++ 8 files changed, 2642 insertions(+), 8 deletions(-) create mode 100644 .changeset/gold-planes-retire.md create mode 100644 tests/fixtures/parser/ast/svelte5/$derived-in-template-with-ts01-input.svelte create mode 100644 tests/fixtures/parser/ast/svelte5/$derived-in-template-with-ts01-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/$derived-in-template-with-ts01-scope-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/$derived-in-template-without-ts01-input.svelte create mode 100644 tests/fixtures/parser/ast/svelte5/$derived-in-template-without-ts01-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/$derived-in-template-without-ts01-scope-output.json diff --git a/.changeset/gold-planes-retire.md b/.changeset/gold-planes-retire.md new file mode 100644 index 00000000..1e1207d8 --- /dev/null +++ b/.changeset/gold-planes-retire.md @@ -0,0 +1,5 @@ +--- +"svelte-eslint-parser": patch +--- + +fix: crash with `$derived()` in template using ts diff --git a/src/parser/typescript/analyze/index.ts b/src/parser/typescript/analyze/index.ts index b6de0a9b..9d784e7a 100644 --- a/src/parser/typescript/analyze/index.ts +++ b/src/parser/typescript/analyze/index.ts @@ -73,15 +73,26 @@ export function analyzeTypeScriptInSvelte( analyzeRuneVariables(result, ctx, context.svelteParseContext); - applyTransforms( - [ - ...analyzeReactiveScopes(result), - ...analyzeDollarDerivedScopes(result, context.svelteParseContext), - ], - ctx, - ); + const scriptTransformers: TransformInfo[] = [ + ...analyzeReactiveScopes(result), + ]; + const templateTransformers: TransformInfo[] = []; + for (const transform of analyzeDollarDerivedScopes( + result, + context.svelteParseContext, + )) { + if (transform.node.range[0] < code.script.length) { + scriptTransformers.push(transform); + } else { + templateTransformers.push(transform); + } + } - analyzeRenderScopes(code, ctx); + applyTransforms(scriptTransformers, ctx); + + analyzeRenderScopes(code, ctx, () => + applyTransforms(templateTransformers, 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 @@ -625,10 +636,12 @@ function* analyzeDollarDerivedScopes( function analyzeRenderScopes( code: { script: string; render: string; rootScope: string }, ctx: VirtualTypeScriptContext, + analyzeInTemplate: () => void, ) { ctx.appendOriginal(code.script.length); const renderFunctionName = ctx.generateUniqueId("render"); ctx.appendVirtualScript(`export function ${renderFunctionName}(){`); + analyzeInTemplate(); ctx.appendOriginal(code.script.length + code.render.length); ctx.appendVirtualScript(`}`); ctx.restoreContext.addRestoreStatementProcess((node, result) => { diff --git a/tests/fixtures/parser/ast/svelte5/$derived-in-template-with-ts01-input.svelte b/tests/fixtures/parser/ast/svelte5/$derived-in-template-with-ts01-input.svelte new file mode 100644 index 00000000..f2935614 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/$derived-in-template-with-ts01-input.svelte @@ -0,0 +1,5 @@ + + + $derived(0)} /> diff --git a/tests/fixtures/parser/ast/svelte5/$derived-in-template-with-ts01-output.json b/tests/fixtures/parser/ast/svelte5/$derived-in-template-with-ts01-output.json new file mode 100644 index 00000000..af4df0a9 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/$derived-in-template-with-ts01-output.json @@ -0,0 +1,1032 @@ +{ + "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": "ImportDeclaration", + "importKind": "value", + "source": { + "type": "Literal", + "raw": "'./MyComponent.svelte'", + "value": "./MyComponent.svelte", + "range": [ + 47, + 69 + ], + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 50 + } + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "MyComponent", + "range": [ + 30, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + "range": [ + 30, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 22 + } + } + } + ], + "range": [ + 23, + 70 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 51 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 71, + 80 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + "range": [ + 0, + 80 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 80, + 82 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "component", + "name": { + "type": "Identifier", + "name": "MyComponent", + "range": [ + 83, + 94 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 12 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": ":foo", + "range": [ + 95, + 99 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 17 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "CallExpression", + "arguments": [ + { + "type": "Literal", + "raw": "0", + "value": 0, + "range": [ + 116, + 117 + ], + "loc": { + "start": { + "line": 5, + "column": 34 + }, + "end": { + "line": 5, + "column": 35 + } + } + } + ], + "callee": { + "type": "Identifier", + "name": "$derived", + "range": [ + 107, + 115 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 33 + } + } + }, + "optional": false, + "range": [ + 107, + 118 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 36 + } + } + }, + "expression": true, + "generator": false, + "id": null, + "params": [], + "range": [ + 101, + 118 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 36 + } + } + }, + "range": [ + 100, + 119 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 37 + } + } + } + ], + "range": [ + 95, + 119 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 37 + } + } + } + ], + "selfClosing": true, + "range": [ + 82, + 122 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 40 + } + } + }, + "children": [], + "endTag": null, + "range": [ + 82, + 122 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 40 + } + } + } + ], + "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": "import", + "range": [ + 23, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + { + "type": "Identifier", + "value": "MyComponent", + "range": [ + 30, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + { + "type": "Identifier", + "value": "from", + "range": [ + 42, + 46 + ], + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 27 + } + } + }, + { + "type": "String", + "value": "'./MyComponent.svelte'", + "range": [ + 47, + 69 + ], + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 50 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 69, + 70 + ], + "loc": { + "start": { + "line": 2, + "column": 50 + }, + "end": { + "line": 2, + "column": 51 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 71, + 72 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 72, + 73 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 73, + 79 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 79, + 80 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 80, + 82 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 82, + 83 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + } + }, + { + "type": "Identifier", + "value": "MyComponent", + "range": [ + 83, + 94 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 12 + } + } + }, + { + "type": "HTMLIdentifier", + "value": ":foo", + "range": [ + 95, + 99 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 99, + 100 + ], + "loc": { + "start": { + "line": 5, + "column": 17 + }, + "end": { + "line": 5, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 100, + 101 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 101, + 102 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 5, + "column": 20 + }, + "end": { + "line": 5, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 104, + 106 + ], + "loc": { + "start": { + "line": 5, + "column": 22 + }, + "end": { + "line": 5, + "column": 24 + } + } + }, + { + "type": "Identifier", + "value": "$derived", + "range": [ + 107, + 115 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 33 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 115, + 116 + ], + "loc": { + "start": { + "line": 5, + "column": 33 + }, + "end": { + "line": 5, + "column": 34 + } + } + }, + { + "type": "Numeric", + "value": "0", + "range": [ + 116, + 117 + ], + "loc": { + "start": { + "line": 5, + "column": 34 + }, + "end": { + "line": 5, + "column": 35 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 117, + 118 + ], + "loc": { + "start": { + "line": 5, + "column": 35 + }, + "end": { + "line": 5, + "column": 36 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 118, + 119 + ], + "loc": { + "start": { + "line": 5, + "column": 36 + }, + "end": { + "line": 5, + "column": 37 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 120, + 121 + ], + "loc": { + "start": { + "line": 5, + "column": 38 + }, + "end": { + "line": 5, + "column": 39 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 121, + 122 + ], + "loc": { + "start": { + "line": 5, + "column": 39 + }, + "end": { + "line": 5, + "column": 40 + } + } + } + ], + "range": [ + 0, + 123 + ], + "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/$derived-in-template-with-ts01-scope-output.json b/tests/fixtures/parser/ast/svelte5/$derived-in-template-with-ts01-scope-output.json new file mode 100644 index 00000000..45ae4174 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/$derived-in-template-with-ts01-scope-output.json @@ -0,0 +1,345 @@ +{ + "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": [ + { + "identifier": { + "type": "Identifier", + "name": "$derived", + "range": [ + 107, + 115 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 33 + } + } + }, + "from": "function", + "init": null, + "resolved": null + } + ] + }, + { + "name": "$effect", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$bindable", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$inspect", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$host", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "MyComponent", + "identifiers": [ + { + "type": "Identifier", + "name": "MyComponent", + "range": [ + 30, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 22 + } + } + } + ], + "defs": [ + { + "type": "ImportBinding", + "name": { + "type": "Identifier", + "name": "MyComponent", + "range": [ + 30, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + "node": { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "MyComponent", + "range": [ + 30, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + "range": [ + 30, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 22 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "MyComponent", + "range": [ + 83, + 94 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 12 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "MyComponent", + "range": [ + 30, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 22 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "MyComponent", + "range": [ + 83, + 94 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 12 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "MyComponent", + "range": [ + 30, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 22 + } + } + } + } + ], + "childScopes": [ + { + "type": "function", + "variables": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "$derived", + "range": [ + 107, + 115 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 33 + } + } + }, + "from": "function", + "init": null, + "resolved": null + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "$derived", + "range": [ + 107, + 115 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 33 + } + } + }, + "from": "function", + "init": null, + "resolved": null + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "$derived", + "range": [ + 107, + 115 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 33 + } + } + }, + "from": "function", + "init": null, + "resolved": null + } + ] + } + ], + "through": [] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/$derived-in-template-without-ts01-input.svelte b/tests/fixtures/parser/ast/svelte5/$derived-in-template-without-ts01-input.svelte new file mode 100644 index 00000000..7e006dff --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/$derived-in-template-without-ts01-input.svelte @@ -0,0 +1,5 @@ + + + $derived(0)} /> diff --git a/tests/fixtures/parser/ast/svelte5/$derived-in-template-without-ts01-output.json b/tests/fixtures/parser/ast/svelte5/$derived-in-template-without-ts01-output.json new file mode 100644 index 00000000..ddf94b02 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/$derived-in-template-without-ts01-output.json @@ -0,0 +1,884 @@ +{ + "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": [], + "selfClosing": false, + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + "body": [ + { + "type": "ImportDeclaration", + "source": { + "type": "Literal", + "raw": "'./MyComponent.svelte'", + "value": "./MyComponent.svelte", + "range": [ + 37, + 59 + ], + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 50 + } + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "MyComponent", + "range": [ + 20, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + "range": [ + 20, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 22 + } + } + } + ], + "range": [ + 13, + 60 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 51 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 61, + 70 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + "range": [ + 0, + 70 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 70, + 72 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "component", + "name": { + "type": "Identifier", + "name": "MyComponent", + "range": [ + 73, + 84 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 12 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": ":foo", + "range": [ + 85, + 89 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 17 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "CallExpression", + "arguments": [ + { + "type": "Literal", + "raw": "0", + "value": 0, + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 34 + }, + "end": { + "line": 5, + "column": 35 + } + } + } + ], + "callee": { + "type": "Identifier", + "name": "$derived", + "range": [ + 97, + 105 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 33 + } + } + }, + "optional": false, + "range": [ + 97, + 108 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 36 + } + } + }, + "expression": true, + "generator": false, + "id": null, + "params": [], + "range": [ + 91, + 108 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 36 + } + } + }, + "range": [ + 90, + 109 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 37 + } + } + } + ], + "range": [ + 85, + 109 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 37 + } + } + } + ], + "selfClosing": true, + "range": [ + 72, + 112 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 40 + } + } + }, + "children": [], + "endTag": null, + "range": [ + 72, + 112 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 40 + } + } + } + ], + "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": "Punctuator", + "value": ">", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + { + "type": "Keyword", + "value": "import", + "range": [ + 13, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + { + "type": "Identifier", + "value": "MyComponent", + "range": [ + 20, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + { + "type": "Identifier", + "value": "from", + "range": [ + 32, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 27 + } + } + }, + { + "type": "String", + "value": "'./MyComponent.svelte'", + "range": [ + 37, + 59 + ], + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 50 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 59, + 60 + ], + "loc": { + "start": { + "line": 2, + "column": 50 + }, + "end": { + "line": 2, + "column": 51 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 61, + 62 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 62, + 63 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 63, + 69 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 69, + 70 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 70, + 72 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 72, + 73 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + } + }, + { + "type": "Identifier", + "value": "MyComponent", + "range": [ + 73, + 84 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 12 + } + } + }, + { + "type": "HTMLIdentifier", + "value": ":foo", + "range": [ + 85, + 89 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 89, + 90 + ], + "loc": { + "start": { + "line": 5, + "column": 17 + }, + "end": { + "line": 5, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 90, + 91 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 91, + 92 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 92, + 93 + ], + "loc": { + "start": { + "line": 5, + "column": 20 + }, + "end": { + "line": 5, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 94, + 96 + ], + "loc": { + "start": { + "line": 5, + "column": 22 + }, + "end": { + "line": 5, + "column": 24 + } + } + }, + { + "type": "Identifier", + "value": "$derived", + "range": [ + 97, + 105 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 33 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 105, + 106 + ], + "loc": { + "start": { + "line": 5, + "column": 33 + }, + "end": { + "line": 5, + "column": 34 + } + } + }, + { + "type": "Numeric", + "value": "0", + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 34 + }, + "end": { + "line": 5, + "column": 35 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 107, + 108 + ], + "loc": { + "start": { + "line": 5, + "column": 35 + }, + "end": { + "line": 5, + "column": 36 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 108, + 109 + ], + "loc": { + "start": { + "line": 5, + "column": 36 + }, + "end": { + "line": 5, + "column": 37 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 110, + 111 + ], + "loc": { + "start": { + "line": 5, + "column": 38 + }, + "end": { + "line": 5, + "column": 39 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 111, + 112 + ], + "loc": { + "start": { + "line": 5, + "column": 39 + }, + "end": { + "line": 5, + "column": 40 + } + } + } + ], + "range": [ + 0, + 113 + ], + "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/$derived-in-template-without-ts01-scope-output.json b/tests/fixtures/parser/ast/svelte5/$derived-in-template-without-ts01-scope-output.json new file mode 100644 index 00000000..0e14a8ee --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/$derived-in-template-without-ts01-scope-output.json @@ -0,0 +1,345 @@ +{ + "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": [ + { + "identifier": { + "type": "Identifier", + "name": "$derived", + "range": [ + 97, + 105 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 33 + } + } + }, + "from": "function", + "init": null, + "resolved": null + } + ] + }, + { + "name": "$effect", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$bindable", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$inspect", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$host", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "MyComponent", + "identifiers": [ + { + "type": "Identifier", + "name": "MyComponent", + "range": [ + 20, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 22 + } + } + } + ], + "defs": [ + { + "type": "ImportBinding", + "name": { + "type": "Identifier", + "name": "MyComponent", + "range": [ + 20, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + "node": { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "MyComponent", + "range": [ + 20, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + "range": [ + 20, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 22 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "MyComponent", + "range": [ + 73, + 84 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 12 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "MyComponent", + "range": [ + 20, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 22 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "MyComponent", + "range": [ + 73, + 84 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 12 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "MyComponent", + "range": [ + 20, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 22 + } + } + } + } + ], + "childScopes": [ + { + "type": "function", + "variables": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "$derived", + "range": [ + 97, + 105 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 33 + } + } + }, + "from": "function", + "init": null, + "resolved": null + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "$derived", + "range": [ + 97, + 105 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 33 + } + } + }, + "from": "function", + "init": null, + "resolved": null + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "$derived", + "range": [ + 97, + 105 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 33 + } + } + }, + "from": "function", + "init": null, + "resolved": null + } + ] + } + ], + "through": [] +} \ No newline at end of file From 3081ac7243ef2fb65c1bed55c7bbdd20b81af7f5 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 3 Apr 2025 18:17:16 +0900 Subject: [PATCH 12/23] chore: release svelte-eslint-parser (#699) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .changeset/gold-planes-retire.md | 5 ----- CHANGELOG.md | 6 ++++++ package.json | 2 +- src/meta.ts | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) delete mode 100644 .changeset/gold-planes-retire.md diff --git a/.changeset/gold-planes-retire.md b/.changeset/gold-planes-retire.md deleted file mode 100644 index 1e1207d8..00000000 --- a/.changeset/gold-planes-retire.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"svelte-eslint-parser": patch ---- - -fix: crash with `$derived()` in template using ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 06414798..28ad9341 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # svelte-eslint-parser +## 1.1.2 + +### Patch Changes + +- [#698](https://github.com/sveltejs/svelte-eslint-parser/pull/698) [`8188302`](https://github.com/sveltejs/svelte-eslint-parser/commit/81883020381ddef27490ddc27ea719135abee89e) Thanks [@ota-meshi](https://github.com/ota-meshi)! - fix: crash with `$derived()` in template using ts + ## 1.1.1 ### Patch Changes diff --git a/package.json b/package.json index 31843489..d60a4f39 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svelte-eslint-parser", - "version": "1.1.1", + "version": "1.1.2", "description": "Svelte parser for ESLint", "repository": "git+https://github.com/sveltejs/svelte-eslint-parser.git", "homepage": "https://github.com/sveltejs/svelte-eslint-parser#readme", diff --git a/src/meta.ts b/src/meta.ts index cb4ca736..fb1bf8af 100644 --- a/src/meta.ts +++ b/src/meta.ts @@ -2,4 +2,4 @@ // This file has been automatically generated, // in order to update its content execute "pnpm run build:meta" export const name = "svelte-eslint-parser"; -export const version = "1.1.1"; +export const version = "1.1.2"; From 18684d6acbab135bfdfe502db86ede9e73c3bc78 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 5 Apr 2025 02:44:28 +0000 Subject: [PATCH 13/23] chore(deps): update dependency eslint to ~9.24.0 (#700) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d60a4f39..7f208e83 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "chai": "^5.2.0", "env-cmd": "^10.1.0", "esbuild": "^0.25.1", - "eslint": "~9.23.0", + "eslint": "~9.24.0", "eslint-config-prettier": "^10.1.1", "eslint-plugin-eslint-comments": "^3.2.0", "eslint-plugin-jsdoc": "^50.6.9", From 3ab9a64a21eb62266d9ad16e4c0333dfb9456602 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 12 Apr 2025 10:44:42 +0800 Subject: [PATCH 14/23] chore(deps): update dependency typescript-eslint-parser-for-extra-files to ^0.8.0 (#702) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7f208e83..bc680ca8 100644 --- a/package.json +++ b/package.json @@ -111,7 +111,7 @@ "tsx": "^4.19.3", "typescript": "~5.8.2", "typescript-eslint": "^8.28.0", - "typescript-eslint-parser-for-extra-files": "^0.7.0" + "typescript-eslint-parser-for-extra-files": "^0.8.0" }, "publishConfig": { "access": "public" From 3f5405b70d564acda54f894731d17208fce4bacf Mon Sep 17 00:00:00 2001 From: Michael Cousins Date: Fri, 18 Apr 2025 20:40:43 -0400 Subject: [PATCH 15/23] test(integration): ensure typescript-eslint packages are consistent (#705) --- package.json | 5 ++--- prettier.config.mjs | 1 + .../integrations/snippet-scope/snippet-shadow-scope-setup.ts | 4 ++-- .../snippet-scope/ts-snippet-hoist-scope-setup.ts | 4 ++-- .../fixtures/integrations/type-info-tests/$derived-setup.ts | 4 ++-- .../integrations/type-info-tests/$derived-ts-setup.ts | 4 ++-- .../fixtures/integrations/type-info-tests/$derived2-setup.ts | 4 ++-- .../integrations/type-info-tests/$derived2-ts-setup.ts | 4 ++-- tests/fixtures/integrations/type-info-tests/$props-setup.ts | 4 ++-- tests/fixtures/integrations/type-info-tests/await-setup.ts | 4 ++-- .../integrations/type-info-tests/await-with-same-id-setup.ts | 4 ++-- tests/fixtures/integrations/type-info-tests/i18n-setup.ts | 4 ++-- .../fixtures/integrations/type-info-tests/issue226-setup.ts | 4 ++-- .../type-info-tests/no-unnecessary-condition01-setup.ts | 4 ++-- .../integrations/type-info-tests/plugin-issue254-setup.ts | 4 ++-- .../fixtures/integrations/type-info-tests/reactive-setup.ts | 4 ++-- .../fixtures/integrations/type-info-tests/reactive2-setup.ts | 4 ++-- .../integrations/type-info-tests/ts-newline-setup.ts | 4 ++-- .../type-info-tests/ts-no-misused-promises-setup.ts | 4 ++-- 19 files changed, 37 insertions(+), 37 deletions(-) create mode 100644 prettier.config.mjs diff --git a/package.json b/package.json index bc680ca8..92e11f9a 100644 --- a/package.json +++ b/package.json @@ -77,9 +77,8 @@ "@types/mocha": "^10.0.10", "@types/node": "^22.13.13", "@types/semver": "^7.7.0", - "@typescript-eslint/eslint-plugin": "^8.28.0", - "@typescript-eslint/parser": "~8.29.0", - "@typescript-eslint/types": "~8.29.0", + "@typescript-eslint/parser": "^8.29.0", + "@typescript-eslint/types": "^8.29.0", "benchmark": "^2.1.4", "c8": "^10.1.3", "chai": "^5.2.0", diff --git a/prettier.config.mjs b/prettier.config.mjs new file mode 100644 index 00000000..ff8b4c56 --- /dev/null +++ b/prettier.config.mjs @@ -0,0 +1 @@ +export default {}; diff --git a/tests/fixtures/integrations/snippet-scope/snippet-shadow-scope-setup.ts b/tests/fixtures/integrations/snippet-scope/snippet-shadow-scope-setup.ts index 303b59e4..52336412 100644 --- a/tests/fixtures/integrations/snippet-scope/snippet-shadow-scope-setup.ts +++ b/tests/fixtures/integrations/snippet-scope/snippet-shadow-scope-setup.ts @@ -1,6 +1,6 @@ import type { Linter } from "eslint"; import { generateParserOptions } from "../../../src/parser/test-utils.js"; -import { rules } from "@typescript-eslint/eslint-plugin"; +import { plugin } from "typescript-eslint"; import * as parser from "../../../../src/index.js"; import globals from "globals"; @@ -8,7 +8,7 @@ export function getConfig(): Linter.Config { return { plugins: { "@typescript-eslint": { - rules: rules as any, + rules: plugin.rules as any, }, }, languageOptions: { diff --git a/tests/fixtures/integrations/snippet-scope/ts-snippet-hoist-scope-setup.ts b/tests/fixtures/integrations/snippet-scope/ts-snippet-hoist-scope-setup.ts index 9b7181f5..fa38171d 100644 --- a/tests/fixtures/integrations/snippet-scope/ts-snippet-hoist-scope-setup.ts +++ b/tests/fixtures/integrations/snippet-scope/ts-snippet-hoist-scope-setup.ts @@ -1,6 +1,6 @@ import type { Linter } from "eslint"; import { generateParserOptions } from "../../../src/parser/test-utils.js"; -import { rules } from "@typescript-eslint/eslint-plugin"; +import { plugin } from "typescript-eslint"; import * as parser from "../../../../src/index.js"; import globals from "globals"; @@ -8,7 +8,7 @@ export function getConfig(): Linter.Config { return { plugins: { "@typescript-eslint": { - rules: rules as any, + rules: plugin.rules as any, }, }, languageOptions: { diff --git a/tests/fixtures/integrations/type-info-tests/$derived-setup.ts b/tests/fixtures/integrations/type-info-tests/$derived-setup.ts index 1751c29e..d412fd99 100644 --- a/tests/fixtures/integrations/type-info-tests/$derived-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/$derived-setup.ts @@ -1,6 +1,6 @@ import type { Linter } from "eslint"; import { generateParserOptions } from "../../../src/parser/test-utils"; -import { rules } from "@typescript-eslint/eslint-plugin"; +import { plugin } from "typescript-eslint"; import * as parser from "../../../../src"; import globals from "globals"; @@ -8,7 +8,7 @@ export function getConfig(): Linter.Config { return { plugins: { "@typescript-eslint": { - rules: rules as any, + rules: plugin.rules as any, }, }, languageOptions: { diff --git a/tests/fixtures/integrations/type-info-tests/$derived-ts-setup.ts b/tests/fixtures/integrations/type-info-tests/$derived-ts-setup.ts index 1751c29e..d412fd99 100644 --- a/tests/fixtures/integrations/type-info-tests/$derived-ts-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/$derived-ts-setup.ts @@ -1,6 +1,6 @@ import type { Linter } from "eslint"; import { generateParserOptions } from "../../../src/parser/test-utils"; -import { rules } from "@typescript-eslint/eslint-plugin"; +import { plugin } from "typescript-eslint"; import * as parser from "../../../../src"; import globals from "globals"; @@ -8,7 +8,7 @@ export function getConfig(): Linter.Config { return { plugins: { "@typescript-eslint": { - rules: rules as any, + rules: plugin.rules as any, }, }, languageOptions: { diff --git a/tests/fixtures/integrations/type-info-tests/$derived2-setup.ts b/tests/fixtures/integrations/type-info-tests/$derived2-setup.ts index 1751c29e..d412fd99 100644 --- a/tests/fixtures/integrations/type-info-tests/$derived2-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/$derived2-setup.ts @@ -1,6 +1,6 @@ import type { Linter } from "eslint"; import { generateParserOptions } from "../../../src/parser/test-utils"; -import { rules } from "@typescript-eslint/eslint-plugin"; +import { plugin } from "typescript-eslint"; import * as parser from "../../../../src"; import globals from "globals"; @@ -8,7 +8,7 @@ export function getConfig(): Linter.Config { return { plugins: { "@typescript-eslint": { - rules: rules as any, + rules: plugin.rules as any, }, }, languageOptions: { diff --git a/tests/fixtures/integrations/type-info-tests/$derived2-ts-setup.ts b/tests/fixtures/integrations/type-info-tests/$derived2-ts-setup.ts index 1751c29e..d412fd99 100644 --- a/tests/fixtures/integrations/type-info-tests/$derived2-ts-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/$derived2-ts-setup.ts @@ -1,6 +1,6 @@ import type { Linter } from "eslint"; import { generateParserOptions } from "../../../src/parser/test-utils"; -import { rules } from "@typescript-eslint/eslint-plugin"; +import { plugin } from "typescript-eslint"; import * as parser from "../../../../src"; import globals from "globals"; @@ -8,7 +8,7 @@ export function getConfig(): Linter.Config { return { plugins: { "@typescript-eslint": { - rules: rules as any, + rules: plugin.rules as any, }, }, languageOptions: { diff --git a/tests/fixtures/integrations/type-info-tests/$props-setup.ts b/tests/fixtures/integrations/type-info-tests/$props-setup.ts index 1751c29e..d412fd99 100644 --- a/tests/fixtures/integrations/type-info-tests/$props-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/$props-setup.ts @@ -1,6 +1,6 @@ import type { Linter } from "eslint"; import { generateParserOptions } from "../../../src/parser/test-utils"; -import { rules } from "@typescript-eslint/eslint-plugin"; +import { plugin } from "typescript-eslint"; import * as parser from "../../../../src"; import globals from "globals"; @@ -8,7 +8,7 @@ export function getConfig(): Linter.Config { return { plugins: { "@typescript-eslint": { - rules: rules as any, + rules: plugin.rules as any, }, }, languageOptions: { diff --git a/tests/fixtures/integrations/type-info-tests/await-setup.ts b/tests/fixtures/integrations/type-info-tests/await-setup.ts index 0776177e..6e873163 100644 --- a/tests/fixtures/integrations/type-info-tests/await-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/await-setup.ts @@ -1,6 +1,6 @@ import type { Linter } from "eslint"; import { generateParserOptions } from "../../../src/parser/test-utils"; -import { rules } from "@typescript-eslint/eslint-plugin"; +import { plugin } from "typescript-eslint"; import * as parser from "../../../../src"; import globals from "globals"; @@ -8,7 +8,7 @@ export function getConfig(): Linter.Config { return { plugins: { "@typescript-eslint": { - rules: rules as any, + rules: plugin.rules as any, }, }, languageOptions: { diff --git a/tests/fixtures/integrations/type-info-tests/await-with-same-id-setup.ts b/tests/fixtures/integrations/type-info-tests/await-with-same-id-setup.ts index 1172dc96..5af1937a 100644 --- a/tests/fixtures/integrations/type-info-tests/await-with-same-id-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/await-with-same-id-setup.ts @@ -1,6 +1,6 @@ import type { Linter } from "eslint"; import { generateParserOptions } from "../../../src/parser/test-utils"; -import { rules } from "@typescript-eslint/eslint-plugin"; +import { plugin } from "typescript-eslint"; import * as parser from "../../../../src"; import globals from "globals"; @@ -8,7 +8,7 @@ export function getConfig(): Linter.Config { return { plugins: { "@typescript-eslint": { - rules: rules as any, + rules: plugin.rules as any, }, }, languageOptions: { diff --git a/tests/fixtures/integrations/type-info-tests/i18n-setup.ts b/tests/fixtures/integrations/type-info-tests/i18n-setup.ts index 0776177e..6e873163 100644 --- a/tests/fixtures/integrations/type-info-tests/i18n-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/i18n-setup.ts @@ -1,6 +1,6 @@ import type { Linter } from "eslint"; import { generateParserOptions } from "../../../src/parser/test-utils"; -import { rules } from "@typescript-eslint/eslint-plugin"; +import { plugin } from "typescript-eslint"; import * as parser from "../../../../src"; import globals from "globals"; @@ -8,7 +8,7 @@ export function getConfig(): Linter.Config { return { plugins: { "@typescript-eslint": { - rules: rules as any, + rules: plugin.rules as any, }, }, languageOptions: { diff --git a/tests/fixtures/integrations/type-info-tests/issue226-setup.ts b/tests/fixtures/integrations/type-info-tests/issue226-setup.ts index 2b458b9d..0ad5e9ea 100644 --- a/tests/fixtures/integrations/type-info-tests/issue226-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/issue226-setup.ts @@ -1,6 +1,6 @@ import type { Linter } from "eslint"; import { generateParserOptions } from "../../../src/parser/test-utils"; -import { rules } from "@typescript-eslint/eslint-plugin"; +import { plugin } from "typescript-eslint"; import * as parser from "../../../../src"; import globals from "globals"; @@ -8,7 +8,7 @@ export function getConfig(): Linter.Config { return { plugins: { "@typescript-eslint": { - rules: rules as any, + rules: plugin.rules as any, }, }, languageOptions: { diff --git a/tests/fixtures/integrations/type-info-tests/no-unnecessary-condition01-setup.ts b/tests/fixtures/integrations/type-info-tests/no-unnecessary-condition01-setup.ts index 14872ebb..05846f7d 100644 --- a/tests/fixtures/integrations/type-info-tests/no-unnecessary-condition01-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/no-unnecessary-condition01-setup.ts @@ -1,6 +1,6 @@ import type { Linter } from "eslint"; import { generateParserOptions } from "../../../src/parser/test-utils"; -import { rules } from "@typescript-eslint/eslint-plugin"; +import { plugin } from "typescript-eslint"; import * as parser from "../../../../src"; import globals from "globals"; @@ -8,7 +8,7 @@ export function getConfig(): Linter.Config { return { plugins: { "@typescript-eslint": { - rules: rules as any, + rules: plugin.rules as any, }, }, languageOptions: { diff --git a/tests/fixtures/integrations/type-info-tests/plugin-issue254-setup.ts b/tests/fixtures/integrations/type-info-tests/plugin-issue254-setup.ts index 14872ebb..05846f7d 100644 --- a/tests/fixtures/integrations/type-info-tests/plugin-issue254-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/plugin-issue254-setup.ts @@ -1,6 +1,6 @@ import type { Linter } from "eslint"; import { generateParserOptions } from "../../../src/parser/test-utils"; -import { rules } from "@typescript-eslint/eslint-plugin"; +import { plugin } from "typescript-eslint"; import * as parser from "../../../../src"; import globals from "globals"; @@ -8,7 +8,7 @@ export function getConfig(): Linter.Config { return { plugins: { "@typescript-eslint": { - rules: rules as any, + rules: plugin.rules as any, }, }, languageOptions: { diff --git a/tests/fixtures/integrations/type-info-tests/reactive-setup.ts b/tests/fixtures/integrations/type-info-tests/reactive-setup.ts index 12eb3010..b90f6180 100644 --- a/tests/fixtures/integrations/type-info-tests/reactive-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/reactive-setup.ts @@ -1,6 +1,6 @@ import type { Linter } from "eslint"; import { generateParserOptions } from "../../../src/parser/test-utils"; -import { rules } from "@typescript-eslint/eslint-plugin"; +import { plugin } from "typescript-eslint"; import * as parser from "../../../../src"; import globals from "globals"; @@ -8,7 +8,7 @@ export function getConfig(): Linter.Config { return { plugins: { "@typescript-eslint": { - rules: rules as any, + rules: plugin.rules as any, }, }, languageOptions: { diff --git a/tests/fixtures/integrations/type-info-tests/reactive2-setup.ts b/tests/fixtures/integrations/type-info-tests/reactive2-setup.ts index 5804c700..96c7ba6f 100644 --- a/tests/fixtures/integrations/type-info-tests/reactive2-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/reactive2-setup.ts @@ -1,6 +1,6 @@ import type { Linter } from "eslint"; import { generateParserOptions } from "../../../src/parser/test-utils"; -import { rules } from "@typescript-eslint/eslint-plugin"; +import { plugin } from "typescript-eslint"; import * as parser from "../../../../src"; import globals from "globals"; @@ -8,7 +8,7 @@ export function getConfig(): Linter.Config { return { plugins: { "@typescript-eslint": { - rules: rules as any, + rules: plugin.rules as any, }, }, languageOptions: { diff --git a/tests/fixtures/integrations/type-info-tests/ts-newline-setup.ts b/tests/fixtures/integrations/type-info-tests/ts-newline-setup.ts index a1a075a0..348575af 100644 --- a/tests/fixtures/integrations/type-info-tests/ts-newline-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/ts-newline-setup.ts @@ -1,6 +1,6 @@ import type { Linter } from "eslint"; import { generateParserOptions } from "../../../src/parser/test-utils"; -import { rules } from "@typescript-eslint/eslint-plugin"; +import { plugin } from "typescript-eslint"; import * as parser from "../../../../src"; import globals from "globals"; @@ -8,7 +8,7 @@ export function getConfig(): Linter.Config { return { plugins: { "@typescript-eslint": { - rules: rules as any, + rules: plugin.rules as any, }, }, languageOptions: { diff --git a/tests/fixtures/integrations/type-info-tests/ts-no-misused-promises-setup.ts b/tests/fixtures/integrations/type-info-tests/ts-no-misused-promises-setup.ts index f8a6a783..50827a22 100644 --- a/tests/fixtures/integrations/type-info-tests/ts-no-misused-promises-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/ts-no-misused-promises-setup.ts @@ -1,6 +1,6 @@ import type { Linter } from "eslint"; import { generateParserOptions } from "../../../src/parser/test-utils"; -import { rules } from "@typescript-eslint/eslint-plugin"; +import { plugin } from "typescript-eslint"; import * as parser from "../../../../src"; import globals from "globals"; @@ -8,7 +8,7 @@ export function getConfig(): Linter.Config { return { plugins: { "@typescript-eslint": { - rules: rules as any, + rules: plugin.rules as any, }, }, languageOptions: { From 0436da6b7190208284de45ce7a54e18c4d31c032 Mon Sep 17 00:00:00 2001 From: Michael Cousins Date: Fri, 18 Apr 2025 20:57:10 -0400 Subject: [PATCH 16/23] perf(typescript): strip `projectService` from parser options when needed (#704) Co-authored-by: Yuichiro Yamashita --- .changeset/spicy-toes-raise.md | 5 +++++ src/parser/converts/root.ts | 7 ++----- src/parser/parser-options.ts | 23 +++++++++++++++++++++++ src/parser/typescript/analyze/index.ts | 17 +++++++---------- 4 files changed, 37 insertions(+), 15 deletions(-) create mode 100644 .changeset/spicy-toes-raise.md diff --git a/.changeset/spicy-toes-raise.md b/.changeset/spicy-toes-raise.md new file mode 100644 index 00000000..533807fa --- /dev/null +++ b/.changeset/spicy-toes-raise.md @@ -0,0 +1,5 @@ +--- +"svelte-eslint-parser": patch +--- + +Strip `projectService` from TS options when type information not needed diff --git a/src/parser/converts/root.ts b/src/parser/converts/root.ts index 5e5e8de3..81614868 100644 --- a/src/parser/converts/root.ts +++ b/src/parser/converts/root.ts @@ -27,6 +27,7 @@ import { getOptionsFromRoot, } from "../compat.js"; import { sortNodes } from "../sort.js"; +import { withoutProjectParserOptions } from "../parser-options.js"; /** * Convert root @@ -259,11 +260,7 @@ function convertGenericsAttribute(script: SvelteScriptElement, ctx: Context) { result = parseScriptWithoutAnalyzeScope( scriptLet, ctx.sourceCode.scripts.attrs, - { - ...ctx.parserOptions, - // Without typings - project: null, - }, + withoutProjectParserOptions(ctx.parserOptions), ) as unknown as TSESParseForESLintResult; } catch { // ignore diff --git a/src/parser/parser-options.ts b/src/parser/parser-options.ts index fd338485..44d43af1 100644 --- a/src/parser/parser-options.ts +++ b/src/parser/parser-options.ts @@ -9,6 +9,8 @@ import { getParserForLang, type UserOptionParser } from "./resolve-parser.js"; export type NormalizedParserOptions = { parser?: UserOptionParser; project?: string | string[] | null; + projectService?: unknown; + EXPERIMENTAL_useProjectService?: unknown; ecmaVersion: number | "latest"; sourceType: "module" | "script"; @@ -104,3 +106,24 @@ export function isTypeScript( return false; } + +/** + * Remove typing-related options from parser options. + * + * Allows the typescript-eslint parser to parse a file without + * trying to collect typing information from TypeScript. + * + * See https://typescript-eslint.io/packages/parser#withoutprojectparseroptionsparseroptions + */ +export function withoutProjectParserOptions( + options: NormalizedParserOptions, +): NormalizedParserOptions { + const { + project: _strippedProject, + projectService: _strippedProjectService, + EXPERIMENTAL_useProjectService: _strippedExperimentalUseProjectService, + ...result + } = options; + + return result; +} diff --git a/src/parser/typescript/analyze/index.ts b/src/parser/typescript/analyze/index.ts index 9d784e7a..cea34041 100644 --- a/src/parser/typescript/analyze/index.ts +++ b/src/parser/typescript/analyze/index.ts @@ -23,6 +23,7 @@ import type { NormalizedParserOptions } from "../../parser-options.js"; import { setParent } from "../set-parent.js"; import { getGlobalsForSvelte, globalsForRunes } from "../../globals.js"; import type { SvelteParseContext } from "../../svelte-parse-context.js"; +import { withoutProjectParserOptions } from "../../parser-options.js"; export type AnalyzeTypeScriptContext = { slots: Set; @@ -53,11 +54,7 @@ export function analyzeTypeScriptInSvelte( const result = parseScriptWithoutAnalyzeScope( code.script + code.render + code.rootScope, attrs, - { - ...parserOptions, - // Without typings - project: null, - }, + withoutProjectParserOptions(parserOptions), ) as unknown as TSESParseForESLintResult; ctx._beforeResult = result; @@ -118,11 +115,11 @@ export function analyzeTypeScript( const ctx = new VirtualTypeScriptContext(code); ctx.appendOriginal(/^\s*/u.exec(code)![0].length); - const result = parseScriptWithoutAnalyzeScope(code, attrs, { - ...parserOptions, - // Without typings - project: null, - }) as unknown as TSESParseForESLintResult; + const result = parseScriptWithoutAnalyzeScope( + code, + attrs, + withoutProjectParserOptions(parserOptions), + ) as unknown as TSESParseForESLintResult; ctx._beforeResult = result; From ce53387a8e788ac7219782b9484e1c341ed3f88b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 19 Apr 2025 09:57:26 +0900 Subject: [PATCH 17/23] chore(deps): update dependency eslint to ~9.25.0 (#706) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 92e11f9a..a31a7a4b 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,7 @@ "chai": "^5.2.0", "env-cmd": "^10.1.0", "esbuild": "^0.25.1", - "eslint": "~9.24.0", + "eslint": "~9.25.0", "eslint-config-prettier": "^10.1.1", "eslint-plugin-eslint-comments": "^3.2.0", "eslint-plugin-jsdoc": "^50.6.9", From 454d1a8fb59a9fdbbd5b27e513575f47f345fd29 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 19 Apr 2025 09:59:48 +0900 Subject: [PATCH 18/23] chore(deps): update dependency prettier-plugin-pkg to ^0.19.0 (#701) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: JounQin --- .prettierignore | 1 + .prettierrc | 3 ++ docs/AST.md | 2 +- docs/internal-mechanism.md | 83 +++++++++++++++++++------------------- package.json | 6 +-- 5 files changed, 50 insertions(+), 45 deletions(-) create mode 100644 .prettierignore create mode 100644 .prettierrc diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..44e54133 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +tests/fixtures diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..877131f6 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,3 @@ +{ + "plugins": ["prettier-plugin-pkg", "prettier-plugin-svelte"] +} diff --git a/docs/AST.md b/docs/AST.md index b8eec7b4..c0f90492 100644 --- a/docs/AST.md +++ b/docs/AST.md @@ -15,7 +15,7 @@ See [ESTree] for the AST node of the script generated by `espree`. [variabledeclarator]: https://github.com/estree/estree/blob/master/es5.md#variabledeclarator [pattern]: https://github.com/estree/estree/blob/master/es5.md#patterns -See details: [../src/ast/*](../src/ast/) +See details: [../src/ast/\*](../src/ast/) ## Common diff --git a/docs/internal-mechanism.md b/docs/internal-mechanism.md index 9cc25972..80fead11 100644 --- a/docs/internal-mechanism.md +++ b/docs/internal-mechanism.md @@ -38,23 +38,26 @@ For example, if you enter `*.svelte` template to listen for input events: ```svelte - + + ``` Parse the following virtual script code as a script: ```ts - - function inputHandler () { - // process - } -;function $_render1(){ - -(inputHandler) as ((e:'input' extends keyof HTMLElementEventMap ? HTMLElementEventMap['input'] : CustomEvent) => void ); +function inputHandler() { + // process +} +function $_render1() { + inputHandler as ( + e: "input" extends keyof HTMLElementEventMap + ? HTMLElementEventMap["input"] + : CustomEvent, + ) => void; } ``` @@ -78,25 +81,24 @@ For example, when using `{#each}` and `{@const}`: ```svelte + {#each array as e} - {@const ee = e * 2} - {ee} + {@const ee = e * 2} + {ee} {/each} ``` Parse the following virtual script code as a script: ```ts - - const array = [1, 2, 3] -;function $_render1(){ - -Array.from(array).forEach((e) => { +const array = [1, 2, 3]; +function $_render1() { + Array.from(array).forEach((e) => { const ee = e * 2; - (ee); -}); + ee; + }); } ``` @@ -121,8 +123,9 @@ TypeScript's type inference is pretty good, so parsing Svelte as-is gives some w e.g. + ```ts -export let foo: { bar: number } | null = null +export let foo: { bar: number } | null = null; $: console.log(foo && foo.bar); // ^ never type @@ -139,13 +142,13 @@ For example: ```svelte {foo && foo.bar} @@ -154,26 +157,24 @@ $: ({ bar: n } = foo || { bar: 42 }); Parse the following virtual script code as a script: ```ts - -export let foo: { bar: number } | null = null +export let foo: { bar: number } | null = null; -$: function $_reactiveStatementScopeFunction1(){ - console.log(foo && foo.bar); +$: function $_reactiveStatementScopeFunction1() { + console.log(foo && foo.bar); } -$: let r =$_reactiveVariableScopeFunction2(); -function $_reactiveVariableScopeFunction2(){ - let $_tmpVar3; - return ($_tmpVar3 = foo && foo.bar); +$: let r = $_reactiveVariableScopeFunction2(); +function $_reactiveVariableScopeFunction2() { + let $_tmpVar3; + return ($_tmpVar3 = foo && foo.bar); } -$: let { bar: n } =$_reactiveVariableScopeFunction4(); -function $_reactiveVariableScopeFunction4(){ - let $_tmpVar5; - return ($_tmpVar5 = foo || { bar: 42 }); +$: let { bar: n } = $_reactiveVariableScopeFunction4(); +function $_reactiveVariableScopeFunction4() { + let $_tmpVar5; + return ($_tmpVar5 = foo || { bar: 42 }); } -;function $_render6(){ - -(foo && foo.bar); +function $_render6() { + foo && foo.bar; } ``` diff --git a/package.json b/package.json index a31a7a4b..deef8105 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "svelte-eslint-parser", "version": "1.1.2", + "type": "module", "description": "Svelte parser for ESLint", "repository": "git+https://github.com/sveltejs/svelte-eslint-parser.git", "homepage": "https://github.com/sveltejs/svelte-eslint-parser#readme", @@ -14,7 +15,6 @@ "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, - "type": "module", "main": "lib/index.js", "files": [ "lib" @@ -40,10 +40,10 @@ "prerelease": "pnpm run clean && pnpm run build", "preversion": "pnpm run lint && pnpm run test", "release": "changeset publish", + "run-update-fixtures": "pnpm run ts ./tools/update-fixtures.ts", "test": "pnpm run mocha \"tests/src/**/*.ts\" --reporter dot --timeout 60000", "ts": "node --import tsx/esm", "update-fixtures": "git add package.json && pnpm i -D svelte@4 && git checkout package.json && pnpm run run-update-fixtures && pnpm i && pnpm run run-update-fixtures", - "run-update-fixtures": "pnpm run ts ./tools/update-fixtures.ts", "version:ci": "env-cmd -e version-ci pnpm run build:meta && changeset version" }, "peerDependencies": { @@ -101,7 +101,7 @@ "magic-string": "^0.30.17", "mocha": "^11.1.0", "prettier": "~3.5.3", - "prettier-plugin-pkg": "^0.18.1", + "prettier-plugin-pkg": "^0.19.0", "prettier-plugin-svelte": "^3.3.3", "rimraf": "^6.0.1", "semver": "^7.7.1", From afd3dca90c80e6db3b0f16371ea2c8652cb86c91 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 19 Apr 2025 10:00:47 +0900 Subject: [PATCH 19/23] chore: release svelte-eslint-parser (#707) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .changeset/spicy-toes-raise.md | 5 ----- CHANGELOG.md | 6 ++++++ package.json | 2 +- src/meta.ts | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) delete mode 100644 .changeset/spicy-toes-raise.md diff --git a/.changeset/spicy-toes-raise.md b/.changeset/spicy-toes-raise.md deleted file mode 100644 index 533807fa..00000000 --- a/.changeset/spicy-toes-raise.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"svelte-eslint-parser": patch ---- - -Strip `projectService` from TS options when type information not needed diff --git a/CHANGELOG.md b/CHANGELOG.md index 28ad9341..7d6479ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # svelte-eslint-parser +## 1.1.3 + +### Patch Changes + +- [#704](https://github.com/sveltejs/svelte-eslint-parser/pull/704) [`0436da6`](https://github.com/sveltejs/svelte-eslint-parser/commit/0436da6b7190208284de45ce7a54e18c4d31c032) Thanks [@mcous](https://github.com/mcous)! - Strip `projectService` from TS options when type information not needed + ## 1.1.2 ### Patch Changes diff --git a/package.json b/package.json index deef8105..8dd22382 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svelte-eslint-parser", - "version": "1.1.2", + "version": "1.1.3", "type": "module", "description": "Svelte parser for ESLint", "repository": "git+https://github.com/sveltejs/svelte-eslint-parser.git", diff --git a/src/meta.ts b/src/meta.ts index fb1bf8af..fb51a49d 100644 --- a/src/meta.ts +++ b/src/meta.ts @@ -2,4 +2,4 @@ // This file has been automatically generated, // in order to update its content execute "pnpm run build:meta" export const name = "svelte-eslint-parser"; -export const version = "1.1.2"; +export const version = "1.1.3"; From 0eb8030bbb8f20979d49677e3332c7ef97011315 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 23 Apr 2025 13:25:00 +0000 Subject: [PATCH 20/23] chore(deps): update dependency eslint-plugin-node-dependencies to ^0.13.0 (#708) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8dd22382..15cbdcf1 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "eslint-plugin-json-schema-validator": "^5.3.1", "eslint-plugin-jsonc": "^2.20.0", "eslint-plugin-n": "^17.17.0", - "eslint-plugin-node-dependencies": "^0.12.0", + "eslint-plugin-node-dependencies": "^0.13.0", "eslint-plugin-prettier": "^5.2.5", "eslint-plugin-regexp": "^2.7.0", "eslint-plugin-svelte": "^3.3.3", From 5b5439f3787d0b8bc8d50e010f1c0d59ba6e97e0 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 30 Apr 2025 22:13:04 +0900 Subject: [PATCH 21/23] chore(deps): update dependency typescript-eslint-parser-for-extra-files to ^0.9.0 (#709) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 15cbdcf1..813b519f 100644 --- a/package.json +++ b/package.json @@ -110,7 +110,7 @@ "tsx": "^4.19.3", "typescript": "~5.8.2", "typescript-eslint": "^8.28.0", - "typescript-eslint-parser-for-extra-files": "^0.8.0" + "typescript-eslint-parser-for-extra-files": "^0.9.0" }, "publishConfig": { "access": "public" From 497d0c0792b15e973af50b108ab96403a840c634 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 1 May 2025 14:10:56 +0000 Subject: [PATCH 22/23] chore(deps): update dependency eslint-plugin-node-dependencies to v1 (#710) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 813b519f..76d1a994 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "eslint-plugin-json-schema-validator": "^5.3.1", "eslint-plugin-jsonc": "^2.20.0", "eslint-plugin-n": "^17.17.0", - "eslint-plugin-node-dependencies": "^0.13.0", + "eslint-plugin-node-dependencies": "^1.0.0", "eslint-plugin-prettier": "^5.2.5", "eslint-plugin-regexp": "^2.7.0", "eslint-plugin-svelte": "^3.3.3", From 10fc353d7fb947ac261d5e5ac95d2ac46366f50c Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 3 May 2025 02:42:13 +0000 Subject: [PATCH 23/23] chore(deps): update dependency eslint to ~9.26.0 (#711) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 76d1a994..598cf544 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,7 @@ "chai": "^5.2.0", "env-cmd": "^10.1.0", "esbuild": "^0.25.1", - "eslint": "~9.25.0", + "eslint": "~9.26.0", "eslint-config-prettier": "^10.1.1", "eslint-plugin-eslint-comments": "^3.2.0", "eslint-plugin-jsdoc": "^50.6.9",