Skip to content

Commit

Permalink
fix: build error with reserved keywords in CSS modules (#9439)
Browse files Browse the repository at this point in the history
  • Loading branch information
inottn authored Feb 24, 2025
1 parent 8f184fe commit 4b72f57
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crates/rspack_plugin_css/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rspack_core::rspack_sources::{ConcatSource, RawStringSource};
use rspack_core::ChunkGraph;
use rspack_core::{
to_identifier, Compilation, CompilerOptions, GenerateContext, PathData, ResourceData,
RuntimeGlobals,
RuntimeGlobals, RESERVED_IDENTIFIER,
};
use rspack_core::{CssExportsConvention, LocalIdentName};
use rspack_error::{error, miette::Diagnostic, Result, TraceableError};
Expand Down Expand Up @@ -296,6 +296,9 @@ pub fn css_modules_exports_to_concatenate_module_string<'a>(
.collect::<Vec<_>>()
.join(" + \" \" + ");
let mut identifier = to_identifier(key);
if RESERVED_IDENTIFIER.contains(identifier.as_ref()) {
identifier = Cow::Owned(format!("_{identifier}"));
}
let mut i = 0;
while used_identifiers.contains(&identifier) {
identifier = Cow::Owned(format!("{identifier}{}", itoa!(i)));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as styles from "./index.module.css";

styles["switch"];
styles["default"];

it("should works", async () => {
const fs = __non_webpack_require__("fs");
const path = __non_webpack_require__("path");
const js = await fs.promises.readFile(
path.resolve(__dirname, "./bundle0.js"),
"utf-8"
);
expect(js).toContain("_switch = ");
expect(js).toContain("_default = ");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.switch {
display: block;
}

.default {
display: block;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import("@rspack/core").Configuration} */
module.exports = {
target: "node",
optimization: {
concatenateModules: true
},
experiments: {
css: true
}
};

2 comments on commit 4b72f57

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on 4b72f57 Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ecosystem CI detail: Open

suite result
modernjs ❌ failure
rspress ✅ success
rslib ✅ success
rsbuild ❌ failure
rsdoctor ❌ failure
examples ✅ success
devserver ✅ success
nuxt ✅ success

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on 4b72f57 Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2025-02-24 e8b77c4) Current Change
10000_big_production-mode_disable-minimize + exec 36.6 s ± 424 ms 37.6 s ± 383 ms +2.52 %
10000_development-mode + exec 1.71 s ± 27 ms 1.71 s ± 12 ms +0.08 %
10000_development-mode_hmr + exec 670 ms ± 13 ms 667 ms ± 6.9 ms -0.48 %
10000_production-mode + exec 2.18 s ± 64 ms 2.19 s ± 54 ms +0.35 %
10000_production-mode_persistent-cold + exec 2.32 s ± 60 ms 2.33 s ± 150 ms +0.42 %
10000_production-mode_persistent-hot + exec 1.63 s ± 23 ms 1.62 s ± 59 ms -0.51 %
arco-pro_development-mode + exec 1.73 s ± 129 ms 1.71 s ± 108 ms -1.42 %
arco-pro_development-mode_hmr + exec 376 ms ± 3.2 ms 375 ms ± 1.2 ms -0.14 %
arco-pro_production-mode + exec 3.58 s ± 42 ms 3.54 s ± 195 ms -1.17 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.56 s ± 197 ms 3.58 s ± 100 ms +0.40 %
arco-pro_production-mode_persistent-cold + exec 3.64 s ± 107 ms 3.63 s ± 167 ms -0.14 %
arco-pro_production-mode_persistent-hot + exec 2.23 s ± 73 ms 2.36 s ± 199 ms +5.91 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.57 s ± 80 ms 3.59 s ± 135 ms +0.57 %
large-dyn-imports_development-mode + exec 1.95 s ± 40 ms 1.99 s ± 68 ms +1.90 %
large-dyn-imports_production-mode + exec 2.02 s ± 20 ms 2.02 s ± 29 ms -0.05 %
threejs_development-mode_10x + exec 1.47 s ± 65 ms 1.44 s ± 27 ms -1.88 %
threejs_development-mode_10x_hmr + exec 813 ms ± 29 ms 781 ms ± 19 ms -3.91 %
threejs_production-mode_10x + exec 5.05 s ± 119 ms 5.06 s ± 259 ms +0.12 %
threejs_production-mode_10x_persistent-cold + exec 5.16 s ± 452 ms 5.15 s ± 334 ms -0.16 %
threejs_production-mode_10x_persistent-hot + exec 4.52 s ± 334 ms 4.43 s ± 164 ms -2.02 %
10000_big_production-mode_disable-minimize + rss memory 8678 MiB ± 53.9 MiB 8674 MiB ± 76.7 MiB -0.05 %
10000_development-mode + rss memory 648 MiB ± 37 MiB 645 MiB ± 23 MiB -0.43 %
10000_development-mode_hmr + rss memory 1268 MiB ± 261 MiB 1251 MiB ± 208 MiB -1.30 %
10000_production-mode + rss memory 618 MiB ± 6.5 MiB 616 MiB ± 15.4 MiB -0.37 %
10000_production-mode_persistent-cold + rss memory 727 MiB ± 11.4 MiB 728 MiB ± 39.8 MiB +0.24 %
10000_production-mode_persistent-hot + rss memory 700 MiB ± 10.1 MiB 703 MiB ± 17.2 MiB +0.37 %
arco-pro_development-mode + rss memory 567 MiB ± 40.7 MiB 567 MiB ± 21.5 MiB -0.06 %
arco-pro_development-mode_hmr + rss memory 652 MiB ± 75.8 MiB 633 MiB ± 49.1 MiB -2.89 %
arco-pro_production-mode + rss memory 714 MiB ± 18.6 MiB 705 MiB ± 11.5 MiB -1.18 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 728 MiB ± 30.3 MiB 730 MiB ± 22.8 MiB +0.34 %
arco-pro_production-mode_persistent-cold + rss memory 785 MiB ± 29.3 MiB 771 MiB ± 26.4 MiB -1.79 %
arco-pro_production-mode_persistent-hot + rss memory 640 MiB ± 28.5 MiB 641 MiB ± 30.6 MiB +0.27 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 717 MiB ± 23.4 MiB 700 MiB ± 11.3 MiB -2.46 %
large-dyn-imports_development-mode + rss memory 643 MiB ± 4.44 MiB 642 MiB ± 4.27 MiB -0.17 %
large-dyn-imports_production-mode + rss memory 523 MiB ± 3.78 MiB 520 MiB ± 3.55 MiB -0.57 %
threejs_development-mode_10x + rss memory 569 MiB ± 19.6 MiB 549 MiB ± 26.8 MiB -3.45 %
threejs_development-mode_10x_hmr + rss memory 1207 MiB ± 75.4 MiB 1068 MiB ± 136 MiB -11.48 %
threejs_production-mode_10x + rss memory 847 MiB ± 44.7 MiB 839 MiB ± 23.7 MiB -1.02 %
threejs_production-mode_10x_persistent-cold + rss memory 969 MiB ± 48 MiB 940 MiB ± 29.3 MiB -3.03 %
threejs_production-mode_10x_persistent-hot + rss memory 802 MiB ± 39.1 MiB 792 MiB ± 55.9 MiB -1.18 %

Threshold exceeded: ["arco-pro_production-mode_persistent-hot + exec"]

Please sign in to comment.