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

feat(parser,codegen): print comment #1046

Closed
Boshen opened this issue Oct 24, 2023 · 6 comments
Closed

feat(parser,codegen): print comment #1046

Boshen opened this issue Oct 24, 2023 · 6 comments
Assignees
Labels
A-codegen Area - Code Generation P-high Priority - High

Comments

@Boshen
Copy link
Member

Boshen commented Oct 24, 2023

Research

After studying babel, esbuild and prettier, I'm leaning towards storing extra data for linking ast node and comments, the data is processed and saved in the parser.

References:

We have the following requirements:

  • jsdoc linter currently tries to find jsdoc comments in a very inefficient way, it is preferred to do a reverse look up of where the comment is attached
  • oxc_prettier needs comment attachment info for printing comments
  • oxc_codegen needs to print special comments for bundlers, e.g. webpack / vite special comments and side effect comments
  • Rolldown needs to add comments to newly inserted nodes, or in arbitrary locations

Proposal

  1. Port https://github.com/babel/babel/blob/main/packages/babel-parser/ast/comment-attachment.md
  2. Add a storage in Trivias for associating ast nodes, preferably AST node ID (we can use the allocator address API today) to ASTKind
@Boshen Boshen self-assigned this Aug 1, 2024
@Boshen Boshen added the P-high Priority - High label Aug 1, 2024
@Boshen Boshen changed the title feat(codegen): print comment feat(parser,codegen): print comment Aug 25, 2024
@SKT1yang
Copy link

Is it possible to configure parsing and retain all comments

@ArnaudBarre
Copy link
Contributor

ArnaudBarre commented Sep 12, 2024

I'll need at least the esbuild behaviour to make the transformer a viable Vite plugin!

@airhorns
Copy link

airhorns commented Sep 13, 2024

Just to weigh in a little to help prioritize -- without comments, the isolatedDeclarations transform is not super useful in its current form. I think anyone building.d.ts files for consumption intends for them to be consumed by humans, like .d.ts files within a node modules that power typechecking and autocomplete. Stripping all the nice documentation or explanation about these files makes those artifacts far far less useful for humans, and much different than the ones that the TypeScript compiler itself would produce.

I know this is probably a super annoying and invasive change to make to oxc but as someone who adopted and then had to un-adopt the isolatedDeclarations transform because of this missing piece, it'd be really great to get actual drop in compatibility with tsc!

@Boshen
Copy link
Member Author

Boshen commented Oct 14, 2024

Codegen now prints useful comments such as jsdoc, vite / webpack specials, pure annotations.

The remaining issue is print all comments, which is really difficult, I'll revisit them when requirements arises. Close as finished in the meantime.

@Boshen Boshen closed this as completed Oct 14, 2024
@ArnaudBarre
Copy link
Contributor

Yeah you can get to at least 38m downloads without printing comments 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area - Code Generation P-high Priority - High
Projects
None yet
Development

No branches or pull requests

5 participants