From 6a175321bf432f31490dd81fcc7fd0f7257c4baa Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 5 May 2017 15:09:54 -0700 Subject: [PATCH] Address comments: simplify, dedupe and clean up --- src/compiler/checker.ts | 24 ++++++++---------------- src/compiler/utilities.ts | 29 +++++++++++++++-------------- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 05af363fb8e7d..aea175ac8b162 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -18110,18 +18110,17 @@ namespace ts { forEach(overloads, o => { const deviation = getEffectiveDeclarationFlags(o, flagsToCheck) ^ canonicalFlags; - const name = getNameOfDeclaration(o); if (deviation & ModifierFlags.Export) { - error(name, Diagnostics.Overload_signatures_must_all_be_exported_or_non_exported); + error(getNameOfDeclaration(o), Diagnostics.Overload_signatures_must_all_be_exported_or_non_exported); } else if (deviation & ModifierFlags.Ambient) { - error(name, Diagnostics.Overload_signatures_must_all_be_ambient_or_non_ambient); + error(getNameOfDeclaration(o), Diagnostics.Overload_signatures_must_all_be_ambient_or_non_ambient); } else if (deviation & (ModifierFlags.Private | ModifierFlags.Protected)) { - error(name || o, Diagnostics.Overload_signatures_must_all_be_public_private_or_protected); + error(getNameOfDeclaration(o) || o, Diagnostics.Overload_signatures_must_all_be_public_private_or_protected); } else if (deviation & ModifierFlags.Abstract) { - error(name, Diagnostics.Overload_signatures_must_all_be_abstract_or_non_abstract); + error(getNameOfDeclaration(o), Diagnostics.Overload_signatures_must_all_be_abstract_or_non_abstract); } }); } @@ -20317,19 +20316,12 @@ namespace ts { return; } - let errorNode: Node; - if (propDeclaration && propDeclaration.kind === SyntaxKind.BinaryExpression) { - const specialAssignmentKind = getSpecialPropertyAssignmentKind(propDeclaration as BinaryExpression); - if (specialAssignmentKind === SpecialPropertyAssignmentKind.Property || - specialAssignmentKind === SpecialPropertyAssignmentKind.PrototypeProperty || - specialAssignmentKind === SpecialPropertyAssignmentKind.ThisProperty) { - errorNode = propDeclaration; - } - } // perform property check if property or indexer is declared in 'type' - // this allows to rule out cases when both property and indexer are inherited from the base class + // this allows us to rule out cases when both property and indexer are inherited from the base class + let errorNode: Node; if (propDeclaration && - (getNameOfDeclaration(propDeclaration).kind === SyntaxKind.ComputedPropertyName || + (propDeclaration.kind === SyntaxKind.BinaryExpression || + getNameOfDeclaration(propDeclaration).kind === SyntaxKind.ComputedPropertyName || prop.parent === containingType.symbol)) { errorNode = propDeclaration; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index e38f0ad331a3a..7b92dbf68b5c3 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1784,21 +1784,21 @@ namespace ts { const kind = getSpecialPropertyAssignmentKind(declaration); const lhs = (declaration as BinaryExpression).left; switch (kind) { - case SpecialPropertyAssignmentKind.None: - case SpecialPropertyAssignmentKind.ModuleExports: - return undefined; - case SpecialPropertyAssignmentKind.ExportsProperty: - if (lhs.kind === SyntaxKind.Identifier) { + case SpecialPropertyAssignmentKind.None: + case SpecialPropertyAssignmentKind.ModuleExports: + return undefined; + case SpecialPropertyAssignmentKind.ExportsProperty: + if (lhs.kind === SyntaxKind.Identifier) { + return (lhs as PropertyAccessExpression).name; + } + else { + return ((lhs as PropertyAccessExpression).expression as PropertyAccessExpression).name; + } + case SpecialPropertyAssignmentKind.ThisProperty: + case SpecialPropertyAssignmentKind.Property: return (lhs as PropertyAccessExpression).name; - } - else { + case SpecialPropertyAssignmentKind.PrototypeProperty: return ((lhs as PropertyAccessExpression).expression as PropertyAccessExpression).name; - } - case SpecialPropertyAssignmentKind.ThisProperty: - case SpecialPropertyAssignmentKind.Property: - return (lhs as PropertyAccessExpression).name; - case SpecialPropertyAssignmentKind.PrototypeProperty: - return ((lhs as PropertyAccessExpression).expression as PropertyAccessExpression).name; } } else { @@ -2025,7 +2025,8 @@ namespace ts { * Symbol. */ export function hasDynamicName(declaration: Declaration): boolean { - return getNameOfDeclaration(declaration) && isDynamicName(getNameOfDeclaration(declaration)); + const name = getNameOfDeclaration(declaration); + return name && isDynamicName(name); } export function isDynamicName(name: DeclarationName): boolean {