Evaluate isPrototypePropertyAssignment lazily (#22728)

This commit is contained in:
Andy
2018-03-20 12:33:30 -07:00
committed by GitHub
parent 1074819be3
commit 9ee5167030
2 changed files with 5 additions and 3 deletions

View File

@@ -4260,13 +4260,11 @@ namespace ts {
if (isPropertyAccessExpression(expression.left) && expression.left.expression.kind === SyntaxKind.ThisKeyword) {
const thisContainer = getThisContainer(expression, /*includeArrowFunctions*/ false);
const isPrototypeProperty = isBinaryExpression(thisContainer.parent) &&
getSpecialPropertyAssignmentKind(thisContainer.parent) === SpecialPropertyAssignmentKind.PrototypeProperty;
// Properties defined in a constructor (or javascript constructor function) don't get undefined added.
// Function expressions that are assigned to the prototype count as methods.
if (thisContainer.kind === SyntaxKind.Constructor ||
thisContainer.kind === SyntaxKind.FunctionDeclaration ||
(thisContainer.kind === SyntaxKind.FunctionExpression && !isPrototypeProperty)) {
(thisContainer.kind === SyntaxKind.FunctionExpression && !isPrototypePropertyAssignment(thisContainer.parent))) {
definedInConstructor = true;
}
else {

View File

@@ -1656,6 +1656,10 @@ namespace ts {
return SpecialPropertyAssignmentKind.None;
}
export function isPrototypePropertyAssignment(node: Node): boolean {
return isBinaryExpression(node) && getSpecialPropertyAssignmentKind(node) === SpecialPropertyAssignmentKind.PrototypeProperty;
}
export function isSpecialPropertyDeclaration(expr: PropertyAccessExpression): boolean {
return isInJavaScriptFile(expr) &&
expr.parent && expr.parent.kind === SyntaxKind.ExpressionStatement &&