Add isCallOrNewExpression helper

This commit is contained in:
Andy Hanson
2017-05-03 10:57:57 -07:00
parent ac7429535e
commit 99c18744d2
5 changed files with 9 additions and 7 deletions

View File

@@ -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 {

View File

@@ -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 (<TaggedTemplateExpression>node).tag;

View File

@@ -341,10 +341,7 @@ namespace ts.formatting {
return Value.Unknown;
}
if (node.parent && (
node.parent.kind === SyntaxKind.CallExpression ||
node.parent.kind === SyntaxKind.NewExpression) &&
(<CallExpression>node.parent).expression !== node) {
if (node.parent && isCallOrNewExpression(node.parent) && (<CallExpression>node.parent).expression !== node) {
const fullCallOrNewExpression = (<CallExpression | NewExpression>node.parent).expression;
const startingExpression = getStartingExpression(fullCallOrNewExpression);

View File

@@ -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 = <CallExpression>node.parent;
// There are 3 cases to handle:
// 1. The token introduces a list, and should begin a signature help session

View File

@@ -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 = <CallExpression | NewExpression>location;
}
else if (isCallExpressionTarget(location) || isNewExpressionTarget(location)) {