I would like to add support to async/await to node repl
Following this issue: https://github.com/nodejs/node/issues/8382
I've tried to use this one https://github.com/paulserraino/babel-repl but it is missing async await suppport
I would like to use this snippet
const awaitMatcher = /^(?:\s*(?:(?:let|var|const)\s)?\s*([^=]+)=\s*|^\s*)(await\s[\s\S]*)/;
const asyncWrapper = (code, binder) => {
let assign = binder ? `root.${binder} = ` : '';
return `(function(){ async function _wrap() { return ${assign}${code} } return _wrap();})()`;
};
// match & transform
const match = input.match(awaitMatcher);
if(match) {
input = `${asyncWrapper(match[2], match[1])}`;
}
How can I add this snippet to a custom eval on node repl?
Example in node repl:
> const user = await User.findOne();
--harmony
? – Landelawait
should be insideasync
function. – Landel