mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-24 02:21:30 -05:00
Merge pull request #26935 from ajafff/abstract-baseclass-property
Error accessing abstract property in constructor of abstract subclass
This commit is contained in:
@@ -18238,7 +18238,7 @@ namespace ts {
|
||||
// Referencing abstract properties within their own constructors is not allowed
|
||||
if ((flags & ModifierFlags.Abstract) && isThisProperty(node) && symbolHasNonMethodDeclaration(prop)) {
|
||||
const declaringClassDeclaration = getClassLikeDeclarationOfSymbol(getParentOfSymbol(prop)!);
|
||||
if (declaringClassDeclaration && isNodeUsedDuringClassInitialization(node, declaringClassDeclaration)) {
|
||||
if (declaringClassDeclaration && isNodeUsedDuringClassInitialization(node)) {
|
||||
error(errorNode, Diagnostics.Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor, symbolToString(prop), getTextOfIdentifierOrLiteral(declaringClassDeclaration.name!)); // TODO: GH#18217
|
||||
return false;
|
||||
}
|
||||
@@ -27449,12 +27449,12 @@ namespace ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
function isNodeUsedDuringClassInitialization(node: Node, classDeclaration: ClassLikeDeclaration) {
|
||||
function isNodeUsedDuringClassInitialization(node: Node) {
|
||||
return !!findAncestor(node, element => {
|
||||
if ((isConstructorDeclaration(element) && nodeIsPresent(element.body) || isPropertyDeclaration(element)) && element.parent === classDeclaration) {
|
||||
if (isConstructorDeclaration(element) && nodeIsPresent(element.body) || isPropertyDeclaration(element)) {
|
||||
return true;
|
||||
}
|
||||
else if (element === classDeclaration || isFunctionLikeDeclaration(element)) {
|
||||
else if (isClassLike(element) || isFunctionLikeDeclaration(element)) {
|
||||
return "quit";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user