* 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
254 lines
5.7 KiB
JSON
254 lines
5.7 KiB
JSON
{
|
|
"type": "File",
|
|
"start": 0,
|
|
"end": 69,
|
|
"loc": {
|
|
"start": {
|
|
"line": 1,
|
|
"column": 0
|
|
},
|
|
"end": {
|
|
"line": 6,
|
|
"column": 18
|
|
}
|
|
},
|
|
"program": {
|
|
"type": "Program",
|
|
"start": 0,
|
|
"end": 69,
|
|
"loc": {
|
|
"start": {
|
|
"line": 1,
|
|
"column": 0
|
|
},
|
|
"end": {
|
|
"line": 6,
|
|
"column": 18
|
|
}
|
|
},
|
|
"sourceType": "script",
|
|
"interpreter": null,
|
|
"body": [
|
|
{
|
|
"type": "VariableDeclaration",
|
|
"start": 0,
|
|
"end": 69,
|
|
"loc": {
|
|
"start": {
|
|
"line": 1,
|
|
"column": 0
|
|
},
|
|
"end": {
|
|
"line": 6,
|
|
"column": 18
|
|
}
|
|
},
|
|
"declarations": [
|
|
{
|
|
"type": "VariableDeclarator",
|
|
"start": 6,
|
|
"end": 68,
|
|
"loc": {
|
|
"start": {
|
|
"line": 1,
|
|
"column": 6
|
|
},
|
|
"end": {
|
|
"line": 6,
|
|
"column": 17
|
|
}
|
|
},
|
|
"id": {
|
|
"type": "ArrayPattern",
|
|
"start": 6,
|
|
"end": 52,
|
|
"loc": {
|
|
"start": {
|
|
"line": 1,
|
|
"column": 6
|
|
},
|
|
"end": {
|
|
"line": 6,
|
|
"column": 1
|
|
}
|
|
},
|
|
"elements": [
|
|
{
|
|
"type": "Identifier",
|
|
"start": 22,
|
|
"end": 23,
|
|
"loc": {
|
|
"start": {
|
|
"line": 3,
|
|
"column": 2
|
|
},
|
|
"end": {
|
|
"line": 3,
|
|
"column": 3
|
|
},
|
|
"identifierName": "x"
|
|
},
|
|
"name": "x",
|
|
"leadingComments": [
|
|
{
|
|
"type": "CommentBlock",
|
|
"value": " One ",
|
|
"start": 10,
|
|
"end": 19,
|
|
"loc": {
|
|
"start": {
|
|
"line": 2,
|
|
"column": 2
|
|
},
|
|
"end": {
|
|
"line": 2,
|
|
"column": 11
|
|
}
|
|
}
|
|
}
|
|
],
|
|
"trailingComments": [
|
|
{
|
|
"type": "CommentBlock",
|
|
"value": " Two ",
|
|
"start": 26,
|
|
"end": 35,
|
|
"loc": {
|
|
"start": {
|
|
"line": 4,
|
|
"column": 2
|
|
},
|
|
"end": {
|
|
"line": 4,
|
|
"column": 11
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"type": "CommentBlock",
|
|
"value": " Three ",
|
|
"start": 39,
|
|
"end": 50,
|
|
"loc": {
|
|
"start": {
|
|
"line": 5,
|
|
"column": 2
|
|
},
|
|
"end": {
|
|
"line": 5,
|
|
"column": 13
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"trailingComments": [
|
|
{
|
|
"type": "CommentBlock",
|
|
"value": " Four ",
|
|
"start": 53,
|
|
"end": 63,
|
|
"loc": {
|
|
"start": {
|
|
"line": 6,
|
|
"column": 2
|
|
},
|
|
"end": {
|
|
"line": 6,
|
|
"column": 12
|
|
}
|
|
}
|
|
}
|
|
]
|
|
},
|
|
"init": {
|
|
"type": "ArrayExpression",
|
|
"start": 66,
|
|
"end": 68,
|
|
"loc": {
|
|
"start": {
|
|
"line": 6,
|
|
"column": 15
|
|
},
|
|
"end": {
|
|
"line": 6,
|
|
"column": 17
|
|
}
|
|
},
|
|
"elements": []
|
|
}
|
|
}
|
|
],
|
|
"kind": "const"
|
|
}
|
|
],
|
|
"directives": []
|
|
},
|
|
"comments": [
|
|
{
|
|
"type": "CommentBlock",
|
|
"value": " One ",
|
|
"start": 10,
|
|
"end": 19,
|
|
"loc": {
|
|
"start": {
|
|
"line": 2,
|
|
"column": 2
|
|
},
|
|
"end": {
|
|
"line": 2,
|
|
"column": 11
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"type": "CommentBlock",
|
|
"value": " Two ",
|
|
"start": 26,
|
|
"end": 35,
|
|
"loc": {
|
|
"start": {
|
|
"line": 4,
|
|
"column": 2
|
|
},
|
|
"end": {
|
|
"line": 4,
|
|
"column": 11
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"type": "CommentBlock",
|
|
"value": " Three ",
|
|
"start": 39,
|
|
"end": 50,
|
|
"loc": {
|
|
"start": {
|
|
"line": 5,
|
|
"column": 2
|
|
},
|
|
"end": {
|
|
"line": 5,
|
|
"column": 13
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"type": "CommentBlock",
|
|
"value": " Four ",
|
|
"start": 53,
|
|
"end": 63,
|
|
"loc": {
|
|
"start": {
|
|
"line": 6,
|
|
"column": 2
|
|
},
|
|
"end": {
|
|
"line": 6,
|
|
"column": 12
|
|
}
|
|
}
|
|
}
|
|
]
|
|
} |