feat: provide javascript compiler api to transform, parse, minify js #10017
feat: provide javascript compiler api to transform, parse, minify js #10017GiveMe-A-Name wants to merge 10 commits intomainfrom
Conversation
✅ Deploy Preview for rspack canceled.
|
2a61374 to
25ef5ed
Compare
CodSpeed Performance ReportMerging #10017 will not alter performanceComparing 🎉 Hooray!
|
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a JavaScriptCompiler API that provides methods to parse, transform, and minify JavaScript code by reusing SWC’s transform and minification features. Key changes include:
- Adding new modules and functions for parsing and minifying JavaScript in rspack_javascript_compiler.
- Updating AST handling and error conversion to use BatchErrors.
- Adjusting examples, build scripts, and bindings to expose the new API and update dependencies.
Reviewed Changes
Copilot reviewed 42 out of 43 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rspack_javascript_compiler/src/compiler/parse.rs | Adds API for parsing JavaScript source code into an AST. |
| crates/rspack_javascript_compiler/src/compiler/minify.rs | Implements JS minification with SWC including error handling and comment processing. |
| crates/rspack_javascript_compiler/src/compiler/mod.rs | Organizes the compiler modules for parsing, minifying, transforming, and stringifying. |
| crates/rspack_javascript_compiler/src/ast.rs | Updates AST construction and error handling functions. |
| Examples (transform.rs, minify.rs) | Provide usage examples for the new compiler API. |
| Build scripts and Cargo.toml files | Update dependency versions and propagate the SWC core version. |
| Node binding files | Expose the transform and minify APIs via the napi interface. |
| rspack_core and related Cargo.toml files | Remove the now defunct rspack_ast dependency and update imports accordingly. |
Files not reviewed (1)
- crates/rspack_ast/LICENSE: Language not supported
Comments suppressed due to low confidence (1)
crates/rspack_javascript_compiler/src/compiler/minify.rs:86
- The use of expect("TODO:") with an unclear message may lead to a panic without providing useful context. Consider replacing it with a more descriptive error message or proper error handling.
let source_map = opts.source_map.as_ref().map(|_| SourceMapsConfig::Bool(true)).unwrap_as_option(|v| { Some(match v { Some(true) => SourceMapsConfig::Bool(true), _ => SourceMapsConfig::Bool(false), }) }).expect("TODO:");
|
This PR would split two parts:
|
Summary
Consider upper layer (rslib, rsbuild or rspress) and js plugin need parse [t|j]s file or minify js. We should provide a compiler api to transform js & minify it.
So we reuse swc transform and minify feature.
Related issue (if exists):
#8998
Checklist