Skip to content

Commit

Permalink
Merge pull request #16864 from janlent1/fixnativecssparsingissue
Browse files Browse the repository at this point in the history
Fix faulty css parser processing
  • Loading branch information
alexander-akait committed Apr 5, 2023
2 parents 7c7ca77 + d511c9f commit b2cd779
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 2 deletions.
11 changes: 9 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 @@ -524,6 +525,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 @@ -574,6 +578,7 @@ class CssParser extends Parser {
const dep = new ConstDependency("", [start, end]);
module.addPresentationalDependency(dep);
} else {
awaitRightParenthesis = true;
modeStack.push(false);
}
break;
Expand Down Expand Up @@ -610,8 +615,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
14 changes: 14 additions & 0 deletions test/configCases/css/css-modules-in-node/index.js
Expand Up @@ -6,6 +6,14 @@ it("should allow to create css modules", done => {
expect(x).toEqual({
global: undefined,
class: prod ? "my-app-491-S" : "./style.module.css-class",
currentWmultiParams: prod ? "my-app-491-yK" : "./style.module.css-local12",
futureWmultiParams: prod ? "my-app-491-Y4" : "./style.module.css-local14",
hasWmultiParams: prod ? "my-app-491-PK" : "./style.module.css-local11",
matchesWmultiParams: prod ? "my-app-491-$Y" : "./style.module.css-local9",
mozAnyWmultiParams: prod ? "my-app-491-TT" : "./style.module.css-local15",
pastWmultiParams: prod ? "my-app-491-P_" : "./style.module.css-local13",
webkitAnyWmultiParams: prod ? "my-app-491-rT" : "./style.module.css-local16",
whereWmultiParams: prod ? "my-app-491-ie" : "./style.module.css-local10",
local: prod
? "my-app-491-Zw my-app-491-yl my-app-491-J_ my-app-491-gc"
: "./style.module.css-local1 ./style.module.css-local2 ./style.module.css-local3 ./style.module.css-local4",
Expand All @@ -15,6 +23,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
14 changes: 14 additions & 0 deletions test/configCases/css/css-modules/index.js
Expand Up @@ -9,6 +9,14 @@ it("should allow to create css modules", done => {
expect(x).toEqual({
global: undefined,
class: prod ? "my-app-491-S" : "./style.module.css-class",
currentWmultiParams: prod ? "my-app-491-yK" : "./style.module.css-local12",
futureWmultiParams: prod ? "my-app-491-Y4" : "./style.module.css-local14",
hasWmultiParams: prod ? "my-app-491-PK" : "./style.module.css-local11",
matchesWmultiParams: prod ? "my-app-491-$Y" : "./style.module.css-local9",
mozAnyWmultiParams: prod ? "my-app-491-TT" : "./style.module.css-local15",
pastWmultiParams: prod ? "my-app-491-P_" : "./style.module.css-local13",
webkitAnyWmultiParams: prod ? "my-app-491-rT" : "./style.module.css-local16",
whereWmultiParams: prod ? "my-app-491-ie" : "./style.module.css-local10",
local: prod
? "my-app-491-Zw my-app-491-yl my-app-491-J_ my-app-491-gc"
: "./style.module.css-local1 ./style.module.css-local2 ./style.module.css-local3 ./style.module.css-local4",
Expand All @@ -18,6 +26,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
55 changes: 55 additions & 0 deletions test/configCases/css/css-modules/style.module.css
Expand Up @@ -16,6 +16,61 @@
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;
}

.local9 :matches(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;
}

.local10 :where(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;
}

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

.local12 div:current(p, span) {
background-color: yellow;
}

.local13 div:past(p, span) {
display: none;
}

.local14 div:future(p, span) {
background-color: yellow;
}

.local15 div:-moz-any(ol, ul, menu, dir) {
list-style-type: square;
}

.local16 li:-webkit-any(:first-child, :last-child) {
background-color: aquamarine;
}

:global(:global(:local(.nested1)).nested2).nested3 {
color: pink;
}
Expand Down
10 changes: 10 additions & 0 deletions test/configCases/css/css-modules/use-style.js
Expand Up @@ -7,6 +7,16 @@ 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}`,
matchesWmultiParams: `${style.local9}`,
whereWmultiParams: `${style.local10}`,
hasWmultiParams: `${style.local11}`,
currentWmultiParams: `${style.local12}`,
pastWmultiParams: `${style.local13}`,
futureWmultiParams: `${style.local14}`,
mozAnyWmultiParams: `${style.local15}`,
webkitAnyWmultiParams: `${style.local16}`,
ident,
keyframes: style.localkeyframes,
animation: style.animation,
Expand Down

0 comments on commit b2cd779

Please sign in to comment.