mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-22 22:55:36 -05:00
Address comments
This commit is contained in:
@@ -6849,17 +6849,11 @@ namespace ts {
|
||||
let needToCaptureLexicalThis = false;
|
||||
|
||||
if (container.kind === SyntaxKind.Constructor) {
|
||||
// Keep track of whether we have seen "super" before encounter "this" so that
|
||||
// we can report appropriate error later in checkConstructorDeclaration
|
||||
// We have to do the check here to make sure we won't give false error when
|
||||
// "this" is used in arrow functions
|
||||
// For example:
|
||||
// constructor() {
|
||||
// (()=>this); // No Error
|
||||
// super();
|
||||
// }
|
||||
const nodeLinks = getNodeLinks(container);
|
||||
nodeLinks.flags |= NodeCheckFlags.HasSeenThisCall;
|
||||
const baseTypeNode = getClassExtendsHeritageClauseElement(<ClassLikeDeclaration>container.parent);
|
||||
if (baseTypeNode && !(getNodeCheckFlags(container) & NodeCheckFlags.HasSeenSuperCall)) {
|
||||
// In ES6, super inside constructor of class-declaration has to precede "this" accessing
|
||||
error(node, Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class);
|
||||
}
|
||||
}
|
||||
|
||||
// Now skip arrow functions to get the "real" owner of 'this'.
|
||||
@@ -9605,10 +9599,7 @@ namespace ts {
|
||||
const containgFunction = getContainingFunction(node.expression);
|
||||
|
||||
if (containgFunction && containgFunction.kind === SyntaxKind.Constructor) {
|
||||
const nodeLinks = getNodeLinks(containgFunction);
|
||||
if (!(nodeLinks.flags & NodeCheckFlags.HasSeenThisCall)) {
|
||||
nodeLinks.flags |= NodeCheckFlags.HasSeenSuperBeforeThis;
|
||||
}
|
||||
getNodeLinks(containgFunction).flags |= NodeCheckFlags.HasSeenSuperCall;
|
||||
}
|
||||
return voidType;
|
||||
}
|
||||
@@ -11210,10 +11201,6 @@ namespace ts {
|
||||
markThisReferencesAsErrors(superCallStatement.expression);
|
||||
}
|
||||
}
|
||||
else if (!(getNodeCheckFlags(node) & NodeCheckFlags.HasSeenSuperBeforeThis)) {
|
||||
// In ES6, super inside constructor of class-declaration has to precede "this" accessing
|
||||
error(superCallStatement, Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class);
|
||||
}
|
||||
}
|
||||
else if (baseConstructorType !== nullType) {
|
||||
error(node, Diagnostics.Constructors_for_derived_classes_must_contain_a_super_call);
|
||||
|
||||
@@ -2030,8 +2030,7 @@ 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 'super' is used before 'this' in constructor function
|
||||
HasSeenThisCall = 0x00040000, // Set during the binding when encounter 'this'
|
||||
HasSeenSuperCall = 0x00040000, // Set during the binding when encounter 'super'
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
|
||||
Reference in New Issue
Block a user