diff --git a/acorn.js b/acorn.js index 6323b1fc6a..81abc2da38 100644 --- a/acorn.js +++ b/acorn.js @@ -444,7 +444,8 @@ ++tokPos; ch = input.charCodeAt(tokPos); } - (tokComments || (tokComments = [])).push(input.slice(start, tokPos)); + if (options.trackComments) + (tokComments || (tokComments = [])).push(input.slice(start, tokPos)); } // Called at the start of the parse and after every token. Skips @@ -878,7 +879,8 @@ if (tokCommentsAfter) { node.commentsAfter = tokCommentsAfter; tokCommentsAfter = null; - } else if (lastFinishedNode && lastFinishedNode.end === lastEnd) { + } else if (lastFinishedNode && lastFinishedNode.end === lastEnd && + lastFinishedNode.commentsAfter) { node.commentsAfter = lastFinishedNode.commentsAfter; lastFinishedNode.commentsAfter = null; } diff --git a/index.html b/index.html index 216adce76a..033605112c 100644 --- a/index.html +++ b/index.html @@ -263,7 +263,8 @@ the right position.
Called at the start of the parse and after every token. Skips
whitespace and comments, and, if options.trackComments is on,
will store all skipped comments in tokComments.
function skipSpace() {
@@ -605,7 +606,8 @@ operator node, not the second literal node.