From 81c5ddf9f2cec291be9b7e31e9d8c430585a7519 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 23 Mar 2023 10:58:53 -0400 Subject: 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. --- ext/console/02_console.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'ext/console') 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, -- cgit v1.2.3