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

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

Open
951565664 opened this issue Jun 23, 2021 · 0 comments

Comments

@951565664
Copy link

951565664 commented Jun 23, 2021

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

const path = require('path');

module.exports = {
  plugins: [
      "minify-dead-code-elimination",
      path.resolve(__dirname, 'plugin/my-plugin.js')
  ]
};

src/index.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",

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