1

Can't get the esprima 4.0.1 parser to work with 'await'. Having difficult times to find the relevant options that can be passed into the parse function for 'await', if that is possible.

Steps to reproduce

const esprima = require('esprima');
esprima.parse("await function_call()")

Expected output

Describing the code structure containing the await call

Actual output

Error: Line 1: Unexpected identifier

Stan Wiechers
  • 1,962
  • 27
  • 45
  • 1
    Just checked, Esprima 4.0.1 is perfectly happy to parse `await` in the correct context. (`await function_call()` is a syntax error outside of an `async` function -- not just in Esprima, but per spec.) – T.J. Crowder Oct 19 '18 at 15:58
  • Assumed that eprima can parse a partial without knowing the async context. Of course it can't. – Stan Wiechers Oct 19 '18 at 17:07

1 Answers1

3

Your code is a SyntaxError. await is only a keyword inside async functions:

 esprima.parse("(async function() {await function_call()})()")
Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151