From e271168cf604611a176f2c9452dcabde4bceab36 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Sun, 4 Jan 2015 22:13:18 +0100 Subject: [PATCH] Make onToken only fire for actual final tokens Issue #189 --- acorn.js | 11 ++++------- test/tests.js | 1 + 2 files changed, 5 insertions(+), 7 deletions(-) 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,