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

Function toCss

packages/tailwindcss/src/ast.ts:685–890  ·  packages/tailwindcss/src/ast.ts::toCss
(ast: AstNode[], track?: boolean)

Source from the content-addressed store, hash-verified

683}
684
685export function toCss(ast: AstNode[], track?: boolean) {
686 let pos = 0
687
688 let source: Source = {
689 file: null,
690 code: class="st">'',
691 }
692
693 function stringify(node: AstNode, depth = 0): string {
694 let css = class="st">''
695 let indent = class="st">' '.repeat(depth)
696
697 class="cm">// Declaration
698 if (node.kind === class="st">'declaration') {
699 css += `${indent}${node.property}: ${node.value}${node.important ? class="st">' !important' : class="st">''};\n`
700
701 if (track) {
702 class="cm">// indent
703 pos += indent.length
704
705 class="cm">// node.property
706 let start = pos
707 pos += node.property.length
708
709 class="cm">// `: `
710 pos += 2
711
712 class="cm">// node.value
713 pos += node.value?.length ?? 0
714
715 class="cm">// !important
716 if (node.important) {
717 pos += 11
718 }
719
720 let end = pos
721
722 class="cm">// `;\n`
723 pos += 2
724
725 node.dst = [source, start, end]
726 }
727 }
728
729 class="cm">// Rule
730 else if (node.kind === class="st">'rule') {
731 css += `${indent}${node.selector} {\n`
732
733 if (track) {
734 class="cm">// indent
735 pos += indent.length
736
737 class="cm">// node.selector
738 let start = pos
739 pos += node.selector.length
740
741 class="cm">// ` `
742 pos += 1

Callers 15

rewriteUrlsFunction · 0.90
parseCssFunction · 0.90
onCircularDependencyFunction · 0.90
buildFunction · 0.90
ast.test.tsFile · 0.90
ast.bench.tsFile · 0.90
expandFunction · 0.90
walk.test.tsFile · 0.90
visitFunction · 0.90
candidatesToCssFunction · 0.90

Calls 1

stringifyFunction · 0.85

Tested by 2

expandFunction · 0.72
analyzeFunction · 0.72