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

Function transform

packages/@tailwindcss-postcss/src/ast.ts:64–117  ·  view source on GitHub ↗
(node: AstNode, parent: postcss.Container)

Source from the content-addressed store, hash-verified

62 }
63
64 function transform(node: AstNode, parent: postcss.Container) {
65 // Declaration
66 if (node.kind === 'declaration') {
67 let astNode = postcss.decl({
68 prop: node.property,
69 value: node.value ?? '',
70 important: node.important,
71 })
72 updateSource(astNode, node.src)
73 parent.append(astNode)
74 }
75
76 // Rule
77 else if (node.kind === 'rule') {
78 let astNode = postcss.rule({ selector: node.selector })
79 updateSource(astNode, node.src)
80 astNode.raws.semicolon = true
81 parent.append(astNode)
82 for (let child of node.nodes) {
83 transform(child, astNode)
84 }
85 }
86
87 // AtRule
88 else if (node.kind === 'at-rule') {
89 let astNode = postcss.atRule({ name: node.name.slice(1), params: node.params })
90 updateSource(astNode, node.src)
91 astNode.raws.semicolon = true
92 parent.append(astNode)
93 for (let child of node.nodes) {
94 transform(child, astNode)
95 }
96 }
97
98 // Comment
99 else if (node.kind === 'comment') {
100 let astNode = postcss.comment({ text: node.value })
101 // Spaces are encoded in our node.value already, no need to add additional
102 // spaces.
103 astNode.raws.left = ''
104 astNode.raws.right = ''
105 updateSource(astNode, node.src)
106 parent.append(astNode)
107 }
108
109 // AtRoot & Context should not happen
110 else if (node.kind === 'at-root' || node.kind === 'context') {
111 }
112
113 // Unknown
114 else {
115 node satisfies never
116 }
117 }
118
119 for (let node of ast) {
120 transform(node, root)

Callers 3

cssAstToPostCssAstFunction · 0.70
postCssAstToCssAstFunction · 0.70
optimizeFunction · 0.50

Calls 8

declFunction · 0.90
ruleFunction · 0.90
atRuleFunction · 0.90
commentFunction · 0.90
updateSourceFunction · 0.85
toSourceFunction · 0.85
commentMethod · 0.80
eachMethod · 0.80

Tested by

no test coverage detected