A high-performance Babel plugin written in Rust to annotate top-level function calls with /*#__PURE__*/ comment for better tree-shaking and optimization.
- Rust Edition: 2021
- Minimum Rust Version: 1.67.0
- Recommended Rust Toolchain: Stable (latest)
- Minimum Version: 16.x
- Recommended Version: 18.x or 20.x
- npm
- yarn
- pnpm (Recommended)
Using pnpm (recommended):
pnpm add -D babel-plugin-pure-toplevelUsing npm:
npm install --save-dev babel-plugin-pure-toplevelUsing yarn:
yarn add -D babel-plugin-pure-toplevel{
"plugins": [
"babel-plugin-pure-toplevel"
]
}import babel from '@babel/core';
import pureTopLevelPlugin from 'babel-plugin-pure-toplevel';
const result = babel.transform(code, {
plugins: [pureTopLevelPlugin()]
});function test() {
Object.create({});
new Date();
}function test() {
/*#__PURE__*/Object.create({});
/*#__PURE__*/new Date();
}- ✅ Annotate top-level function calls
- ✅ Skip TypeScript helper functions
- ✅ Skip function calls with arguments
- ✅ Support for
CallExpressionandNewExpression - 🚀 High-performance Rust implementation
# Build for release
pnpm build
# Build for debug
pnpm build:debug# Rust tests
pnpm test
# Babel integration tests (to be implemented)
pnpm test:babelThis plugin is implemented in Rust, providing near-native performance for AST transformations.
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License
Inspired by Angular's pure annotation strategy and leveraging the power of Rust and SWC.