Search code examples
javascriptnode.jses6-promiseesprima

Await not parsed in esprima 4.0.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


Solution

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

     esprima.parse("(async function() {await function_call()})()")