Skip to content
Draft
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
40 changes: 40 additions & 0 deletions packages/tailwindcss/src/compat/plugin-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1584,6 +1584,46 @@ describe('addBase', () => {
"
`)
})

test('@variant is replaced inside rules using addBase', async () => {
let input = css`
@plugin "my-plugin";
@theme {
--breakpoint-supertiny: 128px;
}
`

let compiler = await compile(input, {
loadModule: async () => ({
path: '',
base: '/root',
module: plugin(function ({ addBase }) {
addBase({
':root': {
'@variant supertiny': {
'--PascalCase': '1',
'--camelCase': '1',
'--UPPERCASE': '1',
},
},
})
}),
}),
})

expect(compiler.build([])).toMatchInlineSnapshot(`
"@layer base {
:root {
@media (width >= 128px) {
--PascalCase: 1;
--camelCase: 1;
--UPPERCASE: 1;
}
}
}
"
`)
})
})

describe('addVariant', () => {
Expand Down
8 changes: 7 additions & 1 deletion packages/tailwindcss/src/compat/plugin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import { escape } from '../utils/escape'
import { inferDataType } from '../utils/infer-data-type'
import { segment } from '../utils/segment'
import { toKeyPath } from '../utils/to-key-path'
import { compoundsForSelectors, IS_VALID_VARIANT_NAME, substituteAtSlot } from '../variants'
import {
compoundsForSelectors,
IS_VALID_VARIANT_NAME,
substituteAtSlot,
substituteAtVariant,
} from '../variants'
import { walk, WalkAction } from '../walk'
import type { ResolvedConfig, UserConfig } from './config/types'
import { createThemeFn } from './plugin-functions'
Expand Down Expand Up @@ -110,6 +115,7 @@ export function buildPluginApi({
if (referenceMode) return
let baseNodes = objectToAst(css)
featuresRef.current |= substituteFunctions(baseNodes, designSystem)
featuresRef.current |= substituteAtVariant(baseNodes, designSystem)
let rule = atRule('@layer', 'base', baseNodes)
walk([rule], (node) => {
node.src = src
Expand Down