Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add more options to Deno.inspect #19337

Merged
merged 4 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:///a/b",
"exportMapKey": "foo|6812|file:///a/b",
"moduleSpecifier": "./b.ts",
"fileName": "file:///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