diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c4c9af07873..8312420b355 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1619,6 +1619,9 @@ module ts { function getDeclarationContainer(node: Node): Node { node = getRootDeclaration(node); + + // Parent chain: + // VaribleDeclaration -> VariableDeclarationList -> VariableStatement -> 'Declaration Container' return node.kind === SyntaxKind.VariableDeclaration ? node.parent.parent.parent : node.parent; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 2db5d9e3b7d..f8312a03d10 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -110,6 +110,18 @@ module ts { return node.pos; } + // Returns true if this node is missing from the actual source code. 'missing' is different + // from 'undefined/defined'. When a node is undefined (which can happen for optional nodes + // in the tree), it is definitel missing. HOwever, a node may be defined, but still be + // missing. This happens whenever the parser knows it needs to parse something, but can't + // get anything in the source code that it expects at that location. For example: + // + // var a: ; + // + // Here, the Type in the Type-Annotation is not-optional (as there is a colon in the source + // code). So the parser will attempt to parse out a type, and will create an actual node. + // However, this node will be 'missing' in the sense that no actual source-code/tokens are + // contained within it. export function nodeIsMissing(node: Node) { if (!node) { return true; @@ -117,7 +129,7 @@ module ts { return node.pos === node.end && node.kind !== SyntaxKind.EndOfFileToken; } - + export function nodeIsPresent(node: Node) { return !nodeIsMissing(node); } @@ -780,7 +792,7 @@ module ts { throw new Error("start < 0"); } if (length < 0) { - throw new Error("start < 0"); + throw new Error("length < 0"); } this._start = start; this._length = length;