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

Support more inner comments #15008

Merged
merged 11 commits into from Oct 24, 2022

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Oct 3, 2022

Q                       A
Fixed Issues? Babel-generator does not print inner comments in certain situations
Patch: Bug Fix? Y
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This PR supports inner comments attached to generators, async methods and async do expressions. Because such inner comments must be block comments due to the noLineTerminator restrictions, we then ensure that such restrictions are respected by the babel-generator.

This PR also relaxes the condition when Babel prints single arrow binding x => {}. Before this PR we prints (x) => {} when x has attached comments. In this PR we relaxes the condition so that we can still output /* leading */x/* trailing */ => {}.

@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: generator labels Oct 3, 2022
@babel-bot
Copy link
Collaborator

babel-bot commented Oct 3, 2022

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

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

Can you add this test? (I don't think we can properly print it and that's fine)

class A {
  async /* 1 */ * /* 2 */ method /* 3 */ ( /* 4 */ ) /* 5 */ {}
}

@JLHwung
Copy link
Contributor Author

JLHwung commented Oct 4, 2022

Yeah. When an AST node has more than one empty spot, the inner comments are not sufficient for recreating code exactly from AST. But at least the printer can preserve such comments instead of discarding them silently.

@liuxingbaoyu
Copy link
Member

Can this be postponed for a while? I'm going to rebase this after the #14979 merge, it's a bit cumbersome to rebase that one. Thanks!

@@ -1 +1 @@
const x = (foo /*: string*/) => {};
const x = foo /*: string*/ => {};
Copy link
Member

Choose a reason for hiding this comment

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

This is not a valid Flow comment. If the arrow function has a single parameter with a trailing block comment that starts with :, we should still print the parentheses.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sad that flow does not support that. In that case we can partially revert the arrow function commit.

Copy link
Member

Choose a reason for hiding this comment

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

There doesn't seem to be a change here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I forgot to update the plugin test fixtures.

@nicolo-ribaudo nicolo-ribaudo merged commit c88e511 into babel:main Oct 24, 2022
@nicolo-ribaudo nicolo-ribaudo deleted the support-more-inner-comments branch October 24, 2022 21:43
@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 Jan 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 24, 2023
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 PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants