Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
set @tailwind utilities nodes
Instead of replacing the node that represents the `@tailwind utilities`
with the generated AST nodes from the rawCandidates, we will set the
nodes of the `@tailwind utilities` rule to the AST nodes instead.

This way we dont' have to remove and replace the `@tailwind utilities`
rule with `n` new nodes. This will later allow us to track the
`@tailwindcss utilities` rule itself and update its `nodes` for
incremental rebuilds.

This also requires a small change to the printer where we now need to
print the children of the `@tailwind utilities` rule. Note: we keep the
same `depth` as-if the `@tailwindcss utilities` rule was not there.
Otherwise additional indentation would be present.
  • Loading branch information
RobinMalfait committed Mar 11, 2024
commit 2820e70d04d74617db2cb007136bd6fcf8bf001c
7 changes: 7 additions & 0 deletions packages/tailwindcss/src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ export function toCss(ast: AstNode[]) {
return css
}

if (node.selector === '@tailwind utilities') {
for (let child of node.nodes) {
css += stringify(child, depth)
}
return css
}

// Print at-rules without nodes with a `;` instead of an empty block.
//
// E.g.:
Expand Down
4 changes: 1 addition & 3 deletions packages/tailwindcss/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ describe('compiling CSS', () => {

.grid {
display: grid;
}

@tailwind utilities;"
}"
`)
})

Expand Down
6 changes: 4 additions & 2 deletions packages/tailwindcss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ export function compile(

// Find `@tailwind utilities` and replace it with the actual generated utility
// class CSS.
walk(ast, (node, { replaceWith }) => {
walk(ast, (node) => {
if (node.kind === 'rule' && node.selector === '@tailwind utilities') {
replaceWith(compileCandidates(rawCandidates, designSystem).astNodes)
// Set the `@tailwind utilities` nodes, to the actual generated CSS
node.nodes = compileCandidates(rawCandidates, designSystem).astNodes

// Stop walking after finding `@tailwind utilities` to avoid walking all
// of the generated CSS. This means `@tailwind utilities` can only appear
// once per file but that's the intended usage at this point in time.
Expand Down