babel / babel/minify

`path.remove` sometimes throws

Open
#300 6 comments 0 reactions 0 assignees View on GitHub
babel bug
Dominant language
JavaScript
Stars
4.4k
Forks
217
PR merge metrics
No merged PRs in 30d

Description

We should probably address this in Babel, but I'm occasionally running into cases of `path.remove()` throwing error about context:

Here's an example from trying to run Nuclide codebase through Babili:

```
➜ Nuclide ./scripts/dev/release_transpile.js
7 workers. 1863 files...
Error transpiling "/Users/kangax/fbsource/fbobjc/Tools/Nuclide/pkg/fb-biggrep-cli/lib/biggrep.js"
/Users/kangax/fbsource/fbobjc/Tools/Nuclide/pkg/nuclide-node-transpiler/lib/NodeTranspiler.js:203
throw err;
^

TypeError: unknown: Property consequent of ConditionalExpression expected node to be of a type ["Expression"] but instead got null
at Object.validate (/Users/kangax/fbsource/fbobjc/Tools/Nuclide/node_modules/babel-types/lib/definitions/index.js:109:13)
at Object.validate (/Users/kangax/fbsource/fbobjc/Tools/Nuclide/node_modules/babel-types/lib/index.js:511:9)
at NodePath._replaceWith (/Users/kangax/fbsource/fbobjc/Tools/Nuclide/node_modules/babel-traverse/lib/path/replacement.js:176:7)
at NodePath._remove (/Users/kangax/fbsource/fbobjc/Tools/Nuclide/node_modules/babel-traverse/lib/path/removal.js:58:10)
at NodePath.remove (/Users/kangax/fbsource/fbobjc/Tools/Nuclide/node_modules/babel-traverse/lib/path/removal.js:30:8)
at PluginPass.CallExpression (/Users/kangax/fbsource/fbobjc/Tools/Nuclide/node_modules/babel-plugin-transform-remove-console/lib/index.js:10:16)
at newFn (/Users/kangax/fbsource/fbobjc/Tools/Nuclide/node_modules/babel-traverse/lib/visitors.js:276:21)
at NodePath._call (/Users/kangax/fbsource/fbobjc/Tools/Nuclide/node_modules/babel-traverse/lib/path/context.js:76:18)
at NodePath.call (/Users/kangax/fbsource/fbobjc/Tools/Nuclide/node_modules/babel-traverse/lib/path/context.js:48:17)
at NodePath.visit (/Users/kangax/fbsource/fbobjc/Tools/Nuclide/node_modules/babel-traverse/lib/path/context.js:105:12)
```

I narrowed it down to a combination of simplify and remove-console plugins, but there might be something else. The source code doesn't have anything unusual; just few expressions with `console.log` and `console.error`.

Temporary solution could be to wrap `path.remove()` in try/catch. Ideal one would be to find out what's causing this and fix it in Babel.

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.