diff --git a/src/cli/usage.js b/src/cli/usage.js index 21a66f34c..9ba5ab599 100644 --- a/src/cli/usage.js +++ b/src/cli/usage.js @@ -73,9 +73,7 @@ function createChoiceUsages(choices, margin, indentation) { (choice) => !choice.deprecated && choice.since !== null ); const threshold = - activeChoices - .map((choice) => choice.value.length) - .reduce((current, length) => Math.max(current, length), 0) + margin; + Math.max(0, ...activeChoices.map((choice) => choice.value.length)) + margin; return activeChoices.map((choice) => indent( createOptionUsageRow(choice.value, choice.description, threshold), diff --git a/src/language-html/print-preprocess.js b/src/language-html/print-preprocess.js index 041db5c58..c6438f1d9 100644 --- a/src/language-html/print-preprocess.js +++ b/src/language-html/print-preprocess.js @@ -303,8 +303,8 @@ function extractInterpolation(ast, options) { * - add `isWhitespaceSensitive`, `isIndentationSensitive` field for text nodes * - remove insensitive whitespaces */ +const WHITESPACE_NODE = { type: "whitespace" }; function extractWhitespaces(ast /*, options*/) { - const TYPE_WHITESPACE = "whitespace"; return ast.map((node) => { if (!node.children) { return node; @@ -330,9 +330,9 @@ function extractWhitespaces(ast /*, options*/) { isIndentationSensitive, children: node.children // extract whitespace nodes - .reduce((newChildren, child) => { + .flatMap((child) => { if (child.type !== "text" || isWhitespaceSensitive) { - return [...newChildren, child]; + return child; } const localChildren = []; @@ -341,7 +341,7 @@ function extractWhitespaces(ast /*, options*/) { getLeadingAndTrailingHtmlWhitespace(child.value); if (leadingWhitespace) { - localChildren.push({ type: TYPE_WHITESPACE }); + localChildren.push(WHITESPACE_NODE); } if (text) { @@ -356,32 +356,25 @@ function extractWhitespaces(ast /*, options*/) { } if (trailingWhitespace) { - localChildren.push({ type: TYPE_WHITESPACE }); + localChildren.push(WHITESPACE_NODE); } - return [...newChildren, ...localChildren]; - }, []) - // set hasLeadingSpaces/hasTrailingSpaces and filter whitespace nodes - .reduce((newChildren, child, i, children) => { - if (child.type === TYPE_WHITESPACE) { - return newChildren; + return localChildren; + }) + // set hasLeadingSpaces/hasTrailingSpaces + .map((child, index, children) => { + if (child === WHITESPACE_NODE) { + return; } - const hasLeadingSpaces = - i !== 0 && children[i - 1].type === TYPE_WHITESPACE; - const hasTrailingSpaces = - i !== children.length - 1 && - children[i + 1].type === TYPE_WHITESPACE; - - return [ - ...newChildren, - { - ...child, - hasLeadingSpaces, - hasTrailingSpaces, - }, - ]; - }, []), + return { + ...child, + hasLeadingSpaces: children[index - 1] === WHITESPACE_NODE, + hasTrailingSpaces: children[index + 1] === WHITESPACE_NODE, + }; + }) + // filter whitespace nodes + .filter(Boolean), }); }); } diff --git a/src/main/parser.js b/src/main/parser.js index 499e1c4ad..9ce082873 100644 --- a/src/main/parser.js +++ b/src/main/parser.js @@ -69,15 +69,19 @@ function parse(text, opts) { // Create a new object {parserName: parseFn}. Uses defineProperty() to only call // the parsers getters when actually calling the parser `parse` function. - const parsersForCustomParserApi = Object.keys(parsers).reduce( - (object, parserName) => - Object.defineProperty(object, parserName, { - enumerable: true, - get() { - return parsers[parserName].parse; + const parsersForCustomParserApi = Object.defineProperties( + {}, + Object.fromEntries( + Object.keys(parsers).map((parserName) => [ + parserName, + { + enumerable: true, + get() { + return parsers[parserName].parse; + }, }, - }), - {} + ]) + ) ); const parser = resolveParser(opts, parsers); diff --git a/src/main/support.js b/src/main/support.js index f3548b5c6..8e0a85016 100644 --- a/src/main/support.js +++ b/src/main/support.js @@ -30,7 +30,7 @@ function getSupportInfo({ const version = currentVersion.split("-", 1)[0]; const languages = plugins - .reduce((all, plugin) => [...all, ...(plugin.languages || [])], []) + .flatMap((plugin) => plugin.languages || []) .filter(filterSince); const options = arrayify(