From 8fef4ca3631eb03c1f113de244b33c4c684169ab Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Wed, 5 Mar 2025 22:58:24 +0900 Subject: [PATCH 1/2] Fix wrong scope for generic attribute (#254) * Fix wrong scope for generic attribute * update --- src/script/generic.ts | 9 +- .../define-model05-with-modifiers/ast.json | 4 +- test/fixtures/ast/multiple-scripts-5/ast.json | 3 +- test/fixtures/ast/multiple-scripts-6/ast.json | 3 +- test/fixtures/ast/multiple-scripts-7/ast.json | 3 +- test/fixtures/ast/multiple-scripts-8/ast.json | 3 +- .../multiple-scripts-with-export01/ast.json | 3 +- .../multiple-scripts-with-export02/ast.json | 12 +- .../multiple-scripts-with-export04/ast.json | 12 +- test/fixtures/ast/multiple-scripts/ast.json | 3 +- .../ast/script-setup-example13/ast.json | 8 +- .../ast/script-setup-example14/ast.json | 3 +- .../ast/script-setup-with-export/ast.json | 3 +- .../ast/slot-scope-destructuring/ast.json | 8 +- .../ast.json | 4 +- .../ast.json | 4 +- .../ast.json | 12 +- .../ast/v-slot-default-shorthand/ast.json | 4 +- test/fixtures/ast/v-slot-default/ast.json | 4 +- .../ast/v-slot-named-shorthand/ast.json | 4 +- test/fixtures/ast/v-slot-named/ast.json | 4 +- test/fixtures/ast/vue3.3-generic-3/scope.json | 155 ++++-------------- 22 files changed, 95 insertions(+), 173 deletions(-) diff --git a/src/script/generic.ts b/src/script/generic.ts index baf96955..5509062d 100644 --- a/src/script/generic.ts +++ b/src/script/generic.ts @@ -94,7 +94,8 @@ export function extractGeneric(element: VElement): GenericProcessInfo | null { typeDefScope: Scope, isRemoveTarget: (nodeOrToken: HasLocation) => boolean, ) { - for (const variable of typeDefScope.variables) { + // eslint-disable-next-line unicorn/no-useless-spread -- The original array is mutated + for (const variable of [...typeDefScope.variables]) { let def = variable.defs.find((d) => isRemoveTarget(d.name as HasLocation), ) @@ -105,13 +106,15 @@ export function extractGeneric(element: VElement): GenericProcessInfo | null { ) } } - for (const reference of typeDefScope.references) { + // eslint-disable-next-line unicorn/no-useless-spread -- The original array is mutated + for (const reference of [...typeDefScope.references]) { if (isRemoveTarget(reference.identifier as HasLocation)) { removeReference(reference, typeDefScope) } } - for (const scope of scopeManager.scopes) { + // eslint-disable-next-line unicorn/no-useless-spread -- The original array is mutated + for (const scope of [...scopeManager.scopes]) { if (isRemoveTarget(scope.block as HasLocation)) { removeScope(scopeManager, scope) } diff --git a/test/fixtures/ast/define-model05-with-modifiers/ast.json b/test/fixtures/ast/define-model05-with-modifiers/ast.json index fc25e5f3..55f8d42e 100644 --- a/test/fixtures/ast/define-model05-with-modifiers/ast.json +++ b/test/fixtures/ast/define-model05-with-modifiers/ast.json @@ -214,7 +214,6 @@ ], "name": "set" }, - "kind": "init", "value": { "type": "FunctionExpression", "start": 71, @@ -522,7 +521,8 @@ } ] } - } + }, + "kind": "init" } ] } diff --git a/test/fixtures/ast/multiple-scripts-5/ast.json b/test/fixtures/ast/multiple-scripts-5/ast.json index 6b026649..fd0cbb7d 100644 --- a/test/fixtures/ast/multiple-scripts-5/ast.json +++ b/test/fixtures/ast/multiple-scripts-5/ast.json @@ -118,7 +118,8 @@ "kind": "let" }, "specifiers": [], - "source": null + "source": null, + "attributes": [] }, { "type": "ImportDeclaration", diff --git a/test/fixtures/ast/multiple-scripts-6/ast.json b/test/fixtures/ast/multiple-scripts-6/ast.json index 06ab461d..4d97bdcb 100644 --- a/test/fixtures/ast/multiple-scripts-6/ast.json +++ b/test/fixtures/ast/multiple-scripts-6/ast.json @@ -260,7 +260,8 @@ "kind": "const" }, "specifiers": [], - "source": null + "source": null, + "attributes": [] } ], "sourceType": "module", diff --git a/test/fixtures/ast/multiple-scripts-7/ast.json b/test/fixtures/ast/multiple-scripts-7/ast.json index eb6d9eae..ca60f41a 100644 --- a/test/fixtures/ast/multiple-scripts-7/ast.json +++ b/test/fixtures/ast/multiple-scripts-7/ast.json @@ -118,7 +118,8 @@ "kind": "let" }, "specifiers": [], - "source": null + "source": null, + "attributes": [] }, { "type": "ImportDeclaration", diff --git a/test/fixtures/ast/multiple-scripts-8/ast.json b/test/fixtures/ast/multiple-scripts-8/ast.json index 2fc13bc3..2055eb94 100644 --- a/test/fixtures/ast/multiple-scripts-8/ast.json +++ b/test/fixtures/ast/multiple-scripts-8/ast.json @@ -118,7 +118,8 @@ "kind": "let" }, "specifiers": [], - "source": null + "source": null, + "attributes": [] }, { "type": "VariableDeclaration", diff --git a/test/fixtures/ast/multiple-scripts-with-export01/ast.json b/test/fixtures/ast/multiple-scripts-with-export01/ast.json index 2b9018f4..9b0ae9fb 100644 --- a/test/fixtures/ast/multiple-scripts-with-export01/ast.json +++ b/test/fixtures/ast/multiple-scripts-with-export01/ast.json @@ -200,7 +200,8 @@ "kind": "let" }, "specifiers": [], - "source": null + "source": null, + "attributes": [] } ], "sourceType": "module", diff --git a/test/fixtures/ast/multiple-scripts-with-export02/ast.json b/test/fixtures/ast/multiple-scripts-with-export02/ast.json index 0d545d97..cf673aae 100644 --- a/test/fixtures/ast/multiple-scripts-with-export02/ast.json +++ b/test/fixtures/ast/multiple-scripts-with-export02/ast.json @@ -364,7 +364,8 @@ "kind": "let" }, "specifiers": [], - "source": null + "source": null, + "attributes": [] }, { "type": "ImportDeclaration", @@ -914,7 +915,8 @@ } } ], - "source": null + "source": null, + "attributes": [] }, { "type": "ExportNamedDeclaration", @@ -1055,7 +1057,8 @@ } } ], - "source": null + "source": null, + "attributes": [] }, { "type": "ExportNamedDeclaration", @@ -1077,7 +1080,8 @@ ], "declaration": null, "specifiers": [], - "source": null + "source": null, + "attributes": [] }, { "type": "VariableDeclaration", diff --git a/test/fixtures/ast/multiple-scripts-with-export04/ast.json b/test/fixtures/ast/multiple-scripts-with-export04/ast.json index c7b5583d..cfbba14f 100644 --- a/test/fixtures/ast/multiple-scripts-with-export04/ast.json +++ b/test/fixtures/ast/multiple-scripts-with-export04/ast.json @@ -118,7 +118,8 @@ "kind": "let" }, "specifiers": [], - "source": null + "source": null, + "attributes": [] }, { "type": "ExportNamedDeclaration", @@ -221,7 +222,8 @@ "kind": "let" }, "specifiers": [], - "source": null + "source": null, + "attributes": [] }, { "type": "ImportDeclaration", @@ -467,7 +469,8 @@ } } ], - "source": null + "source": null, + "attributes": [] }, { "type": "ExportNamedDeclaration", @@ -570,7 +573,8 @@ "kind": "let" }, "specifiers": [], - "source": null + "source": null, + "attributes": [] } ], "sourceType": "module", diff --git a/test/fixtures/ast/multiple-scripts/ast.json b/test/fixtures/ast/multiple-scripts/ast.json index bdaec0c7..0867d769 100644 --- a/test/fixtures/ast/multiple-scripts/ast.json +++ b/test/fixtures/ast/multiple-scripts/ast.json @@ -178,7 +178,8 @@ "kind": "const" }, "specifiers": [], - "source": null + "source": null, + "attributes": [] }, { "type": "VariableDeclaration", diff --git a/test/fixtures/ast/script-setup-example13/ast.json b/test/fixtures/ast/script-setup-example13/ast.json index 6a67da3b..8e2d4fe6 100644 --- a/test/fixtures/ast/script-setup-example13/ast.json +++ b/test/fixtures/ast/script-setup-example13/ast.json @@ -340,7 +340,6 @@ ], "name": "a" }, - "kind": "init", "value": { "type": "Identifier", "start": 62, @@ -360,7 +359,8 @@ 63 ], "name": "a" - } + }, + "kind": "init" }, { "type": "Property", @@ -403,7 +403,6 @@ ], "name": "b" }, - "kind": "init", "value": { "type": "Identifier", "start": 67, @@ -423,7 +422,8 @@ 68 ], "name": "b" - } + }, + "kind": "init" } ] } diff --git a/test/fixtures/ast/script-setup-example14/ast.json b/test/fixtures/ast/script-setup-example14/ast.json index 03765608..288e20da 100644 --- a/test/fixtures/ast/script-setup-example14/ast.json +++ b/test/fixtures/ast/script-setup-example14/ast.json @@ -178,7 +178,8 @@ "kind": "const" }, "specifiers": [], - "source": null + "source": null, + "attributes": [] }, { "type": "VariableDeclaration", diff --git a/test/fixtures/ast/script-setup-with-export/ast.json b/test/fixtures/ast/script-setup-with-export/ast.json index 932e9dd3..f97586b0 100644 --- a/test/fixtures/ast/script-setup-with-export/ast.json +++ b/test/fixtures/ast/script-setup-with-export/ast.json @@ -118,7 +118,8 @@ "kind": "let" }, "specifiers": [], - "source": null + "source": null, + "attributes": [] } ], "sourceType": "module", diff --git a/test/fixtures/ast/slot-scope-destructuring/ast.json b/test/fixtures/ast/slot-scope-destructuring/ast.json index bc1794e2..9ef5942d 100644 --- a/test/fixtures/ast/slot-scope-destructuring/ast.json +++ b/test/fixtures/ast/slot-scope-destructuring/ast.json @@ -319,7 +319,6 @@ ], "name": "a" }, - "kind": "init", "value": { "type": "Identifier", "start": 58, @@ -339,7 +338,8 @@ 59 ], "name": "a" - } + }, + "kind": "init" }, { "type": "Property", @@ -382,7 +382,6 @@ ], "name": "b" }, - "kind": "init", "value": { "type": "Identifier", "start": 61, @@ -402,7 +401,8 @@ 62 ], "name": "b" - } + }, + "kind": "init" }, { "type": "RestElement", diff --git a/test/fixtures/ast/v-bind-same-name-shorthand02-options/ast.json b/test/fixtures/ast/v-bind-same-name-shorthand02-options/ast.json index 84add60c..55f56637 100644 --- a/test/fixtures/ast/v-bind-same-name-shorthand02-options/ast.json +++ b/test/fixtures/ast/v-bind-same-name-shorthand02-options/ast.json @@ -95,7 +95,6 @@ ], "name": "data" }, - "kind": "init", "value": { "type": "FunctionExpression", "start": 33, @@ -244,7 +243,8 @@ } ] } - } + }, + "kind": "init" } ] } diff --git a/test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/ast.json b/test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/ast.json index 7a0ab7e5..05fdd689 100644 --- a/test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/ast.json +++ b/test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/ast.json @@ -95,7 +95,6 @@ ], "name": "data" }, - "kind": "init", "value": { "type": "FunctionExpression", "start": 33, @@ -286,7 +285,8 @@ } ] } - } + }, + "kind": "init" } ] } diff --git a/test/fixtures/ast/v-for-directives-with-destructuring/ast.json b/test/fixtures/ast/v-for-directives-with-destructuring/ast.json index ddf0f4c2..b6ede250 100644 --- a/test/fixtures/ast/v-for-directives-with-destructuring/ast.json +++ b/test/fixtures/ast/v-for-directives-with-destructuring/ast.json @@ -262,7 +262,6 @@ ], "name": "key" }, - "kind": "init", "value": { "type": "Identifier", "start": 28, @@ -282,7 +281,8 @@ 31 ], "name": "key" - } + }, + "kind": "init" }, { "type": "Property", @@ -325,7 +325,6 @@ ], "name": "name" }, - "kind": "init", "value": { "type": "Identifier", "start": 32, @@ -345,7 +344,8 @@ 36 ], "name": "name" - } + }, + "kind": "init" } ] } @@ -1460,7 +1460,6 @@ ], "name": "name" }, - "kind": "init", "value": { "type": "Identifier", "start": 163, @@ -1480,7 +1479,8 @@ 167 ], "name": "name" - } + }, + "kind": "init" } ] } diff --git a/test/fixtures/ast/v-slot-default-shorthand/ast.json b/test/fixtures/ast/v-slot-default-shorthand/ast.json index 1298f1e8..fc107094 100644 --- a/test/fixtures/ast/v-slot-default-shorthand/ast.json +++ b/test/fixtures/ast/v-slot-default-shorthand/ast.json @@ -280,7 +280,6 @@ ], "name": "foo" }, - "kind": "init", "value": { "type": "Identifier", "start": 43, @@ -300,7 +299,8 @@ 46 ], "name": "foo" - } + }, + "kind": "init" } ] } diff --git a/test/fixtures/ast/v-slot-default/ast.json b/test/fixtures/ast/v-slot-default/ast.json index 835b83b8..38fcf4da 100644 --- a/test/fixtures/ast/v-slot-default/ast.json +++ b/test/fixtures/ast/v-slot-default/ast.json @@ -262,7 +262,6 @@ ], "name": "foo" }, - "kind": "init", "value": { "type": "Identifier", "start": 41, @@ -282,7 +281,8 @@ 44 ], "name": "foo" - } + }, + "kind": "init" } ] } diff --git a/test/fixtures/ast/v-slot-named-shorthand/ast.json b/test/fixtures/ast/v-slot-named-shorthand/ast.json index a6a99b82..f7004d68 100644 --- a/test/fixtures/ast/v-slot-named-shorthand/ast.json +++ b/test/fixtures/ast/v-slot-named-shorthand/ast.json @@ -337,7 +337,6 @@ ], "name": "foo" }, - "kind": "init", "value": { "type": "Identifier", "start": 61, @@ -357,7 +356,8 @@ 64 ], "name": "foo" - } + }, + "kind": "init" } ] } diff --git a/test/fixtures/ast/v-slot-named/ast.json b/test/fixtures/ast/v-slot-named/ast.json index dcc9961d..1c337d08 100644 --- a/test/fixtures/ast/v-slot-named/ast.json +++ b/test/fixtures/ast/v-slot-named/ast.json @@ -337,7 +337,6 @@ ], "name": "foo" }, - "kind": "init", "value": { "type": "Identifier", "start": 67, @@ -357,7 +356,8 @@ 70 ], "name": "foo" - } + }, + "kind": "init" } ] } diff --git a/test/fixtures/ast/vue3.3-generic-3/scope.json b/test/fixtures/ast/vue3.3-generic-3/scope.json index fb10e250..01a2cda1 100644 --- a/test/fixtures/ast/vue3.3-generic-3/scope.json +++ b/test/fixtures/ast/vue3.3-generic-3/scope.json @@ -1160,28 +1160,35 @@ "references": [] }, { - "name": "T", + "name": "defineProps", "identifiers": [], "defs": [], "references": [ { "identifier": { "type": "Identifier", - "name": "T", + "name": "defineProps", "loc": { "end": { - "column": 11, - "line": 8 + "line": 5, + "column": 21 }, "start": { - "column": 10, - "line": 8 + "line": 5, + "column": 10 } } }, "from": "module", "init": null - }, + } + ] + }, + { + "name": "T", + "identifiers": [], + "defs": [], + "references": [ { "identifier": { "type": "Identifier", @@ -1203,22 +1210,22 @@ ] }, { - "name": "defineProps", + "name": "U", "identifiers": [], "defs": [], "references": [ { "identifier": { "type": "Identifier", - "name": "defineProps", + "name": "U", "loc": { "end": { "line": 5, - "column": 21 + "column": 36 }, "start": { "line": 5, - "column": 10 + "column": 35 } } }, @@ -1306,78 +1313,6 @@ } ] }, - { - "name": "U", - "identifiers": [ - { - "type": "Identifier", - "name": "U", - "loc": { - "end": { - "column": 6, - "line": 8 - }, - "start": { - "column": 5, - "line": 8 - } - } - } - ], - "defs": [ - { - "type": "Type", - "node": { - "type": "TSTypeAliasDeclaration", - "loc": { - "end": { - "column": 1, - "line": 9 - }, - "start": { - "column": 0, - "line": 8 - } - } - }, - "name": "U" - } - ], - "references": [ - { - "identifier": { - "type": "Identifier", - "name": "U", - "loc": { - "end": { - "line": 5, - "column": 36 - }, - "start": { - "line": 5, - "column": 35 - } - } - }, - "from": "module", - "resolved": { - "type": "Identifier", - "name": "U", - "loc": { - "end": { - "column": 6, - "line": 8 - }, - "start": { - "column": 5, - "line": 8 - } - } - }, - "init": null - } - ] - }, { "name": "p", "identifiers": [ @@ -1621,24 +1556,6 @@ } ], "references": [ - { - "identifier": { - "type": "Identifier", - "name": "T", - "loc": { - "end": { - "column": 11, - "line": 8 - }, - "start": { - "column": 10, - "line": 8 - } - } - }, - "from": "module", - "init": null - }, { "identifier": { "type": "Identifier", @@ -1723,20 +1640,6 @@ } }, "from": "module", - "resolved": { - "type": "Identifier", - "name": "U", - "loc": { - "end": { - "column": 6, - "line": 8 - }, - "start": { - "column": 5, - "line": 8 - } - } - }, "init": null }, { @@ -1860,15 +1763,15 @@ { "identifier": { "type": "Identifier", - "name": "T", + "name": "defineProps", "loc": { "end": { - "column": 11, - "line": 8 + "line": 5, + "column": 21 }, "start": { - "column": 10, - "line": 8 + "line": 5, + "column": 10 } } }, @@ -1878,15 +1781,15 @@ { "identifier": { "type": "Identifier", - "name": "defineProps", + "name": "T", "loc": { "end": { "line": 5, - "column": 21 + "column": 28 }, "start": { "line": 5, - "column": 10 + "column": 27 } } }, @@ -1896,15 +1799,15 @@ { "identifier": { "type": "Identifier", - "name": "T", + "name": "U", "loc": { "end": { "line": 5, - "column": 28 + "column": 36 }, "start": { "line": 5, - "column": 27 + "column": 35 } } }, From 9574d91be036d050f058485a8a73fd2eea17b5fe Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Wed, 5 Mar 2025 22:59:05 +0900 Subject: [PATCH 2/2] 10.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c449c660..500d3790 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-eslint-parser", - "version": "10.1.0", + "version": "10.1.1", "description": "The ESLint custom parser for `.vue` files.", "main": "index.js", "files": [ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy