我想支持添加到异步/等待到节点REPL与异步节点REPL伺机
关注这一问题:https://github.com/nodejs/node/issues/8382
我试图用这个https://github.com/paulserraino/babel-repl但它缺少异步等待suppport
我想用这个片段
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])}`;
}
我怎么能这个片段添加到节点REPL定制的eval?
实施例中节点REPL:
> const user = await User.findOne();
如何在'--harmony'中使用普通的节点7 REPL? – estus
node -harmony-async-await在节点7 REPL不起作用 –
嗯,应该。我会建议检查节点版本。显然,'await'应该在'async'函数内。 – estus