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

Code before:
        }

        // Handle important
        else if (param === 'important') {
          important = true
        }

        // Handle `layer(…)`
        else if (param.startsWith('layer(')) {
          // Whenever we see an `@media layer(…)`, it means one of two things:
          //
          // 1. Somebody added a manual `@media layer(…)` rule, which is not
          //    supported.
          // 2. Somebody used an `@import 'url' something(else) layer(…)` rule,
          //    which is not supported by spec because a `layer(…)` has to be
          //    first.

          // It was an `@import layer(…)`
          if (node.nodes?.[0]?.kind === 'context') {
            let actual = node.nodes[0].context.source.trim().slice(0, -1)
            let expected = segment(actual, ' ')
            let layer = expected.findIndex((part) => part.startsWith('layer('))
            expected.splice(2, 0, ...expected.splice(layer, 1))

            let errorMessage = [
              'A `layer(…)` in an `@import` should come first:',
              '',
              '```diff',
              `- ${actual};`,
              `+ ${expected.join(' ')};`,
              '```',
            ].join('\n')

            throw new Error(errorMessage)
          }

          // It was an `@media layer(…)`
          else {
            let afterNode = structuredClone(node)
            let afterAst = [afterNode]
            walk(afterAst, (node, { replaceWith }) => {
              if (
                node.kind === 'at-rule' &&
                node.name === '@media' &&
                node.params.includes('layer(')
              ) {
                let layer = segment(node.params, ' ')
                  .find((part) => part.startsWith('layer('))
                  ?.slice(6, -1)
                replaceWith(atRule('@layer', layer, node.nodes))
              }

Review comment (suggestion):
```suggestion
              '`layer(…)` in an `@import` should come before any other functions or conditions:',
```

Code after:
        }

        // Handle important
        else if (param === 'important') {
          important = true
        }

        //
        else {
          unknownParams.push(param)
        }
      }

      if (unknownParams.length > 0) {
        node.params = unknownParams.join(' ')
      } else if (params.length > 0) {
        replaceWith(node.nodes)
      }

      return WalkAction.Skip
    }

    // Handle `@theme`
    if (node.name === '@theme') {
      let [themeOptions, themePrefix] = parseThemeOptions(node.params)

      if (themePrefix) {
        if (!IS_VALID_PREFIX.test(themePrefix)) {
          throw new Error(
            `The prefix "${themePrefix}" is invalid. Prefixes must be lowercase ASCII letters (a-z) only.`,
          )
        }

        theme.prefix = themePrefix
      }

      // Record all custom properties in the `@theme` declaration
      walk(node.nodes, (child, { replaceWith }) => {
        // Collect `@keyframes` rules to re-insert with theme variables later,
        // since the `@theme` rule itself will be removed.
        if (child.kind === 'at-rule' && child.name === '@keyframes') {
          theme.addKeyframes(child)
          replaceWith([])
          return WalkAction.Skip
        }

        if (child.kind === 'comment') return
        if (child.kind === 'declaration' && child.property.startsWith('--')) {
          theme.add(child.property, child.value ?? '', themeOptions)
          return
        }