How to oxc-parse -> AST -> oxc-minify in JS
#15043
Replies: 2 comments 1 reply
-
|
I would strongly consider using rolldown for your use case, as it sounds like it can do what you need, if you need to customize the transformation process, you can use rolldown's plugin hooks to mutate the ast, and use magic string to print the mutated ast. To print an AST to a string, take a look at this issue #11495 |
Beta Was this translation helpful? Give feedback.
-
Actually I have a similar simple use case, and I thought But I now even think that in the absence of built-in codegen in What I mean is that AST has given us the indexes of the code block, and we can use these starting and ending indexes to manually splice the original string, which may be enough for simple needs. It's even cheaper than traversing whole AST do codegen. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We have WASM versions of both packages, but I don't see how to use them together?
https://www.npmjs.com/package/oxc-parser
https://www.npmjs.com/package/oxc-minify
oxc-parserseems to only provide one-wayTEXTtoASTparsing, and it appears not able to to regenerate code after editing.Meanwhile,
oxc-minifyseems to only acceptTEXT, not the already parsedAST, implying yet another redundant parsing?How can I combine and utilize these packages in JS?
For example, a use case might be to parse the original JS/TS code, read or change something in the AST, and then regenerate the JS/TS code or directly minify it.
I don't understand Rust and Oxc's internals, but based on the examples I've read:
https://github.com/oxc-project/oxc/blob/main/crates/oxc_minifier/examples/minifier.rs
https://github.com/oxc-project/oxc/blob/main/crates/oxc_codegen/examples/codegen.rs
It seems there are a few issues here:
codegenhas not published as a npm/wasm package.Are there any plans to provide these supports? Or any other suggestions?
I think
rolldownis a bit heavy for this simple task, but should I try and look intorolldown-wasminstead?Beta Was this translation helpful? Give feedback.
All reactions