Cannot read property 'add' of undefined
- Dominant language
- JavaScript
- Stars
- 4.4k
- Forks
- 217
- PR merge metrics
- No merged PRs in 30d
Description
seeing " Cannot read property 'add' of undefined" with the latest
sample code, *junk.js*
```
const y = () => {};
function x(foo = y) {}
```
command: *npx babel junk.js --presets=minify*
*package.json*
```
{
"name": "babelbug",
"version": "1.0.0",
"description": "",
"devDependencies": {
"@babel/core": "^7.7.0",
"@babel/preset-env": "^7.7.0",
"@babel/cli": "^7.7.0",
"babel-preset-minify": "~0.5.0"
}
}
```
stack
```
{ TypeError: C:\babelbug\junk.js: Cannot read property 'add' of undefined
at ScopeTracker.addReference (C:\babelbug\node_modules\babel-plugin-minify-mangle-names\lib\scope-tracker.js:47:34)
at ReferencedIdentifier (C:\babelbug\node_modules\babel-plugin-minify-mangle-names\lib\index.js:196:26)
at newFn (C:\babelbug\node_modules\@babel\traverse\lib\visitors.js:220:17)
at bfsTraverse (C:\babelbug\node_modules\babel-plugin-minify-mangle-names\lib\bfs-traverse.js:32:43)
at Mangler.collect (C:\babelbug\node_modules\babel-plugin-minify-mangle-names\lib\index.js:229:7)
at Mangler.run (C:\babelbug\node_modules\babel-plugin-minify-mangle-names\lib\index.js:54:12)
at PluginPass.exit (C:\babelbug\node_modules\babel-plugin-minify-mangle-names\lib\index.js:558:19)
at newFn (C:\babelbug\node_modules\@babel\traverse\lib\visitors.js:179:21)
at NodePath._call (C:\babelbug\node_modules\@babel\traverse\lib\path\context.js:55:20)
at NodePath.call (C:\babelbug\node_modules\@babel\traverse\lib\path\context.js:42:17) code: 'BABEL_TRANSFORM_ERROR' }
```
Contributor guide
Research direction
Reproduce the failure with junk.js and the npx babel junk.js --presets=minify command. Start in node_modules/babel-plugin-minify-mangle-names/lib/scope-tracker.js at ScopeTracker.addReference, then follow the callers in index.js shown in the stack. Done means the sample completes without the undefined add error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100