Skip to content

Commit

Permalink
Address comments: simplify, dedupe and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
sandersn committed May 5, 2017
1 parent b39c319 commit 6a17532
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 30 deletions.
24 changes: 8 additions & 16 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
Expand Down Expand Up @@ -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;
}
Expand Down
29 changes: 15 additions & 14 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6a17532

Please sign in to comment.