[Bug] DCE is failed with block expression
- Dominant language
- JavaScript
- Stars
- 4.4k
- Forks
- 217
- PR merge metrics
- No merged PRs in 30d
Description
### Code
```javascript
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
```javascript
let isWeb = true;
{
if (isWeb) {
console.log('xyz');
} else {
console.log('abcd');
}
}
```
### Expected
```javascript
let isWeb = true;
{
console.log('xyz');
}
```
Contributor guide
Research direction
Start by running the JavaScript reproduction from the issue with babel-plugin-minify-dead-code-elimination and compare its output with the expected result. Trace the plugin entry point and the handling of the shown block expression, then add coverage for this example and confirm that the unreachable else branch is removed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- babel, javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100