mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -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 {
|
||||
args: "run run/nested_error.ts",
|
||||
output: "run/nested_error.ts.out",
|
||||
args: "run run/nested_error/main.ts",
|
||||
output: "run/nested_error/main.ts.out",
|
||||
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--;
|
||||
|
||||
// Making sure color codes are ignored when calculating the total length
|
||||
const entriesText = colors.stripColor(ArrayPrototypeJoin(entries, ""));
|
||||
const totalLength = entries.length + inspectOptions.indentLevel +
|
||||
colors.stripColor(ArrayPrototypeJoin(entries, "")).length;
|
||||
entriesText.length;
|
||||
|
||||
if (entries.length === 0) {
|
||||
baseString = "{}";
|
||||
} else if (totalLength > LINE_BREAKING_LENGTH || !inspectOptions.compact) {
|
||||
} else if (
|
||||
totalLength > LINE_BREAKING_LENGTH ||
|
||||
!inspectOptions.compact ||
|
||||
StringPrototypeIncludes(entriesText, "\n")
|
||||
) {
|
||||
const entryIndent = StringPrototypeRepeat(
|
||||
DEFAULT_INDENT,
|
||||
inspectOptions.indentLevel + 1,
|
||||
|
|
Loading…
Reference in a new issue