From dc4ab1d9340a58f81beab24ef211e900acbb9ad8 Mon Sep 17 00:00:00 2001 From: Ben Heidemann <56122437+bcheidemann@users.noreply.github.com> Date: Tue, 26 Apr 2022 12:04:28 +0100 Subject: feat(ext/console): Compact empty iterables when calling Deno.inspect with compact false (#14387) --- ext/console/02_console.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'ext') diff --git a/ext/console/02_console.js b/ext/console/02_console.js index 607da2db6..9b54a64a1 100644 --- a/ext/console/02_console.js +++ b/ext/console/02_console.js @@ -465,12 +465,18 @@ const entryIndentation = `,\n${ StringPrototypeRepeat(DEFAULT_INDENT, level + 1) }`; - const closingIndentation = `${inspectOptions.trailingComma ? "," : ""}\n${ - StringPrototypeRepeat(DEFAULT_INDENT, level) - }`; + const closingDelimIndentation = StringPrototypeRepeat( + DEFAULT_INDENT, + level, + ); + const closingIndentation = `${ + inspectOptions.trailingComma ? "," : "" + }\n${closingDelimIndentation}`; let iContent; - if (options.group && entries.length > MIN_GROUP_LENGTH) { + if (entries.length === 0 && !inspectOptions.compact) { + iContent = `\n${closingDelimIndentation}`; + } else if (options.group && entries.length > MIN_GROUP_LENGTH) { const groups = groupEntries(entries, level, value); iContent = `${initIndentation}${ ArrayPrototypeJoin(groups, entryIndentation) -- cgit v1.2.3