From d55aa22d1536cd007dc69c8d1b8bdd2c67438016 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 22 Feb 2018 11:19:44 -0800 Subject: [PATCH] Code cleanup --- src/compiler/binder.ts | 16 ++++++++-------- src/compiler/utilities.ts | 16 ++++------------ 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 1708639758f..053255fbaa7 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2353,14 +2353,13 @@ namespace ts { if (node.expression.kind === SyntaxKind.ThisKeyword) { bindThisPropertyAssignment(node); } - else if (isEntityNameExpression(node) && - isPropertyAccessExpression(node.expression) && - node.expression.name.escapedText === "prototype" && - node.parent.parent.kind === SyntaxKind.SourceFile) { - bindPrototypePropertyAssignment(node as PropertyAccessEntityNameExpression, node.parent); - } else if (isEntityNameExpression(node) && node.parent.parent.kind === SyntaxKind.SourceFile) { - bindStaticPropertyAssignment(node as PropertyAccessEntityNameExpression); + if (isPropertyAccessExpression(node.expression) && node.expression.name.escapedText === "prototype") { + bindPrototypePropertyAssignment(node as PropertyAccessEntityNameExpression, node.parent); + } + else { + bindStaticPropertyAssignment(node as PropertyAccessEntityNameExpression); + } } } @@ -2368,7 +2367,8 @@ namespace ts { function bindPrototypeAssignment(node: BinaryExpression) { node.left.parent = node; node.right.parent = node; - bindPropertyAssignment(node.left as PropertyAccessEntityNameExpression, node.left as PropertyAccessEntityNameExpression, /*isPrototypeProperty*/ false); + const lhs = node.left as PropertyAccessEntityNameExpression; + bindPropertyAssignment(lhs, lhs, /*isPrototypeProperty*/ false); } /** diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 4058b9ac6b8..51c3b6ae22c 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1587,6 +1587,9 @@ namespace ts { return SpecialPropertyAssignmentKind.None; } const lhs = expr.left; + if (lhs.expression.kind === SyntaxKind.ThisKeyword) { + return SpecialPropertyAssignmentKind.ThisProperty; + } if (isIdentifier(lhs.expression)) { if (lhs.expression.escapedText === "exports") { // exports.name = expr @@ -1596,19 +1599,8 @@ namespace ts { // module.exports = expr return SpecialPropertyAssignmentKind.ModuleExports; } - // TODO: Can probably unify these checks with those in the second half - else if (lhs.name.escapedText === "prototype") { - return SpecialPropertyAssignmentKind.Prototype; - } - else { - // F.x = expr - return SpecialPropertyAssignmentKind.Property; - } } - else if (lhs.expression.kind === SyntaxKind.ThisKeyword) { - return SpecialPropertyAssignmentKind.ThisProperty; - } - else if (isEntityNameExpression(lhs.expression)) { + if (isEntityNameExpression(lhs.expression)) { if (lhs.name.escapedText === "prototype" && isObjectLiteralExpression(expr.right)) { // F.prototype = { ... } return SpecialPropertyAssignmentKind.Prototype;