1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

improve indentation when displaying objects with console.log (#5909)

This commit is contained in:
Speykious 2020-05-28 15:04:43 +02:00 committed by GitHub
parent 088fc1556c
commit 6d9b06619d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -124,23 +124,19 @@ function createIterableString<T>(
const iPrefix = `${config.displayName ? config.displayName + " " : ""}`;
const initIndentation = `\n${DEFAULT_INDENT.repeat(level + 1)}`;
const entryIndentation = `,\n${DEFAULT_INDENT.repeat(level + 1)}`;
const closingIndentation = `\n${DEFAULT_INDENT.repeat(level)}`;
let iContent: string;
if (config.group && entries.length > MIN_GROUP_LENGTH) {
const groups = groupEntries(entries, level, value);
const initIndentation = `\n${DEFAULT_INDENT.repeat(level + 1)}`;
const entryIndentation = `,\n${DEFAULT_INDENT.repeat(level + 1)}`;
const closingIndentation = `\n${DEFAULT_INDENT.repeat(level)}`;
iContent = `${initIndentation}${groups.join(
entryIndentation
)}${closingIndentation}`;
} else {
iContent = entries.length === 0 ? "" : ` ${entries.join(", ")} `;
if (stripColor(iContent).length > LINE_BREAKING_LENGTH) {
const initIndentation = `\n${DEFAULT_INDENT.repeat(level + 1)}`;
const entryIndentation = `,\n${DEFAULT_INDENT.repeat(level + 1)}`;
const closingIndentation = `\n`;
iContent = `${initIndentation}${entries.join(
entryIndentation
)}${closingIndentation}`;
@ -343,7 +339,7 @@ function createArrayString(
const ending = emptyItems > 1 ? "s" : "";
return dim(`<${emptyItems} empty item${ending}>`);
} else {
return stringifyWithQuotes(val, ctx, level + 1, maxLevel);
return stringifyWithQuotes(val, ctx, level, maxLevel);
}
},
group: true,