Repository: tailwindlabs/tailwindcss
File: packages/tailwindcss/src/index.ts (TypeScript)

Code before:
          continue
        }

        // Wrap `@keyframes` in `AtRoot` so they are hoisted out of `:root` when
        // printing.
        nodes.push(atRoot([keyframesRule]))
      }
    }
    firstThemeRule.nodes = nodes
  }

  // Replace the `@tailwind utilities` node with a context since it prints
  // children directly.
  if (utilitiesNode) {
    let node = utilitiesNode as AstNode as Context
    node.kind = 'context'
    node.context = {}
  }

  // Replace the `@variant` at-rules with the actual variant rules.
  if (variantNodes.length > 0) {
    for (let variantNode of variantNodes) {
      // Starting with the `&` rule node
      let node = styleRule('&', variantNode.nodes)

      for (let variant of segment(variantNode.params, ':').reverse()) {
        let variantAst = designSystem.parseVariant(variant)
        if (variantAst === null) {
          throw new Error(`Cannot use \`@variant\` with unknown variant: ${variant}`)
        }

        let result = applyVariant(node, variantAst, designSystem.variants)
        if (result === null) {
          throw new Error(`Cannot use \`@variant\` with variant: ${variant}`)
        }
      }

      // Update the variant at-rule node, to be the `&` rule node
      Object.assign(variantNode, node)
    }
    features |= Features.Variants
  }

  features |= substituteFunctions(ast, designSystem)
  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


Review comment (suggestion):
To decide:

Right now this code means that we can use `@variant md:dark:hover {}`. If we _only_ want to allow a single `@variant`, then this could be simplified to just:
```suggestion
      for (let variant of [variantNode.params]) {
```

And get rid of the loop.

Code after:
      )

      for (let keyframesRule of keyframesRules) {
        // Remove any keyframes that aren't used by an animation variable.
        let keyframesName = keyframesRule.params
        if (!animationParts.includes(keyframesName)) {
          continue
        }

        // Wrap `@keyframes` in `AtRoot` so they are hoisted out of `:root` when
        // printing.
        nodes.push(atRoot([keyframesRule]))
      }
    }
    firstThemeRule.nodes = nodes
  }

  // Replace the `@tailwind utilities` node with a context since it prints
  // children directly.
  if (utilitiesNode) {
    let node = utilitiesNode as AstNode as Context
    node.kind = 'context'
    node.context = {}
  }

  // Replace the `@variant` at-rules with the actual variant rules.
  if (variantNodes.length > 0) {
    for (let variantNode of variantNodes) {
      // Starting with the `&` rule node
      let node = styleRule('&', variantNode.nodes)

      let variant = variantNode.params

      let variantAst = designSystem.parseVariant(variant)
      if (variantAst === null) {
        throw new Error(`Cannot use \`@variant\` with unknown variant: ${variant}`)
      }

      let result = applyVariant(node, variantAst, designSystem.variants)
      if (result === null) {
        throw new Error(`Cannot use \`@variant\` with variant: ${variant}`)
      }

      // Update the variant at-rule node, to be the `&` rule node
      Object.assign(variantNode, node)
    }
    features |= Features.Variants
  }

  features |= substituteFunctions(ast, designSystem)
  features |= substituteAtApply(ast, designSystem)