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
This commit is contained in:
Shrey Banga
2019-09-02 17:35:15 -07:00
committed by Huáng Jùnliàng
parent e5afa57cca
commit c0e3fa0081
17 changed files with 1322 additions and 155 deletions

View File

@@ -250,25 +250,7 @@
"label": null
}
],
"test": null,
"leadingComments": [
{
"type": "CommentLine",
"value": " comment",
"start": 47,
"end": 57,
"loc": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 4,
"column": 14
}
}
}
]
"test": null
}
]
}