Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Nothing yet!
### Fixed

- _Experimental_: Improve codemod output, keep CSS after last Tailwind directive unlayered ([#14512](https://github.com/tailwindlabs/tailwindcss/pull/14512))

## [4.0.0-alpha.25] - 2024-09-24

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,9 @@ it('should migrate rules between tailwind directives', async () => {

@tailwind utilities;

@layer utilities {
.utility-a {
}
.utility-b {
}
.utility-a {
}
.utility-b {
}"
`)
})
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,32 @@ export function migrateMissingLayers(): Plugin {

// Track the node
if (lastLayer !== '') {
if (bucket.push(node) !== 1) {
node.remove()
}
bucket.push(node)
}
})

// Add the last bucket if it's not empty
if (bucket.length > 0) {
buckets.push([lastLayer, bucket.splice(0)])
}

// Wrap each bucket in an `@layer` at-rule
for (let [layerName, nodes] of buckets) {
let target = nodes[0]
let layerNode = new AtRule({
name: 'layer',
params: layerName,
nodes,
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) {
return node
}

// Every other node should be removed from its original position. They
// will be added to the new layer node.
return node.remove()
}),
raws: {
tailwind_pretty: true,
},
})
nodes[0].replaceWith(layerNode)
target.replaceWith(layerNode)
}
}

Expand Down