babel / babel/minify

[Bug] DCE is failed with block expression

Open
#1,035 3 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.