function candidates
candidates(input: string): string[]

The expressions to try for one line of input, in order.

Only {-leading input gets two: { a: 1 } is a block containing a labelled statement as a statement and an object as an expression, and a REPL means the object every time — so the parenthesised form is tried first and the bare form is the fallback for input that really was a block. Everything else is itself, unchanged: top-level await, let redeclaration and the completion value of the last statement are all handled by CDP's REPL mode, so there is nothing left for a source transform to do.

import { candidates } from './input.ts';

candidates('1 + 1'); // ['1 + 1']
candidates('{ a: 1 }'); // ['({ a: 1 })', '{ a: 1 }'] — object first, block second

Parameters

input: string

Return Type

string[]

Usage

import { candidates } from "lib/repl/input.ts";