| 94 | }); |
| 95 | |
| 96 | const _eval = function (code: string, filename: string) { |
| 97 | code = code.trim(); |
| 98 | if (!code) return undefined; |
| 99 | |
| 100 | hasTopLevelAwait = false; |
| 101 | |
| 102 | code = babel.transformSync(code, { |
| 103 | filename: filename, |
| 104 | ...babelOptions, |
| 105 | parserOpts: { |
| 106 | allowAwaitOutsideFunction: true, |
| 107 | }, |
| 108 | plugins: (opts.plugins || []).concat([replPlugin]), |
| 109 | }).code; |
| 110 | |
| 111 | if (hasTopLevelAwait) { |
| 112 | code = `(async () => { ${code} })()`; |
| 113 | } |
| 114 | |
| 115 | return vm.runInThisContext(code, { |
| 116 | filename: filename, |
| 117 | }); |
| 118 | }; |
| 119 | |
| 120 | if (opts.eval || opts.print) { |
| 121 | let code = opts.eval; |