diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-03-23 10:58:53 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-23 10:58:53 -0400 |
commit | 81c5ddf9f2cec291be9b7e31e9d8c430585a7519 (patch) | |
tree | 1515f09c274983b23d24799c2f03bf04698d04d7 | |
parent | 6e5a631fe094fa77209d51b65adfcc52d738e197 (diff) |
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.
-rw-r--r-- | cli/tests/integration/run_tests.rs | 4 | ||||
-rw-r--r-- | cli/tests/testdata/run/nested_error.ts.out | 4 | ||||
-rw-r--r-- | cli/tests/testdata/run/nested_error/main.ts (renamed from cli/tests/testdata/run/nested_error.ts) | 0 | ||||
-rw-r--r-- | cli/tests/testdata/run/nested_error/main.ts.out | 4 | ||||
-rw-r--r-- | ext/console/02_console.js | 9 |
5 files changed, 13 insertions, 8 deletions
diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index e4d670935..d46684905 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -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, }); diff --git a/cli/tests/testdata/run/nested_error.ts.out b/cli/tests/testdata/run/nested_error.ts.out deleted file mode 100644 index f5ebeec4d..000000000 --- a/cli/tests/testdata/run/nested_error.ts.out +++ /dev/null @@ -1,4 +0,0 @@ -error: Uncaught { - foo: Error - at file:///[WILDCARD]testdata/run/nested_error.ts:2:8 -} diff --git a/cli/tests/testdata/run/nested_error.ts b/cli/tests/testdata/run/nested_error/main.ts index 69828e1ca..69828e1ca 100644 --- a/cli/tests/testdata/run/nested_error.ts +++ b/cli/tests/testdata/run/nested_error/main.ts diff --git a/cli/tests/testdata/run/nested_error/main.ts.out b/cli/tests/testdata/run/nested_error/main.ts.out new file mode 100644 index 000000000..47c818ac1 --- /dev/null +++ b/cli/tests/testdata/run/nested_error/main.ts.out @@ -0,0 +1,4 @@ +error: Uncaught { + foo: Error + at file:///[WILDCARD]/main.ts:2:8 +} diff --git a/ext/console/02_console.js b/ext/console/02_console.js index 295fef4c3..e93272de1 100644 --- a/ext/console/02_console.js +++ b/ext/console/02_console.js @@ -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, |