Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
ensure CSS before a layer stays unlayered
  • Loading branch information
RobinMalfait committed Oct 4, 2024
commit ee62a313128f4c4ef8f13771018620f4684203d3
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,29 @@ it('should migrate rules between tailwind directives', async () => {
}"
`)
})

it('should keep CSS above a layer unlayered', async () => {
expect(
await migrate(css`
.foo {
color: red;
}

@layer components {
.bar {
color: blue;
}
}
`),
).toMatchInlineSnapshot(`
".foo {
color: red;
}

@layer components {
.bar {
color: blue;
}
}"
`)
})
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ export function migrateMissingLayers(): Plugin {

// Wrap each bucket in an `@layer` at-rule
for (let [layerName, nodes] of buckets) {
let targetLayerName = layerName || firstLayerName || ''
if (targetLayerName === '') {
continue
}

// Do not wrap comments in a layer, if they are the only nodes.
if (nodes.every((node) => node.type === 'comment')) {
continue
Expand Down
27 changes: 27 additions & 0 deletions packages/@tailwindcss-upgrade/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,30 @@ it('should migrate a stylesheet (with preceding rules that should be wrapped in
}"
`)
})

it('should keep CSS as-is before existing `@layer` at-rules', async () => {
expect(
await migrateContents(
css`
.foo {
color: blue;
}

@layer components {
.bar {
color: red;
}
}
`,
{},
),
).toMatchInlineSnapshot(`
".foo {
color: blue;
}

@utility bar {
color: red;
}"
`)
})