Skip to content
Prev Previous commit
Next Next commit
simplify main substituteAtApply call again
Now that we are substituting `@apply` in the correct order via a
topological sort, it means that we don't have to try and first handle
all `@utility` at-rules. This will already be handled in the correct
order.
  • Loading branch information
RobinMalfait committed Jan 7, 2025
commit aa423efb5e80df99ffdcc1ff682c169009486414
24 changes: 5 additions & 19 deletions packages/tailwindcss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,24 +538,15 @@ async function parseCss(
node.context = {}
}

// Post-process `@utility` nodes.
//
// We have to do this as a separate step because if we replace the `@utility`
// nodes when we collect it in the system, then we can't substitute the
// `@apply` at-rules anymore.
//
// We also can't substitute the `@apply` at-rules while collecting the
// `@utility` rules, because if it relies on a utility that is defined later,
// then we wouldn't be able to resolve the applied utility.
//
// Lastly, we can't rely on the single `substituteAtApply` call at the end
// because this replaces `@apply`, but won't replace `@apply` if we injected
// an `@apply`.
features |= substituteFunctions(ast, designSystem.resolveThemeValue)
features |= substituteAtApply(ast, designSystem)

// Remove `@utility`, we couldn't replace it before yet because we had to
// handle the nested `@apply` at-rules first.
walk(ast, (node, { replaceWith }) => {
if (node.kind !== 'at-rule') return

if (node.name === '@utility') {
substituteAtApply(node.nodes, designSystem)
replaceWith([])
}

Expand All @@ -564,11 +555,6 @@ async function parseCss(
return WalkAction.Skip
})

// Replace `@apply` rules with the actual utility classes.
features |= substituteAtApply(ast, designSystem)

features |= substituteFunctions(ast, designSystem.resolveThemeValue)

return {
designSystem,
ast,
Expand Down