Skip to content

Commit 050aa45

Browse files
authored
fix(css): preserve namespaces when unwrapping :is() (#22582)
1 parent 2ce31ce commit 050aa45

7 files changed

Lines changed: 80 additions & 5 deletions

File tree

‎lib/css/syntax-parser.js‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11795,12 +11795,14 @@ const _unwrapLoneIs = (parts) => {
1179511795
_isCompoundText(inner) &&
1179611796
!inner.includes("::") &&
1179711797
!_LEGACY_PSEUDO_ELEMENT_RE.test(inner) &&
11798-
// A type or universal selector only leads a compound.
11798+
// A type or universal only leads a compound, and its namespace must
11799+
// not replace the default namespace constraining the outer compound.
1179911800
(!_startsTypeSelector(inner) ||
11800-
before === -1 ||
11801-
parts[before] === _SEP ||
11802-
parts[before] === "," ||
11803-
_isCombinator(parts[before].charCodeAt(0))) &&
11801+
(!inner.includes("|") &&
11802+
(before === -1 ||
11803+
parts[before] === _SEP ||
11804+
parts[before] === "," ||
11805+
_isCombinator(parts[before].charCodeAt(0))))) &&
1180411806
_pseudosReadable(inner)
1180511807
) {
1180611808
parts[i] = "";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`ConfigCacheTestCases css minimize-is-namespace minimize-is-namespace should compile 1`] = `"@namespace url(http://www.w3.org/2000/svg);@namespace html url(http://www.w3.org/1999/xhtml);:is(*|*){color:red}:is(html|*){background-color:blue}:is(|*){opacity:.5}:is(*|rect){fill:green}*|*:not(:is(*|*)){border-width:1px}.safe{stroke:blue}[lang|=en]{stroke-width:2}"`;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`ConfigTestCases css minimize-is-namespace minimize-is-namespace should compile 1`] = `"@namespace url(http://www.w3.org/2000/svg);@namespace html url(http://www.w3.org/1999/xhtml);:is(*|*){color:red}:is(html|*){background-color:blue}:is(|*){opacity:.5}:is(*|rect){fill:green}*|*:not(:is(*|*)){border-width:1px}.safe{stroke:blue}[lang|=en]{stroke-width:2}"`;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import stylesheet from "./style.css";
2+
3+
it("should emit the stylesheet with its namespace declarations", () => {
4+
expect(stylesheet).toBe("style.css");
5+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@namespace url(http://www.w3.org/2000/svg);
2+
@namespace html url(http://www.w3.org/1999/xhtml);
3+
4+
:is(*|*) {
5+
color: red;
6+
}
7+
8+
:is(html|*) {
9+
background-color: blue;
10+
}
11+
12+
:is(|*) {
13+
opacity: 0.5;
14+
}
15+
16+
:is(*|rect) {
17+
fill: green;
18+
}
19+
20+
*|*:not(:is(*|*)) {
21+
border-width: 1px;
22+
}
23+
24+
:is(.safe) {
25+
stroke: blue;
26+
}
27+
28+
:is([lang|=en]) {
29+
stroke-width: 2px;
30+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"use strict";
2+
3+
const fs = require("fs");
4+
const path = require("path");
5+
6+
module.exports = {
7+
afterExecute(options) {
8+
expect(
9+
fs.readFileSync(path.join(options.output.path, "style.css"), "utf8")
10+
).toMatchSnapshot();
11+
}
12+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use strict";
2+
3+
/** @type {import("../../../../").Configuration} */
4+
module.exports = {
5+
target: "web",
6+
mode: "production",
7+
output: {
8+
publicPath: "",
9+
assetModuleFilename: "[name][ext]"
10+
},
11+
module: {
12+
// Bundled CSS does not support @namespace; minify the standalone asset.
13+
rules: [{ test: /\.css$/, type: "asset/resource" }]
14+
},
15+
optimization: {
16+
minimize: { css: { extractComments: false } },
17+
minimizer: ["..."]
18+
},
19+
experiments: { css: true }
20+
};

0 commit comments

Comments
 (0)