From 7b5440bb8dda9135bb24c844448f3463f8ea7502 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 4 Sep 2014 12:17:35 -0700 Subject: [PATCH] Addressed more CR feedback. --- src/compiler/checker.ts | 11 ----------- src/compiler/parser.ts | 26 ++++++++++++++++++++++++++ src/services/services.ts | 20 +------------------- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d9b2b556b21..e7c0b5bc32a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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 node; - } - } - } } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 7e03366bc1a..eea647999ac 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -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 node; + } + } + } + export function hasRestParameters(s: SignatureDeclaration): boolean { return s.parameters.length > 0 && (s.parameters[s.parameters.length - 1].flags & NodeFlags.Rest) !== 0; } diff --git a/src/services/services.ts b/src/services/services.ts index 5860dee8e8d..2ed73a52cb7 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1312,24 +1312,6 @@ module ts { return node.parent.kind === SyntaxKind.NewExpression && (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) && (node.parent).name === node; @@ -2274,7 +2256,7 @@ module ts { var func = 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; }