Registry / devops / babel-plugin-pure-calls-annotation

babel-plugin-pure-calls-annotation

JSON →
library0.4.2jsnpmunverified

A Babel plugin (v0.4.2, stable, low release cadence) that automatically adds /*#__PURE__*/ comments to call expressions in variable declarators, assignment expressions, call arguments, and other expression contexts. This helps bundlers like Webpack identify side-effect-free calls for tree shaking and dead code elimination. Unlike manual annotation, it eliminates human error and ensures consistent coverage across large codebases. Ships TypeScript types and integrates seamlessly into any Babel-based build pipeline.

npm install babel-plugin-pure-calls-annotation
INSTALL
IMPORT
SIG · BABEL-PLUGIN-PURE-
B
babel-plugin-pure-calls-annotation
devopsjavascriptv0.4.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import pureCallsAnnotation from 'babel-plugin-pure-calls-annotation'
const pureCallsAnnotation = require('babel-plugin-pure-calls-annotation')
Default import works in ESM; CommonJS require is also supported but discouraged for TypeScript
pureCallsAnnotation
import pureCallsAnnotation from 'babel-plugin-pure-calls-annotation'
Plugin is used as a Babel plugin, imported as default and passed to plugins array
BabelPluginPureCallsAnnotation
import BabelPluginPureCallsAnnotation from 'babel-plugin-pure-calls-annotation'
const { BabelPluginPureCallsAnnotation } = require('babel-plugin-pure-calls-annotation')
Named export does not exist; only default export. Use default import.

Add the plugin to Babel config to automatically annotate pure call expressions with /*#__PURE__*/ for tree shaking.

// babel.config.js module.exports = { plugins: [ 'babel-plugin-pure-calls-annotation' ] }; // Input: const result = compute() // Output: const result = /*#__PURE__*/compute()
Debug
Known issues
gotchaThe plugin annotates all eligible call expressions, including those that may have side effects. Use with caution; only include if you are certain the annotated calls are pure.
fix
Manually verify or use other methods (e.g., /*#__PURE__*/ comments) to ensure purity.
affects: *
breakingBREAKING: Version 0.4.0 changed annotation behavior for IIFEs: previously IIFEs were not annotated; now they are.
fix
If you rely on IIFEs not being annotated, downgrade to <0.4.0 or update your code to handle the change.
affects: >=0.4.0
deprecatedThe plugin may not be actively maintained; last release was in 2021. Consider alternatives like manual annotation or custom Babel plugin for tree shaking.
fix
Review current tree shaking needs; use terser-webpack-plugin with sideEffects: false as a more maintained alternative.
affects: *
gotchaDoes not annotate call expressions in all positions (e.g., as standalone statements). Only variable declarators, assignment expressions, and call arguments are covered.
fix
Manually add /*#__PURE__*/ to unannotated pure calls or extend the plugin.
affects: *
Errors
Common errors & fixes
SyntaxError: 'babel-plugin-pure-calls-annotation' threw an error: Cannot find module '@babel/core'
Missing @babel/core as a peer dependency.
fix
npm install @babel/core --save-dev
TypeError: Cannot read properties of undefined (reading 'callee')
The plugin expects a Babel AST node with a callee property; corrupted or outdated Babel version may cause this.
fix
Update Babel to version 7.x or above and ensure the plugin is compatible.
Error: Plugin/preset files are not allowed to export objects, only functions.
This error occurs if the plugin is imported incorrectly (e.g., using named import instead of default).
fix
Use default import: import pureCallsAnnotation from 'babel-plugin-pure-calls-annotation'
Upgrade
Version history
0.4.2latest on npm
Audit
Dependencies
@babel/corerequiredPeer dependency; plugin requires Babel core for transformation
Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
babel-plugin-pure-calls-annotation — npm install babel-plugin-pure-calls-annotation · libregistry