eslint / espree

An Esprima-compatible JavaScript parser
BSD 2-Clause "Simplified" License
2.26k stars 189 forks source link

Should throw on `async () => await 5 ** 6;` #472

Closed fisker closed 3 years ago

fisker commented 3 years ago

espree parse this as await (5 ** 6)

require('espree').parse('async () => await 5 ** 6', {ecmaVersion: 2017}).body[0].expression.body
Node {
  type: 'AwaitExpression',
  start: 12,
  end: 24,
  argument: Node {
    type: 'BinaryExpression',
    start: 18,
    end: 24,
    left: Node { type: 'Literal', start: 18, end: 19, value: 5, raw: '5' },
    operator: '**',
    right: Node { type: 'Literal', start: 23, end: 24, value: 6, raw: '6' }
  }
}

In chrome, this is a syntax error

async () => await 5 ** 6
VM40:1 Uncaught SyntaxError: Unary operator used immediately before exponentiation expression. Parenthesis must be used to disambiguate operator precedence

Babel PR babel/babel#12441

nzakas commented 3 years ago

Can you please provide details in this issue? A link to a PR isn’t enough for us to evaluate this.

fisker commented 3 years ago

I updated the issue description.

nzakas commented 3 years ago

Thanks. This is actually an issue with Acorn, which Espree wraps. I’d suggest opening an issue there. We can pull in the updated version when it’s fixed.

fisker commented 3 years ago

I think acorn already fixed it https://github.com/acornjs/acorn/commit/848d14e20653a211b06c8e167810bd4fae2173cf

nzakas commented 3 years ago

Awesome, then we can look at incorporating it.

mdjermanovic commented 3 years ago

@fisker it seems that the latest Acorn still doesn't throw an error on this particular example. Can you open an issue on https://github.com/acornjs/acorn repository?

robpalme commented 3 years ago

@mdjermanovic as you requested, I have opened an issue and created a PR to fix this in Acorn.

fisker commented 3 years ago

Somehow, I missed this. Thank you @robpalme!

mdjermanovic commented 3 years ago

@robpalme thanks!

robpalme commented 3 years ago

This is now fixed in the Acorn 8.2.2 release.

nzakas commented 3 years ago

You are my hero @robpalme. Thank you.