TypeError: unknown: Cannot read property ‘end’ of null
- Dominant language
- JavaScript
- Stars
- 4.4k
- Forks
- 217
- PR merge metrics
- No merged PRs in 30d
Description
Combining presets `env` (1.7.0) and `minify` (0.4.3) and `babel-core` 6.26.3 with this code:
```js
var a = function() {
var b;
class a {};
return a;
};
```
throws:
```
node_modules/babel-core/lib/transformation/file/index.js:558
throw err;
^
TypeError: unknown: Cannot read property 'end' of null
at _evaluate (node_modules/babel-core/node_modules/babel-traverse/lib/path/evaluation.js:159:58)
at evaluate (node_modules/babel-core/node_modules/babel-traverse/lib/path/evaluation.js:65:17)
at NodePath.evaluate (node_modules/babel-core/node_modules/babel-traverse/lib/path/evaluation.js:41:15)
at evaluateIdentifier (node_modules/babel-helper-evaluate-path/lib/index.js:127:15)
at evaluate (node_modules/babel-helper-evaluate-path/lib/index.js:19:12)
at isPureAndUndefined (node_modules/babel-plugin-transform-remove-undefined/lib/index.js:26:22)
at PluginPass.ReturnStatement (node_modules/babel-plugin-transform-remove-undefined/lib/index.js:157:15)
at newFn (node_modules/babel-core/node_modules/babel-traverse/lib/visitors.js:276:21)
at NodePath._call (node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:76:18)
at NodePath.call (node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:48:17)
at NodePath.visit (node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:105:12)
...
```
You can [see the error in the REPL](https://babeljs.io/repl/#?babili=true&browsers=&build=&builtIns=false&spec=false&loose=false&code_lz=G4QwTgBCELwQZgVwHYGMAuBLA9sgFAJQQDeAUBBKJAEYDc5EqANiAM6tQkC-9FYApukRhkUej1JA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&sourceType=script&lineWrap=true&presets=babili%2Cenv&prettier=false&targets=&version=6.26.0&envVersion=1.6.2). The same error appears for `babel-core` 7.0.0-beta.3 and `babel-minify` 0.5.0-alpha.3cc09dcf.
The real-world case is trying to minify [this file](https://github.com/jashkenas/coffeescript/blob/be702d67f3b5d464c12cdbe9826a496e62e6955e/lib/coffeescript/sourcemap.js) via [this code](https://github.com/jashkenas/coffeescript/blob/7f8b36a8bde340b1039423ecc0e10ec0546e15bd/Cakefile#L69-L81).
Probably related to #847 and #614.
**Workaround**: Pass the options `evaluate: false` and `removeUndefined: false`, as in `[['env'], ['minify', {evaluate: false, removeUndefined: false}]]` to disable [`babel-plugin-minify-constant-folding `](https://github.com/babel/minify/tree/master/packages/babel-plugin-minify-constant-folding) and [`babel-plugin-transform-remove-undefined`](https://github.com/babel/minify/tree/master/packages/babel-plugin-transform-remove-undefined).
Contributor guide
Assessment
This issue has not been assessed yet.