Skip to content

Commit

Permalink
Fix crash for script setup in no-obj-calls rule (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed May 17, 2022
1 parent fb2f67d commit f14d066
Show file tree
Hide file tree
Showing 12 changed files with 2,200 additions and 3 deletions.
3 changes: 3 additions & 0 deletions scripts/update-fixtures-ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ function scopeToJSON(scopeManager) {
reference.resolved.defs[0].name,
),
init: reference.init || null,
vueUsedInTemplate: reference.vueUsedInTemplate
? reference.vueUsedInTemplate
: undefined,
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/script-setup/scope-analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function analyzeUsedInTemplateVariables(

function markVariableAsUsed(name: string) {
const variable = scriptVariables.get(name)
if (!variable) {
if (!variable || variable.identifiers.length === 0) {
return
}
if (markedVariables.has(name)) {
Expand Down
105 changes: 103 additions & 2 deletions test/fixtures/ast/multiple-scripts-7/scope.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,39 @@
}
},
"init": true
},
{
"identifier": {
"type": "Identifier",
"name": "count",
"loc": {
"start": {
"line": 2,
"column": 11
},
"end": {
"line": 2,
"column": 16
}
}
},
"from": "module",
"resolved": {
"type": "Identifier",
"name": "count",
"loc": {
"start": {
"line": 2,
"column": 11
},
"end": {
"line": 2,
"column": 16
}
}
},
"init": null,
"vueUsedInTemplate": true
}
]
},
Expand Down Expand Up @@ -178,7 +211,41 @@
"name": "MyComponent1"
}
],
"references": []
"references": [
{
"identifier": {
"type": "Identifier",
"name": "MyComponent1",
"loc": {
"start": {
"line": 6,
"column": 7
},
"end": {
"line": 6,
"column": 19
}
}
},
"from": "module",
"resolved": {
"type": "Identifier",
"name": "MyComponent1",
"loc": {
"start": {
"line": 6,
"column": 7
},
"end": {
"line": 6,
"column": 19
}
}
},
"init": null,
"vueUsedInTemplate": true
}
]
},
{
"name": "MyComponent2",
Expand Down Expand Up @@ -217,7 +284,41 @@
"name": "MyComponent2"
}
],
"references": []
"references": [
{
"identifier": {
"type": "Identifier",
"name": "MyComponent2",
"loc": {
"start": {
"line": 8,
"column": 7
},
"end": {
"line": 8,
"column": 19
}
}
},
"from": "module",
"resolved": {
"type": "Identifier",
"name": "MyComponent2",
"loc": {
"start": {
"line": 8,
"column": 7
},
"end": {
"line": 8,
"column": 19
}
}
},
"init": null,
"vueUsedInTemplate": true
}
]
},
{
"name": "a",
Expand Down
Loading

0 comments on commit f14d066

Please sign in to comment.