Utilize getContainingFunction in services.

This commit is contained in:
Daniel Rosenwasser
2014-08-29 17:13:14 -07:00
parent 7e5802192e
commit ba396ed28f
2 changed files with 18 additions and 17 deletions

View File

@@ -1313,6 +1313,10 @@ module ts {
}
function isAnyFunction(node: Node): boolean {
if (!node) {
return false;
}
switch (node.kind) {
case SyntaxKind.FunctionExpression:
case SyntaxKind.FunctionDeclaration:
@@ -2267,18 +2271,15 @@ module ts {
}
function getReturnOccurrences(returnStatement: ReturnStatement): ReferenceEntry[]{
var node: Node = returnStatement;
while (!isAnyFunction(node) && node.parent) {
node = node.parent;
}
var func = <FunctionDeclaration>getContainingFunction(returnStatement);
// If we didn't find a containing function with a block body, bail out.
if (!(isAnyFunction(node) && hasKind((<FunctionDeclaration>node).body, SyntaxKind.FunctionBlock))) {
if (!(isAnyFunction(func) && hasKind(func.body, SyntaxKind.FunctionBlock))) {
return undefined;
}
var keywords: Node[] = []
forEachReturnStatement(<Block>(<FunctionDeclaration>node).body, returnStmt => {
forEachReturnStatement(<Block>(<FunctionDeclaration>func).body, returnStmt => {
pushKeywordIf(keywords, returnStmt.getFirstToken(), SyntaxKind.ReturnKeyword);
});