allow usage of 'super' in object literal expressions

This commit is contained in:
vladima
2015-12-11 17:16:28 -08:00
parent 8c6105f4dc
commit 60e1f30182
32 changed files with 940 additions and 137 deletions

View File

@@ -7037,17 +7037,14 @@ namespace ts {
function checkSuperExpression(node: Node): Type {
const isCallExpression = node.parent.kind === SyntaxKind.CallExpression && (<CallExpression>node.parent).expression === node;
const classDeclaration = getContainingClass(node);
const classType = classDeclaration && <InterfaceType>getDeclaredTypeOfSymbol(getSymbolOfNode(classDeclaration));
const baseClassType = classType && getBaseTypes(classType)[0];
let container = getSuperContainer(node, /*includeFunctions*/ true);
let container = getSuperContainer(node, /*stopOnFunctions*/ true);
let needToCaptureLexicalThis = false;
if (!isCallExpression) {
// adjust the container reference in case if super is used inside arrow functions with arbitrary deep nesting
while (container && container.kind === SyntaxKind.ArrowFunction) {
container = getSuperContainer(container, /*includeFunctions*/ true);
container = getSuperContainer(container, /*stopOnFunctions*/ true);
needToCaptureLexicalThis = languageVersion < ScriptTarget.ES6;
}
}
@@ -7055,43 +7052,64 @@ namespace ts {
const canUseSuperExpression = isLegalUsageOfSuperExpression(container);
let nodeCheckFlag: NodeCheckFlags = 0;
// always set NodeCheckFlags for 'super' expression node
if (canUseSuperExpression) {
if ((container.flags & NodeFlags.Static) || isCallExpression) {
nodeCheckFlag = NodeCheckFlags.SuperStatic;
if (!canUseSuperExpression) {
if (isCallExpression) {
error(node, Diagnostics.Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors);
}
else if (!container || !container.parent || !(isClassLike(container.parent) || container.parent.kind === SyntaxKind.ObjectLiteralExpression)) {
error(node, Diagnostics.super_can_only_be_referenced_in_members_of_derived_classes_or_object_literal_expressions);
}
else {
nodeCheckFlag = NodeCheckFlags.SuperInstance;
}
getNodeLinks(node).flags |= nodeCheckFlag;
if (needToCaptureLexicalThis) {
// call expressions are allowed only in constructors so they should always capture correct 'this'
// super property access expressions can also appear in arrow functions -
// in this case they should also use correct lexical this
captureLexicalThis(node.parent, container);
}
}
if (!baseClassType) {
if (!classDeclaration || !getClassExtendsHeritageClauseElement(classDeclaration)) {
error(node, Diagnostics.super_can_only_be_referenced_in_a_derived_class);
// issue more specific error if super is used in computed property name
let current = node;
while (current && current !== container && current.kind !== SyntaxKind.ComputedPropertyName) {
current = current.parent;
}
if (current && current.kind === SyntaxKind.ComputedPropertyName) {
error(node, Diagnostics.super_cannot_be_referenced_in_a_computed_property_name);
}
else {
error(node, Diagnostics.super_property_access_is_permitted_only_in_a_constructor_member_function_or_member_accessor_of_a_derived_class);
}
}
return unknownType;
}
if (!canUseSuperExpression) {
if (container && container.kind === SyntaxKind.ComputedPropertyName) {
error(node, Diagnostics.super_cannot_be_referenced_in_a_computed_property_name);
}
else if (isCallExpression) {
error(node, Diagnostics.Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors);
if ((container.flags & NodeFlags.Static) || isCallExpression) {
nodeCheckFlag = NodeCheckFlags.SuperStatic;
}
else {
nodeCheckFlag = NodeCheckFlags.SuperInstance;
}
getNodeLinks(node).flags |= nodeCheckFlag;
if (needToCaptureLexicalThis) {
// call expressions are allowed only in constructors so they should always capture correct 'this'
// super property access expressions can also appear in arrow functions -
// in this case they should also use correct lexical this
captureLexicalThis(node.parent, container);
}
if (container.parent.kind === SyntaxKind.ObjectLiteralExpression) {
if (languageVersion < ScriptTarget.ES6) {
error(node, Diagnostics.super_in_members_of_object_literal_expressions_is_only_allowed_when_option_target_is_ES2015_or_higher);
return unknownType;
}
else {
error(node, Diagnostics.super_property_access_is_permitted_only_in_a_constructor_member_function_or_member_accessor_of_a_derived_class);
// for object literal assume that type of 'super' is 'any'
return anyType;
}
}
// at this point the only legal case for parent is ClassLikeDeclaration
const classLikeDeclaration = <ClassLikeDeclaration>container.parent;
const classType = <InterfaceType>getDeclaredTypeOfSymbol(getSymbolOfNode(classLikeDeclaration));
const baseClassType = classType && getBaseTypes(classType)[0];
if (!baseClassType) {
if (!getClassExtendsHeritageClauseElement(classLikeDeclaration)) {
error(node, Diagnostics.super_can_only_be_referenced_in_a_derived_class);
}
return unknownType;
}
@@ -7121,8 +7139,8 @@ namespace ts {
// - In a constructor, instance member function, instance member accessor, or instance member variable initializer where this references a derived class instance
// - In a static member function or static member accessor
// topmost container must be something that is directly nested in the class declaration
if (container && isClassLike(container.parent)) {
// topmost container must be something that is directly nested in the class declaration\object literal expression
if (isClassLike(container.parent) || container.parent.kind === SyntaxKind.ObjectLiteralExpression) {
if (container.flags & NodeFlags.Static) {
return container.kind === SyntaxKind.MethodDeclaration ||
container.kind === SyntaxKind.MethodSignature ||

View File

@@ -1759,6 +1759,14 @@
"category": "Error",
"code": 2658
},
"'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher.": {
"category": "Error",
"code": 2659
},
"'super' can only be referenced in members of derived classes or object literal expressions.": {
"category": "Error",
"code": 2660
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
"code": 4000

View File

@@ -775,26 +775,38 @@ namespace ts {
}
}
export function getSuperContainer(node: Node, includeFunctions: boolean): Node {
/**
* Given an super call\property node returns a closest node where either
* - super call\property is legal in the node and not legal in the parent node the node.
* i.e. super call is legal in constructor but not legal in the class body.
* - node is arrow function (so caller might need to call getSuperContainer in case if he needs to climb higher)
* - super call\property is definitely illegal in the node (but might be legal in some subnode)
* i.e. super property access is illegal in function declaration but can be legal in the statement list
*/
export function getSuperContainer(node: Node, stopOnFunctions: boolean): Node {
while (true) {
node = node.parent;
if (!node) return node;
if (!node) {
return node;
}
switch (node.kind) {
case SyntaxKind.ComputedPropertyName:
// If the grandparent node is an object literal (as opposed to a class),
// then the computed property is not a 'super' container.
// A computed property name in a class needs to be a super container
// so that we can error on it.
if (isClassLike(node.parent.parent)) {
return node;
}
// If this is a computed property, then the parent should not
// make it a super container. The parent might be a property
// in an object literal, like a method or accessor. But in order for
// such a parent to be a super container, the reference must be in
// the *body* of the container.
node = node.parent;
break;
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.FunctionExpression:
case SyntaxKind.ArrowFunction:
if (!stopOnFunctions) {
continue;
}
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.MethodSignature:
case SyntaxKind.Constructor:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
return node;
case SyntaxKind.Decorator:
// Decorators are always applied outside of the body of a class or method.
if (node.parent.kind === SyntaxKind.Parameter && isClassElement(node.parent.parent)) {
@@ -808,20 +820,6 @@ namespace ts {
node = node.parent;
}
break;
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.FunctionExpression:
case SyntaxKind.ArrowFunction:
if (!includeFunctions) {
continue;
}
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.MethodSignature:
case SyntaxKind.Constructor:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
return node;
}
}
}

View File

@@ -5780,7 +5780,7 @@ namespace ts {
}
function getReferencesForSuperKeyword(superKeyword: Node): ReferencedSymbol[] {
let searchSpaceNode = getSuperContainer(superKeyword, /*includeFunctions*/ false);
let searchSpaceNode = getSuperContainer(superKeyword, /*stopOnFunctions*/ false);
if (!searchSpaceNode) {
return undefined;
}
@@ -5815,7 +5815,7 @@ namespace ts {
return;
}
let container = getSuperContainer(node, /*includeFunctions*/ false);
let container = getSuperContainer(node, /*stopOnFunctions*/ false);
// If we have a 'super' container, we must have an enclosing class.
// Now make sure the owning class is the same as the search-space

View File

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

View File

@@ -1,4 +1,4 @@
tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES6.ts(9,6): error TS2466: 'super' cannot be referenced in a computed property name.
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.
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES6.ts (1 errors) ====
@@ -12,5 +12,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES6.ts(9,
// use of super in static properties initializers.
[super.bar()]() { }
~~~~~
!!! error TS2466: 'super' cannot be referenced in a computed property name.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
}

View File

@@ -1,4 +1,4 @@
tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts(8,12): error TS2466: 'super' cannot be referenced in a computed property name.
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.
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts (1 errors) ====
@@ -11,6 +11,6 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts(8,
[
{ [super.bar()]: 1 }[0]
~~~~~
!!! error TS2466: 'super' cannot be referenced in a computed property name.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
]() { }
}

View File

@@ -1,4 +1,4 @@
tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES6.ts(10,12): error TS2466: 'super' cannot be referenced in a computed property name.
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.
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES6.ts (1 errors) ====
@@ -13,6 +13,6 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES6.ts(10
[
{ [super.bar()]: 1 }[0]
~~~~~
!!! error TS2466: 'super' cannot be referenced in a computed property name.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
]() { }
}

View File

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

View File

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

View File

@@ -1,4 +1,4 @@
tests/cases/conformance/decorators/class/method/decoratorOnClassMethod12.ts(6,10): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
tests/cases/conformance/decorators/class/method/decoratorOnClassMethod12.ts(6,10): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod12.ts (1 errors) ====
@@ -9,7 +9,7 @@ tests/cases/conformance/decorators/class/method/decoratorOnClassMethod12.ts(6,10
class C extends S {
@super.decorator
~~~~~
!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
method() { }
}
}

View File

@@ -1,6 +1,6 @@
tests/cases/compiler/emitThisInSuperMethodCall.ts(10,17): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
tests/cases/compiler/emitThisInSuperMethodCall.ts(17,17): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
tests/cases/compiler/emitThisInSuperMethodCall.ts(23,13): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
tests/cases/compiler/emitThisInSuperMethodCall.ts(10,17): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/emitThisInSuperMethodCall.ts(17,17): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/emitThisInSuperMethodCall.ts(23,13): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
==== tests/cases/compiler/emitThisInSuperMethodCall.ts (3 errors) ====
@@ -15,7 +15,7 @@ tests/cases/compiler/emitThisInSuperMethodCall.ts(23,13): error TS2338: 'super'
function inner() {
super.sayHello();
~~~~~
!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
}
};
}
@@ -24,7 +24,7 @@ tests/cases/compiler/emitThisInSuperMethodCall.ts(23,13): error TS2338: 'super'
() => {
super.sayHello();
~~~~~
!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
}
}
}
@@ -32,7 +32,7 @@ tests/cases/compiler/emitThisInSuperMethodCall.ts(23,13): error TS2338: 'super'
function inner() {
super.sayHello();
~~~~~
!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
}
}
}

View File

@@ -1,12 +1,12 @@
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(4,9): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(9,9): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(14,9): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(18,9): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(22,9): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(26,9): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(30,16): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(34,9): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(38,9): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(9,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(14,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(18,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(22,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(26,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(30,16): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(34,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(38,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(46,14): error TS1034: 'super' must be followed by an argument list or member access.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(58,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(62,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
@@ -27,50 +27,50 @@ tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(71,9): error T
fn() {
super();
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
}
//super call in class accessor (get and set) with no base type
get foo() {
super();
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
return null;
}
set foo(v) {
super();
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
}
//super call in class member initializer with no base type
p = super();
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
//super call in static class member function with no base type
static fn() {
super();
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
}
//super call in static class member initializer with no base type
static k = super();
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
//super call in static class accessor (get and set) with no base type
static get q() {
super();
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
return null;
}
static set q(n) {
super();
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
}
}

View File

@@ -15,8 +15,8 @@ tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(65,23): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(68,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(69,19): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(73,13): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(76,40): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(73,13): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(76,40): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(87,15): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(91,23): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(94,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
@@ -34,8 +34,8 @@ tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(120,15): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(121,15): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(122,9): error TS2341: Property 'privateStaticFunc' is private and only accessible within class 'SomeBase'.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(127,16): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(127,30): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(127,16): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(127,30): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
==== tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts (38 errors) ====
@@ -147,12 +147,12 @@ tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess
function inner() {
super.publicFunc();
~~~~~
!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
}
var x = {
test: function () { return super.publicFunc(); }
~~~~~
!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
}
}
}
@@ -239,7 +239,7 @@ tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess
// In object literal
var obj = { n: super.wat, p: super.foo() };
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.

View File

@@ -1,4 +1,4 @@
tests/cases/compiler/superCallFromFunction1.ts(3,5): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/compiler/superCallFromFunction1.ts(3,5): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
==== tests/cases/compiler/superCallFromFunction1.ts (1 errors) ====
@@ -6,5 +6,5 @@ tests/cases/compiler/superCallFromFunction1.ts(3,5): error TS2335: 'super' can o
function foo() {
super(value => String(value));
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
}

View File

@@ -1,15 +1,15 @@
tests/cases/compiler/superErrors.ts(3,13): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/compiler/superErrors.ts(3,13): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superErrors.ts(3,18): error TS1034: 'super' must be followed by an argument list or member access.
tests/cases/compiler/superErrors.ts(4,19): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/compiler/superErrors.ts(4,19): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superErrors.ts(4,24): error TS1034: 'super' must be followed by an argument list or member access.
tests/cases/compiler/superErrors.ts(5,31): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/compiler/superErrors.ts(5,31): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superErrors.ts(5,36): error TS1034: 'super' must be followed by an argument list or member access.
tests/cases/compiler/superErrors.ts(22,13): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
tests/cases/compiler/superErrors.ts(27,27): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
tests/cases/compiler/superErrors.ts(31,36): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
tests/cases/compiler/superErrors.ts(22,13): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superErrors.ts(27,27): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superErrors.ts(31,36): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superErrors.ts(31,41): error TS1034: 'super' must be followed by an argument list or member access.
tests/cases/compiler/superErrors.ts(39,27): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
tests/cases/compiler/superErrors.ts(43,36): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
tests/cases/compiler/superErrors.ts(39,27): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superErrors.ts(43,36): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superErrors.ts(43,41): error TS1034: 'super' must be followed by an argument list or member access.
tests/cases/compiler/superErrors.ts(47,22): error TS1034: 'super' must be followed by an argument list or member access.
tests/cases/compiler/superErrors.ts(48,28): error TS1034: 'super' must be followed by an argument list or member access.
@@ -21,17 +21,17 @@ tests/cases/compiler/superErrors.ts(49,40): error TS1034: 'super' must be follow
// super in a non class context
var x = super;
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
~
!!! error TS1034: 'super' must be followed by an argument list or member access.
var y = () => super;
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
~
!!! error TS1034: 'super' must be followed by an argument list or member access.
var z = () => () => () => super;
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
~
!!! error TS1034: 'super' must be followed by an argument list or member access.
}
@@ -52,20 +52,20 @@ tests/cases/compiler/superErrors.ts(49,40): error TS1034: 'super' must be follow
function inner() {
super.sayHello();
~~~~~
!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
}
// super call in a lambda in an inner function in a constructor
function inner2() {
var x = () => super.sayHello();
~~~~~
!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
}
// super call in a lambda in a function expression in a constructor
(function() { return () => super; })();
~~~~~
!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
~
!!! error TS1034: 'super' must be followed by an argument list or member access.
}
@@ -77,13 +77,13 @@ tests/cases/compiler/superErrors.ts(49,40): error TS1034: 'super' must be follow
function inner() {
var x = () => super.sayHello();
~~~~~
!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
}
// super call in a lambda in a function expression in a constructor
(function() { return () => super; })();
~~~~~
!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
~
!!! error TS1034: 'super' must be followed by an argument list or member access.
}

View File

@@ -0,0 +1,95 @@
tests/cases/compiler/superInObjectLiterals_ES5.ts(7,9): error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher.
tests/cases/compiler/superInObjectLiterals_ES5.ts(10,9): error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher.
tests/cases/compiler/superInObjectLiterals_ES5.ts(14,9): error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher.
tests/cases/compiler/superInObjectLiterals_ES5.ts(17,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superInObjectLiterals_ES5.ts(20,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superInObjectLiterals_ES5.ts(23,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superInObjectLiterals_ES5.ts(39,17): error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher.
tests/cases/compiler/superInObjectLiterals_ES5.ts(42,17): error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher.
tests/cases/compiler/superInObjectLiterals_ES5.ts(46,17): error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher.
tests/cases/compiler/superInObjectLiterals_ES5.ts(49,17): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superInObjectLiterals_ES5.ts(52,17): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
==== tests/cases/compiler/superInObjectLiterals_ES5.ts (11 errors) ====
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
~~~~~
!!! error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher.
},
get prop() {
super.method();
~~~~~
!!! error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher.
return 10;
},
set prop(value) {
super.method();
~~~~~
!!! error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher.
},
p1: function () {
super.method();
~~~~~
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
},
p2: function f() {
super.method();
~~~~~
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
},
p3: () => {
super.method();
~~~~~
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
}
};
class A {
method() { }
}
class B extends A {
f() {
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
~~~~~
!!! error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher.
},
get prop() {
super.method();
~~~~~
!!! error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher.
return 10;
},
set prop(value) {
super.method();
~~~~~
!!! error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher.
},
p1: function () {
super.method();
~~~~~
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
},
p2: function f() {
super.method();
~~~~~
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
},
p3: () => {
super.method();
}
};
}
}

View File

@@ -0,0 +1,133 @@
//// [superInObjectLiterals_ES5.ts]
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
},
get prop() {
super.method();
return 10;
},
set prop(value) {
super.method();
},
p1: function () {
super.method();
},
p2: function f() {
super.method();
},
p3: () => {
super.method();
}
};
class A {
method() { }
}
class B extends A {
f() {
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
},
get prop() {
super.method();
return 10;
},
set prop(value) {
super.method();
},
p1: function () {
super.method();
},
p2: function f() {
super.method();
},
p3: () => {
super.method();
}
};
}
}
//// [superInObjectLiterals_ES5.js]
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var obj = {
__proto__: {
method: function () {
}
},
method: function () {
_super.prototype.method.call(this);
},
get prop() {
_super.prototype.method.call(this);
return 10;
},
set prop(value) {
_super.prototype.method.call(this);
},
p1: function () {
_super.method.call(this);
},
p2: function f() {
_super.method.call(this);
},
p3: function () {
_super.method.call(this);
}
};
var A = (function () {
function A() {
}
A.prototype.method = function () { };
return A;
}());
var B = (function (_super) {
__extends(B, _super);
function B() {
_super.apply(this, arguments);
}
B.prototype.f = function () {
var _this = this;
var obj = {
__proto__: {
method: function () {
}
},
method: function () {
_super.prototype.method.call(this);
},
get prop() {
_super.prototype.method.call(this);
return 10;
},
set prop(value) {
_super.prototype.method.call(this);
},
p1: function () {
_super.method.call(this);
},
p2: function f() {
_super.method.call(this);
},
p3: function () {
_super.prototype.method.call(_this);
}
};
};
return B;
}(A));

View File

@@ -0,0 +1,77 @@
tests/cases/compiler/superInObjectLiterals_ES6.ts(17,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superInObjectLiterals_ES6.ts(20,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superInObjectLiterals_ES6.ts(23,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superInObjectLiterals_ES6.ts(49,17): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superInObjectLiterals_ES6.ts(52,17): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
==== tests/cases/compiler/superInObjectLiterals_ES6.ts (5 errors) ====
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
},
get prop() {
super.method();
return 10;
},
set prop(value) {
super.method();
},
p1: function () {
super.method();
~~~~~
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
},
p2: function f() {
super.method();
~~~~~
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
},
p3: () => {
super.method();
~~~~~
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
}
};
class A {
method() { }
}
class B extends A {
f() {
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
},
get prop() {
super.method();
return 10;
},
set prop(value) {
super.method();
},
p1: function () {
super.method();
~~~~~
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
},
p2: function f() {
super.method();
~~~~~
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
},
p3: () => {
super.method();
}
};
}
}

View File

@@ -0,0 +1,119 @@
//// [superInObjectLiterals_ES6.ts]
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
},
get prop() {
super.method();
return 10;
},
set prop(value) {
super.method();
},
p1: function () {
super.method();
},
p2: function f() {
super.method();
},
p3: () => {
super.method();
}
};
class A {
method() { }
}
class B extends A {
f() {
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
},
get prop() {
super.method();
return 10;
},
set prop(value) {
super.method();
},
p1: function () {
super.method();
},
p2: function f() {
super.method();
},
p3: () => {
super.method();
}
};
}
}
//// [superInObjectLiterals_ES6.js]
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
},
get prop() {
super.method();
return 10;
},
set prop(value) {
super.method();
},
p1: function () {
super.method();
},
p2: function f() {
super.method();
},
p3: () => {
super.method();
}
};
class A {
method() { }
}
class B extends A {
f() {
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
},
get prop() {
super.method();
return 10;
},
set prop(value) {
super.method();
},
p1: function () {
super.method();
},
p2: function f() {
super.method();
},
p3: () => {
super.method();
}
};
}
}

View File

@@ -0,0 +1,46 @@
//// [superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts]
class A {
foo() { return 1; }
}
class B extends A {
foo() { return 2; }
bar() {
return class {
[super.foo()]() {
return 100;
}
}
}
}
//// [superPropertyAccessInComputedPropertiesOfNestedType_ES5.js]
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var A = (function () {
function A() {
}
A.prototype.foo = function () { return 1; };
return A;
}());
var B = (function (_super) {
__extends(B, _super);
function B() {
_super.apply(this, arguments);
}
B.prototype.foo = function () { return 2; };
B.prototype.bar = function () {
return (function () {
function class_1() {
}
class_1.prototype[_super.prototype.foo.call(this)] = function () {
return 100;
};
return class_1;
}());
};
return B;
}(A));

View File

@@ -0,0 +1,29 @@
=== tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts ===
class A {
>A : Symbol(A, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 0, 0))
foo() { return 1; }
>foo : Symbol(foo, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 0, 9))
}
class B extends A {
>B : Symbol(B, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 2, 1))
>A : Symbol(A, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 0, 0))
foo() { return 2; }
>foo : Symbol(foo, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 4, 19))
bar() {
>bar : Symbol(bar, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 5, 23))
return class {
[super.foo()]() {
>super.foo : Symbol(A.foo, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 0, 9))
>super : Symbol(A, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 0, 0))
>foo : Symbol(A.foo, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 0, 9))
return 100;
}
}
}
}

View File

@@ -0,0 +1,35 @@
=== tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts ===
class A {
>A : A
foo() { return 1; }
>foo : () => number
>1 : number
}
class B extends A {
>B : B
>A : A
foo() { return 2; }
>foo : () => number
>2 : number
bar() {
>bar : () => typeof (Anonymous class)
return class {
>class { [super.foo()]() { return 100; } } : typeof (Anonymous class)
[super.foo()]() {
>super.foo() : number
>super.foo : () => number
>super : A
>foo : () => number
return 100;
>100 : number
}
}
}
}

View File

@@ -0,0 +1,31 @@
//// [superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts]
class A {
foo() { return 1; }
}
class B extends A {
foo() { return 2; }
bar() {
return class {
[super.foo()]() {
return 100;
}
}
}
}
//// [superPropertyAccessInComputedPropertiesOfNestedType_ES6.js]
class A {
foo() { return 1; }
}
class B extends A {
foo() { return 2; }
bar() {
return class {
[super.foo()]() {
return 100;
}
}
;
}
}

View File

@@ -0,0 +1,29 @@
=== tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts ===
class A {
>A : Symbol(A, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 0, 0))
foo() { return 1; }
>foo : Symbol(foo, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 0, 9))
}
class B extends A {
>B : Symbol(B, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 2, 1))
>A : Symbol(A, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 0, 0))
foo() { return 2; }
>foo : Symbol(foo, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 4, 19))
bar() {
>bar : Symbol(bar, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 5, 23))
return class {
[super.foo()]() {
>super.foo : Symbol(A.foo, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 0, 9))
>super : Symbol(A, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 0, 0))
>foo : Symbol(A.foo, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 0, 9))
return 100;
}
}
}
}

View File

@@ -0,0 +1,35 @@
=== tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts ===
class A {
>A : A
foo() { return 1; }
>foo : () => number
>1 : number
}
class B extends A {
>B : B
>A : A
foo() { return 2; }
>foo : () => number
>2 : number
bar() {
>bar : () => typeof (Anonymous class)
return class {
>class { [super.foo()]() { return 100; } } : typeof (Anonymous class)
[super.foo()]() {
>super.foo() : number
>super.foo : () => number
>super : A
>foo : () => number
return 100;
>100 : number
}
}
}
}

View File

@@ -1,10 +1,10 @@
tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(4,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(5,20): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(5,20): error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher.
tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(7,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(8,13): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(11,20): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(8,13): error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher.
tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(11,20): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(20,17): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(21,24): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(21,24): error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher.
==== tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts (7 errors) ====
@@ -16,19 +16,19 @@ tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(21,24):
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
return super._foo;
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher.
},
set foo(value: string) {
~~~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
super._foo = value;
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher.
},
test: function () {
return super._foo;
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
}
}
}
@@ -42,7 +42,7 @@ tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(21,24):
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
return super.test();
~~~~~
!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
!!! error TS2659: 'super' in members of object literal expressions is only allowed when option 'target' is 'ES2015' or higher.
}
};
}

View File

@@ -38,10 +38,10 @@ var ObjectLiteral;
var ThisInObjectLiteral = {
_foo: '1',
get foo() {
return _super._foo;
return _super.prototype._foo;
},
set foo(value) {
_super._foo = value;
_super.prototype._foo = value;
},
test: function () {
return _super._foo;
@@ -62,7 +62,7 @@ var SuperObjectTest = (function (_super) {
SuperObjectTest.prototype.testing = function () {
var test = {
get F() {
return _super.test.call(this);
return _super.prototype.test.call(this);
}
};
};

View File

@@ -0,0 +1,60 @@
// @target: ES5
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
},
get prop() {
super.method();
return 10;
},
set prop(value) {
super.method();
},
p1: function () {
super.method();
},
p2: function f() {
super.method();
},
p3: () => {
super.method();
}
};
class A {
method() { }
}
class B extends A {
f() {
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
},
get prop() {
super.method();
return 10;
},
set prop(value) {
super.method();
},
p1: function () {
super.method();
},
p2: function f() {
super.method();
},
p3: () => {
super.method();
}
};
}
}

View File

@@ -0,0 +1,60 @@
// @target: ES6
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
},
get prop() {
super.method();
return 10;
},
set prop(value) {
super.method();
},
p1: function () {
super.method();
},
p2: function f() {
super.method();
},
p3: () => {
super.method();
}
};
class A {
method() { }
}
class B extends A {
f() {
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
},
get prop() {
super.method();
return 10;
},
set prop(value) {
super.method();
},
p1: function () {
super.method();
},
p2: function f() {
super.method();
},
p3: () => {
super.method();
}
};
}
}

View File

@@ -0,0 +1,15 @@
// @target: ES5
class A {
foo() { return 1; }
}
class B extends A {
foo() { return 2; }
bar() {
return class {
[super.foo()]() {
return 100;
}
}
}
}

View File

@@ -0,0 +1,15 @@
// @target: ES6
class A {
foo() { return 1; }
}
class B extends A {
foo() { return 2; }
bar() {
return class {
[super.foo()]() {
return 100;
}
}
}
}