mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-18 03:43:28 -06:00
Add basic check for use super before this
Conflicts: src/compiler/diagnosticInformationMap.generated.ts src/compiler/diagnosticMessages.json src/compiler/types.ts
This commit is contained in:
parent
090eb205b2
commit
e15eab9d99
@ -6866,6 +6866,11 @@ namespace ts {
|
||||
// do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks
|
||||
break;
|
||||
case SyntaxKind.Constructor:
|
||||
// TODO(yuisu): Comments
|
||||
if ((<ConstructorDeclaration>container).hasSeenSuperBeforeThis === undefined) {
|
||||
(<ConstructorDeclaration>container).hasSeenSuperBeforeThis = false;
|
||||
}
|
||||
|
||||
if (isInConstructorArgumentInitializer(node, container)) {
|
||||
error(node, Diagnostics.this_cannot_be_referenced_in_constructor_arguments);
|
||||
// do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks
|
||||
@ -9588,6 +9593,10 @@ 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;
|
||||
}
|
||||
return voidType;
|
||||
}
|
||||
if (node.kind === SyntaxKind.NewExpression) {
|
||||
@ -11182,6 +11191,10 @@ namespace ts {
|
||||
markThisReferencesAsErrors(superCallStatement.expression);
|
||||
}
|
||||
}
|
||||
else if (!node.hasSeenSuperBeforeThis) {
|
||||
// TODO: comment
|
||||
error(node, Diagnostics.super_has_to_be_called_before_this_accessing);
|
||||
}
|
||||
}
|
||||
else if (baseConstructorType !== nullType) {
|
||||
error(node, Diagnostics.Constructors_for_derived_classes_must_contain_a_super_call);
|
||||
|
||||
@ -2539,5 +2539,9 @@
|
||||
"A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.": {
|
||||
"category": "Error",
|
||||
"code": 17007
|
||||
},
|
||||
"'super' has to be called before 'this' accessing.": {
|
||||
"category": "Error",
|
||||
"code": 17006
|
||||
}
|
||||
}
|
||||
|
||||
@ -695,6 +695,7 @@ 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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user