Skip to content

Commit 1c80a48

Browse files
committed
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.
1 parent db56e05 commit 1c80a48

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

packages/tailwindcss/src/index.ts

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -538,24 +538,15 @@ async function parseCss(
538538
node.context = {}
539539
}
540540

541-
// Post-process `@utility` nodes.
542-
//
543-
// We have to do this as a separate step because if we replace the `@utility`
544-
// nodes when we collect it in the system, then we can't substitute the
545-
// `@apply` at-rules anymore.
546-
//
547-
// We also can't substitute the `@apply` at-rules while collecting the
548-
// `@utility` rules, because if it relies on a utility that is defined later,
549-
// then we wouldn't be able to resolve the applied utility.
550-
//
551-
// Lastly, we can't rely on the single `substituteAtApply` call at the end
552-
// because this replaces `@apply`, but won't replace `@apply` if we injected
553-
// an `@apply`.
541+
features |= substituteFunctions(ast, designSystem.resolveThemeValue)
542+
features |= substituteAtApply(ast, designSystem)
543+
544+
// Remove `@utility`, we couldn't replace it before yet because we had to
545+
// handle the nested `@apply` at-rules first.
554546
walk(ast, (node, { replaceWith }) => {
555547
if (node.kind !== 'at-rule') return
556548

557549
if (node.name === '@utility') {
558-
substituteAtApply(node.nodes, designSystem)
559550
replaceWith([])
560551
}
561552

@@ -564,11 +555,6 @@ async function parseCss(
564555
return WalkAction.Skip
565556
})
566557

567-
// Replace `@apply` rules with the actual utility classes.
568-
features |= substituteAtApply(ast, designSystem)
569-
570-
features |= substituteFunctions(ast, designSystem.resolveThemeValue)
571-
572558
return {
573559
designSystem,
574560
ast,

0 commit comments

Comments
 (0)