Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Wrapping a UnaryExpression and an exponential base in parentheses gives error #26

Closed
oskardahlberg opened this issue Apr 30, 2016 · 3 comments
Labels

Comments

@oskardahlberg
Copy link

oskardahlberg commented Apr 30, 2016

Both expressions below produces the same error(using the babel online repl in various settings),
"Illegal expression. Wrap left hand side or entire exponentiation in parentheses."

(-2) ** 2;
((-2) ** 2);

According to this reference it should work,
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Exponentiation

Looking briefly at the source,

if (node.operator === "**" && left.type === "UnaryExpression" && left.extra && !left.extra.parenthesizedArgument) {

My best guess is that it should also check if "left.extra.paranthesized" is false!

Cheers

@jmm
Copy link
Member

jmm commented Apr 30, 2016

Thanks @oskardahlberg. I noticed that too and it seems like a bug to me.

@kaicataldo
Copy link
Member

Looks like this has actually been fixed 🎉 https://github.com/babel/babylon/blob/master/src/parser/expression.js#L191-L199

@danez
Copy link
Member

danez commented Sep 5, 2016

Yes this was Fixed in 6.9.0

@danez danez closed this as completed Sep 5, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants