From e05e5ece43a81f9e49f68ae2a059260c402a17f7 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Fri, 8 Mar 2024 11:42:08 +0100 Subject: [PATCH] expose methods instead of raw `DefaultMap`s --- packages/tailwindcss/src/compile.ts | 2 +- packages/tailwindcss/src/design-system.ts | 14 ++++++++------ packages/tailwindcss/src/index.ts | 7 +++++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/tailwindcss/src/compile.ts b/packages/tailwindcss/src/compile.ts index 2d972566d..19629af42 100644 --- a/packages/tailwindcss/src/compile.ts +++ b/packages/tailwindcss/src/compile.ts @@ -31,7 +31,7 @@ export function compileCandidates( } // Sort the variants - let variants = Array.from(designSystem.parsedVariants.values()).sort((a, z) => { + let variants = designSystem.getUsedVariants().sort((a, z) => { return designSystem.variants.compare(a, z) }) diff --git a/packages/tailwindcss/src/design-system.ts b/packages/tailwindcss/src/design-system.ts index 67595322f..55d29e51c 100644 --- a/packages/tailwindcss/src/design-system.ts +++ b/packages/tailwindcss/src/design-system.ts @@ -22,9 +22,8 @@ export type DesignSystem = { parseVariant(variant: string): ReturnType parseAstNode(candidate: string): ReturnType - parsedCandidates: DefaultMap> - parsedVariants: DefaultMap> - parsedAstNodes: DefaultMap> + getUsedVariants(): ReturnType[] + getAstNodeSize(): number invalidRawCandidates: Set } @@ -42,9 +41,6 @@ export function buildDesignSystem(theme: Theme): DesignSystem { theme, utilities, variants, - parsedCandidates, - parsedVariants, - parsedAstNodes, invalidRawCandidates, candidatesToCss(classes: string[]) { @@ -81,6 +77,12 @@ export function buildDesignSystem(theme: Theme): DesignSystem { parseAstNode(candidate: string) { return parsedAstNodes.get(candidate) }, + getUsedVariants() { + return Array.from(parsedVariants.values()) + }, + getAstNodeSize() { + return parsedAstNodes.size + }, } return designSystem diff --git a/packages/tailwindcss/src/index.ts b/packages/tailwindcss/src/index.ts index f09612307..193d97453 100644 --- a/packages/tailwindcss/src/index.ts +++ b/packages/tailwindcss/src/index.ts @@ -174,6 +174,9 @@ export function compile( }) } + // Track all valid candidates, these are the incoming `rawCandidate` that + // resulted in a generated AST Node. All the other `rawCandidates` are invalid + // and should be ignored. let allValidCandidates = new Set() for (let rawCandidate of rawCandidates) { if (!designSystem.invalidRawCandidates.has(rawCandidate)) { @@ -199,13 +202,13 @@ export function compile( } if (tailwindUtilitiesNode) { - let previousAstNodeCount = designSystem.parsedAstNodes.size + let previousAstNodeCount = designSystem.getAstNodeSize() let newNodes = compileCandidates(allValidCandidates, designSystem).astNodes // If no new ast nodes were generated, then we can return the original // CSS. This currently assumes that we only add new ast nodes and never // remove any. - if (previousAstNodeCount === designSystem.parsedAstNodes.size) { + if (previousAstNodeCount === designSystem.getAstNodeSize()) { return compiledCss }