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

Function objectToAst

packages/tailwindcss/src/compat/plugin-api.ts:558–600  ·  packages/tailwindcss/src/compat/plugin-api.ts::objectToAst
(rules: CssInJs | CssInJs[])

Source from the content-addressed store, hash-verified

556export type CssInJs = { [key: string]: string | string[] | CssInJs | CssInJs[] }
557
558export function objectToAst(rules: CssInJs | CssInJs[]): AstNode[] {
559 let ast: AstNode[] = []
560
561 rules = Array.isArray(rules) ? rules : [rules]
562
563 let entries = rules.flatMap((rule) => Object.entries(rule))
564
565 for (let [name, value] of entries) {
566 if (value === null || value === undefined) continue
567
568 class="cm">// @ts-expect-error
569 class="cm">// We do not want `false` present in the types but still need to discard these nodes for
570 class="cm">// compatibility purposes
571 if (value === false) continue
572
573 if (typeof value !== class="st">'object') {
574 if (!name.startsWith(class="st">'--')) {
575 if (value === class="st">'@slot') {
576 ast.push(rule(name, [atRule(class="st">'@slot')]))
577 continue
578 }
579
580 class="cm">// Convert camelCase to kebab-case:
581 class="cm">// https://github.com/postcss/postcss-js/blob/b3db658b932b42f6ac14ca0b1d50f50c4569805b/parser.js#L30-L35
582 name = name.replace(/([A-Z])/g, class="st">'-$1').toLowerCase()
583 }
584
585 ast.push(decl(name, String(value)))
586 } else if (Array.isArray(value)) {
587 for (let item of value) {
588 if (typeof item === class="st">'string') {
589 ast.push(decl(name, item))
590 } else {
591 ast.push(rule(name, objectToAst(item)))
592 }
593 }
594 } else {
595 ast.push(rule(name, objectToAst(value)))
596 }
597 }
598
599 return ast
600}
601
602function parseVariantValue(resolved: string | string[], nodes: AstNode[]): AstNode[] {
603 let resolvedArray = typeof resolved === class="st">'string' ? [resolved] : resolved

Callers 5

keyframesToRulesFunction · 0.90
addBaseFunction · 0.85
addVariantFunction · 0.85
addUtilitiesFunction · 0.85
compileFnFunction · 0.85

Calls 4

ruleFunction · 0.90
atRuleFunction · 0.90
declFunction · 0.90
entriesMethod · 0.45

Tested by

no test coverage detected