Skip to content

Commit 8fef4ca

Browse files
authored
Fix wrong scope for generic attribute (#254)
* Fix wrong scope for generic attribute * update
1 parent 2af9766 commit 8fef4ca

File tree

22 files changed

+95
-173
lines changed

22 files changed

+95
-173
lines changed

src/script/generic.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ export function extractGeneric(element: VElement): GenericProcessInfo | null {
9494
typeDefScope: Scope,
9595
isRemoveTarget: (nodeOrToken: HasLocation) => boolean,
9696
) {
97-
for (const variable of typeDefScope.variables) {
97+
// eslint-disable-next-line unicorn/no-useless-spread -- The original array is mutated
98+
for (const variable of [...typeDefScope.variables]) {
9899
let def = variable.defs.find((d) =>
99100
isRemoveTarget(d.name as HasLocation),
100101
)
@@ -105,13 +106,15 @@ export function extractGeneric(element: VElement): GenericProcessInfo | null {
105106
)
106107
}
107108
}
108-
for (const reference of typeDefScope.references) {
109+
// eslint-disable-next-line unicorn/no-useless-spread -- The original array is mutated
110+
for (const reference of [...typeDefScope.references]) {
109111
if (isRemoveTarget(reference.identifier as HasLocation)) {
110112
removeReference(reference, typeDefScope)
111113
}
112114
}
113115

114-
for (const scope of scopeManager.scopes) {
116+
// eslint-disable-next-line unicorn/no-useless-spread -- The original array is mutated
117+
for (const scope of [...scopeManager.scopes]) {
115118
if (isRemoveTarget(scope.block as HasLocation)) {
116119
removeScope(scopeManager, scope)
117120
}

test/fixtures/ast/define-model05-with-modifiers/ast.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@
214214
],
215215
"name": "set"
216216
},
217-
"kind": "init",
218217
"value": {
219218
"type": "FunctionExpression",
220219
"start": 71,
@@ -522,7 +521,8 @@
522521
}
523522
]
524523
}
525-
}
524+
},
525+
"kind": "init"
526526
}
527527
]
528528
}

test/fixtures/ast/multiple-scripts-5/ast.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@
118118
"kind": "let"
119119
},
120120
"specifiers": [],
121-
"source": null
121+
"source": null,
122+
"attributes": []
122123
},
123124
{
124125
"type": "ImportDeclaration",

test/fixtures/ast/multiple-scripts-6/ast.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@
260260
"kind": "const"
261261
},
262262
"specifiers": [],
263-
"source": null
263+
"source": null,
264+
"attributes": []
264265
}
265266
],
266267
"sourceType": "module",

test/fixtures/ast/multiple-scripts-7/ast.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@
118118
"kind": "let"
119119
},
120120
"specifiers": [],
121-
"source": null
121+
"source": null,
122+
"attributes": []
122123
},
123124
{
124125
"type": "ImportDeclaration",

test/fixtures/ast/multiple-scripts-8/ast.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@
118118
"kind": "let"
119119
},
120120
"specifiers": [],
121-
"source": null
121+
"source": null,
122+
"attributes": []
122123
},
123124
{
124125
"type": "VariableDeclaration",

test/fixtures/ast/multiple-scripts-with-export01/ast.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@
200200
"kind": "let"
201201
},
202202
"specifiers": [],
203-
"source": null
203+
"source": null,
204+
"attributes": []
204205
}
205206
],
206207
"sourceType": "module",

test/fixtures/ast/multiple-scripts-with-export02/ast.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@
364364
"kind": "let"
365365
},
366366
"specifiers": [],
367-
"source": null
367+
"source": null,
368+
"attributes": []
368369
},
369370
{
370371
"type": "ImportDeclaration",
@@ -914,7 +915,8 @@
914915
}
915916
}
916917
],
917-
"source": null
918+
"source": null,
919+
"attributes": []
918920
},
919921
{
920922
"type": "ExportNamedDeclaration",
@@ -1055,7 +1057,8 @@
10551057
}
10561058
}
10571059
],
1058-
"source": null
1060+
"source": null,
1061+
"attributes": []
10591062
},
10601063
{
10611064
"type": "ExportNamedDeclaration",
@@ -1077,7 +1080,8 @@
10771080
],
10781081
"declaration": null,
10791082
"specifiers": [],
1080-
"source": null
1083+
"source": null,
1084+
"attributes": []
10811085
},
10821086
{
10831087
"type": "VariableDeclaration",

test/fixtures/ast/multiple-scripts-with-export04/ast.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@
118118
"kind": "let"
119119
},
120120
"specifiers": [],
121-
"source": null
121+
"source": null,
122+
"attributes": []
122123
},
123124
{
124125
"type": "ExportNamedDeclaration",
@@ -221,7 +222,8 @@
221222
"kind": "let"
222223
},
223224
"specifiers": [],
224-
"source": null
225+
"source": null,
226+
"attributes": []
225227
},
226228
{
227229
"type": "ImportDeclaration",
@@ -467,7 +469,8 @@
467469
}
468470
}
469471
],
470-
"source": null
472+
"source": null,
473+
"attributes": []
471474
},
472475
{
473476
"type": "ExportNamedDeclaration",
@@ -570,7 +573,8 @@
570573
"kind": "let"
571574
},
572575
"specifiers": [],
573-
"source": null
576+
"source": null,
577+
"attributes": []
574578
}
575579
],
576580
"sourceType": "module",

test/fixtures/ast/multiple-scripts/ast.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@
178178
"kind": "const"
179179
},
180180
"specifiers": [],
181-
"source": null
181+
"source": null,
182+
"attributes": []
182183
},
183184
{
184185
"type": "VariableDeclaration",

0 commit comments

Comments
 (0)