From 99c18744d231fdce63f92951197388a8eb17ee0e Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 3 May 2017 10:57:57 -0700 Subject: [PATCH] Add isCallOrNewExpression helper --- src/compiler/checker.ts | 3 ++- src/compiler/utilities.ts | 4 ++++ src/services/formatting/smartIndenter.ts | 5 +---- src/services/signatureHelp.ts | 2 +- src/services/symbolDisplay.ts | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b6ff059380e..61503415d81 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14310,7 +14310,8 @@ namespace ts { } function callLikeExpressionMayHaveTypeArguments(node: CallLikeExpression): node is CallExpression | NewExpression { - return node.kind === SyntaxKind.CallExpression || node.kind === SyntaxKind.NewExpression; + // TODO: Also include tagged templates (https://github.com/Microsoft/TypeScript/issues/11947) + return isCallOrNewExpression(node); } function resolveUntypedCall(node: CallLikeExpression): Signature { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 5314bdacb43..b9b1dbb2a13 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1142,6 +1142,10 @@ namespace ts { } } + export function isCallOrNewExpression(node: Node): node is CallExpression | NewExpression { + return node.kind === SyntaxKind.CallExpression || node.kind === SyntaxKind.NewExpression; + } + export function getInvokedExpression(node: CallLikeExpression): Expression { if (node.kind === SyntaxKind.TaggedTemplateExpression) { return (node).tag; diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 01feaf39081..18b0479c85a 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -341,10 +341,7 @@ namespace ts.formatting { return Value.Unknown; } - if (node.parent && ( - node.parent.kind === SyntaxKind.CallExpression || - node.parent.kind === SyntaxKind.NewExpression) && - (node.parent).expression !== node) { + if (node.parent && isCallOrNewExpression(node.parent) && (node.parent).expression !== node) { const fullCallOrNewExpression = (node.parent).expression; const startingExpression = getStartingExpression(fullCallOrNewExpression); diff --git a/src/services/signatureHelp.ts b/src/services/signatureHelp.ts index 1487bb410a5..7c4f8fb016d 100644 --- a/src/services/signatureHelp.ts +++ b/src/services/signatureHelp.ts @@ -262,7 +262,7 @@ namespace ts.SignatureHelp { * in the argument of an invocation; returns undefined otherwise. */ export function getImmediatelyContainingArgumentInfo(node: Node, position: number, sourceFile: SourceFile): ArgumentListInfo { - if (node.parent.kind === SyntaxKind.CallExpression || node.parent.kind === SyntaxKind.NewExpression) { + if (isCallOrNewExpression(node.parent)) { const callExpression = node.parent; // There are 3 cases to handle: // 1. The token introduces a list, and should begin a signature help session diff --git a/src/services/symbolDisplay.ts b/src/services/symbolDisplay.ts index 41bdf4d8ada..5bf3e37f28a 100644 --- a/src/services/symbolDisplay.ts +++ b/src/services/symbolDisplay.ts @@ -120,7 +120,7 @@ namespace ts.SymbolDisplay { // try get the call/construct signature from the type if it matches let callExpressionLike: CallExpression | NewExpression | JsxOpeningLikeElement; - if (location.kind === SyntaxKind.CallExpression || location.kind === SyntaxKind.NewExpression) { + if (isCallOrNewExpression(location)) { callExpressionLike = location; } else if (isCallExpressionTarget(location) || isNewExpressionTarget(location)) {