Skip to content

Commit

Permalink
fix: lost leading comment after named import (#10901)
Browse files Browse the repository at this point in the history
* create test for 10892

* update expected output

* fixed #10892

* add colon to restart build

* remove colon as it makes tests fail
  • Loading branch information
elevatebart authored and nicolo-ribaudo committed Dec 22, 2019
1 parent 416ce35 commit f651f22
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 5 deletions.
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
}
}
}
]
}

0 comments on commit f651f22

Please sign in to comment.