Babel-eslint: flow type annotations with default parameters in arrow functions fail eslint due to Parsing error: Assigning to rvalue

Created on 5 Oct 2015  路  8Comments  路  Source: babel/babel-eslint

If I have code like this:

`
let hello = (greeting:string = ' world') : string => {
console.log('hello' + greeting);
};

hello();
`

I get a babel-eslint error.

I created a repo to help reproduce it:

https://github.com/davidjnelson/flow-issues

For now I'll workaround by not using default parameters, but I'd sure like them :-) Thanks so much!

babel

Most helpful comment

This link now 404s:

I eventually learned that this was because Babel has switched to Phabricator for their issue tracking, where the Phabricator URL for that issue is here:

Annoyingly, the Phabricator issue doesn't contain any useful information, like the related commits or the version of Babel where this was integrated ... sheesh!

Yet more searching and I was eventually able to track down the commit where this was fixed:

However, the long and short of it is that you currently need to be using babel-eslint 5.0 (in Beta only at the time of writing) if you want to pick this fix up. I changed my config from ^4.1.6 to ^5.0.0-beta6 and now everything's working great :smile:.

All 8 comments

What is the error?

Ah, wow that was fast! :-) Sorry, forgot to paste the error:

Parsing error: Assigning to rvalue

If I don't use arrow functions it works fine, ie:

let hello = function (greeting:string = ' world') : string {
console.log('hello' + greeting);
};

hello();

This isn't a babel-eslint issue. It's a bug in the parser. Please report it on the babel repo.

Ok. Will do, thanks!

Ok, created: https://github.com/babel/babel/issues/2493

Thanks Sebastian!

This link now 404s:

I eventually learned that this was because Babel has switched to Phabricator for their issue tracking, where the Phabricator URL for that issue is here:

Annoyingly, the Phabricator issue doesn't contain any useful information, like the related commits or the version of Babel where this was integrated ... sheesh!

Yet more searching and I was eventually able to track down the commit where this was fixed:

However, the long and short of it is that you currently need to be using babel-eslint 5.0 (in Beta only at the time of writing) if you want to pick this fix up. I changed my config from ^4.1.6 to ^5.0.0-beta6 and now everything's working great :smile:.

@dchambers Thanks, I was looking at the same issue, you saved me precious time! :)

Was this page helpful?
0 / 5 - 0 ratings