encapsulate invalidRawCandidates
This commit is contained in:
parent
d7ec348412
commit
145df6ca53
3 changed files with 13 additions and 6 deletions
|
|
@ -24,7 +24,7 @@ export function compileCandidates(
|
|||
if (throwOnInvalidCandidate) {
|
||||
throw new Error(`Cannot apply unknown utility class: ${rawCandidate}`)
|
||||
}
|
||||
designSystem.invalidRawCandidates.add(rawCandidate)
|
||||
designSystem.markInvalidCandidate(rawCandidate)
|
||||
continue // Bail, invalid candidate
|
||||
}
|
||||
candidates.set(candidate, rawCandidate)
|
||||
|
|
@ -42,7 +42,7 @@ export function compileCandidates(
|
|||
if (throwOnInvalidCandidate) {
|
||||
throw new Error(`Cannot apply unknown utility class: ${rawCandidate}`)
|
||||
}
|
||||
designSystem.invalidRawCandidates.add(rawCandidate)
|
||||
designSystem.markInvalidCandidate(rawCandidate)
|
||||
continue next
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@ export type DesignSystem = {
|
|||
getUsedVariants(): ReturnType<typeof parseVariant>[]
|
||||
getAstNodeSize(): number
|
||||
|
||||
invalidRawCandidates: Set<string>
|
||||
markInvalidCandidate(candidate: string): void
|
||||
isInvalidCandidate(candidate: string): boolean
|
||||
}
|
||||
|
||||
export function buildDesignSystem(theme: Theme): DesignSystem {
|
||||
|
|
@ -41,7 +42,6 @@ export function buildDesignSystem(theme: Theme): DesignSystem {
|
|||
theme,
|
||||
utilities,
|
||||
variants,
|
||||
invalidRawCandidates,
|
||||
|
||||
candidatesToCss(classes: string[]) {
|
||||
let result: (string | null)[] = []
|
||||
|
|
@ -83,6 +83,13 @@ export function buildDesignSystem(theme: Theme): DesignSystem {
|
|||
getAstNodeSize() {
|
||||
return compiledAstNodes.size
|
||||
},
|
||||
|
||||
markInvalidCandidate(candidate: string) {
|
||||
invalidRawCandidates.add(candidate)
|
||||
},
|
||||
isInvalidCandidate(candidate: string) {
|
||||
return invalidRawCandidates.has(candidate)
|
||||
},
|
||||
}
|
||||
|
||||
return designSystem
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ export function compile(
|
|||
// and should be ignored.
|
||||
let allValidCandidates = new Set<string>()
|
||||
for (let rawCandidate of rawCandidates) {
|
||||
if (!designSystem.invalidRawCandidates.has(rawCandidate)) {
|
||||
if (!designSystem.isInvalidCandidate(rawCandidate)) {
|
||||
allValidCandidates.add(rawCandidate)
|
||||
}
|
||||
}
|
||||
|
|
@ -190,7 +190,7 @@ export function compile(
|
|||
// Add all new candidates unless we know that they are invalid.
|
||||
let previousSize = allValidCandidates.size
|
||||
for (let candidate of newRawCandidates) {
|
||||
if (!designSystem.invalidRawCandidates.has(candidate)) {
|
||||
if (!designSystem.isInvalidCandidate(candidate)) {
|
||||
allValidCandidates.add(candidate)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue