Skip to content

Commit b65c577

Browse files
committed
addressed PR feedback
1 parent 60e1f30 commit b65c577

9 files changed

Lines changed: 30 additions & 28 deletions

src/compiler/checker.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7053,24 +7053,26 @@ namespace ts {
70537053
let nodeCheckFlag: NodeCheckFlags = 0;
70547054

70557055
if (!canUseSuperExpression) {
7056-
if (isCallExpression) {
7056+
// issue more specific error if super is used in computed property name
7057+
// class A { foo() { return "1" }}
7058+
// class B {
7059+
// [super.foo()]() {}
7060+
// }
7061+
let current = node;
7062+
while (current && current !== container && current.kind !== SyntaxKind.ComputedPropertyName) {
7063+
current = current.parent;
7064+
}
7065+
if (current && current.kind === SyntaxKind.ComputedPropertyName) {
7066+
error(node, Diagnostics.super_cannot_be_referenced_in_a_computed_property_name);
7067+
}
7068+
else if (isCallExpression) {
70577069
error(node, Diagnostics.Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors);
70587070
}
70597071
else if (!container || !container.parent || !(isClassLike(container.parent) || container.parent.kind === SyntaxKind.ObjectLiteralExpression)) {
70607072
error(node, Diagnostics.super_can_only_be_referenced_in_members_of_derived_classes_or_object_literal_expressions);
70617073
}
70627074
else {
7063-
// issue more specific error if super is used in computed property name
7064-
let current = node;
7065-
while (current && current !== container && current.kind !== SyntaxKind.ComputedPropertyName) {
7066-
current = current.parent;
7067-
}
7068-
if (current && current.kind === SyntaxKind.ComputedPropertyName) {
7069-
error(node, Diagnostics.super_cannot_be_referenced_in_a_computed_property_name);
7070-
}
7071-
else {
7072-
error(node, Diagnostics.super_property_access_is_permitted_only_in_a_constructor_member_function_or_member_accessor_of_a_derived_class);
7073-
}
7075+
error(node, Diagnostics.super_property_access_is_permitted_only_in_a_constructor_member_function_or_member_accessor_of_a_derived_class);
70747076
}
70757077
return unknownType;
70767078
}

tests/baselines/reference/computedPropertyNames24_ES5.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES5.ts(7,6): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
1+
tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES5.ts(7,6): error TS2466: 'super' cannot be referenced in a computed property name.
22

33

44
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES5.ts (1 errors) ====
@@ -10,5 +10,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES5.ts(7,
1010
class C extends Base {
1111
[super.bar()]() { }
1212
~~~~~
13-
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
13+
!!! error TS2466: 'super' cannot be referenced in a computed property name.
1414
}

tests/baselines/reference/computedPropertyNames24_ES6.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES6.ts(9,6): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
1+
tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES6.ts(9,6): error TS2466: 'super' cannot be referenced in a computed property name.
22

33

44
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES6.ts (1 errors) ====
@@ -12,5 +12,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES6.ts(9,
1212
// use of super in static properties initializers.
1313
[super.bar()]() { }
1414
~~~~~
15-
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
15+
!!! error TS2466: 'super' cannot be referenced in a computed property name.
1616
}

tests/baselines/reference/computedPropertyNames26_ES5.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts(8,12): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
1+
tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts(8,12): error TS2466: 'super' cannot be referenced in a computed property name.
22

33

44
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts (1 errors) ====
@@ -11,6 +11,6 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts(8,
1111
[
1212
{ [super.bar()]: 1 }[0]
1313
~~~~~
14-
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
14+
!!! error TS2466: 'super' cannot be referenced in a computed property name.
1515
]() { }
1616
}

tests/baselines/reference/computedPropertyNames26_ES6.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES6.ts(10,12): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
1+
tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES6.ts(10,12): error TS2466: 'super' cannot be referenced in a computed property name.
22

33

44
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES6.ts (1 errors) ====
@@ -13,6 +13,6 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES6.ts(10
1313
[
1414
{ [super.bar()]: 1 }[0]
1515
~~~~~
16-
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
16+
!!! error TS2466: 'super' cannot be referenced in a computed property name.
1717
]() { }
1818
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/es6/computedProperties/computedPropertyNames27_ES5.ts(4,7): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
1+
tests/cases/conformance/es6/computedProperties/computedPropertyNames27_ES5.ts(4,7): error TS2466: 'super' cannot be referenced in a computed property name.
22

33

44
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames27_ES5.ts (1 errors) ====
@@ -7,5 +7,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames27_ES5.ts(4,
77
class C extends Base {
88
[(super(), "prop")]() { }
99
~~~~~
10-
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
10+
!!! error TS2466: 'super' cannot be referenced in a computed property name.
1111
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/es6/computedProperties/computedPropertyNames27_ES6.ts(4,7): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
1+
tests/cases/conformance/es6/computedProperties/computedPropertyNames27_ES6.ts(4,7): error TS2466: 'super' cannot be referenced in a computed property name.
22

33

44
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames27_ES6.ts (1 errors) ====
@@ -7,5 +7,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames27_ES6.ts(4,
77
class C extends Base {
88
[(super(), "prop")]() { }
99
~~~~~
10-
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
10+
!!! error TS2466: 'super' cannot be referenced in a computed property name.
1111
}

tests/baselines/reference/computedPropertyNames30_ES5.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/es6/computedProperties/computedPropertyNames30_ES5.ts(11,19): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
1+
tests/cases/conformance/es6/computedProperties/computedPropertyNames30_ES5.ts(11,19): error TS2466: 'super' cannot be referenced in a computed property name.
22

33

44
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames30_ES5.ts (1 errors) ====
@@ -14,7 +14,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames30_ES5.ts(11
1414
//treatment of other similar violations.
1515
[(super(), "prop")]() { }
1616
~~~~~
17-
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
17+
!!! error TS2466: 'super' cannot be referenced in a computed property name.
1818
};
1919
}
2020
}

tests/baselines/reference/computedPropertyNames30_ES6.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/es6/computedProperties/computedPropertyNames30_ES6.ts(11,19): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
1+
tests/cases/conformance/es6/computedProperties/computedPropertyNames30_ES6.ts(11,19): error TS2466: 'super' cannot be referenced in a computed property name.
22

33

44
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames30_ES6.ts (1 errors) ====
@@ -14,7 +14,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames30_ES6.ts(11
1414
//treatment of other similar violations.
1515
[(super(), "prop")]() { }
1616
~~~~~
17-
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
17+
!!! error TS2466: 'super' cannot be referenced in a computed property name.
1818
};
1919
}
2020
}

0 commit comments

Comments
 (0)