babel-plugin-minify-dead-code-elimination-while-loop-fixed

raw JSON →
0.3.1 verified Sat Apr 25 auth: no javascript

A forked and fixed version of babel-plugin-minify-dead-code-elimination from Babel minify 0.3.x. It inlines bindings, evaluates expressions, and removes unreachable code. This plugin specifically addresses a bug related to while loops (issue #11343). Current stable version: 0.3.1. No regular release cadence; maintained sporadically. Key differentiator: fixes a specific loop elimination bug not present in the original plugin.

error Error: Cannot find module 'babel-plugin-minify-dead-code-elimination-while-loop-fixed'
cause Plugin not installed or typo in module name.
fix
Run npm install babel-plugin-minify-dead-code-elimination-while-loop-fixed --save-dev
error TypeError: The plugin "minify-dead-code-elimination-while-loop-fixed" didn't return a function.
cause Using ESM import instead of require(). The plugin exports via module.exports.
fix
Use require() in Node.js or configure Babel with the string plugin name in .babelrc.
error Error: .babelrc: plugins[0] must be a string or an array of [string, options]
cause Options not nested correctly in an array.
fix
Use [["minify-dead-code-elimination-while-loop-fixed", { ... }]] syntax.
breaking Plugin uses deprecated babel-core API (babel.transform). May not work with Babel 7+.
fix Upgrade to @babel/core and use @babel/plugin-transform-modules-commonjs or similar. Alternatively, stick with Babel 6.
gotcha Plugin only works as a Babel plugin; it cannot be used standalone.
fix Ensure Babel is installed and the plugin is declared in the Babel configuration.
gotcha Options must be nested correctly: [["minify-dead-code-elimination-while-loop-fixed", options]].
fix Use the correct array nesting pattern shown in the documentation.
deprecated The original babel-plugin-minify-dead-code-elimination is deprecated in favor of babel-preset-minify.
fix Consider using babel-preset-minify for a comprehensive minification setup.
npm install babel-plugin-minify-dead-code-elimination-while-loop-fixed
yarn add babel-plugin-minify-dead-code-elimination-while-loop-fixed
pnpm add babel-plugin-minify-dead-code-elimination-while-loop-fixed

Shows how to install and configure the plugin in .babelrc, and the effect of dead code elimination.

// Install the plugin
// npm install babel-plugin-minify-dead-code-elimination-while-loop-fixed

// .babelrc example
{
  "presets": ["@babel/preset-env"],
  "plugins": ["minify-dead-code-elimination-while-loop-fixed"]
}

// Input code
function foo() { var x = 1; }
function bar() { var x = f(); }
function baz() {
  var x = 1;
  console.log(x);
  function unused() { return 5; }
}

// After transformation (output)
// function foo() {}
// function bar() { f(); }
// function baz() {
//   console.log(1);
// }