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

"Cannot read property 'start' of null" #630

Closed
trisys3 opened this issue Jul 13, 2017 · 6 comments
Closed

"Cannot read property 'start' of null" #630

trisys3 opened this issue Jul 13, 2017 · 6 comments
Labels
bug Confirmed bug has PR Has an open PR that fixes this issue

Comments

@trisys3
Copy link

trisys3 commented Jul 13, 2017

Whenever I try to run babel with the full babili preset, I get an error from babel-plugin-transform-remove-undefined:

events.js:160
      throw er; // Unhandled 'error' event
      ^
TypeError: app/app.js: Cannot read property 'start' of null
    at /path/to/project/node_modules/babel-plugin-transform-remove-undefined/lib/index.js:71:32
    at Array.some (native)
    at hasViolation (/path/to/project/node_modules/babel-plugin-transform-remove-undefined/lib/index.js:68:46)
    at PluginPass.VariableDeclaration (/path/to/project/node_modules/babel-plugin-transform-remove-undefined/lib/index.js:192:69)
    at newFn (/path/to/project/node_modules/ec-core/node_modules/babel-traverse/lib/visitors.js:276:21)
    at NodePath._call (/path/to/project/node_modules/ec-core/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/path/to/project/node_modules/ec-core/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/path/to/project/node_modules/ec-core/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/path/to/project/node_modules/ec-core/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitMultiple (/path/to/project/node_modules/ec-core/node_modules/babel-traverse/lib/context.js:103:17)
    at TraversalContext.visit (/path/to/project/node_modules/ec-core/node_modules/babel-traverse/lib/context.js:190:19)
    at Function.traverse.node (/path/to/project/node_modules/ec-core/node_modules/babel-traverse/lib/index.js:114:17)

I tried this with only babel-preset-env and babili. I am using so much ES6 that esprima does not know what to do without at least some plugins. I get "Invalid left-hand side in assignment".

I noticed that the referenced plugin, babel-plugin-transform-remove-undefined, is not in the list of plugins on the main babili README file, either in the main section or in the "Other" section, so I can just copy all the plugins in the main section and use the ones that I want from the "Other" section, and everything works fine. With npm 3, I can even do this without installing all the plugins individually, as long as I remember to install babili itself.

What is the plugin transform-remove-undefined, and why is it not in the plugin list on babili's README file? Is it not finished or deprecated, or is it an internal plugin that babili always uses?

@vigneshshanmugam
Copy link
Member

vigneshshanmugam commented Jul 13, 2017

Hey, By default transform-remove-undefined is applied on the plugins list. Can you give a minimal code to reproduce this issue?

Check the list of defaults here - https://github.com/babel/babili/tree/master/packages/babel-preset-babili#options

There was a similar issue before #615 and it got fixed already in master. We have not released a new version though.

@trisys3
Copy link
Author

trisys3 commented Jul 13, 2017

OK, I will try to get a minimal example running.

If babel-plugin-transform-remove-undefined is part of babili, why is it not documented on babili's README? I am just wondering, as that seems like an omission.

@trisys3
Copy link
Author

trisys3 commented Jul 13, 2017

Versions:

babel-cli: 6.24.1
babili: 0.1.4
babel-preset-env: 1.6.0 (seems to be a conflict between env and babili)

.babelrc:

{
    'presets': [
        'env',
        'babili',
    ],
}

The smallest example I could get is:

const obj = {cat: 'dog'};

let cat;

({cat} = obj);

If I specify a value for cat at the start, I do not get the error:

const obj = {cat: 'dog'};

let cat = '';

({cat} = obj);

It seems to happen only if cat is not specified or is undefined; if I set cat to null at the start, or pretty much anything else, I do not get the error.

The error only shows up if I declare the variable beforehand then attempt to change it with destructuring; if I declare it and set it at the same time, using either const or let, I do not get the error:

const obj = {};
const {cat} = obj;

With all this being said, an easy way to avoid this bug is by setting a value at the start, but it is still an unexpected, hard-to-track-down bug that should be fixed. If you need any more information, just ask.

@vigneshshanmugam
Copy link
Member

Awesome, Thanks for the detailed writeup. Really helpful. Seems to be a bug still in master, Will have a look.

@vigneshshanmugam vigneshshanmugam added the bug Confirmed bug label Jul 14, 2017
@trisys3
Copy link
Author

trisys3 commented Jul 14, 2017

No problem, glad I could help. Thanks for the great plugin and getting back so quickly!

@vigneshshanmugam vigneshshanmugam added the has PR Has an open PR that fixes this issue label Jul 14, 2017
@trisys3
Copy link
Author

trisys3 commented Jul 17, 2017

Looks like it works, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug has PR Has an open PR that fixes this issue
Projects
None yet
Development

No branches or pull requests

2 participants