Skip to content

feat: provide javascript compiler api to transform, parse, minify js #10017

Closed
GiveMe-A-Name wants to merge 10 commits intomainfrom
feat/javascript-compiler
Closed

feat: provide javascript compiler api to transform, parse, minify js #10017
GiveMe-A-Name wants to merge 10 commits intomainfrom
feat/javascript-compiler

Conversation

@GiveMe-A-Name
Copy link
Member

@GiveMe-A-Name GiveMe-A-Name commented Apr 14, 2025

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

  • Tests updated (or not required).
  • Documentation updated (or not required).

@GiveMe-A-Name GiveMe-A-Name marked this pull request as draft April 14, 2025 09:57
@github-actions github-actions bot added release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack. labels Apr 14, 2025
@netlify
Copy link

netlify bot commented Apr 14, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit bcf77cd
🔍 Latest deploy log https://app.netlify.com/sites/rspack/deploys/680af21e69dcb900082aec5d

@GiveMe-A-Name GiveMe-A-Name force-pushed the feat/javascript-compiler branch from 2a61374 to 25ef5ed Compare April 24, 2025 04:08
@codspeed-hq
Copy link

codspeed-hq bot commented Apr 24, 2025

CodSpeed Performance Report

Merging #10017 will not alter performance

Comparing feat/javascript-compiler (bcf77cd) with main (12e8432)

🎉 Hooray! codspeed-node just leveled up to 4.0.1!

A heads-up, this is a breaking change and it might affect your current performance baseline a bit. But here's the exciting part - it's packed with new, cool features and promises improved result stability 🥳!
Curious about what's new? Visit our releases page to delve into all the awesome details about this new version.

Summary

✅ 11 untouched benchmarks

@GiveMe-A-Name GiveMe-A-Name changed the title feat: javascript compiler api feat: provide javascript compiler api to transform, parse, minify js Apr 24, 2025
@GiveMe-A-Name GiveMe-A-Name marked this pull request as ready for review April 25, 2025 02:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:");

@GiveMe-A-Name
Copy link
Member Author

This PR would split two parts:

  1. refactor: unit swc api
  2. export swc api to node_bind
    This two parts will split two PR.

@GiveMe-A-Name GiveMe-A-Name deleted the feat/javascript-compiler branch August 4, 2025 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants