Closed Boshen closed 3 weeks ago
Is it possible to configure parsing and retain all comments
I'll need at least the esbuild behaviour to make the transformer a viable Vite plugin!
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
!
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.
Yeah you can get to at least 38m downloads without printing comments 😁
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:
oxc_prettier
needs comment attachment info for printing commentsoxc_codegen
needs to print special comments for bundlers, e.g. webpack / vite special comments and side effect commentsProposal
Trivias
for associating ast nodes, preferably AST node ID (we can use the allocator address API today) to ASTKind