From cdc9323cccdee544562712018f722026bdfbbd6c Mon Sep 17 00:00:00 2001 From: uki00a Date: Wed, 20 May 2020 02:33:11 +0900 Subject: fix: REPL does not exit properly when close() is called (#5451) --- cli/js/repl.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'cli/js') diff --git a/cli/js/repl.ts b/cli/js/repl.ts index 138b30c3e..c84be68b1 100644 --- a/cli/js/repl.ts +++ b/cli/js/repl.ts @@ -32,6 +32,13 @@ function isRecoverableError(e: Error): boolean { return recoverableErrorMessages.includes(e.message); } +// Returns `true` if `close()` is called in REPL. +// We should quit the REPL when this function returns `true`. +function isCloseCalled(): boolean { + // @ts-ignore + return globalThis.closed; +} + // eslint-disable-next-line @typescript-eslint/no-explicit-any type Value = any; @@ -45,7 +52,9 @@ function evaluate(code: string): boolean { const [result, errInfo] = core.evalContext(code); if (!errInfo) { lastEvalResult = result; - replLog(result); + if (!isCloseCalled()) { + replLog(result); + } } else if (errInfo.isCompileError && isRecoverableError(errInfo.thrown)) { // Recoverable compiler error return false; // don't consume code. @@ -110,6 +119,10 @@ export async function replLoop(): Promise { replLog("exit using ctrl+d or close()"); while (true) { + if (isCloseCalled()) { + quitRepl(0); + } + let code = ""; // Top level read try { -- cgit v1.2.3