diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 5731d636103..2e17d8bf3a1 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -528,7 +528,7 @@ module ts { // var x; // } // 'var x' will be placed into the function locals and 'let x' - into the locals of the block - bindChildren(node, 0, /*isBlockScopeContainer*/ !isAnyFunction(node.parent)); + bindChildren(node, 0, /*isBlockScopeContainer*/ !isFunctionLike(node.parent)); break; case SyntaxKind.CatchClause: case SyntaxKind.ForStatement: diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index eae595cfaf5..8908501593c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5045,7 +5045,7 @@ module ts { function isInsideFunction(node: Node, threshold: Node): boolean { var current = node; while (current && current !== threshold) { - if (isAnyFunction(current)) { + if (isFunctionLike(current)) { return true; } current = current.parent; @@ -8550,7 +8550,7 @@ module ts { // if block scoped variable is defined in the function\module\source file scope (because of variable hoisting) var namesShareScope = container && - (container.kind === SyntaxKind.Block && isAnyFunction(container.parent) || + (container.kind === SyntaxKind.Block && isFunctionLike(container.parent) || (container.kind === SyntaxKind.ModuleBlock && container.kind === SyntaxKind.ModuleDeclaration) || container.kind === SyntaxKind.SourceFile); @@ -9065,7 +9065,7 @@ module ts { if (!checkGrammarStatementInAmbientContext(node)) { var current = node.parent; while (current) { - if (isAnyFunction(current)) { + if (isFunctionLike(current)) { break; } if (current.kind === SyntaxKind.LabeledStatement && (current).label.text === node.label.text) { @@ -11623,7 +11623,7 @@ module ts { function checkGrammarBreakOrContinueStatement(node: BreakOrContinueStatement): boolean { var current: Node = node; while (current) { - if (isAnyFunction(current)) { + if (isFunctionLike(current)) { return grammarErrorOnNode(node, Diagnostics.Jump_target_cannot_cross_function_boundary); } @@ -11954,7 +11954,7 @@ module ts { // Find containing block which is either Block, ModuleBlock, SourceFile var links = getNodeLinks(node); - if (!links.hasReportedStatementInAmbientContext && isAnyFunction(node.parent)) { + if (!links.hasReportedStatementInAmbientContext && isFunctionLike(node.parent)) { return getNodeLinks(node).hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts) } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index ec9ab083fbc..d3b248b41ff 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3888,7 +3888,7 @@ module ts { function getEnclosingBlockScopeContainer(node: Node): Node { var current = node; while (current) { - if (isAnyFunction(current)) { + if (isFunctionLike(current)) { return current; } switch (current.kind) { @@ -3903,7 +3903,7 @@ module ts { case SyntaxKind.Block: // function block is not considered block-scope container // see comment in binder.ts: bind(...), case for SyntaxKind.Block - if (!isAnyFunction(current.parent)) { + if (!isFunctionLike(current.parent)) { return current; } } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index efbe9e9825c..63c2edad6c2 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -395,7 +395,25 @@ module ts { } } - export function isAnyFunction(node: Node): boolean { + /* @internal */ + export function isVariableLike(node: Node): boolean { + if (node) { + switch (node.kind) { + case SyntaxKind.VariableDeclaration: + case SyntaxKind.Parameter: + case SyntaxKind.BindingElement: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertyAssignment: + case SyntaxKind.ShorthandPropertyAssignment: + case SyntaxKind.EnumMember: + return true; + } + } + + return false; + } + + export function isFunctionLike(node: Node): boolean { if (node) { switch (node.kind) { case SyntaxKind.Constructor: @@ -422,7 +440,7 @@ module ts { } export function isFunctionBlock(node: Node) { - return node && node.kind === SyntaxKind.Block && isAnyFunction(node.parent); + return node && node.kind === SyntaxKind.Block && isFunctionLike(node.parent); } export function isObjectLiteralMethod(node: Node) { @@ -432,7 +450,7 @@ module ts { export function getContainingFunction(node: Node): FunctionLikeDeclaration { while (true) { node = node.parent; - if (!node || isAnyFunction(node)) { + if (!node || isFunctionLike(node)) { return node; } } @@ -1151,7 +1169,7 @@ module ts { } export function nodeStartsNewLexicalEnvironment(n: Node): boolean { - return isAnyFunction(n) || n.kind === SyntaxKind.ModuleDeclaration || n.kind === SyntaxKind.SourceFile; + return isFunctionLike(n) || n.kind === SyntaxKind.ModuleDeclaration || n.kind === SyntaxKind.SourceFile; } export function nodeIsSynthesized(node: Node): boolean { diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index bd4cc841854..d59718322c9 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -259,7 +259,7 @@ module ts.BreakpointResolver { } // return type of function go to previous token - if (isAnyFunction(node.parent) && (node.parent).type === node) { + if (isFunctionLike(node.parent) && (node.parent).type === node) { return spanInPreviousNode(node); } @@ -499,7 +499,7 @@ module ts.BreakpointResolver { function spanInColonToken(node: Node): TextSpan { // Is this : specifying return annotation of the function declaration - if (isAnyFunction(node.parent) || node.parent.kind === SyntaxKind.PropertyAssignment) { + if (isFunctionLike(node.parent) || node.parent.kind === SyntaxKind.PropertyAssignment) { return spanInPreviousNode(node); } diff --git a/src/services/services.ts b/src/services/services.ts index cd8fc13a2b7..3b06b887a05 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2014,7 +2014,7 @@ module ts { function isNameOfFunctionDeclaration(node: Node): boolean { return node.kind === SyntaxKind.Identifier && - isAnyFunction(node.parent) && (node.parent).name === node; + isFunctionLike(node.parent) && (node.parent).name === node; } /** Returns true if node is a name of an object literal property, e.g. "a" in x = { "a": 1 } */ @@ -3799,7 +3799,7 @@ module ts { } } // Do not cross function boundaries. - else if (!isAnyFunction(node)) { + else if (!isFunctionLike(node)) { forEachChild(node, aggregate); } }; @@ -3931,7 +3931,7 @@ module ts { statementAccumulator.push(node); } // Do not cross function boundaries. - else if (!isAnyFunction(node)) { + else if (!isFunctionLike(node)) { forEachChild(node, aggregate); } }; @@ -3962,7 +3962,7 @@ module ts { break; default: // Don't cross function boundaries. - if (isAnyFunction(node)) { + if (isFunctionLike(node)) { return undefined; } break; diff --git a/src/services/utilities.ts b/src/services/utilities.ts index ee92ed8af0d..e0ff5293546 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -283,7 +283,7 @@ module ts { return (node).typeArguments; } - if (isAnyFunction(node) || node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.InterfaceDeclaration) { + if (isFunctionLike(node) || node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.InterfaceDeclaration) { return (node).typeParameters; }