mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
Address PR feedback
Conflicts: src/compiler/diagnosticInformationMap.generated.ts src/compiler/diagnosticMessages.json src/compiler/types.ts
This commit is contained in:
@@ -6859,9 +6859,8 @@ namespace ts {
|
||||
// (()=>this); // No Error
|
||||
// super();
|
||||
// }
|
||||
if ((<ConstructorDeclaration>container).hasSeenSuperBeforeThis === undefined) {
|
||||
(<ConstructorDeclaration>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 && (<ConstructorDeclaration>containgFunction).hasSeenSuperBeforeThis === undefined) {
|
||||
(<ConstructorDeclaration>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) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user