Check own-constructor in abstract prop access error

This commit is contained in:
Nathan Shively-Sanders
2017-10-16 09:19:46 -07:00
parent d4c0377395
commit 5e7bfad2a7

View File

@@ -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)) {