summaryrefslogtreecommitdiff
path: root/js/repl.ts
diff options
context:
space:
mode:
authorKevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com>2019-08-17 09:51:51 -0700
committerRyan Dahl <ry@tinyclouds.org>2019-08-17 12:51:51 -0400
commit9acb17742fc2c7ee503e6b2be8f88b97dae65dc6 (patch)
tree0a25e25a8f7049a1c124fb7825ce43af6eafc582 /js/repl.ts
parentde713e42c8807e3124c9b5d418a69d2ea3460058 (diff)
Implement console.trace() (#2780)
groupCollapsed alias to group, remove noTrailingNewline, move newline out of stringifyArgs, fix console.dir, add tests, and fix a repl log quirk. For repl logging quirks, I believe we should not indent repl logging. If we really want such indentation, we probably also want to indent "> " prompts.
Diffstat (limited to 'js/repl.ts')
-rw-r--r--js/repl.ts27
1 files changed, 22 insertions, 5 deletions
diff --git a/js/repl.ts b/js/repl.ts
index be162cb7e..daf4fd154 100644
--- a/js/repl.ts
+++ b/js/repl.ts
@@ -8,6 +8,23 @@ import { exit } from "./os";
import { window } from "./window";
import { core } from "./core";
import { formatError } from "./format_error";
+import { stringifyArgs } from "./console";
+
+/**
+ * REPL logging.
+ * In favor of console.log to avoid unwanted indentation
+ */
+function replLog(...args: unknown[]): void {
+ core.print(stringifyArgs(args) + "\n");
+}
+
+/**
+ * REPL logging for errors.
+ * In favor of console.error to avoid unwanted indentation
+ */
+function replError(...args: unknown[]): void {
+ core.print(stringifyArgs(args) + "\n", true);
+}
const helpMsg = [
"exit Exit the REPL",
@@ -86,7 +103,7 @@ function isRecoverableError(e: Error): boolean {
function evaluate(code: string): boolean {
const [result, errInfo] = core.evalContext(code);
if (!errInfo) {
- console.log(result);
+ replLog(result);
} else if (errInfo.isCompileError && isRecoverableError(errInfo.thrown)) {
// Recoverable compiler error
return false; // don't consume code.
@@ -95,9 +112,9 @@ function evaluate(code: string): boolean {
const formattedError = formatError(
core.errorToJSON(errInfo.thrown as Error)
);
- console.error(formattedError);
+ replError(formattedError);
} else {
- console.error("Thrown:", errInfo.thrown);
+ replError("Thrown:", errInfo.thrown);
}
}
return true;
@@ -135,7 +152,7 @@ export async function replLoop(): Promise<void> {
// e.g. this happens when we have deno.close(3).
// We want to display the problem.
const formattedError = formatError(core.errorToJSON(err));
- console.error(formattedError);
+ replError(formattedError);
}
// Quit REPL anyways.
quitRepl(1);
@@ -157,7 +174,7 @@ export async function replLoop(): Promise<void> {
// e.g. this happens when we have deno.close(3).
// We want to display the problem.
const formattedError = formatError(core.errorToJSON(err));
- console.error(formattedError);
+ replError(formattedError);
quitRepl(1);
}
}