Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unreachable-branch-transform

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unreachable-branch-transform

Browserify transform to remove unreachable code

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8.1K
decreased by-14.09%
Maintainers
1
Weekly downloads
 
Created
Source

unreachable-branch-transform

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.

Credit

lib/evaluator.js is from the esmangle project.

Keywords

FAQs

Package last updated on 24 Jan 2015

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc