Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/script-setup/scope-analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,10 @@ function analyzeScriptSetupVariables(
)

const genericDefineNames = new Set<string>()
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)
}
Expand Down
46 changes: 25 additions & 21 deletions test/fixtures/ast/vue3.3-generic-2/scope.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down Expand Up @@ -1296,7 +1321,6 @@
}
},
"from": "module",
"resolved": null,
"init": null
},
{
Expand Down Expand Up @@ -1451,7 +1475,6 @@
}
},
"from": "module",
"resolved": null,
"init": null
},
{
Expand All @@ -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",
Expand Down
92 changes: 50 additions & 42 deletions test/fixtures/ast/vue3.3-generic-3/scope.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down Expand Up @@ -1296,7 +1346,6 @@
}
},
"from": "module",
"resolved": null,
"init": null
},
{
Expand All @@ -1315,7 +1364,6 @@
}
},
"from": "module",
"resolved": null,
"init": null
},
{
Expand Down Expand Up @@ -1470,7 +1518,6 @@
}
},
"from": "module",
"resolved": null,
"init": null
},
{
Expand All @@ -1489,7 +1536,6 @@
}
},
"from": "module",
"resolved": null,
"init": null
},
{
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script lang="ts">
export default {}
</script>
<script setup lang="ts" generic="T extends Foo | Bar">
type Foo = number | string
type Bar = number[] | string[]
interface Props {
msg?: T
}
defineProps<Props>(), {
msg: 'hello',
}
</script>