oxc icon indicating copy to clipboard operation
oxc copied to clipboard

transformer: API changes

Open Boshen opened this issue 1 year ago • 2 comments

In napi/transform, all transformations are enabled, we need a way to disable these typescript and react transform individually via typescript: false and react : false.

https://github.com/oxc-project/oxc/blob/ea908f742d8165e8a01aad5e3b2e68b3f6953dc0/napi/transform/index.d.ts#L197-L199

There are situations where the passed in filename is .vue, but we need to force parse and transform it as .jsx. We need to filename for sourcemaps, but use another extension for parsing.

We need to decouple these options from the source type, and make everything overridable. I propose an api like `parseAsExtension: ".jsx").

react should be jsx, it's not just for react anymore. Get rid of all mentions of React to Jsx. e.g. in esbuild https://esbuild.github.io/api/#jsx

Transform need define API. It seems like we need to expose our pipeline to the JS side for maximum usability.

Rolldown currently reexports oxc's transformer https://github.com/rolldown/rolldown/blob/1ed9d77e55030742d6ac1bedf0d0d0f8715b2e45/crates/rolldown_binding/src/lib.rs#L25

so rolldown-vite don't have to import another set of plugins from npm.

What rolldown-vite actually need is to re-use the oxc pipeline as napi defined in

https://github.com/rolldown/rolldown/blob/1ed9d77e55030742d6ac1bedf0d0d0f8715b2e45/crates/rolldown/src/utils/pre_process_ecma_ast.rs#L89-L117

napi package for unified pipeline, as well as individual napi packages for different use cases.

Boshen avatar Sep 29 '24 03:09 Boshen

It seems like we need a TransformerFactory for storing options, otherwise we'll be repeatedly initializing the options.

But ... I'll just add define and inject options to TransformOptions to get things going.

Boshen avatar Oct 01 '24 08:10 Boshen

Unified pipeline is super hard to get right.

The pipeline needs to be expose from the oxc crate with a napi feature. And then all the individual napi packages will just export parts from the oxc crate.

Boshen avatar Oct 02 '24 15:10 Boshen