Skip to content

Commit 6a17532

Browse files
committed
Address comments: simplify, dedupe and clean up
1 parent b39c319 commit 6a17532

File tree

2 files changed

+23
-30
lines changed

2 files changed

+23
-30
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18110,18 +18110,17 @@ namespace ts {
1811018110

1811118111
forEach(overloads, o => {
1811218112
const deviation = getEffectiveDeclarationFlags(o, flagsToCheck) ^ canonicalFlags;
18113-
const name = getNameOfDeclaration(o);
1811418113
if (deviation & ModifierFlags.Export) {
18115-
error(name, Diagnostics.Overload_signatures_must_all_be_exported_or_non_exported);
18114+
error(getNameOfDeclaration(o), Diagnostics.Overload_signatures_must_all_be_exported_or_non_exported);
1811618115
}
1811718116
else if (deviation & ModifierFlags.Ambient) {
18118-
error(name, Diagnostics.Overload_signatures_must_all_be_ambient_or_non_ambient);
18117+
error(getNameOfDeclaration(o), Diagnostics.Overload_signatures_must_all_be_ambient_or_non_ambient);
1811918118
}
1812018119
else if (deviation & (ModifierFlags.Private | ModifierFlags.Protected)) {
18121-
error(name || o, Diagnostics.Overload_signatures_must_all_be_public_private_or_protected);
18120+
error(getNameOfDeclaration(o) || o, Diagnostics.Overload_signatures_must_all_be_public_private_or_protected);
1812218121
}
1812318122
else if (deviation & ModifierFlags.Abstract) {
18124-
error(name, Diagnostics.Overload_signatures_must_all_be_abstract_or_non_abstract);
18123+
error(getNameOfDeclaration(o), Diagnostics.Overload_signatures_must_all_be_abstract_or_non_abstract);
1812518124
}
1812618125
});
1812718126
}
@@ -20317,19 +20316,12 @@ namespace ts {
2031720316
return;
2031820317
}
2031920318

20320-
let errorNode: Node;
20321-
if (propDeclaration && propDeclaration.kind === SyntaxKind.BinaryExpression) {
20322-
const specialAssignmentKind = getSpecialPropertyAssignmentKind(propDeclaration as BinaryExpression);
20323-
if (specialAssignmentKind === SpecialPropertyAssignmentKind.Property ||
20324-
specialAssignmentKind === SpecialPropertyAssignmentKind.PrototypeProperty ||
20325-
specialAssignmentKind === SpecialPropertyAssignmentKind.ThisProperty) {
20326-
errorNode = propDeclaration;
20327-
}
20328-
}
2032920319
// perform property check if property or indexer is declared in 'type'
20330-
// this allows to rule out cases when both property and indexer are inherited from the base class
20320+
// this allows us to rule out cases when both property and indexer are inherited from the base class
20321+
let errorNode: Node;
2033120322
if (propDeclaration &&
20332-
(getNameOfDeclaration(propDeclaration).kind === SyntaxKind.ComputedPropertyName ||
20323+
(propDeclaration.kind === SyntaxKind.BinaryExpression ||
20324+
getNameOfDeclaration(propDeclaration).kind === SyntaxKind.ComputedPropertyName ||
2033320325
prop.parent === containingType.symbol)) {
2033420326
errorNode = propDeclaration;
2033520327
}

src/compiler/utilities.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,21 +1784,21 @@ namespace ts {
17841784
const kind = getSpecialPropertyAssignmentKind(declaration);
17851785
const lhs = (declaration as BinaryExpression).left;
17861786
switch (kind) {
1787-
case SpecialPropertyAssignmentKind.None:
1788-
case SpecialPropertyAssignmentKind.ModuleExports:
1789-
return undefined;
1790-
case SpecialPropertyAssignmentKind.ExportsProperty:
1791-
if (lhs.kind === SyntaxKind.Identifier) {
1787+
case SpecialPropertyAssignmentKind.None:
1788+
case SpecialPropertyAssignmentKind.ModuleExports:
1789+
return undefined;
1790+
case SpecialPropertyAssignmentKind.ExportsProperty:
1791+
if (lhs.kind === SyntaxKind.Identifier) {
1792+
return (lhs as PropertyAccessExpression).name;
1793+
}
1794+
else {
1795+
return ((lhs as PropertyAccessExpression).expression as PropertyAccessExpression).name;
1796+
}
1797+
case SpecialPropertyAssignmentKind.ThisProperty:
1798+
case SpecialPropertyAssignmentKind.Property:
17921799
return (lhs as PropertyAccessExpression).name;
1793-
}
1794-
else {
1800+
case SpecialPropertyAssignmentKind.PrototypeProperty:
17951801
return ((lhs as PropertyAccessExpression).expression as PropertyAccessExpression).name;
1796-
}
1797-
case SpecialPropertyAssignmentKind.ThisProperty:
1798-
case SpecialPropertyAssignmentKind.Property:
1799-
return (lhs as PropertyAccessExpression).name;
1800-
case SpecialPropertyAssignmentKind.PrototypeProperty:
1801-
return ((lhs as PropertyAccessExpression).expression as PropertyAccessExpression).name;
18021802
}
18031803
}
18041804
else {
@@ -2025,7 +2025,8 @@ namespace ts {
20252025
* Symbol.
20262026
*/
20272027
export function hasDynamicName(declaration: Declaration): boolean {
2028-
return getNameOfDeclaration(declaration) && isDynamicName(getNameOfDeclaration(declaration));
2028+
const name = getNameOfDeclaration(declaration);
2029+
return name && isDynamicName(name);
20292030
}
20302031

20312032
export function isDynamicName(name: DeclarationName): boolean {

0 commit comments

Comments
 (0)