MCPcopy
hub / github.com/tailwindlabs/tailwindcss / compoundsWith

Method compoundsWith

packages/tailwindcss/src/variants.ts:161–194  ·  view source on GitHub ↗
(parent: string, child: string | Variant)

Source from the content-addressed store, hash-verified

159 }
160
161 compoundsWith(parent: string, child: string | Variant) {
162 let parentInfo = this.variants.get(parent)
163 let childInfo =
164 typeof child === 'string'
165 ? this.variants.get(child)
166 : child.kind === 'arbitrary'
167 ? // This isn't strictly necessary but it'll allow us to bail quickly
168 // when parsing candidates
169 { compounds: compoundsForSelectors([child.selector]) }
170 : this.variants.get(child.root)
171
172 // One of the variants don't exist
173 if (!parentInfo || !childInfo) return false
174
175 // The parent variant is not a compound variant
176 if (parentInfo.kind !== 'compound') return false
177
178 // The variant `parent` may _compound with_ `child` if `parent` supports the
179 // rules that `child` generates. We instead use static registration metadata
180 // about what `parent` and `child` support instead of trying to apply the
181 // variant at runtime to see if the rules are compatible.
182
183 // The `child` variant cannot compound *ever*
184 if (childInfo.compounds === Compounds.Never) return false
185
186 // The `parent` variant cannot compound *ever*
187 // This shouldn't ever happen because `kind` is `compound`
188 if (parentInfo.compoundsWith === Compounds.Never) return false
189
190 // Any rule that `child` may generate must be supported by `parent`
191 if ((parentInfo.compoundsWith & childInfo.compounds) === 0) return false
192
193 return true
194 }
195
196 suggest(name: string, suggestions: () => string[]) {
197 this.completions.set(name, suggestions)

Callers 2

createVariantsFunction · 0.95
parseVariantFunction · 0.80

Calls 2

compoundsForSelectorsFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected