Addressed more CR feedback.

This commit is contained in:
Daniel Rosenwasser 2014-09-04 12:17:35 -07:00
parent 837dddaec3
commit 7b5440bb8d
3 changed files with 27 additions and 30 deletions

View File

@ -7113,15 +7113,4 @@ module ts {
return checker;
}
export function getContainingFunction(node: Node): SignatureDeclaration {
while (true) {
node = node.parent;
if (!node || node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.FunctionExpression ||
node.kind === SyntaxKind.ArrowFunction || node.kind === SyntaxKind.Method || node.kind === SyntaxKind.Constructor ||
node.kind === SyntaxKind.GetAccessor || node.kind === SyntaxKind.SetAccessor) {
return <SignatureDeclaration>node;
}
}
}
}

View File

@ -380,6 +380,32 @@ module ts {
}
}
export function isAnyFunction(node: Node): boolean {
if (node) {
switch (node.kind) {
case SyntaxKind.FunctionExpression:
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.ArrowFunction:
case SyntaxKind.Method:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
case SyntaxKind.Constructor:
return true;
}
}
return false;
}
export function getContainingFunction(node: Node): SignatureDeclaration {
while (true) {
node = node.parent;
if (!node || isAnyFunction(node)) {
return <SignatureDeclaration>node;
}
}
}
export function hasRestParameters(s: SignatureDeclaration): boolean {
return s.parameters.length > 0 && (s.parameters[s.parameters.length - 1].flags & NodeFlags.Rest) !== 0;
}

View File

@ -1312,24 +1312,6 @@ module ts {
return node.parent.kind === SyntaxKind.NewExpression && (<CallExpression>node.parent).func === node;
}
function isAnyFunction(node: Node): boolean {
if (!node) {
return false;
}
switch (node.kind) {
case SyntaxKind.FunctionExpression:
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.ArrowFunction:
case SyntaxKind.Method:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
case SyntaxKind.Constructor:
return true;
}
return false;
}
function isNameOfFunctionDeclaration(node: Node): boolean {
return node.kind === SyntaxKind.Identifier &&
isAnyFunction(node.parent) && (<FunctionDeclaration>node.parent).name === node;
@ -2274,7 +2256,7 @@ module ts {
var func = <FunctionDeclaration>getContainingFunction(returnStatement);
// If we didn't find a containing function with a block body, bail out.
if (!(isAnyFunction(func) && hasKind(func.body, SyntaxKind.FunctionBlock))) {
if (!(func && hasKind(func.body, SyntaxKind.FunctionBlock))) {
return undefined;
}