From dd06cbb3156aa6499756cf4da75e3492ae4b2e0a Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 27 Mar 2017 14:32:45 -0700 Subject: [PATCH] getSpecialPropertyAssignmentKind: Always check for BinaryExpression *outside*, always check for JS file *inside* --- src/compiler/binder.ts | 48 +++++++++++++++++++-------------------- src/compiler/checker.ts | 6 ++--- src/compiler/utilities.ts | 5 +--- 3 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 650797c6dba2a..45e8efdf5128c 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -259,7 +259,7 @@ namespace ts { case SyntaxKind.ExportAssignment: return (node).isExportEquals ? "export=" : "default"; case SyntaxKind.BinaryExpression: - switch (getSpecialPropertyAssignmentKind(node)) { + switch (getSpecialPropertyAssignmentKind(node as BinaryExpression)) { case SpecialPropertyAssignmentKind.ModuleExports: // module.exports = ... return "export="; @@ -2017,30 +2017,28 @@ namespace ts { } break; case SyntaxKind.BinaryExpression: - if (isInJavaScriptFile(node)) { - const specialKind = getSpecialPropertyAssignmentKind(node); - switch (specialKind) { - case SpecialPropertyAssignmentKind.ExportsProperty: - bindExportsPropertyAssignment(node); - break; - case SpecialPropertyAssignmentKind.ModuleExports: - bindModuleExportsAssignment(node); - break; - case SpecialPropertyAssignmentKind.PrototypeProperty: - bindPrototypePropertyAssignment(node); - break; - case SpecialPropertyAssignmentKind.ThisProperty: - bindThisPropertyAssignment(node); - break; - case SpecialPropertyAssignmentKind.Property: - bindStaticPropertyAssignment(node); - break; - case SpecialPropertyAssignmentKind.None: - // Nothing to do - break; - default: - Debug.fail("Unknown special property assignment kind"); - } + const specialKind = getSpecialPropertyAssignmentKind(node as BinaryExpression); + switch (specialKind) { + case SpecialPropertyAssignmentKind.ExportsProperty: + bindExportsPropertyAssignment(node); + break; + case SpecialPropertyAssignmentKind.ModuleExports: + bindModuleExportsAssignment(node); + break; + case SpecialPropertyAssignmentKind.PrototypeProperty: + bindPrototypePropertyAssignment(node); + break; + case SpecialPropertyAssignmentKind.ThisProperty: + bindThisPropertyAssignment(node); + break; + case SpecialPropertyAssignmentKind.Property: + bindStaticPropertyAssignment(node); + break; + case SpecialPropertyAssignmentKind.None: + // Nothing to do + break; + default: + Debug.fail("Unknown special property assignment kind"); } return checkStrictModeBinaryExpression(node); case SyntaxKind.CatchClause: diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4e55a1c46b564..408739f480f25 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11929,8 +11929,8 @@ namespace ts { // If this is a function in a JS file, it might be a class method. Check if it's the RHS // of a x.prototype.y = function [name]() { .... } if (container.kind === SyntaxKind.FunctionExpression && - isInJavaScriptFile(container.parent) && - getSpecialPropertyAssignmentKind(container.parent) === SpecialPropertyAssignmentKind.PrototypeProperty) { + container.parent.kind === SyntaxKind.BinaryExpression && + getSpecialPropertyAssignmentKind(container.parent as BinaryExpression) === SpecialPropertyAssignmentKind.PrototypeProperty) { // Get the 'x' of 'x.prototype.y = f' (here, 'f' is 'container') const className = (((container.parent as BinaryExpression) // x.prototype.y = f .left as PropertyAccessExpression) // x.prototype.y @@ -21641,7 +21641,7 @@ namespace ts { } function getSpecialPropertyAssignmentSymbolFromEntityName(entityName: EntityName | PropertyAccessExpression) { - const specialPropertyAssignmentKind = getSpecialPropertyAssignmentKind(entityName.parent.parent); + const specialPropertyAssignmentKind = getSpecialPropertyAssignmentKind(entityName.parent.parent as BinaryExpression); switch (specialPropertyAssignmentKind) { case SpecialPropertyAssignmentKind.ExportsProperty: case SpecialPropertyAssignmentKind.PrototypeProperty: diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 33cb0d8f4898d..f0916855986cc 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1450,13 +1450,10 @@ namespace ts { /// Given a BinaryExpression, returns SpecialPropertyAssignmentKind for the various kinds of property /// assignments we treat as special in the binder - export function getSpecialPropertyAssignmentKind(expression: Node): SpecialPropertyAssignmentKind { + export function getSpecialPropertyAssignmentKind(expression: ts.BinaryExpression): SpecialPropertyAssignmentKind { if (!isInJavaScriptFile(expression)) { return SpecialPropertyAssignmentKind.None; } - if (expression.kind !== SyntaxKind.BinaryExpression) { - return SpecialPropertyAssignmentKind.None; - } const expr = expression; if (expr.operatorToken.kind !== SyntaxKind.EqualsToken || expr.left.kind !== SyntaxKind.PropertyAccessExpression) { return SpecialPropertyAssignmentKind.None;