From 38179fd85506ebfd22ebaacab02025c1def1c754 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Thu, 28 Feb 2013 19:28:20 +0100 Subject: [PATCH] Fix node boundaries for unexpected regular expressions Closes #33 --- acorn.js | 3 ++- test/tests.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/acorn.js b/acorn.js index d61d19cc2c..b2a513d52a 100644 --- a/acorn.js +++ b/acorn.js @@ -679,7 +679,8 @@ } function readToken(forceRegexp) { - tokStart = tokPos; + if (!forceRegexp) tokStart = tokPos; + else tokPos = tokStart + 1; if (options.locations) tokStartLoc = new line_loc_t; if (forceRegexp) return readRegexp(); if (tokPos >= inputLen) return finishToken(_eof); diff --git a/test/tests.js b/test/tests.js index f01f5d3c53..b4c0005687 100644 --- a/test/tests.js +++ b/test/tests.js @@ -26097,6 +26097,38 @@ test("foo: 10; foo: 20;", { ] }); +test("if(1)/ foo/", { + type: "Program", + start: 0, + end: 12, + body: [ + { + type: "IfStatement", + start: 0, + end: 12, + test: { + type: "Literal", + start: 3, + end: 4, + value: 1, + raw: "1" + }, + consequent: { + type: "ExpressionStatement", + start: 5, + end: 12, + expression: { + type: "Literal", + start: 5, + end: 12, + raw: "/ foo/" + } + }, + alternate: null + } + ] +}); + // option tests test("var a = 1;", {