
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
unreachable-branch-transform
Advanced tools
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.
npm install unreachable-branch-transform
// 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');
}
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.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'.
esmangle-evaluator is from the esmangle project.
FAQs
Browserify transform to remove unreachable code
The npm package unreachable-branch-transform receives a total of 8,749 weekly downloads. As such, unreachable-branch-transform popularity was classified as popular.
We found that unreachable-branch-transform demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.