{"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,"search_vec":"'0.5.0':64 '18':67 '7.0.0':73 'activ':77 'adopt':109 'altern':88 'annot':4,14,91 'annotate-pure-call-in-variable-declar':90 'api':81 'assign':25 'automat':11 'babel':2,7,111 'babel-plugin-annotate-pure-cal':1 'babel/core':72 'break':56 'broader':100 'bundl':38 'call':6,19,47,93 'code':34,57 'compar':86 'context':26,101 'cover':99 'current':60 'dead':33 'declar':96 'depend':70 'effect':52,116 'elimin':35 'enabl':27 'express':20,23 'free':53 'general':49 'iif':102,104 'improv':37 'insert':12 'javascript':110 'level':18,46 'librari':42 'like':89 'maintain':78 'may':55 'misappli':59 'nest':103 'new':22 'node':66 'peer':69 'perform':32 'plugin':3,8,75,98,112 'pure':5,13,92,113 'side':51,115 'side-effect':114 'side-effect-fre':50 'simpl':83 'size':39 'stabl':61,85 'target':40 'terser':30 'top':17,45 'top-level':16,44 'uglifyj':28,117 'v0.5.0':9 'variabl':95 'version':62 'wide':108","created_at":"2026-04-25T11:15:39.060417+00:00","updated_at":"2026-04-25T11:15:39.060417+00:00","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,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/Andarist/babel-plugin-annotate-pure-calls","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/babel-plugin-annotate-pure-calls","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-24","install_tag":null}}