mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 01:49:57 -05:00
Address PR feedback
Conflicts: src/compiler/diagnosticInformationMap.generated.ts src/compiler/diagnosticMessages.json src/compiler/types.ts
This commit is contained in:
committed by
Kanchalai Tanglertsampan
parent
42ccabe8e5
commit
40ba1be0a9
@@ -7251,9 +7251,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'.
|
||||
@@ -10200,6 +10199,14 @@ namespace ts {
|
||||
|
||||
const signature = getResolvedSignature(node);
|
||||
if (node.expression.kind === SyntaxKind.SuperKeyword) {
|
||||
let containgFunction = getContainingFunction(node.expression);
|
||||
|
||||
if (containgFunction && containgFunction.kind === SyntaxKind.Constructor) {
|
||||
let nodeLinks = getNodeLinks(containgFunction);
|
||||
if (!(nodeLinks.flags & NodeCheckFlags.HasSeenThisCall)) {
|
||||
nodeLinks.flags |= NodeCheckFlags.HasSeenSuperBeforeThis;
|
||||
}
|
||||
}
|
||||
return voidType;
|
||||
}
|
||||
if (node.kind === SyntaxKind.NewExpression) {
|
||||
@@ -11828,9 +11835,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) {
|
||||
|
||||
@@ -2642,5 +2642,9 @@
|
||||
"JSX element '{0}' has no corresponding closing tag.": {
|
||||
"category": "Error",
|
||||
"code": 17008
|
||||
},
|
||||
"'super' must be called before accessing 'this' in the constructor of a derived class.": {
|
||||
"category": "Error",
|
||||
"code": 17008
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2068,6 +2068,8 @@ namespace ts {
|
||||
LoopWithCapturedBlockScopedBinding = 0x00010000, // Loop that contains block scoped variable captured in closure
|
||||
CapturedBlockScopedBinding = 0x00020000, // Block-scoped binding that is captured in some function
|
||||
BlockScopedBindingInLoop = 0x00040000, // Block-scoped binding with declaration nested inside iteration statement
|
||||
HasSeenSuperBeforeThis = 0x00080000, // Set during the binding if the 'super' is used before 'this' in constructor function
|
||||
HasSeenThisCall = 0x00100000, // Set during the binding when encounter 'this'
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
|
||||
Reference in New Issue
Block a user