Skip to content
Prev Previous commit
Next Next commit
repl: try parse again and allowAwaitOutsideFunction
  • Loading branch information
jenthone authored and meixg committed Aug 24, 2025
commit 13b2c530a7c10c295c95db2c1f3e116d5add9fbe
20 changes: 20 additions & 0 deletions lib/internal/repl/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,26 @@ function setupReverseSearch(repl) {

const startsWithBraceRegExp = /^\s*{/;
const endsWithSemicolonRegExp = /;\s*$/;
function isValidSyntax(input) {
const Parser = require('internal/deps/acorn/acorn/dist/acorn').Parser;
try {
Parser.parse(input, {
ecmaVersion: 'latest',
allowAwaitOutsideFunction: true,
});
return true;
} catch {
try {
Parser.parse(`_=${input}`, {
ecmaVersion: 'latest',
allowAwaitOutsideFunction: true,
});
return true;
} catch {
return false;
}
}
}

/**
* Checks if some provided code represents an object literal.
Expand Down