From 9ee51670308609ff56b94ff1d6c87ddb5b416c09 Mon Sep 17 00:00:00 2001 From: Andy Date: Tue, 20 Mar 2018 12:33:30 -0700 Subject: [PATCH] Evaluate isPrototypePropertyAssignment lazily (#22728) --- src/compiler/checker.ts | 4 +--- src/compiler/utilities.ts | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4c3a98b12dc..a0675e957dd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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 { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index a5ba7c30cd2..69249952166 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -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 &&