Skip to content

Commit

Permalink
fix: removal of unecessary underscore logic in escape job #8735 (#8958)
Browse files Browse the repository at this point in the history
  • Loading branch information
daveskybet authored Jan 7, 2025
1 parent eb7595d commit 0dbc9ac
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 133 deletions.
7 changes: 1 addition & 6 deletions crates/rspack_plugin_css/src/dependency/local_ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,7 @@ impl DependencyTemplate for CssLocalIdentDependency {
source: &mut TemplateReplaceSource,
_code_generatable_context: &mut TemplateContext,
) {
source.replace(
self.start,
self.end,
&escape_css(&self.local_ident, false),
None,
);
source.replace(self.start, self.end, &escape_css(&self.local_ident), None);
}

fn dependency_id(&self) -> Option<DependencyId> {
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_plugin_css/src/dependency/self_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl DependencyTemplate for CssSelfReferenceLocalIdentDependency {
source.replace(
replace.start,
replace.end,
&escape_css(&replace.local_ident, false),
&escape_css(&replace.local_ident),
None,
);
}
Expand Down
14 changes: 3 additions & 11 deletions crates/rspack_plugin_css/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ use crate::parser_and_generator::CssExport;
pub const AUTO_PUBLIC_PATH_PLACEHOLDER: &str = "__RSPACK_PLUGIN_CSS_AUTO_PUBLIC_PATH__";
pub static LEADING_DIGIT_REGEX: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^((-?[0-9])|--)").expect("Invalid regexp"));
pub static PREFIX_UNDERSCORE_REGEX: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^[0-9_-]").expect("Invalid regexp"));

#[derive(Debug, Clone)]
pub struct LocalIdentOptions<'a> {
Expand Down Expand Up @@ -116,16 +114,10 @@ impl LocalIdentNameRenderOptions<'_> {
static UNESCAPE_CSS_IDENT_REGEX: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"([^a-zA-Z0-9_\u0081-\uffff-])").expect("invalid regex"));

pub fn escape_css(s: &str, omit_optional_underscore: bool) -> Cow<str> {
pub fn escape_css(s: &str) -> Cow<str> {
let escaped = UNESCAPE_CSS_IDENT_REGEX.replace_all(s, |s: &Captures| format!("\\{}", &s[0]));
if !omit_optional_underscore
&& !escaped.starts_with("--")
&& PREFIX_UNDERSCORE_REGEX.is_match(&escaped)
{
format!("_{}", escaped).into()
} else {
escaped
}

escaped
}

pub(crate) fn export_locals_convention(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`config config/builtin-lightningcss-loader/basic-include exported tests should transform css correct 1`] = `
body {
& ._-_6ec1c834ac8cc99e-used {
& .-_6ec1c834ac8cc99e-used {
color: #00f;
}
}
Expand Down
Loading

2 comments on commit 0dbc9ac

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on 0dbc9ac Jan 7, 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 ✅ success
rsdoctor ✅ success
examples ✅ success
devserver ✅ success
nuxt ✅ success

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on 0dbc9ac Jan 7, 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-01-07 0a4e43a) Current Change
10000_big_production-mode_disable-minimize + exec 37.4 s ± 374 ms 38.2 s ± 578 ms +1.90 %
10000_development-mode + exec 1.88 s ± 30 ms 1.88 s ± 17 ms +0.22 %
10000_development-mode_hmr + exec 679 ms ± 2.4 ms 692 ms ± 33 ms +1.89 %
10000_production-mode + exec 2.53 s ± 44 ms 2.5 s ± 36 ms -1.12 %
arco-pro_development-mode + exec 1.73 s ± 91 ms 1.76 s ± 63 ms +1.86 %
arco-pro_development-mode_hmr + exec 377 ms ± 1.2 ms 378 ms ± 1 ms +0.28 %
arco-pro_production-mode + exec 3.65 s ± 83 ms 3.58 s ± 72 ms -1.68 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.66 s ± 87 ms 3.63 s ± 137 ms -0.82 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.62 s ± 92 ms 3.62 s ± 117 ms -0.06 %
threejs_development-mode_10x + exec 1.51 s ± 18 ms 1.52 s ± 26 ms +0.85 %
threejs_development-mode_10x_hmr + exec 774 ms ± 25 ms 792 ms ± 28 ms +2.24 %
threejs_production-mode_10x + exec 5.36 s ± 68 ms 5.38 s ± 182 ms +0.40 %
10000_big_production-mode_disable-minimize + rss memory 9486 MiB ± 155 MiB 9507 MiB ± 39.9 MiB +0.22 %
10000_development-mode + rss memory 658 MiB ± 15 MiB 665 MiB ± 18.9 MiB +1.10 %
10000_development-mode_hmr + rss memory 1353 MiB ± 356 MiB 1380 MiB ± 354 MiB +1.99 %
10000_production-mode + rss memory 622 MiB ± 31.1 MiB 646 MiB ± 28 MiB +3.89 %
arco-pro_development-mode + rss memory 602 MiB ± 27.6 MiB 557 MiB ± 41.1 MiB -7.49 %
arco-pro_development-mode_hmr + rss memory 651 MiB ± 66.9 MiB 628 MiB ± 78.6 MiB -3.56 %
arco-pro_production-mode + rss memory 754 MiB ± 70.8 MiB 720 MiB ± 41.9 MiB -4.51 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 748 MiB ± 38 MiB 730 MiB ± 49.6 MiB -2.48 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 757 MiB ± 81.4 MiB 721 MiB ± 41.6 MiB -4.78 %
threejs_development-mode_10x + rss memory 630 MiB ± 27.7 MiB 573 MiB ± 14.6 MiB -9.06 %
threejs_development-mode_10x_hmr + rss memory 1222 MiB ± 197 MiB 1145 MiB ± 186 MiB -6.31 %
threejs_production-mode_10x + rss memory 911 MiB ± 48.7 MiB 866 MiB ± 42.2 MiB -4.93 %
large-dyn-imports_development-mode + exec - 2.16 s ± 35 ms -
large-dyn-imports_production-mode + exec - 2.17 s ± 42 ms -
large-dyn-imports_development-mode + rss memory - 637 MiB ± 4.37 MiB -
large-dyn-imports_production-mode + rss memory - 534 MiB ± 2.51 MiB -

Please sign in to comment.