{"id":19025,"library":"babel-plugin-annotate-pure-calls","title":"babel-plugin-annotate-pure-calls","description":"Babel plugin (v0.5.0) that automatically inserts #__PURE__ annotations on top-level call expressions and new expressions in assignment contexts, enabling UglifyJS and Terser to perform dead code elimination for improved bundle sizes. Targeted at libraries where top-level calls are generally side-effect-free, but may break code if misapplied. Current stable version is 0.5.0 with Node >= 18 and peer dependency on @babel/core ^7.0.0. The plugin is actively maintained but the API is simple and stable. Compared to alternatives like 'annotate-pure-call-in-variable-declarator', this plugin covers broader contexts (IIFEs, nested IIFEs) and is more widely adopted.","status":"active","version":"0.5.0","language":"javascript","source_language":"en","source_url":"https://github.com/Andarist/babel-plugin-annotate-pure-calls","tags":["javascript","babel","plugin","pure","side-effects","uglifyjs"],"install":[{"cmd":"npm install babel-plugin-annotate-pure-calls","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-annotate-pure-calls","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-annotate-pure-calls","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"The plugin is a Babel transform and requires @babel/core to function as a plugin.","package":"@babel/core","optional":false}],"imports":[{"note":"The plugin name is 'annotate-pure-calls' when used in Babel config; the full npm package name is optional.","wrong":"plugins: ['babel-plugin-annotate-pure-calls']","symbol":"plugin","correct":"// In .babelrc or babel.config.js: plugins: ['annotate-pure-calls']"},{"note":"The plugin is exported as CommonJS; ES import may not work depending on bundler configuration.","wrong":"import annotatePureCalls from 'babel-plugin-annotate-pure-calls';","symbol":"default","correct":"const annotatePureCalls = require('babel-plugin-annotate-pure-calls');"},{"note":"When using programmatic API, you must pass the plugin object, not a string. Strings only work in config files.","wrong":"babel.transform(code, { plugins: ['annotate-pure-calls'] });","symbol":"annotate-pure-calls","correct":"// programmatic usage:\nconst babel = require('@babel/core');\nbabel.transform(code, { plugins: [require('babel-plugin-annotate-pure-calls')] });"}],"quickstart":{"code":"// Install: npm install --save-dev babel-plugin-annotate-pure-calls\n// .babelrc\n{\n  \"plugins\": [\"annotate-pure-calls\"]\n}\n\n// Input: top-level call\nvar inc = add(1);\n\n// Output: annotated with #__PURE__\nvar inc = /*#__PURE__*/add(1);\n\n// Note: Only top-level calls in assignment contexts are annotated; calls like mutate({}) remain unannotated.","lang":"javascript","description":"Shows installation, configuration, and a simple example of the plugin annotating a pure call."},"warnings":[{"fix":"Use only for libraries where top-level calls are predominantly side-effect-free; manually review or use additional linting.","message":"Plugin may annotate impure top-level calls (e.g., calls with side effects) as pure, leading to broken code after minification.","severity":"gotcha","affected_versions":"all"},{"fix":"Understand the plugin's scope: only variable declarations and assignment expressions at top level are annotated.","message":"Calls not in an assignment context (e.g., pure statements like mutate({})) are NOT annotated, which is correct but may be surprising for those expecting all top-level calls to be annotated.","severity":"gotcha","affected_versions":"all"},{"fix":"Upgrade Node to version 18 or later, or use an older version of the plugin (if available).","message":"The plugin requires Node >= 18 as of version 0.5.0; older versions may not work.","severity":"gotcha","affected_versions":">=0.5.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run npm install --save-dev babel-plugin-annotate-pure-calls in the project directory.","cause":"Plugin not installed or installed globally instead of locally.","error":"Cannot find module 'babel-plugin-annotate-pure-calls'"},{"fix":"Install @babel/core: npm install --save-dev @babel/core (ensure version ^7.0.0).","cause":"Missing or incompatible version of @babel/core.","error":"Unmet peer dependency @babel/core@^7.0.0"},{"fix":"Use require('babel-plugin-annotate-pure-calls') instead of a string in Babel transform options.","cause":"Plugin is not a function; imported incorrectly when using programmatic API.","error":"TypeError: Cannot read properties of undefined (reading 'Program')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}