Skip to content

Commit 5c568c1

Browse files
Ensure @Keyframes are still printed
1 parent 4e200f4 commit 5c568c1

File tree

2 files changed

+48
-15
lines changed

2 files changed

+48
-15
lines changed

packages/tailwindcss/src/index.test.ts

Lines changed: 45 additions & 9 deletions
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
})
@@ -1822,7 +1822,7 @@ describe('Parsing theme values from CSS', () => {
18221822
`)
18231823
})
18241824

1825-
test('theme values added as reference are not included in the output as variables', async () => {
1825+
test('theme values added as reference are not included in the output as variables but emit fallback values', async () => {
18261826
expect(
18271827
await compileCss(
18281828
css`
@@ -1875,6 +1875,16 @@ describe('Parsing theme values from CSS', () => {
18751875
).toMatchInlineSnapshot(`
18761876
".animate-foo {
18771877
animation: var(--animate-foo, foo 1s infinite);
1878+
}
1879+
1880+
@keyframes foo {
1881+
0%, 100% {
1882+
color: red;
1883+
}
1884+
1885+
50% {
1886+
color: #00f;
1887+
}
18781888
}"
18791889
`)
18801890
})
@@ -1916,6 +1926,16 @@ describe('Parsing theme values from CSS', () => {
19161926
19171927
.bg-pink {
19181928
background-color: var(--color-pink);
1929+
}
1930+
1931+
@keyframes foo {
1932+
0%, 100% {
1933+
color: red;
1934+
}
1935+
1936+
50% {
1937+
color: #00f;
1938+
}
19191939
}"
19201940
`)
19211941
})
@@ -3696,7 +3716,7 @@ it("should error when `layer(…)` is used, but it's not the first param", async
36963716
)
36973717
})
36983718

3699-
describe('`@reference "…" reference`', () => {
3719+
describe('`@reference "…" imports`', () => {
37003720
test('recursively removes styles', async () => {
37013721
let loadStylesheet = async (id: string, base: string) => {
37023722
if (id === './foo/baz.css') {
@@ -3851,11 +3871,17 @@ describe('`@reference "…" reference`', () => {
38513871
).resolves.toMatchInlineSnapshot(`
38523872
".bar {
38533873
animation: var(--animate-spin, spin 1s linear infinite);
3874+
}
3875+
3876+
@keyframes spin {
3877+
to {
3878+
transform: rotate(360deg);
3879+
}
38543880
}"
38553881
`)
38563882
})
38573883

3858-
test('emits theme variables and keyframes defined inside @reference-ed files', async () => {
3884+
test('emits CSS variable fallback and keyframes defined inside @reference-ed files', async () => {
38593885
let loadStylesheet = async (id: string, base: string) => {
38603886
switch (id) {
38613887
case './one.css': {
@@ -3915,6 +3941,16 @@ describe('`@reference "…" reference`', () => {
39153941
".bar {
39163942
animation: var(--animate-wiggle, wiggle 1s ease-in-out infinite);
39173943
color: var(--color-red, red);
3944+
}
3945+
3946+
@keyframes wiggle {
3947+
0%, 100% {
3948+
transform: rotate(-3deg);
3949+
}
3950+
3951+
50% {
3952+
transform: rotate(3deg);
3953+
}
39183954
}"
39193955
`)
39203956
})

packages/tailwindcss/src/index.ts

Lines changed: 3 additions & 6 deletions
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(context({ theme: true }, [atRoot([keyframes])]))
549546
}
550547

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

0 commit comments

Comments
 (0)