Incorrect output in minify-dead-code-elimination
- Dominant language
- JavaScript
- Stars
- 4.4k
- Forks
- 217
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
A strange edge case code does not get eliminated correctly.
**To Reproduce**
Minimal code to reproduce the bug
```js
function b() {}
function a() {
if ('production' === 'production') {
return
}
var c = b()
if (!c) {
return
}
}
```
**Actual Output**
If there is no Error thrown,
```js
function b() {}
function a() {
var c = b();
}
```
**Expected Output**
```js
function b() {}
function a() {
}
```
**Configuration**
How are you using babel-minify?
`babel dependency`
babel version : `7.0.0-beta.3`
Used stand alone using the Node Api + babel-core
```json5
{
plugins: [],
presets: []
}
```
**Additional context**
See it in action in the [babel-repl](https://babeljs.io/repl#?babili=false&browsers=&build=&builtIns=false&spec=false&loose=false&code_lz=GYVwdgxgLglg9mABAIwBQEpEG8C-AoPUSWBRAQw2z0URmEVQHIAHAJzgBMRp4xHEAvEMQt2XHgkaYs1GolYBTKCFZhZ-WQDcyrRBEEoMBGnQYBCCNNk1Fy1erz4gA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=react%2Cstage-2&prettier=false&targets=&version=6.26.0&envVersion=)
Encountered this construction [here](https://github.com/atlassian/react-beautiful-dnd/blob/b276e4780c42ad662400631c9f315edc791a9cd8/src/view/droppable-dimension-publisher/droppable-dimension-publisher.jsx#L53-L77)
Tried to recreate it as minimal as possible using only babel-core and the dead-code plugin
Contributor guide
Research direction
Reproduce the example with babel-core and the minify-dead-code-elimination plugin, using the JavaScript snippet and configuration in the issue. Trace the plugin's handling of the unreachable branch and add or update a regression test if the repository provides one; done means the temporary variable and unreachable code are eliminated as shown in the expected output.
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
- 42/100