1
0
Fork 0
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:
David Sherret 2023-03-23 10:58:53 -04:00 committed by GitHub
parent 6e5a631fe0
commit 81c5ddf9f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 8 deletions

View file

@ -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,
});

View file

@ -1,4 +0,0 @@
error: Uncaught {
foo: Error
at file:///[WILDCARD]testdata/run/nested_error.ts:2:8
}

View file

@ -0,0 +1,4 @@
error: Uncaught {
foo: Error
at file:///[WILDCARD]/main.ts:2:8
}

View file

@ -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,