babel / babel/minify

After executing my plug-in after the minify-dead-code-elimination, I still get the deleted dead code in my plug-in

Open
#1,014 0 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

After executing my plug-in after the minify-dead-code-elimination, I still get the deleted dead code in my plug-in

**To Reproduce**

Minimal code to reproduce the bug

babel.config.js
```js
const path = require('path');

module.exports = {
plugins: [
"minify-dead-code-elimination",
path.resolve(__dirname, 'plugin/my-plugin.js')
]
};
```
src/index.js
```js
import strA from './a.js'
console.log('b')
if(false){
console.log(strA)
}

my-plugin.js

```js
module.exports = function (babel) {
return {
visitor: {
Identifier(path) {
const { name } = path.node
name === 'strA' && console.log(path.node)
}
}
};
};
```

**Actual Output**

Print the result of console.log
```
Node {
type: 'Identifier',
start: 68,
end: 72,
loc: SourceLocation {
start: Position { line: 4, column: 14 },
end: Position { line: 4, column: 18 },
filename: undefined,
identifierName: 'strA'
},
range: undefined,
leadingComments: undefined,
trailingComments: undefined,
innerComments: undefined,
extra: undefined,
name: 'strA'
}
```

so ```console.log(strA)``` in the ```if(false)``` code block is not deleted

**Expected Output**

When my plug-in is behind the deadcode plug-in, my plug-in should not get the dead code that was removed

"babel-plugin-minify-dead-code-elimination": "^0.5.1"
"@babel/core": "7.14.6",

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.