Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] DCE is failed with block expression #1035

Open
SoloJiang opened this issue May 10, 2022 · 3 comments
Open

[Bug] DCE is failed with block expression #1035

SoloJiang opened this issue May 10, 2022 · 3 comments

Comments

@SoloJiang
Copy link

SoloJiang commented May 10, 2022

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
Copy link
Author

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

@SoloJiang
Copy link
Author

SoloJiang commented May 10, 2022

The reason of I updated the babel-plugin-minify-dead-code-elimination is the latest version @babel/traverse will remove the ThisExpression #1028

@SoloJiang
Copy link
Author

SoloJiang commented May 10, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant