Skip to content

Commit 9ee5167

Browse files
author
Andy
authored
Evaluate isPrototypePropertyAssignment lazily (#22728)
1 parent 1074819 commit 9ee5167

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4260,13 +4260,11 @@ namespace ts {
42604260

42614261
if (isPropertyAccessExpression(expression.left) && expression.left.expression.kind === SyntaxKind.ThisKeyword) {
42624262
const thisContainer = getThisContainer(expression, /*includeArrowFunctions*/ false);
4263-
const isPrototypeProperty = isBinaryExpression(thisContainer.parent) &&
4264-
getSpecialPropertyAssignmentKind(thisContainer.parent) === SpecialPropertyAssignmentKind.PrototypeProperty;
42654263
// Properties defined in a constructor (or javascript constructor function) don't get undefined added.
42664264
// Function expressions that are assigned to the prototype count as methods.
42674265
if (thisContainer.kind === SyntaxKind.Constructor ||
42684266
thisContainer.kind === SyntaxKind.FunctionDeclaration ||
4269-
(thisContainer.kind === SyntaxKind.FunctionExpression && !isPrototypeProperty)) {
4267+
(thisContainer.kind === SyntaxKind.FunctionExpression && !isPrototypePropertyAssignment(thisContainer.parent))) {
42704268
definedInConstructor = true;
42714269
}
42724270
else {

src/compiler/utilities.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,10 @@ namespace ts {
16561656
return SpecialPropertyAssignmentKind.None;
16571657
}
16581658

1659+
export function isPrototypePropertyAssignment(node: Node): boolean {
1660+
return isBinaryExpression(node) && getSpecialPropertyAssignmentKind(node) === SpecialPropertyAssignmentKind.PrototypeProperty;
1661+
}
1662+
16591663
export function isSpecialPropertyDeclaration(expr: PropertyAccessExpression): boolean {
16601664
return isInJavaScriptFile(expr) &&
16611665
expr.parent && expr.parent.kind === SyntaxKind.ExpressionStatement &&

0 commit comments

Comments
 (0)