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

Fix faulty css parser processing #16864

Merged
merged 8 commits into from Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/css/CssParser.js
Expand Up @@ -138,6 +138,7 @@ class CssParser extends Parser {
let singleClassSelector = undefined;
let lastIdentifier = undefined;
const modeStack = [];
let awaitRightParenthesis = false;
const isTopLevelLocal = () =>
modeData === "local" ||
(this.defaultMode === "local" && modeData === undefined);
Expand Down Expand Up @@ -511,6 +512,9 @@ class CssParser extends Parser {
rightParenthesis: (input, start, end) => {
switch (mode) {
case CSS_MODE_TOP_LEVEL: {
if (awaitRightParenthesis) {
awaitRightParenthesis = false;
}
const newModeData = modeStack.pop();
if (newModeData !== false) {
modeData = newModeData;
Expand Down Expand Up @@ -560,6 +564,9 @@ class CssParser extends Parser {
modeData = "local";
const dep = new ConstDependency("", [start, end]);
module.addPresentationalDependency(dep);
} else if ([":not", ":is"].includes(name)) {
janlent1 marked this conversation as resolved.
Show resolved Hide resolved
awaitRightParenthesis = true;
modeStack.push(false);
janlent1 marked this conversation as resolved.
Show resolved Hide resolved
} else {
modeStack.push(false);
}
Expand Down Expand Up @@ -597,8 +604,10 @@ class CssParser extends Parser {
comma: (input, start, end) => {
switch (mode) {
case CSS_MODE_TOP_LEVEL:
modeData = undefined;
modeStack.length = 0;
if (!awaitRightParenthesis) {
modeData = undefined;
modeStack.length = 0;
}
break;
case CSS_MODE_IN_LOCAL_RULE:
processDeclarationValueDone(input, start);
Expand Down
6 changes: 6 additions & 0 deletions test/configCases/css/css-modules-in-node/index.js
Expand Up @@ -15,6 +15,12 @@ it("should allow to create css modules", done => {
nested: prod
? "my-app-491-RX undefined my-app-491-X2"
: "./style.module.css-nested1 undefined ./style.module.css-nested3",
notWmultiParams: prod
? "my-app-491-Kw"
: "./style.module.css-local7",
isWmultiParams: prod
? "my-app-491-rw"
: "./style.module.css-local8",
ident: prod ? "my-app-491-yR" : "./style.module.css-ident",
keyframes: prod ? "my-app-491-y3" : "./style.module.css-localkeyframes",
animation: prod ? "my-app-491-oQ" : "./style.module.css-animation",
Expand Down
6 changes: 6 additions & 0 deletions test/configCases/css/css-modules/index.js
Expand Up @@ -18,6 +18,12 @@ it("should allow to create css modules", done => {
nested: prod
? "my-app-491-RX undefined my-app-491-X2"
: "./style.module.css-nested1 undefined ./style.module.css-nested3",
notWmultiParams: prod
? "my-app-491-Kw"
: "./style.module.css-local7",
isWmultiParams: prod
? "my-app-491-rw"
: "./style.module.css-local8",
ident: prod ? "my-app-491-yR" : "./style.module.css-ident",
keyframes: prod ? "my-app-491-y3" : "./style.module.css-localkeyframes",
animation: prod ? "my-app-491-oQ" : "./style.module.css-animation",
Expand Down
13 changes: 13 additions & 0 deletions test/configCases/css/css-modules/style.module.css
Expand Up @@ -16,6 +16,19 @@
color: blue;
}

.local7 div:not(.disabled, .mButtonDisabled, .tipOnly) {
pointer-events: initial !important;
}

.local8 :is(div.parent1.child1.vertical-tiny,
div.parent1.child1.vertical-small,
div.otherDiv.horizontal-tiny,
div.otherDiv.horizontal-small div.description) {
max-height: 0;
margin: 0;
overflow: hidden;
}

:global(:global(:local(.nested1)).nested2).nested3 {
color: pink;
}
Expand Down
2 changes: 2 additions & 0 deletions test/configCases/css/css-modules/use-style.js
Expand Up @@ -7,6 +7,8 @@ export default {
local: `${local1} ${local2} ${local3} ${local4}`,
local2: `${style.local5} ${style.local6}`,
nested: `${style.nested1} ${style.nested2} ${style.nested3}`,
notWmultiParams: `${style.local7}`,
isWmultiParams: `${style.local8}`,
ident,
keyframes: style.localkeyframes,
animation: style.animation,
Expand Down