Skip to content

Comments in parentheses disappear#12560

Closed
Robinsstudio wants to merge 5 commits intobabel:mainfrom
Robinsstudio:comments-in-parentheses-disappear
Closed

Comments in parentheses disappear#12560
Robinsstudio wants to merge 5 commits intobabel:mainfrom
Robinsstudio:comments-in-parentheses-disappear

Conversation

@Robinsstudio
Copy link
Copy Markdown

@Robinsstudio Robinsstudio commented Dec 25, 2020

Q                       A
Fixed Issues? Fixes #11576
Patch: Bug Fix? Yes
Major: Breaking Change? No
Minor: New Feature? No
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

@Robinsstudio Robinsstudio marked this pull request as draft December 25, 2020 00:09
@babel-bot
Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/36479/

@codesandbox-ci
Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 11df46a:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@Robinsstudio
Copy link
Copy Markdown
Author

Robinsstudio commented Dec 26, 2020

From my understanding, the bug involves the parser. When a node has inner comments, they are first considered as trailing comments and then set as inner comments. Except that this was never the case because of two inconsistent if statements. (see the changes in comments.js file)

Another problem involves the generators. In particular a CallExpression doesn't print its inner comments between its parentheses. But that raises other questions. What about an OptionalCallExpression (same thing with ?. instead of .)?

And what about a ParenthesizedExpression? Or a ClassProperty?

It looks like those inner comments can be found in plenty of places. As I barely have any technical knowledge about Babel, I would highly appreciate some help to try and figure out how wide spread this problem is. The idea is to see how much code this bugfix should impact.

Thanks! 🎅

foo
/* WORKING */
(
/* NOT WORKING */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only consider comments in params as innerComments of CallExpression when it does not have param, otherwise the comment should be categorized as leading / trailing comments of adjacent parameters.

CI fails because`/* comment 1*/ in input source

fn(a, b, /* comment 1 */) /* comment 2*/;

was now an innerComment. Generally Babel avoids generating innerComments because where they should be inserted can be vague.

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 7, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Comments in parentheses disappear

3 participants