summaryrefslogtreecommitdiff
path: root/ext/console/02_console.js
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-03-23 10:58:53 -0400
committerGitHub <noreply@github.com>2023-03-23 10:58:53 -0400
commit81c5ddf9f2cec291be9b7e31e9d8c430585a7519 (patch)
tree1515f09c274983b23d24799c2f03bf04698d04d7 /ext/console/02_console.js
parent6e5a631fe094fa77209d51b65adfcc52d738e197 (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.
Diffstat (limited to 'ext/console/02_console.js')
-rw-r--r--ext/console/02_console.js9
1 files changed, 7 insertions, 2 deletions
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,