swc-project / swc

Rust-based platform for the Web
https://swc.rs
Apache License 2.0
31.23k stars 1.23k forks source link

Emit original sourcemap instance #4677

Open h-a-n-a opened 2 years ago

h-a-n-a commented 2 years ago

Describe the feature

Currently, source map forces to be generated as code, which restricts upper-stream developer to consume sourcemap instance directly. I was wondering if we could provide an option to output sourcemap directly, which avoids unnecessary serializations and deserializations

Babel plugin or link to the feature description

No response

Additional context

No response

kdy1 commented 2 years ago

Do you mean sourcemap::SourceMap vs String? Or from js side?

If you mean js side, string-based approach is marginally faster

h-a-n-a commented 2 years ago

Do you mean sourcemap::SourceMap vs String? Or from js side?

If you mean js side, string-based approach is marginally faster

From rust side, in some scenario we might choose sourcemap::SourceMap over String in order to do something next and we still keep the JS side as is.

kdy1 commented 2 years ago

You can generate sourcemap::SourceMap using swc_common swc is not a good choice for most of the downstream crates I think.

Almost all modules of swc, including ASTs, are exposed in reusable form.

What's your usecase? @swc/core + custom passes? This is the main intended usecase for the crate swc but I'm not sure why sourcemap::SourceMap is required for this kind of usage.

h-a-n-a commented 2 years ago

You can generate sourcemap::SourceMap using swc_common swc is not a good choice for most of the downstream crates I think.

Almost all modules of swc, including ASTs, are exposed in reusable form.

What's your usecase? @swc/core + custom passes? This is the main intended usecase for the crate swc but I'm not sure why sourcemap::SourceMap is required for this kind of usage.

Thanks for the quick reply, I will see if using swc_common directly could help. However, from my perspective of view, this would largely expose swc interior code to upper-stream.