Merge pull request #8712 from Microsoft/readonly_assignment_in_constructor

Allow assignment to readonly parameter property within the constructor
This commit is contained in:
Andy
2016-05-23 13:21:22 -07:00
4 changed files with 187 additions and 1 deletions

View File

@@ -11877,8 +11877,14 @@ namespace ts {
if (symbol.flags & SymbolFlags.Property &&
(expr.kind === SyntaxKind.PropertyAccessExpression || expr.kind === SyntaxKind.ElementAccessExpression) &&
(expr as PropertyAccessExpression | ElementAccessExpression).expression.kind === SyntaxKind.ThisKeyword) {
// Look for if this is the constructor for the class that `symbol` is a property of.
const func = getContainingFunction(expr);
return !(func && func.kind === SyntaxKind.Constructor && func.parent === symbol.valueDeclaration.parent);
if (!(func && func.kind === SyntaxKind.Constructor))
return true;
// If func.parent is a class and symbol is a (readonly) property of that class, or
// if func is a constructor and symbol is a (readonly) parameter property declared in it,
// then symbol is writeable here.
return !(func.parent === symbol.valueDeclaration.parent || func === symbol.valueDeclaration.parent);
}
return true;
}