From 096b2b0712b4b2ffd62e515c88913f3e1e6966b1 Mon Sep 17 00:00:00 2001 From: Andy Date: Mon, 19 Mar 2018 13:35:01 -0700 Subject: [PATCH] Use isFunctionLike instead of switch (#22698) --- src/compiler/checker.ts | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fe5a746a74d..1de0b837d09 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6836,32 +6836,17 @@ namespace ts { const result: Signature[] = []; for (let i = 0; i < symbol.declarations.length; i++) { const node = symbol.declarations[i]; - switch (node.kind) { - case SyntaxKind.FunctionType: - case SyntaxKind.ConstructorType: - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - case SyntaxKind.Constructor: - case SyntaxKind.CallSignature: - case SyntaxKind.ConstructSignature: - case SyntaxKind.IndexSignature: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - case SyntaxKind.FunctionExpression: - case SyntaxKind.ArrowFunction: - case SyntaxKind.JSDocFunctionType: - // Don't include signature if node is the implementation of an overloaded function. A node is considered - // an implementation node if it has a body and the previous node is of the same kind and immediately - // precedes the implementation node (i.e. has the same parent and ends where the implementation starts). - if (i > 0 && (node).body) { - const previous = symbol.declarations[i - 1]; - if (node.parent === previous.parent && node.kind === previous.kind && node.pos === previous.end) { - break; - } - } - result.push(getSignatureFromDeclaration(node)); + if (!isFunctionLike(node)) continue; + // Don't include signature if node is the implementation of an overloaded function. A node is considered + // an implementation node if it has a body and the previous node is of the same kind and immediately + // precedes the implementation node (i.e. has the same parent and ends where the implementation starts). + if (i > 0 && (node as FunctionLikeDeclaration).body) { + const previous = symbol.declarations[i - 1]; + if (node.parent === previous.parent && node.kind === previous.kind && node.pos === previous.end) { + continue; + } } + result.push(getSignatureFromDeclaration(node)); } return result; }