Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: lost leading comment after named import #10901

Merged
merged 5 commits into from Dec 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 3 additions & 5 deletions packages/babel-parser/src/parser/comments.js
Expand Up @@ -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) {
Expand Down
@@ -0,0 +1,7 @@
import { foo } from "bar"

/**
* lost comment
*/
export default {
}
@@ -0,0 +1,3 @@
{
"sourceType": "module"
}
@@ -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
}
}
}
]
}