Skip to content

Commit bc39dcb

Browse files
committed
fix: typeParameters->typeArguments in some places to align with TSESTree spec
fixes TyrealHu/acorn-typescript#66
1 parent e0704b3 commit bc39dcb

File tree

19 files changed

+49
-43
lines changed

19 files changed

+49
-43
lines changed

.changeset/tame-eggs-dress.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/acorn-typescript': patch
3+
---
4+
5+
fix: typeParameters->typeArguments in some places to align with TSESTree spec

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ Version 1.0 of `@sveltejs/acorn-typescript` has some breaking changes compared t
2929
- JSX parsing is disabled by default now (you can turn it back on by passing `{ jsx: true }`)
3030
- `allowSatisfies` option was removed, `satisfies` operator is always parsed now
3131
- `index` on `loc` was removed
32+
- `typeParameters` is now `typeArguments` in some places (like `TSTypeReference`) to align with the TSESTree spec
3233

3334
Changelog of the project this originated from: https://github.com/TyrealHu/acorn-typescript/CHANGELOG.md

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"check": "tsc --noEmit",
1515
"lint": "prettier --check .",
1616
"test": "vitest run",
17-
"test:update": "cross-env UPDATE_SNAPSHOT=true vitest run",
18-
"test:test262": "npm run build && node ./__test__/run_test262.js",
17+
"test:update": "cross-env UPDATE_SNAPSHOT=true vitest run && npm run format",
18+
"test:test262": "npm run build && node ./test/run_test262.js",
1919
"changeset:version": "changeset version && git add --all",
2020
"changeset:release": "changeset publish"
2121
},

src/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,7 @@ export function tsPlugin(options?: {
14491449
// type and not as a const signifier. We'll *never* be able to find this
14501450
// name, since const isn't allowed as a type name. So in this instance we
14511451
// get to pretend we're the type checker.
1452-
if (typeReference.typeParameters) {
1452+
if (typeReference.typeParameters || typeReference.typeArguments) {
14531453
this.raise(
14541454
typeReference.typeName.start,
14551455
TypeScriptError.CannotFindName({
@@ -1573,7 +1573,7 @@ export function tsPlugin(options?: {
15731573
node.qualifier = this.tsParseEntityName();
15741574
}
15751575
if (this.tsMatchLeftRelational()) {
1576-
node.typeParameters = this.tsParseTypeArguments();
1576+
node.typeArguments = this.tsParseTypeArguments();
15771577
}
15781578
return this.finishNode(node, 'TSImportType');
15791579
}
@@ -1587,7 +1587,7 @@ export function tsPlugin(options?: {
15871587
node.exprName = this.tsParseEntityName();
15881588
}
15891589
if (!this.hasPrecedingLineBreak() && this.tsMatchLeftRelational()) {
1590-
node.typeParameters = this.tsParseTypeArguments();
1590+
node.typeArguments = this.tsParseTypeArguments();
15911591
}
15921592
return this.finishNode(node, 'TSTypeQuery');
15931593
}
@@ -1652,7 +1652,7 @@ export function tsPlugin(options?: {
16521652

16531653
if (
16541654
type.type === 'TSTypeReference' &&
1655-
!type.typeParameters &&
1655+
!type.typeArguments &&
16561656
type.typeName.type === 'Identifier'
16571657
) {
16581658
labeledNode.label = type.typeName as any;
@@ -1735,7 +1735,7 @@ export function tsPlugin(options?: {
17351735
const node = this.startNode();
17361736
node.typeName = this.tsParseEntityName();
17371737
if (!this.hasPrecedingLineBreak() && this.tsMatchLeftRelational()) {
1738-
node.typeParameters = this.tsParseTypeArguments();
1738+
node.typeArguments = this.tsParseTypeArguments();
17391739
}
17401740
return this.finishNode(node, 'TSTypeReference');
17411741
}
@@ -2886,7 +2886,7 @@ export function tsPlugin(options?: {
28862886
// ---start parseNewCallee extension
28872887
const { callee } = node;
28882888
if (callee.type === 'TSInstantiationExpression' && !callee.extra?.parenthesized) {
2889-
node.typeParameters = callee.typeParameters;
2889+
node.typeArguments = callee.typeArguments;
28902890
node.callee = callee.expression;
28912891
}
28922892
// ---end
@@ -4591,7 +4591,7 @@ export function tsPlugin(options?: {
45914591
startLoc,
45924592
_optionalChained
45934593
);
4594-
result.typeParameters = typeArguments;
4594+
result.typeArguments = typeArguments;
45954595
return result;
45964596
}
45974597

@@ -4609,7 +4609,7 @@ export function tsPlugin(options?: {
46094609
);
46104610
// Handles invalid case: `f<T>(a:b)`
46114611
this.tsCheckForInvalidTypeCasts(node.arguments);
4612-
node.typeParameters = typeArguments;
4612+
node.typeArguments = typeArguments;
46134613
if (_optionalChained) {
46144614
node.optional = isOptionalCall;
46154615
}
@@ -4633,7 +4633,7 @@ export function tsPlugin(options?: {
46334633
}
46344634
const node = this.startNodeAt(startPos, startLoc);
46354635
node.expression = base;
4636-
node.typeParameters = typeArguments;
4636+
node.typeArguments = typeArguments;
46374637
return this.finishNode(node, 'TSInstantiationExpression');
46384638
});
46394639
if (missingParenErrorLoc) {
@@ -5152,7 +5152,7 @@ export function tsPlugin(options?: {
51525152
const typeArguments = this.tsTryParseAndCatch(() =>
51535153
this.tsParseTypeArgumentsInExpression()
51545154
);
5155-
if (typeArguments) node.typeParameters = typeArguments;
5155+
if (typeArguments) node.typeArguments = typeArguments;
51565156
}
51575157

51585158
node.attributes = [];

test/class_issue_33/expected.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
},
139139
"name": "Map"
140140
},
141-
"typeParameters": {
141+
"typeArguments": {
142142
"type": "TSTypeParameterInstantiation",
143143
"start": 81,
144144
"end": 96,
@@ -284,7 +284,7 @@
284284
},
285285
"name": "Set"
286286
},
287-
"typeParameters": {
287+
"typeArguments": {
288288
"type": "TSTypeParameterInstantiation",
289289
"start": 149,
290290
"end": 157,
@@ -541,7 +541,7 @@
541541
},
542542
"name": "ReadonlySet"
543543
},
544-
"typeParameters": {
544+
"typeArguments": {
545545
"type": "TSTypeParameterInstantiation",
546546
"start": 294,
547547
"end": 302,

test/class_issue_34/expected.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@
249249
},
250250
"name": "Map"
251251
},
252-
"typeParameters": {
252+
"typeArguments": {
253253
"type": "TSTypeParameterInstantiation",
254254
"start": 121,
255255
"end": 141,
@@ -716,7 +716,7 @@
716716
},
717717
"name": "Map"
718718
},
719-
"typeParameters": {
719+
"typeArguments": {
720720
"type": "TSTypeParameterInstantiation",
721721
"start": 369,
722722
"end": 402,
@@ -1313,7 +1313,7 @@
13131313
},
13141314
"name": "Record"
13151315
},
1316-
"typeParameters": {
1316+
"typeArguments": {
13171317
"type": "TSTypeParameterInstantiation",
13181318
"start": 670,
13191319
"end": 684,
@@ -1927,7 +1927,7 @@
19271927
},
19281928
"name": "Record"
19291929
},
1930-
"typeParameters": {
1930+
"typeArguments": {
19311931
"type": "TSTypeParameterInstantiation",
19321932
"start": 938,
19331933
"end": 971,

test/class_issue_35/expected.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@
517517
},
518518
"name": "ReadonlyMap"
519519
},
520-
"typeParameters": {
520+
"typeArguments": {
521521
"type": "TSTypeParameterInstantiation",
522522
"start": 259,
523523
"end": 274,
@@ -1016,7 +1016,7 @@
10161016
},
10171017
"name": "ReadonlyMap"
10181018
},
1019-
"typeParameters": {
1019+
"typeArguments": {
10201020
"type": "TSTypeParameterInstantiation",
10211021
"start": 560,
10221022
"end": 583,
@@ -1276,7 +1276,7 @@
12761276
},
12771277
"name": "Map"
12781278
},
1279-
"typeParameters": {
1279+
"typeArguments": {
12801280
"type": "TSTypeParameterInstantiation",
12811281
"start": 686,
12821282
"end": 714,
@@ -1437,7 +1437,7 @@
14371437
},
14381438
"name": "Set"
14391439
},
1440-
"typeParameters": {
1440+
"typeArguments": {
14411441
"type": "TSTypeParameterInstantiation",
14421442
"start": 771,
14431443
"end": 783,
@@ -1773,7 +1773,7 @@
17731773
},
17741774
"name": "Parameters"
17751775
},
1776-
"typeParameters": {
1776+
"typeArguments": {
17771777
"type": "TSTypeParameterInstantiation",
17781778
"start": 921,
17791779
"end": 945,
@@ -2040,7 +2040,7 @@
20402040
},
20412041
"name": "ReadonlySet"
20422042
},
2043-
"typeParameters": {
2043+
"typeArguments": {
20442044
"type": "TSTypeParameterInstantiation",
20452045
"start": 1040,
20462046
"end": 1048,
@@ -2153,7 +2153,7 @@
21532153
},
21542154
"name": "Promise"
21552155
},
2156-
"typeParameters": {
2156+
"typeArguments": {
21572157
"type": "TSTypeParameterInstantiation",
21582158
"start": 1074,
21592159
"end": 1117,
@@ -2213,7 +2213,7 @@
22132213
},
22142214
"name": "ReturnType"
22152215
},
2216-
"typeParameters": {
2216+
"typeArguments": {
22172217
"type": "TSTypeParameterInstantiation",
22182218
"start": 1085,
22192219
"end": 1109,
@@ -2432,7 +2432,7 @@
24322432
},
24332433
"name": "Promise"
24342434
},
2435-
"typeParameters": {
2435+
"typeArguments": {
24362436
"type": "TSTypeParameterInstantiation",
24372437
"start": 1156,
24382438
"end": 1199,
@@ -2492,7 +2492,7 @@
24922492
},
24932493
"name": "ReturnType"
24942494
},
2495-
"typeParameters": {
2495+
"typeArguments": {
24962496
"type": "TSTypeParameterInstantiation",
24972497
"start": 1167,
24982498
"end": 1191,

test/class_issue_36/expected.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@
14091409
},
14101410
"name": "Set"
14111411
},
1412-
"typeParameters": {
1412+
"typeArguments": {
14131413
"type": "TSTypeParameterInstantiation",
14141414
"start": 627,
14151415
"end": 635,
@@ -2516,7 +2516,7 @@
25162516
},
25172517
"name": "Array"
25182518
},
2519-
"typeParameters": {
2519+
"typeArguments": {
25202520
"type": "TSTypeParameterInstantiation",
25212521
"start": 38,
25222522
"end": 43,

test/class_static_async_methods/expected.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
},
156156
"name": "Promise"
157157
},
158-
"typeParameters": {
158+
"typeArguments": {
159159
"type": "TSTypeParameterInstantiation",
160160
"start": 46,
161161
"end": 52,
@@ -403,7 +403,7 @@
403403
},
404404
"name": "AsyncIterable"
405405
},
406-
"typeParameters": {
406+
"typeArguments": {
407407
"type": "TSTypeParameterInstantiation",
408408
"start": 129,
409409
"end": 137,

test/dts_expression_type_test_issue_29/expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@
943943
},
944944
"name": "Ref"
945945
},
946-
"typeParameters": {
946+
"typeArguments": {
947947
"type": "TSTypeParameterInstantiation",
948948
"start": 328,
949949
"end": 338,

test/function_type_test_async_generator_function/expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
},
107107
"name": "Promise"
108108
},
109-
"typeParameters": {
109+
"typeArguments": {
110110
"type": "TSTypeParameterInstantiation",
111111
"start": 32,
112112
"end": 42,

test/jsx_issue_46/expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@
316316
"name": "ComponentProps"
317317
}
318318
},
319-
"typeParameters": {
319+
"typeArguments": {
320320
"type": "TSTypeParameterInstantiation",
321321
"start": 125,
322322
"end": 140,

test/jsx_issue_48/expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@
335335
}
336336
]
337337
},
338-
"typeParameters": {
338+
"typeArguments": {
339339
"type": "TSTypeParameterInstantiation",
340340
"start": 119,
341341
"end": 134,

test/jsx_jsx_with_type_generics/expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
},
7272
"name": "Select"
7373
},
74-
"typeParameters": {
74+
"typeArguments": {
7575
"type": "TSTypeParameterInstantiation",
7676
"start": 7,
7777
"end": 15,

test/jsx_tsx/expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@
737737
},
738738
"name": "H1"
739739
},
740-
"typeParameters": {
740+
"typeArguments": {
741741
"type": "TSTypeParameterInstantiation",
742742
"start": 254,
743743
"end": 262,

test/variables_declaration_expression_equal_async_arrow_function/expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
},
117117
"name": "Promise"
118118
},
119-
"typeParameters": {
119+
"typeArguments": {
120120
"type": "TSTypeParameterInstantiation",
121121
"start": 28,
122122
"end": 34,

test/variables_declaration_expression_equal_async_function/expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
},
122122
"name": "Promise"
123123
},
124-
"typeParameters": {
124+
"typeArguments": {
125125
"type": "TSTypeParameterInstantiation",
126126
"start": 36,
127127
"end": 42,

test/variables_declaration_parse_generics_with_comma/expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
},
102102
"name": "Foo"
103103
},
104-
"typeParameters": {
104+
"typeArguments": {
105105
"type": "TSTypeParameterInstantiation",
106106
"start": 12,
107107
"end": 17,

test/variables_declaration_parse_generics_without_comma/expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
},
102102
"name": "Foo"
103103
},
104-
"typeParameters": {
104+
"typeArguments": {
105105
"type": "TSTypeParameterInstantiation",
106106
"start": 12,
107107
"end": 15,

0 commit comments

Comments
 (0)