diff --git a/packages/babel-parser/src/parser/comments.js b/packages/babel-parser/src/parser/comments.js index 5a50c15c6414..bf936d2dce10 100644 --- a/packages/babel-parser/src/parser/comments.js +++ b/packages/babel-parser/src/parser/comments.js @@ -174,11 +174,9 @@ export default class CommentsParser extends BaseParser { (this.state.commentPreviousNode.type === "ExportSpecifier" && node.type !== "ExportSpecifier")) ) { - this.adjustCommentsAfterTrailingComma( - node, - [this.state.commentPreviousNode], - true, - ); + this.adjustCommentsAfterTrailingComma(node, [ + this.state.commentPreviousNode, + ]); } if (lastChild) { diff --git a/packages/babel-parser/test/fixtures/comments/regression/10892/input.js b/packages/babel-parser/test/fixtures/comments/regression/10892/input.js new file mode 100644 index 000000000000..05a56ffa976c --- /dev/null +++ b/packages/babel-parser/test/fixtures/comments/regression/10892/input.js @@ -0,0 +1,7 @@ +import { foo } from "bar" + +/** + * lost comment + */ +export default { +} diff --git a/packages/babel-parser/test/fixtures/comments/regression/10892/options.json b/packages/babel-parser/test/fixtures/comments/regression/10892/options.json new file mode 100644 index 000000000000..2104ca43283f --- /dev/null +++ b/packages/babel-parser/test/fixtures/comments/regression/10892/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/comments/regression/10892/output.json b/packages/babel-parser/test/fixtures/comments/regression/10892/output.json new file mode 100644 index 000000000000..1ca2d06ab94e --- /dev/null +++ b/packages/babel-parser/test/fixtures/comments/regression/10892/output.json @@ -0,0 +1,206 @@ +{ + "type": "File", + "start": 0, + "end": 69, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 69, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "imported": { + "type": "Identifier", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "local": { + "type": "Identifier", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "foo" + }, + "name": "foo" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 20, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "extra": { + "rawValue": "bar", + "raw": "\"bar\"" + }, + "value": "bar" + }, + "trailingComments": [ + { + "type": "CommentBlock", + "value": "*\n * lost comment\n ", + "start": 27, + "end": 50, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 5, + "column": 3 + } + } + } + ] + }, + { + "type": "ExportDefaultDeclaration", + "start": 51, + "end": 69, + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "declaration": { + "type": "ObjectExpression", + "start": 66, + "end": 69, + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "properties": [] + }, + "leadingComments": [ + { + "type": "CommentBlock", + "value": "*\n * lost comment\n ", + "start": 27, + "end": 50, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 5, + "column": 3 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentBlock", + "value": "*\n * lost comment\n ", + "start": 27, + "end": 50, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 5, + "column": 3 + } + } + } + ] +} \ No newline at end of file