mirror of
https://github.com/denoland/deno.git
synced 2025-03-10 14:17:49 -04:00
feat: add more options to Deno.inspect (#19337)
For https://github.com/denoland/deno_std/issues/3404 --------- Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
This commit is contained in:
parent
cd041fd128
commit
26506ff0c2
5 changed files with 38 additions and 2 deletions
|
@ -4715,7 +4715,7 @@ fn lsp_completions_auto_import() {
|
||||||
"source": "./b.ts",
|
"source": "./b.ts",
|
||||||
"data": {
|
"data": {
|
||||||
"exportName": "foo",
|
"exportName": "foo",
|
||||||
"exportMapKey": "foo|6810|file:///a/b",
|
"exportMapKey": "foo|6812|file:///a/b",
|
||||||
"moduleSpecifier": "./b.ts",
|
"moduleSpecifier": "./b.ts",
|
||||||
"fileName": "file:///a/b.ts"
|
"fileName": "file:///a/b.ts"
|
||||||
},
|
},
|
||||||
|
|
|
@ -2278,3 +2278,27 @@ Deno.test(function inspectAnonymousFunctions() {
|
||||||
"[AsyncGeneratorFunction (anonymous)]",
|
"[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
cli/tsc/dts/lib.deno.ns.d.ts
vendored
8
cli/tsc/dts/lib.deno.ns.d.ts
vendored
|
@ -4240,6 +4240,14 @@ declare namespace Deno {
|
||||||
*
|
*
|
||||||
* @default {4} */
|
* @default {4} */
|
||||||
depth?: number;
|
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.
|
/** The maximum number of iterable entries to print.
|
||||||
*
|
*
|
||||||
* @default {100} */
|
* @default {100} */
|
||||||
|
|
|
@ -2427,6 +2427,7 @@ const denoInspectDefaultOptions = {
|
||||||
colors: false,
|
colors: false,
|
||||||
showProxy: false,
|
showProxy: false,
|
||||||
breakLength: 80,
|
breakLength: 80,
|
||||||
|
escapeSequences: true,
|
||||||
compact: 3,
|
compact: 3,
|
||||||
sorted: false,
|
sorted: false,
|
||||||
getters: false,
|
getters: false,
|
||||||
|
@ -2500,7 +2501,9 @@ function quoteString(string, ctx) {
|
||||||
ctx.quotes[0];
|
ctx.quotes[0];
|
||||||
const escapePattern = new SafeRegExp(`(?=[${quote}\\\\])`, "g");
|
const escapePattern = new SafeRegExp(`(?=[${quote}\\\\])`, "g");
|
||||||
string = StringPrototypeReplace(string, escapePattern, "\\");
|
string = StringPrototypeReplace(string, escapePattern, "\\");
|
||||||
|
if (ctx.escapeSequences) {
|
||||||
string = replaceEscapeSequences(string);
|
string = replaceEscapeSequences(string);
|
||||||
|
}
|
||||||
return `${quote}${string}${quote}`;
|
return `${quote}${string}${quote}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,6 +134,7 @@ const inspectDefaultOptions = {
|
||||||
colors: false,
|
colors: false,
|
||||||
showProxy: false,
|
showProxy: false,
|
||||||
breakLength: 80,
|
breakLength: 80,
|
||||||
|
escapeSequences: true,
|
||||||
compact: 3,
|
compact: 3,
|
||||||
sorted: false,
|
sorted: false,
|
||||||
getters: false,
|
getters: false,
|
||||||
|
|
Loading…
Add table
Reference in a new issue