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

243 lines
5.5 KiB
JSON

{
"type": "File",
"start": 0,
"end": 46,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 46
}
},
"program": {
"type": "Program",
"start": 0,
"end": 46,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 46
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 46,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 46
}
},
"expression": {
"type": "CallExpression",
"start": 0,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 29
}
},
"callee": {
"type": "Identifier",
"start": 0,
"end": 2,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 2
},
"identifierName": "fn"
},
"name": "fn"
},
"arguments": [
{
"type": "Identifier",
"start": 3,
"end": 4,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 4
},
"identifierName": "a"
},
"name": "a"
},
{
"type": "ObjectExpression",
"start": 6,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 11
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 8,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 9
}
},
"method": false,
"key": {
"type": "Identifier",
"start": 8,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 9
},
"identifierName": "b"
},
"name": "b"
},
"computed": false,
"shorthand": true,
"value": {
"type": "Identifier",
"start": 8,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 9
},
"identifierName": "b"
},
"name": "b"
},
"extra": {
"shorthand": true
}
}
],
"trailingComments": [
{
"type": "CommentBlock",
"value": " comment 1 ",
"start": 13,
"end": 28,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 28
}
}
}
]
}
],
"trailingComments": [
{
"type": "CommentBlock",
"value": " comment 2 ",
"start": 30,
"end": 45,
"loc": {
"start": {
"line": 1,
"column": 30
},
"end": {
"line": 1,
"column": 45
}
}
}
]
}
}
],
"directives": []
},
"comments": [
{
"type": "CommentBlock",
"value": " comment 1 ",
"start": 13,
"end": 28,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 28
}
}
},
{
"type": "CommentBlock",
"value": " comment 2 ",
"start": 30,
"end": 45,
"loc": {
"start": {
"line": 1,
"column": 30
},
"end": {
"line": 1,
"column": 45
}
}
}
]
}