From 2eb1a213c724bcf429134d09795f8d2bfcf724e6 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 9 Feb 2015 14:55:54 -0800 Subject: [PATCH] Prevent index out of bounds exception. --- src/compiler/parser.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index cd0d86bed4..a1dc0ef7b1 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -850,7 +850,7 @@ module ts { // Much of the time the parser will need the very next node in the array that // we just returned a node from.So just simply check for that case and move // forward in the array instead of searching for the node again. - if (current && current.end === position && currentArrayIndex < currentArray.length) { + if (current && current.end === position && currentArrayIndex < (currentArray.length - 1)) { currentArrayIndex++; current = currentArray[currentArrayIndex]; } @@ -886,6 +886,7 @@ module ts { // Recurse into the source file to find the highest node at this position. forEachChild(sourceFile, visitNode, visitArray); + return; function visitNode(node: Node) { if (position >= node.pos && position < node.end) {