Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Print multi-line inner comments of arrowFunc #15159

Conversation

liuxingbaoyu
Copy link
Member

@liuxingbaoyu liuxingbaoyu commented Nov 8, 2022

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

@liuxingbaoyu liuxingbaoyu added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: generator area: comments PR: Fixes failing main labels Nov 8, 2022
@liuxingbaoyu liuxingbaoyu marked this pull request as draft November 8, 2022 08:54
@babel-bot
Copy link
Collaborator

babel-bot commented Nov 8, 2022

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

@liuxingbaoyu liuxingbaoyu marked this pull request as ready for review November 8, 2022 08:56
this.print(node.returnType, node, node.type === "ArrowFunctionExpression");
this.print(node.returnType, node);
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure if this is going to be removed, although we no longer wrap comments here.

@liuxingbaoyu liuxingbaoyu force-pushed the fix-arrow-multiline-inner-comments branch from 848d6e6 to 0229ccc Compare November 9, 2022 13:49
@liuxingbaoyu liuxingbaoyu removed PR: Fixes failing main PR: Bug Fix 🐛 A type of pull request used for our changelog categories labels Nov 9, 2022
@liuxingbaoyu liuxingbaoyu self-assigned this Nov 14, 2022
@liuxingbaoyu liuxingbaoyu force-pushed the fix-arrow-multiline-inner-comments branch from 0229ccc to 89f704a Compare November 26, 2022 22:18
Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

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

I feel like we should just remove this test case.

In this case, the innerComments are not generated by the parser from a valid JS, instead it is manipulated by the AST transform.

The fact that

(x, y) /* line break here
*/ => {}

is invalid implies that the transformed AST is invalid. Babel generator should not guarantee that it work with an invalid AST. In this case, I think it is fine to do nothing and just remove this test case. The generator may generate invalid JS if the AST is invalid.

@liuxingbaoyu
Copy link
Member Author

This test has nothing to do with this PR, this is a regression test, in #15160 (comment) we decided to never generate invalid code due to invalid comments.

@JLHwung
Copy link
Contributor

JLHwung commented Nov 28, 2022

As is mentioned there, #15160 conflicts with this PR. The #15160 ensures that the generator prints valid code in comments: false and it somehow works with multi-line inner comments in arrow function.

It seems to me this PR "more specifically" supports multi-line inner comments in the [NLTH] position of the arrow function () [No LineTerminator Here] => {}. I am not convinced that we should do that, because

  1. The generator should spend the least efforts on in valid AST, as it is very likely a plugin issue. Moreover, a plugin can add inner comments to any AST nodes, e.g. var x = 1 would not have inner comments at all. The current behaviour is to treat them as trailing comments of VariableDeclaration, which I think is fine. Of course we could print them around the = location, but doing so requires more efforts.
  2. If we really want to change the behaviour, it should be applied to other NLTH as well, such as async [NLTH] do, module [NLTH] {, yield [NLTH] AssignmentExpression, etc.

@liuxingbaoyu
Copy link
Member Author

My personal preference is that we don't guarantee it but if someone wants to do it or if someone opens an issue about it we will accept it.
Because it's easy to implement without complicating the code.

Also this should restore the previous behavior where it was printed as inner comments a few PRs ago.

@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 Mar 23, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: comments outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: generator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants