Merge pull request #23 from danez/fix-comments

Fix leading comments added from previous node
This commit is contained in:
Sebastian McKenzie
2016-06-22 12:44:12 +01:00
committed by GitHub
4 changed files with 46 additions and 71 deletions

View File

@@ -42,7 +42,7 @@ pp.processComment = function (node) {
let stack = this.state.commentStack;
let lastChild, trailingComments, i;
let lastChild, trailingComments, i, j;
if (this.state.trailingComments.length > 0) {
// If the first comment in trailingComments comes after the
@@ -93,8 +93,18 @@ pp.processComment = function (node) {
}
} else if (this.state.leadingComments.length > 0) {
if (last(this.state.leadingComments).end <= node.start) {
node.leadingComments = this.state.leadingComments;
this.state.leadingComments = [];
if (this.state.commentPreviousNode) {
for (j = 0; j < this.state.leadingComments.length; j++) {
if (this.state.leadingComments[j].end < this.state.commentPreviousNode.end) {
this.state.leadingComments.splice(j, 1);
j--;
}
}
}
if (this.state.leadingComments.length > 0) {
node.leadingComments = this.state.leadingComments;
this.state.leadingComments = [];
}
} else {
// https://github.com/eslint/espree/issues/2
//
@@ -131,6 +141,8 @@ pp.processComment = function (node) {
}
}
this.state.commentPreviousNode = node;
if (trailingComments) {
if (trailingComments.length && trailingComments[0].start >= node.start && last(trailingComments).end <= node.end) {
node.innerComments = trailingComments;