A library providing composable primitives for dead code elimination in Babel AST, version 1.0.12. It is not a Babel plugin but a set of utilities (deadCodeElimination, findReferencedIdentifiers) to integrate into custom transforms. Released as a stable package with frequent patches, it differs from full-featured plugins by offering fine-grained control and working directly with the AST. Main use cases: removing unused variables, handling side-effects carefully via referenced identifier tracking, and preserving runtime behavior (e.g., object rest patterns). Ships TypeScript types.
npm install babel-dead-code-eliminationVerified import paths — ran on the pinned version, not inferred.
Parses a module, eliminates unreferenced variable 'b', then regenerates code. Shows basic usage.
Use findReferencedIdentifiers before transforms and pass the set as second argument to deadCodeElimination to preserve existing references.
Upgrade to >=1.0.5 to avoid eliminating function expressions.
Ensure your code does not rely on elimination of unused variables in object patterns with rest elements (e.g., let { a, ...rest } = obj;).If you rely on elimination of arrow functions, reconsider the design; they are safe from removal.
Upgrade to >=1.0.8 to ensure const/let iterators are preserved.
Run npm install babel-dead-code-elimination. Use import { ... } from 'babel-dead-code-elimination' for ESM, or const { ... } = require('babel-dead-code-elimination') for CommonJS.Use named import: import { deadCodeElimination } from 'babel-dead-code-elimination'.Set type: 'module' in package.json or use .mjs extension. Alternatively, use require.