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
always add layer(…) as the first param
  • Loading branch information
RobinMalfait committed Nov 22, 2024
commit 25c626a7953105d55ab0bbe52e0a4ca11ca379fb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ it('should add missing `layer(…)` to imported files', async () => {
`)
})

it('should add missing `layer(…)` as the first param after the import itself', async () => {
expect(
await migrate(css`
@import 'tailwindcss/utilities' supports(--foo); /* Expected no layer */
@import './foo.css' supports(--foo); /* Expected layer(utilities) supports(--foo) */
@import './bar.css' supports(--foo); /* Expected layer(utilities) supports(--foo) */
@import 'tailwindcss/components' supports(--foo); /* Expected no layer */
`),
).toMatchInlineSnapshot(`
"@import 'tailwindcss/utilities' supports(--foo); /* Expected no layer */
@import './foo.css' layer(utilities) supports(--foo); /* Expected layer(utilities) supports(--foo) */
@import './bar.css' layer(utilities) supports(--foo); /* Expected layer(utilities) supports(--foo) */
@import 'tailwindcss/components' supports(--foo); /* Expected no layer */"
`)
})

it('should not migrate anything if no `@tailwind` directives (or imports) are found', async () => {
expect(
await migrate(css`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AtRule, type ChildNode, type Plugin, type Root } from 'postcss'
import { segment } from '../../../tailwindcss/src/utils/segment'

export function migrateMissingLayers(): Plugin {
function migrate(root: Root) {
Expand Down Expand Up @@ -119,7 +120,9 @@ export function migrateMissingLayers(): Plugin {
if (node.type !== 'atrule' || node.name !== 'import') continue

if (!node.params.includes('layer(')) {
node.params += ` layer(${targetLayerName})`
let params = segment(node.params, ' ')
params.splice(1, 0, `layer(${targetLayerName})`)
node.params = params.join(' ')
node.raws.tailwind_injected_layer = true
}
}
Expand Down