From c765d2bc5f576a2968b54a597f53812fe81b4b55 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Sun, 11 Jun 2023 10:51:24 +0900 Subject: [PATCH] Fix wrong scope for generics with multiple script blocks --- src/script-setup/scope-analyzer.ts | 11 +-- test/fixtures/ast/vue3.3-generic-2/scope.json | 46 +++++----- test/fixtures/ast/vue3.3-generic-3/scope.json | 92 ++++++++++--------- .../no-undef/valid/generic2.vue | 13 +++ 4 files changed, 92 insertions(+), 70 deletions(-) create mode 100644 test/fixtures/integrations/script-setup-with-typescript-eslint/no-undef/valid/generic2.vue diff --git a/src/script-setup/scope-analyzer.ts b/src/script-setup/scope-analyzer.ts index 15d23a3a..46ae6cef 100644 --- a/src/script-setup/scope-analyzer.ts +++ b/src/script-setup/scope-analyzer.ts @@ -321,13 +321,10 @@ function analyzeScriptSetupVariables( ) const genericDefineNames = new Set() - const scriptElement = df.children.find(isScriptElement) - if ( - scriptElement && - isScriptSetupElement(scriptElement) && - findGenericDirective(scriptElement) - ) { - for (const variable of scriptElement.variables) { + const scriptElements = df.children.filter(isScriptElement) + const scriptSetupElement = scriptElements.find(isScriptSetupElement) + if (scriptSetupElement && findGenericDirective(scriptSetupElement)) { + for (const variable of scriptSetupElement.variables) { if (variable.kind === "generic") { genericDefineNames.add(variable.id.name) } diff --git a/test/fixtures/ast/vue3.3-generic-2/scope.json b/test/fixtures/ast/vue3.3-generic-2/scope.json index 9629ab05..261ad368 100644 --- a/test/fixtures/ast/vue3.3-generic-2/scope.json +++ b/test/fixtures/ast/vue3.3-generic-2/scope.json @@ -907,6 +907,31 @@ "init": null } ] + }, + { + "name": "T", + "identifiers": [], + "defs": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "T", + "loc": { + "start": { + "line": 5, + "column": 27 + }, + "end": { + "line": 5, + "column": 28 + } + } + }, + "from": "module", + "init": null + } + ] } ], "references": [], @@ -1296,7 +1321,6 @@ } }, "from": "module", - "resolved": null, "init": null }, { @@ -1451,7 +1475,6 @@ } }, "from": "module", - "resolved": null, "init": null }, { @@ -1477,25 +1500,6 @@ } ], "through": [ - { - "identifier": { - "type": "Identifier", - "name": "T", - "loc": { - "start": { - "line": 5, - "column": 27 - }, - "end": { - "line": 5, - "column": 28 - } - } - }, - "from": "module", - "resolved": null, - "init": null - }, { "identifier": { "type": "Identifier", diff --git a/test/fixtures/ast/vue3.3-generic-3/scope.json b/test/fixtures/ast/vue3.3-generic-3/scope.json index 7deedb76..07bfd168 100644 --- a/test/fixtures/ast/vue3.3-generic-3/scope.json +++ b/test/fixtures/ast/vue3.3-generic-3/scope.json @@ -907,6 +907,56 @@ "init": null } ] + }, + { + "name": "T", + "identifiers": [], + "defs": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "T", + "loc": { + "start": { + "line": 5, + "column": 27 + }, + "end": { + "line": 5, + "column": 28 + } + } + }, + "from": "module", + "init": null + } + ] + }, + { + "name": "U", + "identifiers": [], + "defs": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "U", + "loc": { + "start": { + "line": 5, + "column": 35 + }, + "end": { + "line": 5, + "column": 36 + } + } + }, + "from": "module", + "init": null + } + ] } ], "references": [], @@ -1296,7 +1346,6 @@ } }, "from": "module", - "resolved": null, "init": null }, { @@ -1315,7 +1364,6 @@ } }, "from": "module", - "resolved": null, "init": null }, { @@ -1470,7 +1518,6 @@ } }, "from": "module", - "resolved": null, "init": null }, { @@ -1489,7 +1536,6 @@ } }, "from": "module", - "resolved": null, "init": null }, { @@ -1515,44 +1561,6 @@ } ], "through": [ - { - "identifier": { - "type": "Identifier", - "name": "T", - "loc": { - "start": { - "line": 5, - "column": 27 - }, - "end": { - "line": 5, - "column": 28 - } - } - }, - "from": "module", - "resolved": null, - "init": null - }, - { - "identifier": { - "type": "Identifier", - "name": "U", - "loc": { - "start": { - "line": 5, - "column": 35 - }, - "end": { - "line": 5, - "column": 36 - } - } - }, - "from": "module", - "resolved": null, - "init": null - }, { "identifier": { "type": "Identifier", diff --git a/test/fixtures/integrations/script-setup-with-typescript-eslint/no-undef/valid/generic2.vue b/test/fixtures/integrations/script-setup-with-typescript-eslint/no-undef/valid/generic2.vue new file mode 100644 index 00000000..7d10afcf --- /dev/null +++ b/test/fixtures/integrations/script-setup-with-typescript-eslint/no-undef/valid/generic2.vue @@ -0,0 +1,13 @@ + + 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