unreachable-branch-transform

WebJar for unreachable-branch-transform

License

License

MIT
Categories

Categories

ORM Data
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

unreachable-branch-transform
Last Version

Last Version

0.5.1
Release Date

Release Date

Type

Type

jar
Description

Description

unreachable-branch-transform
WebJar for unreachable-branch-transform
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/zertosh/unreachable-branch-transform

Download unreachable-branch-transform

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/unreachable-branch-transform/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>unreachable-branch-transform</artifactId>
    <version>0.5.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/unreachable-branch-transform/
implementation 'org.webjars.npm:unreachable-branch-transform:0.5.1'
// https://jarcasting.com/artifacts/org.webjars.npm/unreachable-branch-transform/
implementation ("org.webjars.npm:unreachable-branch-transform:0.5.1")
'org.webjars.npm:unreachable-branch-transform:jar:0.5.1'
<dependency org="org.webjars.npm" name="unreachable-branch-transform" rev="0.5.1">
  <artifact name="unreachable-branch-transform" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='unreachable-branch-transform', version='0.5.1')
)
libraryDependencies += "org.webjars.npm" % "unreachable-branch-transform" % "0.5.1"
[org.webjars.npm/unreachable-branch-transform "0.5.1"]

Dependencies

compile (2)

Group / Artifact Type Version
org.webjars.npm : esmangle-evaluator jar [1.0.0,2)
org.webjars.npm : recast jar [0.11.4,0.12)

Project Modules

There are no modules declared in this project.

unreachable-branch-transform

Build Status

Removes unreachable code branches in if statements, ternaries ?, and logical operations || &&, where the test is determinable (like comparing two constants). This is similar to what UglifyJS's "dead_code" compressor option does, but without the extra code transformations.

When combined with something like envify and browserify, you can perform conditional require calls without including more code than you need.

Install

npm install unreachable-branch-transform

Example outputs

// original 
var transport = process.env.TARGET === 'client' ? require('ajax') : require('fs');

// after envify
var transport = 'server' === 'client' ? require('ajax') : require('fs');
// then after unreachable-branch-transform
var transport = require('fs');
// original
if (process.env.NODE_ENV === 'development') {
  console.log('in dev mode');
} else {
  console.log('in some other mode');
}

// after envify
if ('production' === 'development') {
  console.log('in dev mode');
} else {
  console.log('in some other mode');
}

// then after unreachable-branch-transform
{
  console.log('in some other mode');
}

Usage

  • unreachable-branch-transform can be used a browserify transform. Just include it like any other transform.
  • unreachable-branch-transform can also be used on raw code by calling the transform function exposed by requiring the package.

Frequently asked questions

Why are undefined equality references not removed?

If you have a branch with the format

if (undefined === 'production') {
  /* ... */
}

it will not be removed. Unfortunately, undefined is not a constant in older browser runtimes and can be reassigned. In this case, it could be possible that undefined does indeed equal 'production'.

Credit

esmangle-evaluator is from the esmangle project.

Versions

Version
0.5.1
0.3.0