diff --git a/acorn.js b/acorn.js index aa9b60664e..1fec39199f 100644 --- a/acorn.js +++ b/acorn.js @@ -634,9 +634,6 @@ if (shouldSkipSpace !== false) skipSpace(); tokVal = val; tokRegexpAllowed = type.beforeExpr; - if (options.onToken) { - options.onToken(new Token()); - } } function skipBlockComment() { @@ -1232,6 +1229,9 @@ // Continue to the next token. function next() { + if (options.onToken) + options.onToken(new Token()); + lastStart = tokStart; lastEnd = tokEnd; lastEndLoc = tokEndLoc; @@ -1542,9 +1542,7 @@ first = false; } - lastStart = tokStart; - lastEnd = tokEnd; - lastEndLoc = tokEndLoc; + next(); return finishNode(node, "Program"); } @@ -2664,5 +2662,4 @@ node.generator = isGenerator; return finishNode(node, "ComprehensionExpression"); } - }); diff --git a/test/tests.js b/test/tests.js index f6df2edc5e..f1d7ce340a 100644 --- a/test/tests.js +++ b/test/tests.js @@ -28757,6 +28757,7 @@ var tokTypes = acorn.tokTypes; test('var x = (1 + 2)', {}, { locations: true, + loose: false, onToken: [ { type: tokTypes._var,