diff --git a/src/script-setup/scope-analyzer.ts b/src/script-setup/scope-analyzer.ts index 15d23a3..46ae6ce 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 9629ab0..261ad36 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 7deedb7..07bfd16 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 0000000..7d10afc --- /dev/null +++ b/test/fixtures/integrations/script-setup-with-typescript-eslint/no-undef/valid/generic2.vue @@ -0,0 +1,13 @@ + +