oxc-plugin-worklets
A Rust port of React Native Reanimated's worklets Babel plugin, built on top of oxc.
Designed to integrate with the Rolldown bundler.
Requirements
- mise (manages Rust, Node, just)
- oxc 0.115.0 (pinned for Rolldown compatibility)
Setup
mise install
Development
just just build just test just lint just fmt just snapshot
Testing
just test
Integration tests live in tests/transform.rs and use insta for snapshot testing. Snapshots are stored in tests/snapshots/.
Release
just release 0.2.0
Usage
API
use oxc::allocator::Allocator;
use oxc::ast::ast::Program;
use oxc_plugin_worklets::{WorkletsVisitor, PluginOptions};
fn example(allocator: &Allocator, program: &mut Program<'_>) {
let opts = PluginOptions {
filename: Some("/path/to/file.js".to_string()),
is_release: true,
..Default::default()
};
let mut visitor = WorkletsVisitor::new(allocator, opts);
visitor.visit_program(program).expect("transform failed");
}
Rolldown Integration
use oxc_plugin_worklets::{WorkletsVisitor, PluginOptions};
ast.with_mut(|fields| {
let opts = PluginOptions {
filename: Some(filename.to_string()),
..Default::default()
};
let mut visitor = WorkletsVisitor::new(fields.allocator, opts);
visitor.visit_program(fields.program)
.expect("worklets transform failed");
});
License
MIT