* 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
257 lines
5.5 KiB
JSON
257 lines
5.5 KiB
JSON
{
|
|
"type": "File",
|
|
"start": 0,
|
|
"end": 35,
|
|
"loc": {
|
|
"start": {
|
|
"line": 1,
|
|
"column": 0
|
|
},
|
|
"end": {
|
|
"line": 7,
|
|
"column": 1
|
|
}
|
|
},
|
|
"program": {
|
|
"type": "Program",
|
|
"start": 0,
|
|
"end": 35,
|
|
"loc": {
|
|
"start": {
|
|
"line": 1,
|
|
"column": 0
|
|
},
|
|
"end": {
|
|
"line": 7,
|
|
"column": 1
|
|
}
|
|
},
|
|
"sourceType": "script",
|
|
"interpreter": null,
|
|
"body": [
|
|
{
|
|
"type": "ExpressionStatement",
|
|
"start": 0,
|
|
"end": 25,
|
|
"loc": {
|
|
"start": {
|
|
"line": 1,
|
|
"column": 0
|
|
},
|
|
"end": {
|
|
"line": 4,
|
|
"column": 1
|
|
}
|
|
},
|
|
"expression": {
|
|
"type": "AssignmentExpression",
|
|
"start": 0,
|
|
"end": 25,
|
|
"loc": {
|
|
"start": {
|
|
"line": 1,
|
|
"column": 0
|
|
},
|
|
"end": {
|
|
"line": 4,
|
|
"column": 1
|
|
}
|
|
},
|
|
"operator": "=",
|
|
"left": {
|
|
"type": "Identifier",
|
|
"start": 0,
|
|
"end": 1,
|
|
"loc": {
|
|
"start": {
|
|
"line": 1,
|
|
"column": 0
|
|
},
|
|
"end": {
|
|
"line": 1,
|
|
"column": 1
|
|
},
|
|
"identifierName": "A"
|
|
},
|
|
"name": "A"
|
|
},
|
|
"right": {
|
|
"type": "ObjectExpression",
|
|
"start": 4,
|
|
"end": 25,
|
|
"loc": {
|
|
"start": {
|
|
"line": 1,
|
|
"column": 4
|
|
},
|
|
"end": {
|
|
"line": 4,
|
|
"column": 1
|
|
}
|
|
},
|
|
"properties": [
|
|
{
|
|
"type": "ObjectProperty",
|
|
"start": 8,
|
|
"end": 13,
|
|
"loc": {
|
|
"start": {
|
|
"line": 2,
|
|
"column": 2
|
|
},
|
|
"end": {
|
|
"line": 2,
|
|
"column": 7
|
|
}
|
|
},
|
|
"method": false,
|
|
"key": {
|
|
"type": "Identifier",
|
|
"start": 8,
|
|
"end": 9,
|
|
"loc": {
|
|
"start": {
|
|
"line": 2,
|
|
"column": 2
|
|
},
|
|
"end": {
|
|
"line": 2,
|
|
"column": 3
|
|
},
|
|
"identifierName": "a"
|
|
},
|
|
"name": "a"
|
|
},
|
|
"computed": false,
|
|
"shorthand": false,
|
|
"value": {
|
|
"type": "NumericLiteral",
|
|
"start": 11,
|
|
"end": 13,
|
|
"loc": {
|
|
"start": {
|
|
"line": 2,
|
|
"column": 5
|
|
},
|
|
"end": {
|
|
"line": 2,
|
|
"column": 7
|
|
}
|
|
},
|
|
"extra": {
|
|
"rawValue": 42,
|
|
"raw": "42"
|
|
},
|
|
"value": 42
|
|
},
|
|
"trailingComments": [
|
|
{
|
|
"type": "CommentLine",
|
|
"value": " One",
|
|
"start": 17,
|
|
"end": 23,
|
|
"loc": {
|
|
"start": {
|
|
"line": 3,
|
|
"column": 2
|
|
},
|
|
"end": {
|
|
"line": 3,
|
|
"column": 8
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
},
|
|
"trailingComments": [
|
|
{
|
|
"type": "CommentLine",
|
|
"value": " Two",
|
|
"start": 27,
|
|
"end": 33,
|
|
"loc": {
|
|
"start": {
|
|
"line": 6,
|
|
"column": 0
|
|
},
|
|
"end": {
|
|
"line": 6,
|
|
"column": 6
|
|
}
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"type": "ExpressionStatement",
|
|
"start": 34,
|
|
"end": 35,
|
|
"loc": {
|
|
"start": {
|
|
"line": 7,
|
|
"column": 0
|
|
},
|
|
"end": {
|
|
"line": 7,
|
|
"column": 1
|
|
}
|
|
},
|
|
"expression": {
|
|
"type": "Identifier",
|
|
"start": 34,
|
|
"end": 35,
|
|
"loc": {
|
|
"start": {
|
|
"line": 7,
|
|
"column": 0
|
|
},
|
|
"end": {
|
|
"line": 7,
|
|
"column": 1
|
|
},
|
|
"identifierName": "B"
|
|
},
|
|
"name": "B"
|
|
}
|
|
}
|
|
],
|
|
"directives": []
|
|
},
|
|
"comments": [
|
|
{
|
|
"type": "CommentLine",
|
|
"value": " One",
|
|
"start": 17,
|
|
"end": 23,
|
|
"loc": {
|
|
"start": {
|
|
"line": 3,
|
|
"column": 2
|
|
},
|
|
"end": {
|
|
"line": 3,
|
|
"column": 8
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"type": "CommentLine",
|
|
"value": " Two",
|
|
"start": 27,
|
|
"end": 33,
|
|
"loc": {
|
|
"start": {
|
|
"line": 6,
|
|
"column": 0
|
|
},
|
|
"end": {
|
|
"line": 6,
|
|
"column": 6
|
|
}
|
|
}
|
|
}
|
|
]
|
|
} |