A SWC plugin that processes TypeScript type annotations to identify special engine keywords (view and producer) and transforms them into instrumented code. This is a Rust implementation of the functionality provided by @c11/engine.babel-plugin-syntax.
npm install @c11/engine.swc-plugin-syntaxAdd the plugin to your SWC configuration:
{
"jsc": {
"experimental": {
"plugins": [
["@c11/engine.swc-plugin-syntax", {
"output": true,
"viewLibrary": "engineViewLibrary"
}]
]
}
}
}output(boolean): Whether to generate instrumentation output in.app-structure.jsonviewLibrary(string): The library name to import view functions fromroot(string): Root path for output file generation
const MyComponent: view = ({ count = observe.count }) => {
return <div>{count}</div>
};const incrementCount: producer = ({ count = update.count }) => {
count(prev => prev + 1);
};- Rust toolchain
- wasm32-wasi target (
rustup target add wasm32-wasi) - Node.js and npm/yarn
cargo build --target wasm32-wasi --releasecargo testSee the examples directory for usage examples.
This SWC plugin is a direct port of the Babel plugin functionality to Rust. It:
- Uses the same visitor pattern for AST manipulation
- Generates identical instrumentation output
- Maintains the same configuration options
- Produces compatible
.app-structure.jsonoutput
The main differences are:
- Implemented in Rust using SWC's plugin system
- Better performance due to Rust and SWC optimizations
- Slightly different error messages due to Rust's error handling
MIT License - see LICENSE for details