Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add transform wrapper method, use it for @keyframes rules #994

Merged
merged 3 commits into from
Feb 7, 2023
Merged
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
4 changes: 3 additions & 1 deletion .changeset/empty-snakes-deny.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
'@vanilla-extract/css': patch
---

Fix generation of invalid CSS inside `@keyframes` rules by transforming `content` property values
Align transformation of `@keyframes` rules with other rules

This fixes a bug where invalid CSS could be generated inside `@keyframes` rules.
4 changes: 4 additions & 0 deletions packages/css/src/transformCss.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1375,10 +1375,12 @@ describe('transformCss', () => {
from: {
opacity: 0,
content: 'none',
padding: 0,
},
to: {
opacity: 1,
content: 'foo',
padding: 10,
},
},
},
Expand All @@ -1389,10 +1391,12 @@ describe('transformCss', () => {
from {
content: none;
opacity: 0;
padding: 0;
}
to {
content: "foo";
opacity: 1;
padding: 10px;
}
}"
`);
Expand Down
18 changes: 9 additions & 9 deletions packages/css/src/transformCss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class Stylesheet {
if (root.type === 'keyframes') {
root.rule = Object.fromEntries(
Object.entries(root.rule).map(([keyframe, rule]) => {
return [keyframe, this.transformContent(rule)];
return [keyframe, this.transformProperties(rule)];
}),
);
this.keyframesRules.push(root);
Expand Down Expand Up @@ -184,10 +184,8 @@ class Stylesheet {
}

addConditionalRule(cssRule: CSSRule, conditions: Array<string>) {
// Run `pixelifyProperties` before `transformVars` as we don't want to pixelify CSS Vars
const rule = this.transformVars(
this.transformContent(this.pixelifyProperties(cssRule.rule)),
);
// Run `transformProperties` before `transformVars` as we don't want to pixelify CSS Vars
const rule = this.transformVars(this.transformProperties(cssRule.rule));
const selector = this.transformSelector(cssRule.selector);

if (!this.currConditionalRuleset) {
Expand All @@ -208,10 +206,8 @@ class Stylesheet {
}

addRule(cssRule: CSSRule) {
// Run `pixelifyProperties` before `transformVars` as we don't want to pixelify CSS Vars
const rule = this.transformVars(
this.transformContent(this.pixelifyProperties(cssRule.rule)),
);
// Run `transformProperties` before `transformVars` as we don't want to pixelify CSS Vars
const rule = this.transformVars(this.transformProperties(cssRule.rule));
const selector = this.transformSelector(cssRule.selector);

this.rules.push({
Expand All @@ -220,6 +216,10 @@ class Stylesheet {
});
}

transformProperties(cssRule: CSSPropertiesWithVars) {
askoufis marked this conversation as resolved.
Show resolved Hide resolved
return this.transformContent(this.pixelifyProperties(cssRule));
}

pixelifyProperties(cssRule: CSSPropertiesWithVars) {
forEach(cssRule, (value, key) => {
if (
Expand Down