From 400cf91e9698a677e2e05492a4b2366732408ffe Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Dec 2014 18:23:14 -0800 Subject: [PATCH] Nodes are not resuable if the parser has a outstanding, unattached, parse error. This is conservative, but safe. If we wanted to support node reuse here, we'd have to carefully ensure that the errors and tree shape would be the same that hte normal parse would produce. --- src/compiler/parser.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index ba05c01d199..7d098d315e3 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1436,6 +1436,17 @@ module ts { } function currentNode(parsingContext: ParsingContext): Node { + // If there is an outstanding parse error that we've encountered, but not attached to + // some node, then we cannot get a node from the old source tree. This is because we + // want to mark the next node we encounter as being unusable. + // + // Note: This may be too conservative. Perhaps we could reuse hte node and set the bit + // on it (or its leftmost child) as having the error. For now though, being conservative + // is nice and likely won't ever affect perf. + if (parseErrorBeforeNextFinishedNode) { + return undefined; + } + var node: Node = currentNodeFromCursor(); if (!node) { return undefined;