minify icon indicating copy to clipboard operation
minify copied to clipboard

[Bug] DCE is failed with block expression

Open SoloJiang opened this issue 3 years ago • 3 comments

Code

const { transform } = require('@babel/core');

console.log(
  transform(
    `let isWeb = true;
    {
      if (isWeb) {
        console.log('xyz');
      } else {
        console.log('abcd');
      }
    }
`,
    {
      plugins: ['babel-plugin-minify-dead-code-elimination'],
    }
  )
);

If code with a block expression, it will not remove the console.log('abcd');

Output

let isWeb = true;
    {
      if (isWeb) {
        console.log('xyz');
      } else {
        console.log('abcd');
      }
    }

Expected

let isWeb = true;
    {
      console.log('xyz');
    }

SoloJiang avatar May 10 '22 08:05 SoloJiang

babel-plugin-minify-dead-code-elimination v0.3.0 is the expected output.

SoloJiang avatar May 10 '22 08:05 SoloJiang

The reason of I updated the babel-plugin-minify-dead-code-elimination is the latest version @babel/traverse will remove the ThisExpression https://github.com/babel/minify/issues/1028

SoloJiang avatar May 10 '22 08:05 SoloJiang

In my view, is it a break change for @babel/traverse ?

SoloJiang avatar May 10 '22 08:05 SoloJiang