Skip to content

Commit 8fef4ca

Browse files
authoredMar 5, 2025··
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

+6-3
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

+2-2
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

+2-1
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

+2-1
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

+2-1
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

+2-1
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

+2-1
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

+8-4
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

+8-4
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

+2-1
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",

‎test/fixtures/ast/script-setup-example13/ast.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@
340340
],
341341
"name": "a"
342342
},
343-
"kind": "init",
344343
"value": {
345344
"type": "Identifier",
346345
"start": 62,
@@ -360,7 +359,8 @@
360359
63
361360
],
362361
"name": "a"
363-
}
362+
},
363+
"kind": "init"
364364
},
365365
{
366366
"type": "Property",
@@ -403,7 +403,6 @@
403403
],
404404
"name": "b"
405405
},
406-
"kind": "init",
407406
"value": {
408407
"type": "Identifier",
409408
"start": 67,
@@ -423,7 +422,8 @@
423422
68
424423
],
425424
"name": "b"
426-
}
425+
},
426+
"kind": "init"
427427
}
428428
]
429429
}

‎test/fixtures/ast/script-setup-example14/ast.json

+2-1
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",

‎test/fixtures/ast/script-setup-with-export/ast.json

+2-1
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
"sourceType": "module",

‎test/fixtures/ast/slot-scope-destructuring/ast.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@
319319
],
320320
"name": "a"
321321
},
322-
"kind": "init",
323322
"value": {
324323
"type": "Identifier",
325324
"start": 58,
@@ -339,7 +338,8 @@
339338
59
340339
],
341340
"name": "a"
342-
}
341+
},
342+
"kind": "init"
343343
},
344344
{
345345
"type": "Property",
@@ -382,7 +382,6 @@
382382
],
383383
"name": "b"
384384
},
385-
"kind": "init",
386385
"value": {
387386
"type": "Identifier",
388387
"start": 61,
@@ -402,7 +401,8 @@
402401
62
403402
],
404403
"name": "b"
405-
}
404+
},
405+
"kind": "init"
406406
},
407407
{
408408
"type": "RestElement",

‎test/fixtures/ast/v-bind-same-name-shorthand02-options/ast.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
],
9696
"name": "data"
9797
},
98-
"kind": "init",
9998
"value": {
10099
"type": "FunctionExpression",
101100
"start": 33,
@@ -244,7 +243,8 @@
244243
}
245244
]
246245
}
247-
}
246+
},
247+
"kind": "init"
248248
}
249249
]
250250
}

‎test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/ast.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
],
9696
"name": "data"
9797
},
98-
"kind": "init",
9998
"value": {
10099
"type": "FunctionExpression",
101100
"start": 33,
@@ -286,7 +285,8 @@
286285
}
287286
]
288287
}
289-
}
288+
},
289+
"kind": "init"
290290
}
291291
]
292292
}

‎test/fixtures/ast/v-for-directives-with-destructuring/ast.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@
262262
],
263263
"name": "key"
264264
},
265-
"kind": "init",
266265
"value": {
267266
"type": "Identifier",
268267
"start": 28,
@@ -282,7 +281,8 @@
282281
31
283282
],
284283
"name": "key"
285-
}
284+
},
285+
"kind": "init"
286286
},
287287
{
288288
"type": "Property",
@@ -325,7 +325,6 @@
325325
],
326326
"name": "name"
327327
},
328-
"kind": "init",
329328
"value": {
330329
"type": "Identifier",
331330
"start": 32,
@@ -345,7 +344,8 @@
345344
36
346345
],
347346
"name": "name"
348-
}
347+
},
348+
"kind": "init"
349349
}
350350
]
351351
}
@@ -1460,7 +1460,6 @@
14601460
],
14611461
"name": "name"
14621462
},
1463-
"kind": "init",
14641463
"value": {
14651464
"type": "Identifier",
14661465
"start": 163,
@@ -1480,7 +1479,8 @@
14801479
167
14811480
],
14821481
"name": "name"
1483-
}
1482+
},
1483+
"kind": "init"
14841484
}
14851485
]
14861486
}

‎test/fixtures/ast/v-slot-default-shorthand/ast.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@
280280
],
281281
"name": "foo"
282282
},
283-
"kind": "init",
284283
"value": {
285284
"type": "Identifier",
286285
"start": 43,
@@ -300,7 +299,8 @@
300299
46
301300
],
302301
"name": "foo"
303-
}
302+
},
303+
"kind": "init"
304304
}
305305
]
306306
}

‎test/fixtures/ast/v-slot-default/ast.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@
262262
],
263263
"name": "foo"
264264
},
265-
"kind": "init",
266265
"value": {
267266
"type": "Identifier",
268267
"start": 41,
@@ -282,7 +281,8 @@
282281
44
283282
],
284283
"name": "foo"
285-
}
284+
},
285+
"kind": "init"
286286
}
287287
]
288288
}

‎test/fixtures/ast/v-slot-named-shorthand/ast.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@
337337
],
338338
"name": "foo"
339339
},
340-
"kind": "init",
341340
"value": {
342341
"type": "Identifier",
343342
"start": 61,
@@ -357,7 +356,8 @@
357356
64
358357
],
359358
"name": "foo"
360-
}
359+
},
360+
"kind": "init"
361361
}
362362
]
363363
}

‎test/fixtures/ast/v-slot-named/ast.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@
337337
],
338338
"name": "foo"
339339
},
340-
"kind": "init",
341340
"value": {
342341
"type": "Identifier",
343342
"start": 67,
@@ -357,7 +356,8 @@
357356
70
358357
],
359358
"name": "foo"
360-
}
359+
},
360+
"kind": "init"
361361
}
362362
]
363363
}

‎test/fixtures/ast/vue3.3-generic-3/scope.json

+29-126
Original file line numberDiff line numberDiff line change
@@ -1160,28 +1160,35 @@
11601160
"references": []
11611161
},
11621162
{
1163-
"name": "T",
1163+
"name": "defineProps",
11641164
"identifiers": [],
11651165
"defs": [],
11661166
"references": [
11671167
{
11681168
"identifier": {
11691169
"type": "Identifier",
1170-
"name": "T",
1170+
"name": "defineProps",
11711171
"loc": {
11721172
"end": {
1173-
"column": 11,
1174-
"line": 8
1173+
"line": 5,
1174+
"column": 21
11751175
},
11761176
"start": {
1177-
"column": 10,
1178-
"line": 8
1177+
"line": 5,
1178+
"column": 10
11791179
}
11801180
}
11811181
},
11821182
"from": "module",
11831183
"init": null
1184-
},
1184+
}
1185+
]
1186+
},
1187+
{
1188+
"name": "T",
1189+
"identifiers": [],
1190+
"defs": [],
1191+
"references": [
11851192
{
11861193
"identifier": {
11871194
"type": "Identifier",
@@ -1203,22 +1210,22 @@
12031210
]
12041211
},
12051212
{
1206-
"name": "defineProps",
1213+
"name": "U",
12071214
"identifiers": [],
12081215
"defs": [],
12091216
"references": [
12101217
{
12111218
"identifier": {
12121219
"type": "Identifier",
1213-
"name": "defineProps",
1220+
"name": "U",
12141221
"loc": {
12151222
"end": {
12161223
"line": 5,
1217-
"column": 21
1224+
"column": 36
12181225
},
12191226
"start": {
12201227
"line": 5,
1221-
"column": 10
1228+
"column": 35
12221229
}
12231230
}
12241231
},
@@ -1306,78 +1313,6 @@
13061313
}
13071314
]
13081315
},
1309-
{
1310-
"name": "U",
1311-
"identifiers": [
1312-
{
1313-
"type": "Identifier",
1314-
"name": "U",
1315-
"loc": {
1316-
"end": {
1317-
"column": 6,
1318-
"line": 8
1319-
},
1320-
"start": {
1321-
"column": 5,
1322-
"line": 8
1323-
}
1324-
}
1325-
}
1326-
],
1327-
"defs": [
1328-
{
1329-
"type": "Type",
1330-
"node": {
1331-
"type": "TSTypeAliasDeclaration",
1332-
"loc": {
1333-
"end": {
1334-
"column": 1,
1335-
"line": 9
1336-
},
1337-
"start": {
1338-
"column": 0,
1339-
"line": 8
1340-
}
1341-
}
1342-
},
1343-
"name": "U"
1344-
}
1345-
],
1346-
"references": [
1347-
{
1348-
"identifier": {
1349-
"type": "Identifier",
1350-
"name": "U",
1351-
"loc": {
1352-
"end": {
1353-
"line": 5,
1354-
"column": 36
1355-
},
1356-
"start": {
1357-
"line": 5,
1358-
"column": 35
1359-
}
1360-
}
1361-
},
1362-
"from": "module",
1363-
"resolved": {
1364-
"type": "Identifier",
1365-
"name": "U",
1366-
"loc": {
1367-
"end": {
1368-
"column": 6,
1369-
"line": 8
1370-
},
1371-
"start": {
1372-
"column": 5,
1373-
"line": 8
1374-
}
1375-
}
1376-
},
1377-
"init": null
1378-
}
1379-
]
1380-
},
13811316
{
13821317
"name": "p",
13831318
"identifiers": [
@@ -1621,24 +1556,6 @@
16211556
}
16221557
],
16231558
"references": [
1624-
{
1625-
"identifier": {
1626-
"type": "Identifier",
1627-
"name": "T",
1628-
"loc": {
1629-
"end": {
1630-
"column": 11,
1631-
"line": 8
1632-
},
1633-
"start": {
1634-
"column": 10,
1635-
"line": 8
1636-
}
1637-
}
1638-
},
1639-
"from": "module",
1640-
"init": null
1641-
},
16421559
{
16431560
"identifier": {
16441561
"type": "Identifier",
@@ -1723,20 +1640,6 @@
17231640
}
17241641
},
17251642
"from": "module",
1726-
"resolved": {
1727-
"type": "Identifier",
1728-
"name": "U",
1729-
"loc": {
1730-
"end": {
1731-
"column": 6,
1732-
"line": 8
1733-
},
1734-
"start": {
1735-
"column": 5,
1736-
"line": 8
1737-
}
1738-
}
1739-
},
17401643
"init": null
17411644
},
17421645
{
@@ -1860,15 +1763,15 @@
18601763
{
18611764
"identifier": {
18621765
"type": "Identifier",
1863-
"name": "T",
1766+
"name": "defineProps",
18641767
"loc": {
18651768
"end": {
1866-
"column": 11,
1867-
"line": 8
1769+
"line": 5,
1770+
"column": 21
18681771
},
18691772
"start": {
1870-
"column": 10,
1871-
"line": 8
1773+
"line": 5,
1774+
"column": 10
18721775
}
18731776
}
18741777
},
@@ -1878,15 +1781,15 @@
18781781
{
18791782
"identifier": {
18801783
"type": "Identifier",
1881-
"name": "defineProps",
1784+
"name": "T",
18821785
"loc": {
18831786
"end": {
18841787
"line": 5,
1885-
"column": 21
1788+
"column": 28
18861789
},
18871790
"start": {
18881791
"line": 5,
1889-
"column": 10
1792+
"column": 27
18901793
}
18911794
}
18921795
},
@@ -1896,15 +1799,15 @@
18961799
{
18971800
"identifier": {
18981801
"type": "Identifier",
1899-
"name": "T",
1802+
"name": "U",
19001803
"loc": {
19011804
"end": {
19021805
"line": 5,
1903-
"column": 28
1806+
"column": 36
19041807
},
19051808
"start": {
19061809
"line": 5,
1907-
"column": 27
1810+
"column": 35
19081811
}
19091812
}
19101813
},

0 commit comments

Comments
 (0)
Please sign in to comment.