mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-19 01:33:15 -05:00
Check own-constructor in abstract prop access error
This commit is contained in:
@@ -14906,12 +14906,11 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
// Referencing Abstract Properties within Constructors is not allowed
|
||||
// Referencing abstract properties within their own constructors is not allowed
|
||||
if ((flags & ModifierFlags.Abstract) && symbolHasNonMethodDeclaration(prop)) {
|
||||
const declaringClassDeclaration = <ClassLikeDeclaration>getClassLikeDeclarationOfSymbol(getParentOfSymbol(prop));
|
||||
|
||||
if (declaringClassDeclaration && isNodeWithinConstructor(node, declaringClassDeclaration)) {
|
||||
error(errorNode, Diagnostics.Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor, symbolToString(prop), typeToString(getDeclaringClass(prop)));
|
||||
if (declaringClassDeclaration && isNodeWithinConstructorOfClass(node, declaringClassDeclaration)) {
|
||||
error(errorNode, Diagnostics.Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor, symbolToString(prop), getTextOfIdentifierOrLiteral(declaringClassDeclaration.name));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -23227,9 +23226,9 @@ namespace ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
function isNodeWithinConstructor(node: Node, classDeclaration: ClassLikeDeclaration) {
|
||||
function isNodeWithinConstructorOfClass(node: Node, classDeclaration: ClassLikeDeclaration) {
|
||||
return findAncestor(node, element => {
|
||||
if (isConstructorDeclaration(element) && nodeIsPresent(element.body)) {
|
||||
if (isConstructorDeclaration(element) && nodeIsPresent(element.body) && element.parent === classDeclaration) {
|
||||
return true;
|
||||
}
|
||||
else if (element === classDeclaration || isFunctionLikeDeclaration(element)) {
|
||||
|
||||
Reference in New Issue
Block a user