Skip to content

Commit

Permalink
feat: add more options to Deno.inspect (denoland#19337)
Browse files Browse the repository at this point in the history
For denoland/deno_std#3404

---------

Co-authored-by: Yoshiya Hinosawa <[email protected]>
  • Loading branch information
crowlKats and kt3k committed Jun 5, 2023
1 parent 77a950a commit 08bd239
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cli/tests/integration/lsp_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4715,7 +4715,7 @@ fn lsp_completions_auto_import() {
"source": "./b.ts",
"data": {
"exportName": "foo",
"exportMapKey": "foo|6810|file:https:///a/b",
"exportMapKey": "foo|6812|file:https:///a/b",
"moduleSpecifier": "./b.ts",
"fileName": "file:https:///a/b.ts"
},
Expand Down
24 changes: 24 additions & 0 deletions cli/tests/unit/console_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"',
);
});
8 changes: 8 additions & 0 deletions cli/tsc/dts/lib.deno.ns.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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} */
Expand Down
5 changes: 4 additions & 1 deletion ext/console/01_console.js
Original file line number Diff line number Diff line change
Expand Up @@ -2427,6 +2427,7 @@ const denoInspectDefaultOptions = {
colors: false,
showProxy: false,
breakLength: 80,
escapeSequences: true,
compact: 3,
sorted: false,
getters: false,
Expand Down Expand Up @@ -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}`;
}

Expand Down
1 change: 1 addition & 0 deletions ext/node/polyfills/internal/util/inspect.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ const inspectDefaultOptions = {
colors: false,
showProxy: false,
breakLength: 80,
escapeSequences: true,
compact: 3,
sorted: false,
getters: false,
Expand Down

0 comments on commit 08bd239

Please sign in to comment.