From 97f4e9a0268ca1bc5c4a1a18618878fd0dc668ef Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Wed, 17 Dec 2014 11:53:20 +0100 Subject: [PATCH] [loose parser] Make unclosed objects / lists span to the start of the next node That way, whitespace at their end is considered part of them, and Tern can recognize when the cursor is inside of them. --- acorn_loose.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/acorn_loose.js b/acorn_loose.js index 39157f310e..97a3df603a 100644 --- a/acorn_loose.js +++ b/acorn_loose.js @@ -905,7 +905,12 @@ } } popCx(); - eat(tt.braceR); + if (!eat(tt.braceR)) { + // If there is no closing brace, make the node span to the start + // of the next token (this is useful for Tern) + lastEnd = token.start; + if (options.locations) lastEndLoc = token.startLoc; + } if (isClass) { semicolon(); finishNode(node.body, "ClassBody"); @@ -1152,7 +1157,12 @@ eat(tt.comma); } popCx(); - eat(close); + if (!eat(close)) { + // If there is no closing brace, make the node span to the start + // of the next token (this is useful for Tern) + lastEnd = token.start; + if (options.locations) lastEndLoc = token.startLoc; + } return elts; } });