Skip to content

Commit 85b933b

Browse files
Ensure @Keyframes are still printed
1 parent 4e200f4 commit 85b933b

File tree

3 files changed

+121
-15
lines changed

3 files changed

+121
-15
lines changed

packages/tailwindcss/src/__snapshots__/index.test.ts.snap

+31
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,36 @@ exports[`compiling CSS > \`@tailwind utilities\` is replaced by utilities using
9090
syntax: "*";
9191
inherits: false;
9292
initial-value: 0 0 #0000;
93+
}
94+
95+
@keyframes spin {
96+
to {
97+
transform: rotate(360deg);
98+
}
99+
}
100+
101+
@keyframes ping {
102+
75%, 100% {
103+
opacity: 0;
104+
transform: scale(2);
105+
}
106+
}
107+
108+
@keyframes pulse {
109+
50% {
110+
opacity: .5;
111+
}
112+
}
113+
114+
@keyframes bounce {
115+
0%, 100% {
116+
animation-timing-function: cubic-bezier(.8, 0, 1, 1);
117+
transform: translateY(-25%);
118+
}
119+
120+
50% {
121+
animation-timing-function: cubic-bezier(0, 0, .2, 1);
122+
transform: none;
123+
}
93124
}"
94125
`;

packages/tailwindcss/src/index.test.ts

+87-9
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,6 @@ describe('@apply', () => {
325325
}
326326
}
327327
328-
@keyframes spin {
329-
to {
330-
transform: rotate(360deg);
331-
}
332-
}
333-
334328
@property --tw-translate-x {
335329
syntax: "*";
336330
inherits: false;
@@ -347,6 +341,12 @@ describe('@apply', () => {
347341
syntax: "*";
348342
inherits: false;
349343
initial-value: 0;
344+
}
345+
346+
@keyframes spin {
347+
to {
348+
transform: rotate(360deg);
349+
}
350350
}"
351351
`)
352352
})
@@ -1155,6 +1155,12 @@ describe('Parsing theme values from CSS', () => {
11551155
11561156
.accent-red {
11571157
accent-color: var(--color-red);
1158+
}
1159+
1160+
@keyframes foo {
1161+
to {
1162+
opacity: 1;
1163+
}
11581164
}"
11591165
`)
11601166
})
@@ -1241,6 +1247,12 @@ describe('Parsing theme values from CSS', () => {
12411247
12421248
.accent-green {
12431249
accent-color: var(--color-green);
1250+
}
1251+
1252+
@keyframes spin {
1253+
to {
1254+
transform: rotate(360deg);
1255+
}
12441256
}"
12451257
`)
12461258
})
@@ -1288,6 +1300,12 @@ describe('Parsing theme values from CSS', () => {
12881300
12891301
.accent-green {
12901302
accent-color: var(--color-green);
1303+
}
1304+
1305+
@keyframes spin {
1306+
to {
1307+
transform: rotate(360deg);
1308+
}
12911309
}"
12921310
`)
12931311
})
@@ -1563,6 +1581,12 @@ describe('Parsing theme values from CSS', () => {
15631581
animation: var(--animate-foobar);
15641582
}
15651583
1584+
@keyframes foo {
1585+
to {
1586+
opacity: 1;
1587+
}
1588+
}
1589+
15661590
@keyframes foobar {
15671591
to {
15681592
opacity: 0;
@@ -1609,6 +1633,12 @@ describe('Parsing theme values from CSS', () => {
16091633
to {
16101634
opacity: 1;
16111635
}
1636+
}
1637+
1638+
@keyframes unused {
1639+
to {
1640+
opacity: 0;
1641+
}
16121642
}"
16131643
`)
16141644
})
@@ -1685,6 +1715,12 @@ describe('Parsing theme values from CSS', () => {
16851715
to {
16861716
opacity: 1;
16871717
}
1718+
}
1719+
1720+
@keyframes unused {
1721+
to {
1722+
opacity: 0;
1723+
}
16881724
}"
16891725
`)
16901726
})
@@ -1773,6 +1809,12 @@ describe('Parsing theme values from CSS', () => {
17731809
to {
17741810
opacity: 1;
17751811
}
1812+
}
1813+
1814+
@keyframes unused {
1815+
to {
1816+
opacity: 0;
1817+
}
17761818
}"
17771819
`)
17781820
})
@@ -1822,7 +1864,7 @@ describe('Parsing theme values from CSS', () => {
18221864
`)
18231865
})
18241866

1825-
test('theme values added as reference are not included in the output as variables', async () => {
1867+
test('theme values added as reference are not included in the output as variables but emit fallback values', async () => {
18261868
expect(
18271869
await compileCss(
18281870
css`
@@ -1875,6 +1917,16 @@ describe('Parsing theme values from CSS', () => {
18751917
).toMatchInlineSnapshot(`
18761918
".animate-foo {
18771919
animation: var(--animate-foo, foo 1s infinite);
1920+
}
1921+
1922+
@keyframes foo {
1923+
0%, 100% {
1924+
color: red;
1925+
}
1926+
1927+
50% {
1928+
color: #00f;
1929+
}
18781930
}"
18791931
`)
18801932
})
@@ -1916,6 +1968,16 @@ describe('Parsing theme values from CSS', () => {
19161968
19171969
.bg-pink {
19181970
background-color: var(--color-pink);
1971+
}
1972+
1973+
@keyframes foo {
1974+
0%, 100% {
1975+
color: red;
1976+
}
1977+
1978+
50% {
1979+
color: #00f;
1980+
}
19191981
}"
19201982
`)
19211983
})
@@ -3696,7 +3758,7 @@ it("should error when `layer(…)` is used, but it's not the first param", async
36963758
)
36973759
})
36983760

3699-
describe('`@reference "…" reference`', () => {
3761+
describe('`@reference "…" imports`', () => {
37003762
test('recursively removes styles', async () => {
37013763
let loadStylesheet = async (id: string, base: string) => {
37023764
if (id === './foo/baz.css') {
@@ -3851,11 +3913,17 @@ describe('`@reference "…" reference`', () => {
38513913
).resolves.toMatchInlineSnapshot(`
38523914
".bar {
38533915
animation: var(--animate-spin, spin 1s linear infinite);
3916+
}
3917+
3918+
@keyframes spin {
3919+
to {
3920+
transform: rotate(360deg);
3921+
}
38543922
}"
38553923
`)
38563924
})
38573925

3858-
test('emits theme variables and keyframes defined inside @reference-ed files', async () => {
3926+
test('emits CSS variable fallback and keyframes defined inside @reference-ed files', async () => {
38593927
let loadStylesheet = async (id: string, base: string) => {
38603928
switch (id) {
38613929
case './one.css': {
@@ -3915,6 +3983,16 @@ describe('`@reference "…" reference`', () => {
39153983
".bar {
39163984
animation: var(--animate-wiggle, wiggle 1s ease-in-out infinite);
39173985
color: var(--color-red, red);
3986+
}
3987+
3988+
@keyframes wiggle {
3989+
0%, 100% {
3990+
transform: rotate(-3deg);
3991+
}
3992+
3993+
50% {
3994+
transform: rotate(3deg);
3995+
}
39183996
}"
39193997
`)
39203998
})

packages/tailwindcss/src/index.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -468,10 +468,6 @@ async function parseCss(
468468
// since the `@theme` rule itself will be removed.
469469
if (child.kind === 'at-rule' && child.name === '@keyframes') {
470470
// Do not track/emit `@keyframes`, if they are part of a `@theme reference`.
471-
if (themeOptions & ThemeOptions.REFERENCE) {
472-
return WalkAction.Skip
473-
}
474-
475471
theme.addKeyframes(child)
476472
return WalkAction.Skip
477473
}
@@ -544,8 +540,9 @@ async function parseCss(
544540
let keyframesRules = designSystem.theme.getKeyframes()
545541
for (let keyframes of keyframesRules) {
546542
// Wrap `@keyframes` in `AtRoot` so they are hoisted out of `:root` when
547-
// printing.
548-
nodes.push(atRoot([keyframes]))
543+
// printing. We push it to the top-level of the AST so that an eventual
544+
// `@reference` does not cut it out when printing the document.
545+
ast.push(atRoot([keyframes]))
549546
}
550547

551548
firstThemeRule.nodes = [context({ theme: true }, nodes)]

0 commit comments

Comments
 (0)