Skip to content

if..else dead_code elimination - preserve vars #48

@boopathi

Description

@boopathi
if ( 0 ) {
  var x = foo();
}

// or
if (0) var x = bar();

out:

var x;

This can either be done by hoisting vars for all functions before IfStatement is reached, or by analysing the pathToBeRemoved for var declarations.

I tried the latter approach here - https://github.com/boopathi/babel-minify/blob/0fbb45d18b13df53dd225dbd36ef0af88c7190ea/packages/babel-plugin-transform-conditionals/src/replace-with.js#L65-L88

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions