Skip to content

Commit ad66939

Browse files
Allow @variant to be used inside addBase (#19480)
This seems like an unintentional omission --------- Co-authored-by: Robin Malfait <[email protected]>
1 parent d42b34a commit ad66939

3 files changed

Lines changed: 57 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2626
- Ensure standalone `@tailwindcss/cli` binaries are ignored when scanning for class candidates ([#20139](https://github.com/tailwindlabs/tailwindcss/pull/20139))
2727
- Ensure class candidates are extracted from Twig `addClass(…)` and `removeClass(…)` calls ([#20198](https://github.com/tailwindlabs/tailwindcss/pull/20198))
2828
- Don't crash in the Ruby or Vue preprocessors when scanning files containing invalid UTF-8 bytes ([#19588](https://github.com/tailwindlabs/tailwindcss/pull/19588))
29+
- Allow `@variant` to be used inside `addBase` ([#19480](https://github.com/tailwindlabs/tailwindcss/pull/19480))
2930

3031
### Changed
3132

‎packages/tailwindcss/src/compat/plugin-api.test.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,55 @@ describe('addBase', () => {
14781478
"
14791479
`)
14801480
})
1481+
1482+
test('@variant is replaced inside rules using addBase', async () => {
1483+
expect(
1484+
await compileCss(
1485+
css`
1486+
@plugin "my-plugin";
1487+
@theme {
1488+
--breakpoint-supertiny: 128px;
1489+
}
1490+
`,
1491+
{
1492+
loadModule: async () => ({
1493+
path: '',
1494+
base: '/root',
1495+
module: plugin(function ({ addBase }) {
1496+
addBase({
1497+
':root': {
1498+
'@variant supertiny': {
1499+
'--PascalCase': '1',
1500+
'--camelCase': '1',
1501+
'--UPPERCASE': '1',
1502+
},
1503+
'@variant data-enabled:focus, disabled': {
1504+
'--x': '1',
1505+
},
1506+
},
1507+
})
1508+
}),
1509+
}),
1510+
},
1511+
),
1512+
).toMatchInlineSnapshot(`
1513+
"
1514+
@layer base {
1515+
@media (min-width: 128px) {
1516+
:root {
1517+
--PascalCase: 1;
1518+
--camelCase: 1;
1519+
--UPPERCASE: 1;
1520+
}
1521+
}
1522+
1523+
:root[data-enabled]:focus, :root:disabled {
1524+
--x: 1;
1525+
}
1526+
}
1527+
"
1528+
`)
1529+
})
14811530
})
14821531

14831532
describe('addVariant', () => {

‎packages/tailwindcss/src/compat/plugin-api.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ import { escape } from '../utils/escape'
1313
import { inferDataType } from '../utils/infer-data-type'
1414
import { segment } from '../utils/segment'
1515
import { toKeyPath } from '../utils/to-key-path'
16-
import { compoundsForSelectors, IS_VALID_VARIANT_NAME, substituteAtSlot } from '../variants'
16+
import {
17+
compoundsForSelectors,
18+
IS_VALID_VARIANT_NAME,
19+
substituteAtSlot,
20+
substituteAtVariant,
21+
} from '../variants'
1722
import { walk, WalkAction } from '../walk'
1823
import type { ResolvedConfig, UserConfig } from './config/types'
1924
import { createThemeFn } from './plugin-functions'
@@ -110,6 +115,7 @@ export function buildPluginApi({
110115
if (referenceMode) return
111116
let baseNodes = objectToAst(css)
112117
featuresRef.current |= substituteFunctions(baseNodes, designSystem)
118+
featuresRef.current |= substituteAtVariant(baseNodes, designSystem)
113119
let rule = atRule('@layer', 'base', baseNodes)
114120
walk([rule], (node) => {
115121
node.src = src

0 commit comments

Comments
 (0)