Repository: tailwindlabs/tailwindcss
File: packages/@tailwindcss-upgrade/src/codemods/migrate-missing-layers.ts (TypeScript)

Code before:
        // Already in a layer
        if (node.name === 'layer') {
          if (bucket.length > 0) {
            buckets.push([lastLayer, bucket.splice(0)])
          }
          return
        }

        // Add layer to `@import` at-rules
        if (node.name === 'import') {
          if (lastLayer !== '' && !node.params.includes('layer(')) {
            node.params += ` layer(${lastLayer})`
          }

          if (bucket.length > 0) {
            buckets.push([lastLayer, bucket.splice(0)])
          }
          return
        }
      }

      // (License) comments, body-less `@layer` and `@charset` can stay at the
      // top, when we haven't found any `@tailwind` at-rules yet.
      if (
        lastLayer === '' &&
        (node.type === 'comment' /* Comment*/ ||
          (node.type === 'atrule' && !node.nodes) || // @layer foo, bar, baz;
          (node.type === 'atrule' && node.name === 'charset')) // @charset "UTF-8";
      ) {
        return
      }

      // Track the node
      bucket.push(node)
    })

    // Wrap each bucket in an `@layer` at-rule
    for (let [layerName, nodes] of buckets) {
      // Do not wrap comments in a layer, if they are the only nodes.
      if (nodes.every((node) => node.type === 'comment')) {
        continue
      }

      let target = nodes[0]
      let layerNode = new AtRule({
        name: 'layer',
        params: layerName || firstLayerName || '',
        nodes: nodes.map((node) => {
          // Keep the target node as-is, because we will be replacing that one
          // with the new layer node.
          if (node === target) {

Review comment (suggestion):
```suggestion
        (node.type === 'comment' /* Comment */ ||
```

Code after:
        // Already in a layer
        if (node.name === 'layer') {
          if (bucket.length > 0) {
            buckets.push([lastLayer, bucket.splice(0)])
          }
          return
        }

        // Add layer to `@import` at-rules
        if (node.name === 'import') {
          if (lastLayer !== '' && !node.params.includes('layer(')) {
            node.params += ` layer(${lastLayer})`
          }

          if (bucket.length > 0) {
            buckets.push([lastLayer, bucket.splice(0)])
          }
          return
        }
      }

      // (License) comments, body-less `@layer` and `@charset` can stay at the
      // top, when we haven't found any `@tailwind` at-rules yet.
      if (
        lastLayer === '' &&
        (node.type === 'comment' /* Comment */ ||
          (node.type === 'atrule' && !node.nodes) || // @layer foo, bar, baz;
          (node.type === 'atrule' && node.name === 'charset')) // @charset "UTF-8";
      ) {
        return
      }

      // Track the node
      bucket.push(node)
    })

    // Wrap each bucket in an `@layer` at-rule
    for (let [layerName, nodes] of buckets) {
      // Do not wrap comments in a layer, if they are the only nodes.
      if (nodes.every((node) => node.type === 'comment')) {
        continue
      }

      let target = nodes[0]
      let layerNode = new AtRule({
        name: 'layer',
        params: layerName || firstLayerName || '',
        nodes: nodes.map((node) => {
          // Keep the target node as-is, because we will be replacing that one
          // with the new layer node.
          if (node === target) {