How do i create an await expression using recast/esprima

179 Views Asked by At

I have a js function

export const cleanUp = async () => {
    await User.destroy({ where: {} });
};

I am trying to insert a line below await User.destroy({ where: {} }) using

recast.parse(`await ${module}.destroy({ where: {} });`);

But I keep. getting Unexpected Identifier because esprima expects an async declaration. How else can I achieve this?

1

There are 1 best solutions below

0
fonkap On

esprima claims "Full support for ECMAScript 2016 (ECMA-262 7th Edition)" while "await" initial definition was in "ECMAScript 2017 (ECMA-262)"

I think this can be the problem.

http://esprima.org/ (Features paragraph)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await#Specifications