Skip to content

Commit

Permalink
fix: handle vendor prefixed keyframes and animation in CSS modules
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Apr 12, 2023
1 parent ecdcc1a commit f84a051
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/css/CssParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,7 @@ class CssParser extends Parser {
dep.setLoc(sl, sc, el, ec);
module.addDependency(dep);
declaredCssVariables.add(name);
} else if (
propertyName.toLowerCase() === "animation-name" ||
propertyName.toLowerCase() === "animation"
) {
} else if (/^(-\w+-)?animation(-name)?$/i.test(propertyName)) {
modeData = "animation";
lastIdentifier = undefined;
}
Expand Down Expand Up @@ -361,7 +358,7 @@ class CssParser extends Parser {
supports: undefined
};
}
if (name === "@keyframes") {
if (/^@(-\w+-)?keyframes$/.test(name)) {
let pos = end;
pos = walkCssTokens.eatWhitespaceAndComments(input, pos);
if (pos === input.length) return pos;
Expand Down
3 changes: 3 additions & 0 deletions test/configCases/css/css-modules-in-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ it("should allow to create css modules", done => {
VARS: prod
? "--my-app-491-DJ my-app-491-ms undefined my-app-491-cU"
: "--./style.module.css-LOCAL-COLOR ./style.module.css-VARS undefined ./style.module.css-globalVarsUpperCase",
animationName: prod
? "my-app-491-w3"
: "./style.module.css-animationName",
});
} catch (e) {
return done(e);
Expand Down
3 changes: 3 additions & 0 deletions test/configCases/css/css-modules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ it("should allow to create css modules", done => {
VARS: prod
? "--my-app-491-DJ my-app-491-ms undefined my-app-491-cU"
: "--./style.module.css-LOCAL-COLOR ./style.module.css-VARS undefined ./style.module.css-globalVarsUpperCase",
animationName: prod
? "my-app-491-w3"
: "./style.module.css-animationName",
});
} catch (e) {
return done(e);
Expand Down
37 changes: 37 additions & 0 deletions test/configCases/css/css-modules/style.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,40 @@
COLOR: VAR(--GLOBAR-COLOR);
--GLOBAR-COLOR: red;
}

.a {
animation: 3s animationName;
-webkit-animation: 3s animationName;
}

.b {
animation: animationName 3s;
-webkit-animation: animationName 3s;
}

.c {
animation-name: animationName;
-webkit-animation-name: animationName;
}

.d {
--animation-name: animationName;
}

@keyframes animationName {
0% {
background: white;
}
100% {
background: red;
}
}

@-webkit-keyframes animationName {
0% {
background: white;
}
100% {
background: red;
}
}
1 change: 1 addition & 0 deletions test/configCases/css/css-modules/use-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ export default {
supportsInMedia: style.displayFlexInSupportsInMedia,
displayFlexInSupportsInMediaUpperCase: style.displayFlexInSupportsInMediaUpperCase,
VARS: `${style["LOCAL-COLOR"]} ${style.VARS} ${style["GLOBAL-COLOR"]} ${style.globalVarsUpperCase}`,
animationName: style.animationName,
};

0 comments on commit f84a051

Please sign in to comment.