summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/rt/02_console.js26
-rw-r--r--cli/tests/unit/console_test.ts13
2 files changed, 25 insertions, 14 deletions
diff --git a/cli/rt/02_console.js b/cli/rt/02_console.js
index 34e106ff2..f82262a7e 100644
--- a/cli/rt/02_console.js
+++ b/cli/rt/02_console.js
@@ -405,7 +405,7 @@
switch (typeof value) {
case "string":
- return value;
+ return green(quoteString(value));
case "number": // Numbers are yellow
// Special handling of -0
return yellow(Object.is(value, -0) ? "-0" : `${value}`);
@@ -1265,8 +1265,12 @@
if (a > 0) {
string += " ";
}
- // Use default maximum depth for null or undefined arguments.
- string += inspectValue(args[a], new Set(), 0, rInspectOptions);
+ if (typeof args[a] == "string") {
+ string += args[a];
+ } else {
+ // Use default maximum depth for null or undefined arguments.
+ string += inspectValue(args[a], new Set(), 0, rInspectOptions);
+ }
}
if (rInspectOptions.indentLevel > 0) {
@@ -1543,16 +1547,12 @@
value,
inspectOptions = {},
) {
- if (typeof value === "string") {
- return value;
- } else {
- return inspectValue(value, new Set(), 0, {
- ...DEFAULT_INSPECT_OPTIONS,
- ...inspectOptions,
- // TODO(nayeemrmn): Indent level is not supported.
- indentLevel: 0,
- });
- }
+ return inspectValue(value, new Set(), 0, {
+ ...DEFAULT_INSPECT_OPTIONS,
+ ...inspectOptions,
+ // TODO(nayeemrmn): Indent level is not supported.
+ indentLevel: 0,
+ });
}
// Expose these fields to internalObject for tests.
diff --git a/cli/tests/unit/console_test.ts b/cli/tests/unit/console_test.ts
index 8b5079a59..3df4b13e4 100644
--- a/cli/tests/unit/console_test.ts
+++ b/cli/tests/unit/console_test.ts
@@ -831,7 +831,7 @@ unitTest(function consoleTestWithStringFormatSpecifier(): void {
unitTest(function consoleTestWithObjectFormatSpecifier(): void {
assertEquals(stringify("%o"), "%o");
assertEquals(stringify("%o", 42), "42");
- assertEquals(stringify("%o", "foo"), "foo");
+ assertEquals(stringify("%o", "foo"), `"foo"`);
assertEquals(stringify("o: %o, a: %O", {}, []), "o: {}, a: []");
assertEquals(stringify("%o", { a: 42 }), "{ a: 42 }");
assertEquals(
@@ -1424,6 +1424,17 @@ unitTest(function consoleTrace(): void {
});
});
+unitTest(function inspectString(): void {
+ assertEquals(
+ stripColor(Deno.inspect("\0")),
+ `"\\x00"`,
+ );
+ assertEquals(
+ stripColor(Deno.inspect("\x1b[2J")),
+ `"\\x1b[2J"`,
+ );
+});
+
unitTest(function inspectSorted(): void {
assertEquals(
stripColor(Deno.inspect({ b: 2, a: 1 }, { sorted: true })),