From a7688592b2aef3678f10ef246d0f2e49854ae1d1 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 6 Oct 2015 19:46:46 -0700 Subject: [PATCH] Address PR feedback Conflicts: src/compiler/diagnosticInformationMap.generated.ts src/compiler/diagnosticMessages.json src/compiler/types.ts --- src/compiler/checker.ts | 17 ++++++++++------- src/compiler/diagnosticMessages.json | 4 ++-- src/compiler/types.ts | 3 ++- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b328a4c8366..fb47d6bd57c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6859,9 +6859,8 @@ namespace ts { // (()=>this); // No Error // super(); // } - if ((container).hasSeenSuperBeforeThis === undefined) { - (container).hasSeenSuperBeforeThis = false; - } + let nodeLinks = getNodeLinks(container); + nodeLinks.flags |= NodeCheckFlags.HasSeenThisCall; } // Now skip arrow functions to get the "real" owner of 'this'. @@ -9605,8 +9604,12 @@ namespace ts { const signature = getResolvedSignature(node); if (node.expression.kind === SyntaxKind.SuperKeyword) { let containgFunction = getContainingFunction(node.expression); - if (containgFunction && containgFunction.kind === SyntaxKind.Constructor && (containgFunction).hasSeenSuperBeforeThis === undefined) { - (containgFunction).hasSeenSuperBeforeThis = true; + + if (containgFunction && containgFunction.kind === SyntaxKind.Constructor) { + let nodeLinks = getNodeLinks(containgFunction); + if (!(nodeLinks.flags & NodeCheckFlags.HasSeenThisCall)) { + nodeLinks.flags |= NodeCheckFlags.HasSeenSuperBeforeThis; + } } return voidType; } @@ -11208,9 +11211,9 @@ namespace ts { markThisReferencesAsErrors(superCallStatement.expression); } } - else if (!node.hasSeenSuperBeforeThis) { + else if (!(getNodeCheckFlags(node) & NodeCheckFlags.HasSeenSuperBeforeThis)){ // In ES6, super inside constructor of class-declaration has to precede "this" accessing - error(superCallStatement, Diagnostics.super_has_to_be_called_before_this_accessing); + error(superCallStatement, Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class); } } else if (baseConstructorType !== nullType) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 51a4e2c6c8f..4bf83bd3e45 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2540,8 +2540,8 @@ "category": "Error", "code": 17007 }, - "'super' has to be called before 'this' accessing.": { + "'super' must be called before accessing 'this' in the constructor of a derived class.": { "category": "Error", - "code": 17006 + "code": 17008 } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5a216f8bbcd..9aded35059a 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -695,7 +695,6 @@ namespace ts { // @kind(SyntaxKind.Constructor) export interface ConstructorDeclaration extends FunctionLikeDeclaration, ClassElement { body?: FunctionBody; - hasSeenSuperBeforeThis: boolean; // TODDO (yuisu): comment } // For when we encounter a semicolon in a class declaration. ES6 allows these as class elements. @@ -2031,6 +2030,8 @@ namespace ts { BlockScopedBindingInLoop = 0x00004000, LexicalModuleMergesWithClass = 0x00008000, // Instantiated lexical module declaration is merged with a previous class declaration. LoopWithBlockScopedBindingCapturedInFunction = 0x00010000, // Loop that contains block scoped variable captured in closure + HasSeenSuperBeforeThis = 0x00020000, // Set during the binding if the 'super' is used before 'this' in constructor function + HasSeenThisCall = 0x00040000, // Set during the binding when encounter 'this' } /* @internal */