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

Function toCss

packages/tailwindcss/src/ast.ts:685–890  ·  view source on GitHub ↗
(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: '',
691 }
692
693 function stringify(node: AstNode, depth = 0): string {
694 let css = ''
695 let indent = ' '.repeat(depth)
696
697 // Declaration
698 if (node.kind === 'declaration') {
699 css += `${indent}${node.property}: ${node.value}${node.important ? ' !important' : ''};\n`
700
701 if (track) {
702 // indent
703 pos += indent.length
704
705 // node.property
706 let start = pos
707 pos += node.property.length
708
709 // `: `
710 pos += 2
711
712 // node.value
713 pos += node.value?.length ?? 0
714
715 // !important
716 if (node.important) {
717 pos += 11
718 }
719
720 let end = pos
721
722 // `;\n`
723 pos += 2
724
725 node.dst = [source, start, end]
726 }
727 }
728
729 // Rule
730 else if (node.kind === 'rule') {
731 css += `${indent}${node.selector} {\n`
732
733 if (track) {
734 // indent
735 pos += indent.length
736
737 // node.selector
738 let start = pos
739 pos += node.selector.length
740
741 // ` `
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