mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-11 16:38:46 -05:00
Evaluate isPrototypePropertyAssignment lazily (#22728)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 &&
|
||||
|
||||
Reference in New Issue
Block a user