Skip to content

Commit

Permalink
fix trailingComments contain innerComments
Browse files Browse the repository at this point in the history
  • Loading branch information
shaodahong committed Jun 9, 2020
1 parent 4108524 commit 6602bee
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/babel-parser/src/parser/comments.js
Expand Up @@ -264,7 +264,17 @@ export default class CommentsParser extends BaseParser {
) {
node.innerComments = trailingComments;
} else {
node.trailingComments = trailingComments;
// TrailingComments maybe contain innerComments
const findIndex = trailingComments.findIndex(
comment => comment.end >= node.end,
);

if (findIndex !== -1 && findIndex !== 0) {
node.innerComments = trailingComments.slice(0, findIndex);
node.trailingComments = trailingComments.slice(findIndex);
} else {
node.trailingComments = trailingComments;
}
}
}

Expand Down

0 comments on commit 6602bee

Please sign in to comment.