Skip to content

Commit

Permalink
Fix: leading comments added from previous node (fixes #256)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicataldo committed Mar 13, 2016
1 parent 4aabc03 commit d1b4929
Show file tree
Hide file tree
Showing 4 changed files with 488 additions and 2 deletions.
19 changes: 18 additions & 1 deletion lib/comment-attachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,26 @@ module.exports = {
processComment: function(node) {
var lastChild,
trailingComments,
i;
i,
j;

if (node.type === astNodeTypes.Program) {
// Remove leading comments that are incorrectly added when no expression exists
// between comment and the current node
for (i = 1; i < node.body.length; i++) {
if (node.body[i].leadingComments) {
for (j = 0; j < node.body[i].leadingComments.length; j++) {
if (node.body[i].leadingComments[j].range[1] < node.body[i - 1].range[1]) {
node.body[i].leadingComments.splice(j, 1);
}
}

if (node.body[i].leadingComments.length === 0) {
delete node.body[i].leadingComments;
}
}
}

if (node.body.length > 0) {
return;
}
Expand Down
Loading

0 comments on commit d1b4929

Please sign in to comment.