summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/tests/integration/lsp_tests.rs2
-rw-r--r--cli/tests/unit/console_test.ts24
-rw-r--r--cli/tsc/dts/lib.deno.ns.d.ts8
-rw-r--r--ext/console/01_console.js5
-rw-r--r--ext/node/polyfills/internal/util/inspect.mjs1
5 files changed, 38 insertions, 2 deletions
diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs
index eee83c4a2..fa8cb6a3c 100644
--- a/cli/tests/integration/lsp_tests.rs
+++ b/cli/tests/integration/lsp_tests.rs
@@ -4715,7 +4715,7 @@ fn lsp_completions_auto_import() {
"source": "./b.ts",
"data": {
"exportName": "foo",
- "exportMapKey": "foo|6810|file:///a/b",
+ "exportMapKey": "foo|6812|file:///a/b",
"moduleSpecifier": "./b.ts",
"fileName": "file:///a/b.ts"
},
diff --git a/cli/tests/unit/console_test.ts b/cli/tests/unit/console_test.ts
index c4f2f64a4..b177b956b 100644
--- a/cli/tests/unit/console_test.ts
+++ b/cli/tests/unit/console_test.ts
@@ -2278,3 +2278,27 @@ Deno.test(function inspectAnonymousFunctions() {
"[AsyncGeneratorFunction (anonymous)]",
);
});
+
+Deno.test(function inspectBreakLengthOption() {
+ assertEquals(
+ Deno.inspect("123456789\n".repeat(3), { breakLength: 34 }),
+ `"123456789\\n123456789\\n123456789\\n"`,
+ );
+ assertEquals(
+ Deno.inspect("123456789\n".repeat(3), { breakLength: 33 }),
+ `"123456789\\n" +
+ "123456789\\n" +
+ "123456789\\n"`,
+ );
+});
+
+Deno.test(function inspectEscapeSequencesFalse() {
+ assertEquals(
+ Deno.inspect("foo\nbar", { escapeSequences: true }),
+ '"foo\\nbar"',
+ ); // default behavior
+ assertEquals(
+ Deno.inspect("foo\nbar", { escapeSequences: false }),
+ '"foo\nbar"',
+ );
+});
diff --git a/cli/tsc/dts/lib.deno.ns.d.ts b/cli/tsc/dts/lib.deno.ns.d.ts
index a7d6adab8..0247eda9c 100644
--- a/cli/tsc/dts/lib.deno.ns.d.ts
+++ b/cli/tsc/dts/lib.deno.ns.d.ts
@@ -4240,6 +4240,14 @@ declare namespace Deno {
*
* @default {4} */
depth?: number;
+ /** The maximum length for an inspection to take up a single line.
+ *
+ * @default {80} */
+ breakLength?: number;
+ /** Whether or not to escape sequences.
+ *
+ * @default {true} */
+ escapeSequences?: boolean;
/** The maximum number of iterable entries to print.
*
* @default {100} */
diff --git a/ext/console/01_console.js b/ext/console/01_console.js
index dbbc549ca..11b6c549c 100644
--- a/ext/console/01_console.js
+++ b/ext/console/01_console.js
@@ -2427,6 +2427,7 @@ const denoInspectDefaultOptions = {
colors: false,
showProxy: false,
breakLength: 80,
+ escapeSequences: true,
compact: 3,
sorted: false,
getters: false,
@@ -2500,7 +2501,9 @@ function quoteString(string, ctx) {
ctx.quotes[0];
const escapePattern = new SafeRegExp(`(?=[${quote}\\\\])`, "g");
string = StringPrototypeReplace(string, escapePattern, "\\");
- string = replaceEscapeSequences(string);
+ if (ctx.escapeSequences) {
+ string = replaceEscapeSequences(string);
+ }
return `${quote}${string}${quote}`;
}
diff --git a/ext/node/polyfills/internal/util/inspect.mjs b/ext/node/polyfills/internal/util/inspect.mjs
index 671ab2acf..2d34db9c7 100644
--- a/ext/node/polyfills/internal/util/inspect.mjs
+++ b/ext/node/polyfills/internal/util/inspect.mjs
@@ -134,6 +134,7 @@ const inspectDefaultOptions = {
colors: false,
showProxy: false,
breakLength: 80,
+ escapeSequences: true,
compact: 3,
sorted: false,
getters: false,