Shrey Banga c0e3fa0081 Refactor trailing comma comment adjustment (#10380)
* Refactor trailing comment adjustment

Following up from https://github.com/babel/babel/pull/10369

- Unify the logic for adjusting trailing comments into a separate
  function
- Use it for all three cases, which fixes a bug for ObjectExpressions
  and CallExpressions
- Update tests to check for the fixed bug

* Fix tests

- Only modify trailingComments if necessary
- Update snapshots of a couple of affected tests

* Drop the underscore in adjustCommentsAfterTrailingComma_

* Handle ArrayPattern

* Handle ObjectPattern

* Handle import and export declarations

These have to be handled a bit differently, because the  node is visited after the  and before the declaration. So we intercept when we are going from the last specifier to the source node.

* Remove unnecessary check
2019-09-02 20:35:15 -04:00

255 lines
5.3 KiB
JSON

{
"type": "File",
"start": 0,
"end": 76,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 24
}
},
"program": {
"type": "Program",
"start": 0,
"end": 76,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 24
}
},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ImportDeclaration",
"start": 0,
"end": 76,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 24
}
},
"specifiers": [
{
"type": "ImportSpecifier",
"start": 21,
"end": 24,
"loc": {
"start": {
"line": 2,
"column": 12
},
"end": {
"line": 2,
"column": 15
}
},
"imported": {
"type": "Identifier",
"start": 21,
"end": 24,
"loc": {
"start": {
"line": 2,
"column": 12
},
"end": {
"line": 2,
"column": 15
},
"identifierName": "Foo"
},
"name": "Foo"
},
"local": {
"type": "Identifier",
"start": 21,
"end": 24,
"loc": {
"start": {
"line": 2,
"column": 12
},
"end": {
"line": 2,
"column": 15
},
"identifierName": "Foo"
},
"name": "Foo"
},
"leadingComments": [
{
"type": "CommentBlock",
"value": " One ",
"start": 11,
"end": 20,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 11
}
}
}
],
"trailingComments": [
{
"type": "CommentBlock",
"value": " Two ",
"start": 27,
"end": 36,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 11
}
}
},
{
"type": "CommentBlock",
"value": " Three ",
"start": 40,
"end": 51,
"loc": {
"start": {
"line": 4,
"column": 2
},
"end": {
"line": 4,
"column": 13
}
}
},
{
"type": "CommentBlock",
"value": " Four ",
"start": 54,
"end": 64,
"loc": {
"start": {
"line": 5,
"column": 2
},
"end": {
"line": 5,
"column": 12
}
}
}
]
}
],
"source": {
"type": "StringLiteral",
"start": 70,
"end": 75,
"loc": {
"start": {
"line": 5,
"column": 18
},
"end": {
"line": 5,
"column": 23
}
},
"extra": {
"rawValue": "foo",
"raw": "\"foo\""
},
"value": "foo"
}
}
],
"directives": []
},
"comments": [
{
"type": "CommentBlock",
"value": " One ",
"start": 11,
"end": 20,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 11
}
}
},
{
"type": "CommentBlock",
"value": " Two ",
"start": 27,
"end": 36,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 11
}
}
},
{
"type": "CommentBlock",
"value": " Three ",
"start": 40,
"end": 51,
"loc": {
"start": {
"line": 4,
"column": 2
},
"end": {
"line": 4,
"column": 13
}
}
},
{
"type": "CommentBlock",
"value": " Four ",
"start": 54,
"end": 64,
"loc": {
"start": {
"line": 5,
"column": 2
},
"end": {
"line": 5,
"column": 12
}
}
}
]
}