From a9a234f396017a1234907de5f7e7c6a74fe7be70 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Wed, 5 Mar 2025 22:48:03 +0900 Subject: [PATCH 1/2] Fix wrong scope for generic attribute --- src/script/generic.ts | 9 +- test/fixtures/ast/vue3.3-generic-3/scope.json | 155 ++++-------------- 2 files changed, 35 insertions(+), 129 deletions(-) diff --git a/src/script/generic.ts b/src/script/generic.ts index baf9695..5509062 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/vue3.3-generic-3/scope.json b/test/fixtures/ast/vue3.3-generic-3/scope.json index fb10e25..01a2cda 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 939844a8bbbcb7846c2f60d2e402db9904aea26b Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Wed, 5 Mar 2025 22:53:49 +0900 Subject: [PATCH 2/2] update --- .../ast/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 ++- .../ast/multiple-scripts-with-export01/ast.json | 3 ++- .../ast/multiple-scripts-with-export02/ast.json | 12 ++++++++---- .../ast/multiple-scripts-with-export04/ast.json | 12 ++++++++---- test/fixtures/ast/multiple-scripts/ast.json | 3 ++- test/fixtures/ast/script-setup-example13/ast.json | 8 ++++---- test/fixtures/ast/script-setup-example14/ast.json | 3 ++- test/fixtures/ast/script-setup-with-export/ast.json | 3 ++- test/fixtures/ast/slot-scope-destructuring/ast.json | 8 ++++---- .../v-bind-same-name-shorthand02-options/ast.json | 4 ++-- .../v-bind-same-name-shorthand04-with-v-for/ast.json | 4 ++-- .../ast/v-for-directives-with-destructuring/ast.json | 12 ++++++------ test/fixtures/ast/v-slot-default-shorthand/ast.json | 4 ++-- test/fixtures/ast/v-slot-default/ast.json | 4 ++-- test/fixtures/ast/v-slot-named-shorthand/ast.json | 4 ++-- test/fixtures/ast/v-slot-named/ast.json | 4 ++-- 20 files changed, 60 insertions(+), 44 deletions(-) diff --git a/test/fixtures/ast/define-model05-with-modifiers/ast.json b/test/fixtures/ast/define-model05-with-modifiers/ast.json index fc25e5f..55f8d42 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 6b02664..fd0cbb7 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 06ab461..4d97bdc 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 eb6d9ea..ca60f41 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 2fc13bc..2055eb9 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 2b9018f..9b0ae9f 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 0d545d9..cf673aa 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 c7b5583..cfbba14 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 bdaec0c..0867d76 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 6a67da3..8e2d4fe 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 0376560..288e20d 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 932e9dd..f97586b 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 bc1794e..9ef5942 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 84add60..55f5663 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 7a0ab7e..05fdd68 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 ddf0f4c..b6ede25 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 1298f1e..fc10709 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 835b83b..38fcf4d 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 a6a99b8..f7004d6 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 dcc9961..1c337d0 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" } ] } 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