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

Rest operator in function argument declaration throws "Parsing error Invalid left-hand side in formals list" #243

Closed
jaapz opened this issue Jan 22, 2016 · 11 comments

Comments

@jaapz
Copy link

jaapz commented Jan 22, 2016

When I run eslint on code like this:

{
    initialize({someVar, otherVar, ...options}) {
        // ... do some stuff with options ...
    }
}

I get the error: "Parsing error: Invalid left-hand side in formals list".

This was already reported on eslint, but there it was mentioned that this should be reported on espree, and I cannot find any issue on this project about this so I created this one.

I have experimentalObjectSpread: true in my .eslintrc.

@nzakas
Copy link
Member

nzakas commented Jan 22, 2016

What version are you using?

@ilyavolodin
Copy link
Member

The flag name is actually experimentalObjectRestSpread, not experimentalObjectSpread. So maybe that's the issue?

@jaapz
Copy link
Author

jaapz commented Jan 22, 2016

@ilyavolodin I actually typo'd in the issue here, I've got the correct flag name in my .eslintrc.
@nzakas espree@2.2.5 which apparently comes with eslint@1.10.3.

@nzakas
Copy link
Member

nzakas commented Jan 22, 2016

Okay, this might be fixed in 3.0.0. Can you check the master branch of ESLint to see if you're still having the problem?

@jaapz
Copy link
Author

jaapz commented Jan 23, 2016

When I install the master branch of eslint using npm install eslint/eslint#master, the error seems to be replaced by a different one:

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

Which is reported on the first import of the file.

I have no idea why this is, and I can't find any documentation on sourceType: module.

I'm not sure this actually fixes the problem though, as eslint seems to crap out directly after seeing a Parsing error. So it might be that the error still persists, but eslint just doesn't get to the line with the spread operator.

@nzakas
Copy link
Member

nzakas commented Jan 23, 2016

2.0.0 has different options, see http://eslint.org/docs/2.0.0/user-guide/migrating-to-2.0.0#language-options.

I'd also suggest using --no-eslintrc for a sanity check as some rules are different.

@jaapz
Copy link
Author

jaapz commented Jan 23, 2016

Ok, I followed the guide and moved my config to the 2.0.0 options.
These are the results:

jaapz at tommy in <REDACTED> (master●) (.env)
$ eslint <REDACTED>/page.js
<REDACTED>/page.js
  42:56  error  Parsing error: Unexpected token ..

✖ 1 problem (1 error, 0 warnings)


jaapz at tommy in <REDACTED> (master●) (.env)
$ eslint <REDACTED>/page.js --no-eslintrc

<REDACTED>/page.js
  1:1  error  Parsing error: The keyword 'import' is reserved

✖ 1 problem (1 error, 0 warnings)

So the problem exists, but it's a different error message now, it still points to the ...options though.

When running with --no-eslintrc the ES6 config isn't loaded so it doesn't understand the import statement.

@nzakas
Copy link
Member

nzakas commented Jan 25, 2016

OK thanks, I'll take a look.

nzakas added a commit that referenced this issue Jan 25, 2016
@nzakas
Copy link
Member

nzakas commented Jan 25, 2016

I've tried this a couple of times and I'm unable to reproduce. I added your exact code as a test and it parses fine: #244

Is it possible you have a typo in your config file? For ESLint 2.0.0, you'd need a config that looks like this:

{
    "parserOptions": {
        "ecmaVersion": 6,
        "ecmaFeatures": {
            "experimentalObjectRestSpread": true
        }
    }
}

@jaapz
Copy link
Author

jaapz commented Jan 26, 2016

Thanks, I'm not sure if I have the correct config then for eslint 2.0.0. I'll check later when I get back to my laptop.

@nzakas
Copy link
Member

nzakas commented Feb 2, 2016

This was definitely broken in Espree 2.x. In Espree 3.x, it was also broken, but was fixed in #249.

@nzakas nzakas closed this as completed Feb 2, 2016
nzakas added a commit that referenced this issue Feb 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants