mirror of
https://github.com/denoland/deno.git
synced 2025-02-01 20:25:12 -05:00
fix(inspect): ensure non-compact output when object literal has newline in entry text (#18366)
Fixes `Deno.inspect` to make an object literal non-compact when an entry has multiple lines in it.
This commit is contained in:
parent
6e5a631fe0
commit
81c5ddf9f2
5 changed files with 13 additions and 8 deletions
|
@ -3261,8 +3261,8 @@ itest!(unhandled_rejection_dynamic_import2 {
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(nested_error {
|
itest!(nested_error {
|
||||||
args: "run run/nested_error.ts",
|
args: "run run/nested_error/main.ts",
|
||||||
output: "run/nested_error.ts.out",
|
output: "run/nested_error/main.ts.out",
|
||||||
exit_code: 1,
|
exit_code: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
4
cli/tests/testdata/run/nested_error.ts.out
vendored
4
cli/tests/testdata/run/nested_error.ts.out
vendored
|
@ -1,4 +0,0 @@
|
||||||
error: Uncaught {
|
|
||||||
foo: Error
|
|
||||||
at file:///[WILDCARD]testdata/run/nested_error.ts:2:8
|
|
||||||
}
|
|
4
cli/tests/testdata/run/nested_error/main.ts.out
vendored
Normal file
4
cli/tests/testdata/run/nested_error/main.ts.out
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
error: Uncaught {
|
||||||
|
foo: Error
|
||||||
|
at file:///[WILDCARD]/main.ts:2:8
|
||||||
|
}
|
|
@ -1291,12 +1291,17 @@ function inspectRawObject(
|
||||||
inspectOptions.indentLevel--;
|
inspectOptions.indentLevel--;
|
||||||
|
|
||||||
// Making sure color codes are ignored when calculating the total length
|
// Making sure color codes are ignored when calculating the total length
|
||||||
|
const entriesText = colors.stripColor(ArrayPrototypeJoin(entries, ""));
|
||||||
const totalLength = entries.length + inspectOptions.indentLevel +
|
const totalLength = entries.length + inspectOptions.indentLevel +
|
||||||
colors.stripColor(ArrayPrototypeJoin(entries, "")).length;
|
entriesText.length;
|
||||||
|
|
||||||
if (entries.length === 0) {
|
if (entries.length === 0) {
|
||||||
baseString = "{}";
|
baseString = "{}";
|
||||||
} else if (totalLength > LINE_BREAKING_LENGTH || !inspectOptions.compact) {
|
} else if (
|
||||||
|
totalLength > LINE_BREAKING_LENGTH ||
|
||||||
|
!inspectOptions.compact ||
|
||||||
|
StringPrototypeIncludes(entriesText, "\n")
|
||||||
|
) {
|
||||||
const entryIndent = StringPrototypeRepeat(
|
const entryIndent = StringPrototypeRepeat(
|
||||||
DEFAULT_INDENT,
|
DEFAULT_INDENT,
|
||||||
inspectOptions.indentLevel + 1,
|
inspectOptions.indentLevel + 1,
|
||||||
|
|
Loading…
Add table
Reference in a new issue