From a652fdf8d2590d51863aec01c4b4bba138334c0e Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Sun, 13 Jan 2013 21:28:03 +0100 Subject: [PATCH] Fix for: Track comments will take the comment after the next token instead of the current. Also do "delete" of property instead of setting it to null for cleaner AST tree. --- Objective-J/acorn.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Objective-J/acorn.js b/Objective-J/acorn.js index 320f7743a..8c0a2ee07 100644 --- a/Objective-J/acorn.js +++ b/Objective-J/acorn.js @@ -156,7 +156,7 @@ if (!exports.acorn) { // These are used to hold arrays of comments when // `options.trackComments` is true. - var tokCommentsBefore, tokCommentsAfter; + var tokCommentsBefore, tokCommentsAfter, lastTokCommentsAfter; // These are used to hold arrays of spaces when // `options.trackSpaces` is true. @@ -505,6 +505,7 @@ if (!exports.acorn) { tokType = type; skipSpace(); tokVal = val; + lastTokCommentsAfter = tokCommentsAfter; tokCommentsAfter = tokComments; tokSpacesAfter = tokSpaces; tokRegexpAllowed = type.beforeExpr; @@ -1056,7 +1057,7 @@ if (!exports.acorn) { node.start = other.start; if (other.commentsBefore) { node.commentsBefore = other.commentsBefore; - other.commentsBefore = null; + delete other.commentsBefore; } if (options.locations) { node.loc = new node_loc_t(); @@ -1083,13 +1084,13 @@ if (!exports.acorn) { node.type = type; node.end = lastEnd; if (options.trackComments) { - if (tokCommentsAfter) { - node.commentsAfter = tokCommentsAfter; + if (lastTokCommentsAfter) { + node.commentsAfter = lastTokCommentsAfter; tokCommentsAfter = null; } else if (lastFinishedNode && lastFinishedNode.end === lastEnd && lastFinishedNode.commentsAfter) { node.commentsAfter = lastFinishedNode.commentsAfter; - lastFinishedNode.commentsAfter = null; + delete lastFinishedNode.commentsAfter; } if (!options.trackSpaces) lastFinishedNode = node;