From 60e1f301822daba4afa67a37ec777b4fa47b6691 Mon Sep 17 00:00:00 2001 From: vladima Date: Fri, 11 Dec 2015 17:16:28 -0800 Subject: [PATCH] allow usage of 'super' in object literal expressions --- src/compiler/checker.ts | 86 ++++++----- src/compiler/diagnosticMessages.json | 8 ++ src/compiler/utilities.ts | 54 ++++--- src/services/services.ts | 4 +- .../computedPropertyNames24_ES5.errors.txt | 4 +- .../computedPropertyNames24_ES6.errors.txt | 4 +- .../computedPropertyNames26_ES5.errors.txt | 4 +- .../computedPropertyNames26_ES6.errors.txt | 4 +- .../computedPropertyNames27_ES5.errors.txt | 4 +- .../computedPropertyNames27_ES6.errors.txt | 4 +- .../decoratorOnClassMethod12.errors.txt | 4 +- .../emitThisInSuperMethodCall.errors.txt | 12 +- .../reference/errorSuperCalls.errors.txt | 32 ++--- .../errorSuperPropertyAccess.errors.txt | 16 +-- .../superCallFromFunction1.errors.txt | 4 +- .../reference/superErrors.errors.txt | 32 ++--- .../superInObjectLiterals_ES5.errors.txt | 95 +++++++++++++ .../reference/superInObjectLiterals_ES5.js | 133 ++++++++++++++++++ .../superInObjectLiterals_ES6.errors.txt | 77 ++++++++++ .../reference/superInObjectLiterals_ES6.js | 119 ++++++++++++++++ ...essInComputedPropertiesOfNestedType_ES5.js | 46 ++++++ ...ComputedPropertiesOfNestedType_ES5.symbols | 29 ++++ ...InComputedPropertiesOfNestedType_ES5.types | 35 +++++ ...essInComputedPropertiesOfNestedType_ES6.js | 31 ++++ ...ComputedPropertiesOfNestedType_ES6.symbols | 29 ++++ ...InComputedPropertiesOfNestedType_ES6.types | 35 +++++ ...ect-literal-getters-and-setters.errors.txt | 16 +-- ...side-object-literal-getters-and-setters.js | 6 +- .../compiler/superInObjectLiterals_ES5.ts | 60 ++++++++ .../compiler/superInObjectLiterals_ES6.ts | 60 ++++++++ ...essInComputedPropertiesOfNestedType_ES5.ts | 15 ++ ...essInComputedPropertiesOfNestedType_ES6.ts | 15 ++ 32 files changed, 940 insertions(+), 137 deletions(-) create mode 100644 tests/baselines/reference/superInObjectLiterals_ES5.errors.txt create mode 100644 tests/baselines/reference/superInObjectLiterals_ES5.js create mode 100644 tests/baselines/reference/superInObjectLiterals_ES6.errors.txt create mode 100644 tests/baselines/reference/superInObjectLiterals_ES6.js create mode 100644 tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES5.js create mode 100644 tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES5.symbols create mode 100644 tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES5.types create mode 100644 tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES6.js create mode 100644 tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES6.symbols create mode 100644 tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES6.types create mode 100644 tests/cases/compiler/superInObjectLiterals_ES5.ts create mode 100644 tests/cases/compiler/superInObjectLiterals_ES6.ts create mode 100644 tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts create mode 100644 tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 76bd39a00bf..6af7ddba419 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7037,17 +7037,14 @@ namespace ts { function checkSuperExpression(node: Node): Type { const isCallExpression = node.parent.kind === SyntaxKind.CallExpression && (node.parent).expression === node; - const classDeclaration = getContainingClass(node); - const classType = classDeclaration && 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 = container.parent; + const classType = 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 || diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 54123808932..30b46e5cde2 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -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 diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index eee09fc641f..a85432418cc 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -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; } } } diff --git a/src/services/services.ts b/src/services/services.ts index a9dda549ead..2d42172832f 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -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 diff --git a/tests/baselines/reference/computedPropertyNames24_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames24_ES5.errors.txt index 121b39450a6..e06373fb1e3 100644 --- a/tests/baselines/reference/computedPropertyNames24_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames24_ES5.errors.txt @@ -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. } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames24_ES6.errors.txt b/tests/baselines/reference/computedPropertyNames24_ES6.errors.txt index cab0ba6a85c..331723afe34 100644 --- a/tests/baselines/reference/computedPropertyNames24_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNames24_ES6.errors.txt @@ -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. } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames26_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames26_ES5.errors.txt index e7039712734..c8e24abfa9d 100644 --- a/tests/baselines/reference/computedPropertyNames26_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames26_ES5.errors.txt @@ -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. ]() { } } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames26_ES6.errors.txt b/tests/baselines/reference/computedPropertyNames26_ES6.errors.txt index d7e2b5ce7c5..ec20ed57144 100644 --- a/tests/baselines/reference/computedPropertyNames26_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNames26_ES6.errors.txt @@ -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. ]() { } } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames27_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames27_ES5.errors.txt index 1fbc7b37543..97964d48176 100644 --- a/tests/baselines/reference/computedPropertyNames27_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames27_ES5.errors.txt @@ -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. } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames27_ES6.errors.txt b/tests/baselines/reference/computedPropertyNames27_ES6.errors.txt index edf84201647..30e1ce5b14f 100644 --- a/tests/baselines/reference/computedPropertyNames27_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNames27_ES6.errors.txt @@ -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. } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassMethod12.errors.txt b/tests/baselines/reference/decoratorOnClassMethod12.errors.txt index 3ad3cabebe2..c285d5f12c9 100644 --- a/tests/baselines/reference/decoratorOnClassMethod12.errors.txt +++ b/tests/baselines/reference/decoratorOnClassMethod12.errors.txt @@ -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() { } } } \ No newline at end of file diff --git a/tests/baselines/reference/emitThisInSuperMethodCall.errors.txt b/tests/baselines/reference/emitThisInSuperMethodCall.errors.txt index 06211ef771f..c8d694c8567 100644 --- a/tests/baselines/reference/emitThisInSuperMethodCall.errors.txt +++ b/tests/baselines/reference/emitThisInSuperMethodCall.errors.txt @@ -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. } } } diff --git a/tests/baselines/reference/errorSuperCalls.errors.txt b/tests/baselines/reference/errorSuperCalls.errors.txt index 9ecc7a1565e..49bcb4b4d45 100644 --- a/tests/baselines/reference/errorSuperCalls.errors.txt +++ b/tests/baselines/reference/errorSuperCalls.errors.txt @@ -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. } } diff --git a/tests/baselines/reference/errorSuperPropertyAccess.errors.txt b/tests/baselines/reference/errorSuperPropertyAccess.errors.txt index c34ed912046..c54ace99f17 100644 --- a/tests/baselines/reference/errorSuperPropertyAccess.errors.txt +++ b/tests/baselines/reference/errorSuperPropertyAccess.errors.txt @@ -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. \ No newline at end of file diff --git a/tests/baselines/reference/superCallFromFunction1.errors.txt b/tests/baselines/reference/superCallFromFunction1.errors.txt index 374a3aeb16c..b993d9f1253 100644 --- a/tests/baselines/reference/superCallFromFunction1.errors.txt +++ b/tests/baselines/reference/superCallFromFunction1.errors.txt @@ -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. } \ No newline at end of file diff --git a/tests/baselines/reference/superErrors.errors.txt b/tests/baselines/reference/superErrors.errors.txt index 26e0ba3a6c4..5c6d7365a67 100644 --- a/tests/baselines/reference/superErrors.errors.txt +++ b/tests/baselines/reference/superErrors.errors.txt @@ -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. } diff --git a/tests/baselines/reference/superInObjectLiterals_ES5.errors.txt b/tests/baselines/reference/superInObjectLiterals_ES5.errors.txt new file mode 100644 index 00000000000..944766cb5ae --- /dev/null +++ b/tests/baselines/reference/superInObjectLiterals_ES5.errors.txt @@ -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(); + } + }; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/superInObjectLiterals_ES5.js b/tests/baselines/reference/superInObjectLiterals_ES5.js new file mode 100644 index 00000000000..f701ca7df7b --- /dev/null +++ b/tests/baselines/reference/superInObjectLiterals_ES5.js @@ -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)); diff --git a/tests/baselines/reference/superInObjectLiterals_ES6.errors.txt b/tests/baselines/reference/superInObjectLiterals_ES6.errors.txt new file mode 100644 index 00000000000..dcd9692f5e3 --- /dev/null +++ b/tests/baselines/reference/superInObjectLiterals_ES6.errors.txt @@ -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(); + } + }; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/superInObjectLiterals_ES6.js b/tests/baselines/reference/superInObjectLiterals_ES6.js new file mode 100644 index 00000000000..4cd62e68947 --- /dev/null +++ b/tests/baselines/reference/superInObjectLiterals_ES6.js @@ -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(); + } + }; + } +} diff --git a/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES5.js b/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES5.js new file mode 100644 index 00000000000..a91dfc76e3d --- /dev/null +++ b/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES5.js @@ -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)); diff --git a/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES5.symbols b/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES5.symbols new file mode 100644 index 00000000000..1379d50179f --- /dev/null +++ b/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES5.symbols @@ -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; + } + } + } +} diff --git a/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES5.types b/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES5.types new file mode 100644 index 00000000000..d435bff69b5 --- /dev/null +++ b/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES5.types @@ -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 + } + } + } +} diff --git a/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES6.js b/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES6.js new file mode 100644 index 00000000000..825fa7682e2 --- /dev/null +++ b/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES6.js @@ -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; + } + } + ; + } +} diff --git a/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES6.symbols b/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES6.symbols new file mode 100644 index 00000000000..12446259f32 --- /dev/null +++ b/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES6.symbols @@ -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; + } + } + } +} diff --git a/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES6.types b/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES6.types new file mode 100644 index 00000000000..817e3b73ba4 --- /dev/null +++ b/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES6.types @@ -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 + } + } + } +} diff --git a/tests/baselines/reference/super_inside-object-literal-getters-and-setters.errors.txt b/tests/baselines/reference/super_inside-object-literal-getters-and-setters.errors.txt index 4f1faf78a78..16a66bf6fa4 100644 --- a/tests/baselines/reference/super_inside-object-literal-getters-and-setters.errors.txt +++ b/tests/baselines/reference/super_inside-object-literal-getters-and-setters.errors.txt @@ -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. } }; } diff --git a/tests/baselines/reference/super_inside-object-literal-getters-and-setters.js b/tests/baselines/reference/super_inside-object-literal-getters-and-setters.js index be70ee33183..db6db37ac8a 100644 --- a/tests/baselines/reference/super_inside-object-literal-getters-and-setters.js +++ b/tests/baselines/reference/super_inside-object-literal-getters-and-setters.js @@ -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); } }; }; diff --git a/tests/cases/compiler/superInObjectLiterals_ES5.ts b/tests/cases/compiler/superInObjectLiterals_ES5.ts new file mode 100644 index 00000000000..96cdfaa5b7b --- /dev/null +++ b/tests/cases/compiler/superInObjectLiterals_ES5.ts @@ -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(); + } + }; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/superInObjectLiterals_ES6.ts b/tests/cases/compiler/superInObjectLiterals_ES6.ts new file mode 100644 index 00000000000..05b2853a90b --- /dev/null +++ b/tests/cases/compiler/superInObjectLiterals_ES6.ts @@ -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(); + } + }; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts b/tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts new file mode 100644 index 00000000000..9c7d28f96a4 --- /dev/null +++ b/tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts @@ -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; + } + } + } +} \ No newline at end of file diff --git a/tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts b/tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts new file mode 100644 index 00000000000..6a8c2e1a7d6 --- /dev/null +++ b/tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts @@ -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; + } + } + } +} \ No newline at end of file