minification.deadCodeElimination

How to use the minification.deadCodeElimination transformer.

Remove dead code.

Usage

require("babel").transform("code", { optional: ["minification.deadCodeElimination"] });
$ babel --optional minification.deadCodeElimination script.js

Examples

Always truthy if statements

In

if (true) {
  foo();
} else {
  bar();
}

Out

foo();

Always falsey if statements

In

if (false) {
  foo();
} else {
  bar();
}

Out

bar();

Empty alternate blocks

In

if (foo) {
} else {
  bar();
}

Out

if (!foo) {
  bar();
}

Empty consequent blocks

In

if (foo) {
  bar();
} else {
}

Out

if (foo) {
  bar();
}

Truthy conditional expressions

In

true ? foo : bar

Out

foo

Falsy conditional expressions

In

false ? foo : bar

Out

bar

Unused class declarations

In

class Foo {}
class Bar {}
new Foo;

Out

class Foo {}
new Foo;

Unused function declarations

In

function foo() {}
function bar() {}
foo();

Out

function foo() {}
foo();

Pure values used only once

In

var foo = "bar";
bar(foo);

Out

bar("bar");