MCPcopy Index your code
hub / github.com/nodejs/node / isValidSyntax

Function isValidSyntax

lib/internal/repl/utils.js:758–776  ·  view source on GitHub ↗
(input)

Source from the content-addressed store, hash-verified

756const startsWithBraceRegExp = /^\s*{/;
757const endsWithSemicolonRegExp = /;\s*$/;
758function isValidSyntax(input) {
759 try {
760 AcornParser.parse(input, {
761 ecmaVersion: 'latest',
762 allowAwaitOutsideFunction: true,
763 });
764 return true;
765 } catch {
766 try {
767 AcornParser.parse(`_=${input}`, {
768 ecmaVersion: 'latest',
769 allowAwaitOutsideFunction: true,
770 });
771 return true;
772 } catch {
773 return false;
774 }
775 }
776}
777
778/**
779 * Checks if some provided code represents an object literal.

Callers 2

defaultEvalMethod · 0.85
getInputPreviewFunction · 0.85

Calls 1

parseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…