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

path.remove sometimes throws #300

Open
kangax opened this issue Nov 26, 2016 · 6 comments
Open

path.remove sometimes throws #300

kangax opened this issue Nov 26, 2016 · 6 comments
Labels
babel This is an issue in the upstream project - Babel bug Confirmed bug

Comments

@kangax
Copy link
Member

kangax commented Nov 26, 2016

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.

@kangax kangax added the bug Confirmed bug label Nov 26, 2016
@kangax
Copy link
Member Author

kangax commented Nov 26, 2016

The problem could be us transforming if (x) { console.log('...') } to if (x) { } and then trying to turn that to x && ... where the RHS doesn't exist? Or something along those lines.

@kangax
Copy link
Member Author

kangax commented Nov 26, 2016

facebook/react-native#10412 seems related (as brought up by @danez)

@boopathi
Copy link
Member

Hmmm.. I tried reproducing that in babel.

http://astexplorer.net/#/G38YR5EEES

@danez
Copy link
Member

danez commented Nov 26, 2016

It seems in a lot of cases console.log cannot just simply be removed but would rather need to be replaced by something.

In the example I replaced it with undefined.

http://astexplorer.net/#/G38YR5EEES/2

@boopathi
Copy link
Member

boopathi commented Nov 26, 2016

@danez

Ah. That makes sense. When we remove, we have to know the context of where it is. But doesn't babel's path.remove already do this? It inserts an EmptyStatement or a BlockStatement when you remove node.consequent or alternate in a IfStatement.

@danez
Copy link
Member

danez commented Nov 26, 2016

Maybe this is broken.

Interestingly if i do:

var t = () => console.log('1st');

it turns correctly into:

var t = () => void 0;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
babel This is an issue in the upstream project - Babel bug Confirmed bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants