From ad01f49b269e47ec56c213d682a236b4c0a6d164 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Sat, 2 Jul 2022 16:15:06 -0400 Subject: [PATCH] Fix #1764 (#1824) --- src/repl.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/repl.ts b/src/repl.ts index eed95a0d7..3137daa49 100644 --- a/src/repl.ts +++ b/src/repl.ts @@ -207,6 +207,7 @@ export function createRepl(options: CreateReplOptions = {}) { state, input: code, context, + overrideIsCompletion: false, }); assert(result.containsTopLevelAwait === false); return result.value; @@ -512,6 +513,12 @@ function appendCompileAndEvalInput(options: { /** Enable top-level await but only if the TSNode service allows it. */ enableTopLevelAwait?: boolean; context: Context | undefined; + /** + * Added so that `evalCode` can be guaranteed *not* to trigger the `isCompletion` + * codepath. However, the `isCompletion` logic is ancient and maybe should be removed entirely. + * Nobody's looked at it in a long time. + */ + overrideIsCompletion?: boolean; }): AppendCompileAndEvalInputResult { const { service, @@ -519,6 +526,7 @@ function appendCompileAndEvalInput(options: { wrappedErr, enableTopLevelAwait = false, context, + overrideIsCompletion, } = options; let { input } = options; @@ -533,7 +541,7 @@ function appendCompileAndEvalInput(options: { } const lines = state.lines; - const isCompletion = !/\n$/.test(input); + const isCompletion = overrideIsCompletion ?? !/\n$/.test(input); const undo = appendToEvalState(state, input); let output: string;