Skip to content

Commit 9bc3f9a

Browse files
committed
fix(49704): parse type arguments in super call expression
1 parent 93f2d2b commit 9bc3f9a

14 files changed

+31
-314
lines changed

src/compiler/parser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5285,12 +5285,13 @@ namespace ts {
52855285

52865286
function parseSuperExpression(): MemberExpression {
52875287
const pos = getNodePos();
5288-
const expression = parseTokenNode<PrimaryExpression>();
5288+
let expression = parseTokenNode<MemberExpression>();
52895289
if (token() === SyntaxKind.LessThanToken) {
52905290
const startPos = getNodePos();
52915291
const typeArguments = tryParse(parseTypeArgumentsInExpression);
52925292
if (typeArguments !== undefined) {
52935293
parseErrorAt(startPos, getNodePos(), Diagnostics.super_may_not_use_type_arguments);
5294+
expression = factory.createExpressionWithTypeArguments(expression, typeArguments);
52945295
}
52955296
}
52965297

tests/baselines/reference/errorSuperCalls.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(30,16): error
88
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(34,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
99
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(38,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
1010
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(46,14): error TS2754: 'super' may not use type arguments.
11+
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(46,15): error TS2558: Expected 0 type arguments, but got 1.
1112
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(58,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
1213
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(62,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
1314
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(67,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
1415
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(71,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
1516

1617

17-
==== tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts (14 errors) ====
18+
==== tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts (15 errors) ====
1819
//super call in class constructor with no base type
1920
class NoBase {
2021
constructor() {
@@ -81,6 +82,8 @@ tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(71,9): error T
8182
super<string>();
8283
~~~~~~~~
8384
!!! error TS2754: 'super' may not use type arguments.
85+
~~~~~~
86+
!!! error TS2558: Expected 0 type arguments, but got 1.
8487
super();
8588
}
8689
}

tests/baselines/reference/parserSuperExpression2.symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ class C {
66
>M : Symbol(C.M, Decl(parserSuperExpression2.ts, 0, 9))
77

88
super<T>(0);
9+
>T : Symbol(T)
910
}
1011
}

tests/baselines/reference/superWithTypeArgument.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
tests/cases/compiler/superWithTypeArgument.ts(7,14): error TS2754: 'super' may not use type arguments.
2+
tests/cases/compiler/superWithTypeArgument.ts(7,15): error TS2558: Expected 0 type arguments, but got 1.
23

34

4-
==== tests/cases/compiler/superWithTypeArgument.ts (1 errors) ====
5+
==== tests/cases/compiler/superWithTypeArgument.ts (2 errors) ====
56
class C {
67

78
}
@@ -11,5 +12,7 @@ tests/cases/compiler/superWithTypeArgument.ts(7,14): error TS2754: 'super' may n
1112
super<T>();
1213
~~~
1314
!!! error TS2754: 'super' may not use type arguments.
15+
~
16+
!!! error TS2558: Expected 0 type arguments, but got 1.
1417
}
1518
}

tests/baselines/reference/superWithTypeArgument.symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ class D<T> extends C {
1212
constructor() {
1313
super<T>();
1414
>super : Symbol(C, Decl(superWithTypeArgument.ts, 0, 0))
15+
>T : Symbol(T, Decl(superWithTypeArgument.ts, 4, 8))
1516
}
1617
}

tests/baselines/reference/superWithTypeArgument2.errors.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests/cases/compiler/superWithTypeArgument2.ts(7,14): error TS2754: 'super' may not use type arguments.
2-
tests/cases/compiler/superWithTypeArgument2.ts(7,18): error TS2554: Expected 0 arguments, but got 1.
2+
tests/cases/compiler/superWithTypeArgument2.ts(7,15): error TS2558: Expected 0 type arguments, but got 1.
33

44

55
==== tests/cases/compiler/superWithTypeArgument2.ts (2 errors) ====
@@ -12,7 +12,7 @@ tests/cases/compiler/superWithTypeArgument2.ts(7,18): error TS2554: Expected 0 a
1212
super<T>(x);
1313
~~~
1414
!!! error TS2754: 'super' may not use type arguments.
15-
~
16-
!!! error TS2554: Expected 0 arguments, but got 1.
15+
~
16+
!!! error TS2558: Expected 0 type arguments, but got 1.
1717
}
1818
}

tests/baselines/reference/superWithTypeArgument2.symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class D<T> extends C<T> {
1919

2020
super<T>(x);
2121
>super : Symbol(C, Decl(superWithTypeArgument2.ts, 0, 0))
22+
>T : Symbol(T, Decl(superWithTypeArgument2.ts, 4, 8))
2223
>x : Symbol(x, Decl(superWithTypeArgument2.ts, 5, 16))
2324
}
2425
}

tests/baselines/reference/superWithTypeArgument3.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
tests/cases/compiler/superWithTypeArgument3.ts(8,14): error TS2754: 'super' may not use type arguments.
2+
tests/cases/compiler/superWithTypeArgument3.ts(8,15): error TS2558: Expected 0 type arguments, but got 1.
23

34

4-
==== tests/cases/compiler/superWithTypeArgument3.ts (1 errors) ====
5+
==== tests/cases/compiler/superWithTypeArgument3.ts (2 errors) ====
56
class C<T> {
67
foo: T;
78
bar<U>(x: U) { }
@@ -12,6 +13,8 @@ tests/cases/compiler/superWithTypeArgument3.ts(8,14): error TS2754: 'super' may
1213
super<T>();
1314
~~~
1415
!!! error TS2754: 'super' may not use type arguments.
16+
~
17+
!!! error TS2558: Expected 0 type arguments, but got 1.
1518
}
1619
bar() {
1720
super.bar<T>(null);

tests/baselines/reference/superWithTypeArgument3.symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class D<T> extends C<T> {
2323
constructor() {
2424
super<T>();
2525
>super : Symbol(C, Decl(superWithTypeArgument3.ts, 0, 0))
26+
>T : Symbol(T, Decl(superWithTypeArgument3.ts, 5, 8))
2627
}
2728
bar() {
2829
>bar : Symbol(D.bar, Decl(superWithTypeArgument3.ts, 8, 5))

tests/baselines/reference/taggedTemplatesWithTypeArguments2.errors.txt

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)