From 1c23b0a9ed522d46ca5845d872b720bd485cb307 Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Thu, 13 Aug 2020 08:56:27 -0400 Subject: [PATCH] Use lodash for flatMap --- src/flagged/applyComplexClasses.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/flagged/applyComplexClasses.js b/src/flagged/applyComplexClasses.js index c91c13a42..2be8eec46 100644 --- a/src/flagged/applyComplexClasses.js +++ b/src/flagged/applyComplexClasses.js @@ -125,23 +125,22 @@ function mergeAdjacentRules(initialRule, rulesToInsert) { function makeExtractUtilityRules(css) { const utilityMap = buildUtilityMap(css) const orderUtilityMap = Object.fromEntries( - Object.entries(utilityMap).flatMap(([_utilityName, utilities]) => { + _.flatMap(Object.entries(utilityMap), ([_utilityName, utilities]) => { return utilities.map(utility => { return [utility.index, utility] }) }) ) return function(utilityNames, rule) { - return utilityNames - .flatMap(utilityName => { - if (utilityMap[utilityName] === undefined) { - throw rule.error( - `The \`${utilityName}\` utility does not exist. If you're sure that \`${utilityName}\` exists, make sure that any \`@import\` statements are being properly processed before Tailwind CSS sees your CSS, as \`@apply\` can only be used for classes in the same CSS tree.`, - { word: utilityName } - ) - } - return utilityMap[utilityName].map(({ index }) => index) - }) + return _.flatMap(utilityNames, utilityName => { + if (utilityMap[utilityName] === undefined) { + throw rule.error( + `The \`${utilityName}\` utility does not exist. If you're sure that \`${utilityName}\` exists, make sure that any \`@import\` statements are being properly processed before Tailwind CSS sees your CSS, as \`@apply\` can only be used for classes in the same CSS tree.`, + { word: utilityName } + ) + } + return utilityMap[utilityName].map(({ index }) => index) + }) .sort((a, b) => a - b) .map(i => orderUtilityMap[i]) }