Skip to content

Commit d3b4c6a

Browse files
author
Andy Hanson
committed
Improve readability
1 parent dcbaada commit d3b4c6a

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

src/compiler/checker.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11882,18 +11882,14 @@ namespace ts {
1188211882
if (symbol.flags & SymbolFlags.Property &&
1188311883
(expr.kind === SyntaxKind.PropertyAccessExpression || expr.kind === SyntaxKind.ElementAccessExpression) &&
1188411884
(expr as PropertyAccessExpression | ElementAccessExpression).expression.kind === SyntaxKind.ThisKeyword) {
11885-
return !isInConstructor(getContainingFunction(expr));
11886-
function isInConstructor(func: FunctionLikeDeclaration) {
11887-
if (!func)
11888-
return false;
11889-
if (func.kind !== SyntaxKind.Constructor)
11890-
return false;
11891-
if (func.parent === symbol.valueDeclaration.parent) // If the symbol was declared in the class:
11892-
return true;
11893-
if (func === symbol.valueDeclaration.parent) // If symbolDecl is a parameter property of the constructor:
11894-
return true;
11895-
return false;
11896-
}
11885+
// Look for if this is the constructor for the class that `symbol` is a property of.
11886+
const func = getContainingFunction(expr);
11887+
if (!(func && func.kind === SyntaxKind.Constructor))
11888+
return true;
11889+
// If func.parent is a class and symbol is a (readonly) property of that class, or
11890+
// if func is a constructor and symbol is a (readonly) parameter property declared in it,
11891+
// then symbol is writeable here.
11892+
return !(func.parent === symbol.valueDeclaration.parent || func === symbol.valueDeclaration.parent);
1189711893
}
1189811894
return true;
1189911895
}

0 commit comments

Comments
 (0)