Skip to content

Commit 99c1874

Browse files
author
Andy Hanson
committed
Add isCallOrNewExpression helper
1 parent ac74295 commit 99c1874

File tree

5 files changed

+9
-7
lines changed

5 files changed

+9
-7
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14310,7 +14310,8 @@ namespace ts {
1431014310
}
1431114311

1431214312
function callLikeExpressionMayHaveTypeArguments(node: CallLikeExpression): node is CallExpression | NewExpression {
14313-
return node.kind === SyntaxKind.CallExpression || node.kind === SyntaxKind.NewExpression;
14313+
// TODO: Also include tagged templates (https://github.com/Microsoft/TypeScript/issues/11947)
14314+
return isCallOrNewExpression(node);
1431414315
}
1431514316

1431614317
function resolveUntypedCall(node: CallLikeExpression): Signature {

src/compiler/utilities.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,10 @@ namespace ts {
11421142
}
11431143
}
11441144

1145+
export function isCallOrNewExpression(node: Node): node is CallExpression | NewExpression {
1146+
return node.kind === SyntaxKind.CallExpression || node.kind === SyntaxKind.NewExpression;
1147+
}
1148+
11451149
export function getInvokedExpression(node: CallLikeExpression): Expression {
11461150
if (node.kind === SyntaxKind.TaggedTemplateExpression) {
11471151
return (<TaggedTemplateExpression>node).tag;

src/services/formatting/smartIndenter.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,7 @@ namespace ts.formatting {
341341
return Value.Unknown;
342342
}
343343

344-
if (node.parent && (
345-
node.parent.kind === SyntaxKind.CallExpression ||
346-
node.parent.kind === SyntaxKind.NewExpression) &&
347-
(<CallExpression>node.parent).expression !== node) {
344+
if (node.parent && isCallOrNewExpression(node.parent) && (<CallExpression>node.parent).expression !== node) {
348345

349346
const fullCallOrNewExpression = (<CallExpression | NewExpression>node.parent).expression;
350347
const startingExpression = getStartingExpression(fullCallOrNewExpression);

src/services/signatureHelp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ namespace ts.SignatureHelp {
262262
* in the argument of an invocation; returns undefined otherwise.
263263
*/
264264
export function getImmediatelyContainingArgumentInfo(node: Node, position: number, sourceFile: SourceFile): ArgumentListInfo {
265-
if (node.parent.kind === SyntaxKind.CallExpression || node.parent.kind === SyntaxKind.NewExpression) {
265+
if (isCallOrNewExpression(node.parent)) {
266266
const callExpression = <CallExpression>node.parent;
267267
// There are 3 cases to handle:
268268
// 1. The token introduces a list, and should begin a signature help session

src/services/symbolDisplay.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ namespace ts.SymbolDisplay {
120120

121121
// try get the call/construct signature from the type if it matches
122122
let callExpressionLike: CallExpression | NewExpression | JsxOpeningLikeElement;
123-
if (location.kind === SyntaxKind.CallExpression || location.kind === SyntaxKind.NewExpression) {
123+
if (isCallOrNewExpression(location)) {
124124
callExpressionLike = <CallExpression | NewExpression>location;
125125
}
126126
else if (isCallExpressionTarget(location) || isNewExpressionTarget(location)) {

0 commit comments

Comments
 (0)