Skip to content

Commit

Permalink
Fix .await in REPL
Browse files Browse the repository at this point in the history
  • Loading branch information
tobeno committed Nov 17, 2023
1 parent 1484353 commit 3cd4659
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/sol/sol-repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,18 @@ function prepareSolCommand(cmd: string): string {
plugins: ['typescript'],
});

let traverseFn: (typeof import('@babel/traverse'))['default'] = traverse;
if ('default' in traverseFn) {
traverseFn = traverseFn.default as any;
}

let generateFn: (typeof import('@babel/generator'))['default'] = generate;
if ('default' in generateFn) {
generateFn = generateFn.default as any;
}

// Replace something.await with await something
traverse(cmdRootNode, {
traverseFn(cmdRootNode, {
Identifier(path) {
if (
path.node.name === 'await' &&
Expand All @@ -76,8 +86,9 @@ function prepareSolCommand(cmd: string): string {
});

// Regenerate command
preparedCmd = generate(cmdRootNode, {}).code;
preparedCmd = generateFn(cmdRootNode, {}).code;
} catch (e) {
console.log(e);
// Ignore babel errors and let the VM handle it
}

Expand Down

0 comments on commit 3cd4659

Please sign in to comment.