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

in acorn_loose/statement.js recovered node for bogus import statements could be improved #409

Closed
othomann opened this issue May 5, 2016 · 2 comments

Comments

@othomann
Copy link

othomann commented May 5, 2016

I am using acorn 3.1.0, but this is still in master.
The following code reports an error when used with infer.js (from Tern) because there is no local for the corresponding import statement specifier.

   import * from "./exports"

I propose to replace line 378:

 if (this.eatContextual("as")) elt.local = this.parseIdent()

with:

elt.local = this.eatContextual("as") ? this.parseIdent() : this.dummyIdent();

Doing this we make sure that the specifier has a local (recovered in this case). acorn will properly reports a syntax error on the 'from' and infer.js won't fail anymore.

infer.js has the following code:

    ImportDeclaration: function(node, scope) {
      for (var i = 0; i < node.specifiers.length; i++)
        addVar(scope, node.specifiers[i].local)
    }

So without a local being set to a recovered node, addVar fails with: TypeError: Cannot read property 'name' of undefined.

@RReverser
Copy link
Member

Sounds good to me. But really, it's better to just send a PR instead of an issue when you already identified what needs to be changed. Would you want to do that?

@othomann
Copy link
Author

othomann commented May 6, 2016

Ok, I'll prepare one. Thanks.

othomann added a commit to othomann/acorn that referenced this issue May 6, 2016
othomann added a commit to othomann/acorn that referenced this issue May 6, 2016
othomann added a commit to othomann/acorn that referenced this issue May 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants