Skip to content

Commit 5511172

Browse files
[babel 8] Rename superTypeParameters -> superTypeArguments (#16997)
1 parent c407283 commit 5511172

49 files changed

Lines changed: 637 additions & 30 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

eslint/babel-eslint-parser/src/analyze-scope.cts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,14 @@ class Referencer extends OriginalReferencer {
117117

118118
// Flow super types.
119119
this._visitTypeAnnotation(node.implements);
120-
this._visitTypeAnnotation(node.superTypeParameters?.params);
120+
this._visitTypeAnnotation(
121+
(process.env.BABEL_8_BREAKING
122+
? // @ts-ignore(Babel 7 vs Babel 8) Renamed
123+
node.superTypeArguments
124+
: // @ts-ignore(Babel 7 vs Babel 8) Renamed
125+
node.superTypeParameters
126+
)?.params,
127+
);
121128

122129
// Basic.
123130
super.visitClass(node);

packages/babel-generator/src/generators/classes.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ export function ClassDeclaration(
5252
this.word("extends");
5353
this.space();
5454
this.print(node.superClass);
55-
this.print(node.superTypeParameters);
55+
this.print(
56+
process.env.BABEL_8_BREAKING
57+
? // @ts-ignore(Babel 7 vs Babel 8) Renamed
58+
node.superTypeArguments
59+
: // @ts-ignore(Babel 7 vs Babel 8) Renamed
60+
node.superTypeParameters,
61+
);
5662
}
5763

5864
if (node.implements) {

packages/babel-parser/src/plugins/flow/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2585,7 +2585,11 @@ export default (superClass: typeof Parser) =>
25852585
parseClassSuper(node: N.Class): void {
25862586
super.parseClassSuper(node);
25872587
if (node.superClass && this.match(tt.lt)) {
2588-
node.superTypeParameters = this.flowParseTypeParameterInstantiation();
2588+
if (process.env.BABEL_8_BREAKING) {
2589+
node.superTypeArguments = this.flowParseTypeParameterInstantiation();
2590+
} else {
2591+
node.superTypeParameters = this.flowParseTypeParameterInstantiation();
2592+
}
25892593
}
25902594
if (this.isContextual(tt._implements)) {
25912595
this.next();

packages/babel-parser/src/plugins/typescript/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3352,7 +3352,11 @@ export default (superClass: ClassWithMixin<typeof Parser, IJSXParserMixin>) =>
33523352
super.parseClassSuper(node);
33533353
// handle `extends f<<T>
33543354
if (node.superClass && (this.match(tt.lt) || this.match(tt.bitShiftL))) {
3355-
node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
3355+
if (process.env.BABEL_8_BREAKING) {
3356+
node.superTypeArguments = this.tsParseTypeArgumentsInExpression();
3357+
} else {
3358+
node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
3359+
}
33563360
}
33573361
if (this.eatContextual(tt._implements)) {
33583362
node.implements = this.tsParseHeritageClause("implements");

packages/babel-parser/src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,8 @@ export interface ClassBase extends HasDecorators {
865865
decorators?: Decorator[];
866866
// TODO: All not in spec
867867
typeParameters?: TypeParameterDeclarationBase | null;
868-
superTypeParameters?: TypeParameterInstantiationBase | null;
868+
superTypeParameters?: TypeParameterInstantiationBase | null; // babel 7
869+
superTypeArguments?: TypeParameterInstantiationBase | null; // babel 8
869870
abstract?: boolean;
870871
implements?: TSClassImplements[] | undefined | null | FlowClassImplements[];
871872
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a = class Foo<T> extends Bar<T> { }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"BABEL_8_BREAKING": false
3+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"type": "File",
3+
"start":0,"end":35,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":35,"index":35}},
4+
"program": {
5+
"type": "Program",
6+
"start":0,"end":35,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":35,"index":35}},
7+
"sourceType": "module",
8+
"interpreter": null,
9+
"body": [
10+
{
11+
"type": "ExpressionStatement",
12+
"start":0,"end":35,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":35,"index":35}},
13+
"expression": {
14+
"type": "AssignmentExpression",
15+
"start":0,"end":35,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":35,"index":35}},
16+
"operator": "=",
17+
"left": {
18+
"type": "Identifier",
19+
"start":0,"end":1,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":1,"index":1},"identifierName":"a"},
20+
"name": "a"
21+
},
22+
"right": {
23+
"type": "ClassExpression",
24+
"start":4,"end":35,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":35,"index":35}},
25+
"id": {
26+
"type": "Identifier",
27+
"start":10,"end":13,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":13,"index":13},"identifierName":"Foo"},
28+
"name": "Foo"
29+
},
30+
"typeParameters": {
31+
"type": "TypeParameterDeclaration",
32+
"start":13,"end":16,"loc":{"start":{"line":1,"column":13,"index":13},"end":{"line":1,"column":16,"index":16}},
33+
"params": [
34+
{
35+
"type": "TypeParameter",
36+
"start":14,"end":15,"loc":{"start":{"line":1,"column":14,"index":14},"end":{"line":1,"column":15,"index":15}},
37+
"name": "T",
38+
"variance": null
39+
}
40+
]
41+
},
42+
"superClass": {
43+
"type": "Identifier",
44+
"start":25,"end":28,"loc":{"start":{"line":1,"column":25,"index":25},"end":{"line":1,"column":28,"index":28},"identifierName":"Bar"},
45+
"name": "Bar"
46+
},
47+
"superTypeParameters": {
48+
"type": "TypeParameterInstantiation",
49+
"start":28,"end":31,"loc":{"start":{"line":1,"column":28,"index":28},"end":{"line":1,"column":31,"index":31}},
50+
"params": [
51+
{
52+
"type": "GenericTypeAnnotation",
53+
"start":29,"end":30,"loc":{"start":{"line":1,"column":29,"index":29},"end":{"line":1,"column":30,"index":30}},
54+
"typeParameters": null,
55+
"id": {
56+
"type": "Identifier",
57+
"start":29,"end":30,"loc":{"start":{"line":1,"column":29,"index":29},"end":{"line":1,"column":30,"index":30},"identifierName":"T"},
58+
"name": "T"
59+
}
60+
}
61+
]
62+
},
63+
"body": {
64+
"type": "ClassBody",
65+
"start":32,"end":35,"loc":{"start":{"line":1,"column":32,"index":32},"end":{"line":1,"column":35,"index":35}},
66+
"body": []
67+
}
68+
}
69+
}
70+
}
71+
],
72+
"directives": [],
73+
"extra": {
74+
"topLevelAwait": false
75+
}
76+
}
77+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"BABEL_8_BREAKING": true
3+
}

packages/babel-parser/test/fixtures/flow/type-annotations/46/output.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"start":25,"end":28,"loc":{"start":{"line":1,"column":25,"index":25},"end":{"line":1,"column":28,"index":28},"identifierName":"Bar"},
4545
"name": "Bar"
4646
},
47-
"superTypeParameters": {
47+
"superTypeArguments": {
4848
"type": "TypeParameterInstantiation",
4949
"start":28,"end":31,"loc":{"start":{"line":1,"column":28,"index":28},"end":{"line":1,"column":31,"index":31}},
5050
"params": [

0 commit comments

Comments
 (0)