[Bug]: @babel/traverse v7.17.10 broken `this` scope with dead code elimination plugin
- Dominant language
- JavaScript
- Stars
- 4.4k
- Forks
- 217
- PR merge metrics
- No merged PRs in 30d
Description
### 💻
- [ ] Would you like to work on a fix?
### How are you using Babel?
@babel/cli
### Input code
Reproduced in [Babel REPL](https://babel.dev/repl#?browsers=defaults%2C%20not%20ie%2011%2C%20not%20ie_mob%2011&build=&builtIns=false&corejs=3.21&spec=false&loose=false&code_lz=MYGwhgzhAEBiD28BGYBO0DeAoa1jwDsIAXVAV2GPlQAoBKTHXaYgCwEsIA6AM0RXQBeaABYATAG4muGvWiCAfI2bN2PaDTade_NNACEg4eIbYVKtqngB3aAQCmtgKKortAORaYfZGnsATdzopc2gAX2lwunoQ8KwI_CJiaB95O0c4XVpgrCA&debug=false&forceAllTransforms=true&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=false&presets=env&prettier=false&targets=&version=7.17.11&externalPlugins=babel-plugin-minify-dead-code-elimination%400.5.1&assumptions=%7B%7D).
### Configuration file name
_No response_
### Configuration
_No response_
### Current and expected behavior
Enabling `babel-plugin-minify-dead-code-elimination` plugin destroys `this` scope for arrow functions inside classes.
The `var _this = this` workaround should not be eliminated as it is absolutely necessary for the `this` scope to work in locally defined arrow functions.
### Environment
- Babel version v7.17.11
### Possible solution
_No response_
### Additional context
I narrowed the problem down locally to `@babel/traverse` v7.17.10. By reverting that package to v7.17.9 this problem does not occur.
Contributor guide
Research direction
Start with the Babel REPL reproduction and the babel-plugin-minify-dead-code-elimination configuration described in the issue. Compare behavior with @babel/traverse v7.17.10 and v7.17.9, focusing on arrow functions inside classes and the `var _this = this` workaround. Done means the workaround is preserved and the reproduced transformation retains the correct `this` scope.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100