Skip to content

Commit

Permalink
feat(css/prefixer): Implement more rules for prefixer (#4013)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Mar 15, 2022
1 parent 677a7f7 commit 4f6f244
Show file tree
Hide file tree
Showing 49 changed files with 1,367 additions and 496 deletions.
46 changes: 46 additions & 0 deletions crates/swc_css_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,49 @@ where
{
node.visit_mut_with(&mut FunctionNameReplacer { from, to });
}

pub struct PseudoClassSelectorNameReplacer<'a> {
from: &'a str,
to: &'a str,
}

impl VisitMut for PseudoClassSelectorNameReplacer<'_> {
fn visit_mut_pseudo_class_selector(&mut self, n: &mut PseudoClassSelector) {
n.visit_mut_children_with(self);

if &*n.name.value.to_lowercase() == self.from {
n.name.value = self.to.into();
n.name.raw = self.to.into();
}
}
}

pub fn replace_pseudo_class_selector_name<N>(node: &mut N, from: &str, to: &str)
where
N: for<'aa> VisitMutWith<PseudoClassSelectorNameReplacer<'aa>>,
{
node.visit_mut_with(&mut PseudoClassSelectorNameReplacer { from, to });
}

pub struct PseudoElementSelectorNameReplacer<'a> {
from: &'a str,
to: &'a str,
}

impl VisitMut for PseudoElementSelectorNameReplacer<'_> {
fn visit_mut_pseudo_element_selector(&mut self, n: &mut PseudoElementSelector) {
n.visit_mut_children_with(self);

if &*n.name.value.to_lowercase() == self.from {
n.name.value = self.to.into();
n.name.raw = self.to.into();
}
}
}

pub fn replace_pseudo_element_selector_name<N>(node: &mut N, from: &str, to: &str)
where
N: for<'aa> VisitMutWith<PseudoElementSelectorNameReplacer<'aa>>,
{
node.visit_mut_with(&mut PseudoElementSelectorNameReplacer { from, to });
}
Loading

1 comment on commit 4f6f244

@github-actions
Copy link

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: 4f6f244 Previous: c27b84c Ratio
base_tr_fixer 19604 ns/iter (± 368) 21967 ns/iter (± 671) 0.89
base_tr_resolver_and_hygiene 82504 ns/iter (± 12300) 91312 ns/iter (± 16132) 0.90
codegen_es2015 24578 ns/iter (± 512) 27701 ns/iter (± 154) 0.89
codegen_es2016 24355 ns/iter (± 699) 27771 ns/iter (± 243) 0.88
codegen_es2017 24419 ns/iter (± 358) 27720 ns/iter (± 155) 0.88
codegen_es2018 24509 ns/iter (± 152) 27695 ns/iter (± 230) 0.88
codegen_es2019 24489 ns/iter (± 235) 27722 ns/iter (± 415) 0.88
codegen_es2020 24476 ns/iter (± 178) 27796 ns/iter (± 287) 0.88
codegen_es3 24488 ns/iter (± 212) 27761 ns/iter (± 204) 0.88
codegen_es5 24456 ns/iter (± 138) 27960 ns/iter (± 171) 0.87
full_es2015 111402447 ns/iter (± 4133688) 132425709 ns/iter (± 13286809) 0.84
full_es2016 110878693 ns/iter (± 2897631) 137684270 ns/iter (± 4762872) 0.81
full_es2017 109176797 ns/iter (± 2398000) 135396421 ns/iter (± 7559516) 0.81
full_es2018 108385711 ns/iter (± 3497312) 128821833 ns/iter (± 4578300) 0.84
full_es2019 107502176 ns/iter (± 2829918) 127634274 ns/iter (± 222913482) 0.84
full_es2020 102938945 ns/iter (± 3395985) 116981764 ns/iter (± 7489968) 0.88
full_es3 160148465 ns/iter (± 3972691) 180061517 ns/iter (± 4706625) 0.89
full_es5 151245154 ns/iter (± 8209878) 170083523 ns/iter (± 4105812) 0.89
parser 479330 ns/iter (± 16461) 542263 ns/iter (± 14734) 0.88
ser_ast_node 133 ns/iter (± 2) 151 ns/iter (± 2) 0.88
ser_serde 128 ns/iter (± 2) 145 ns/iter (± 3) 0.88
emit_colors 4992259 ns/iter (± 3515742) 4997346 ns/iter (± 3468886) 1.00
emit_large 117166968 ns/iter (± 152286067) 120026524 ns/iter (± 183802003) 0.98
base_clone 2483220 ns/iter (± 22647) 2555728 ns/iter (± 27122) 0.97
fold_span 4039921 ns/iter (± 28927) 4104200 ns/iter (± 31166) 0.98
fold_span_panic 4202683 ns/iter (± 119275) 4245386 ns/iter (± 299227) 0.99
visit_mut_span 2976618 ns/iter (± 519529) 2726080 ns/iter (± 19587) 1.09
visit_mut_span_panic 2465196 ns/iter (± 88270) 2766330 ns/iter (± 77485) 0.89
usage_builtin_type 12608521 ns/iter (± 8067850) 14737428 ns/iter (± 9171265) 0.86
usage_property 308092 ns/iter (± 15768) 353042 ns/iter (± 1124) 0.87
boxing_boxed 119 ns/iter (± 11) 135 ns/iter (± 1) 0.88
boxing_boxed_clone 65 ns/iter (± 3) 75 ns/iter (± 0) 0.87
boxing_unboxed 97 ns/iter (± 4) 115 ns/iter (± 1) 0.84
boxing_unboxed_clone 54 ns/iter (± 1) 62 ns/iter (± 0) 0.87
time_10 322 ns/iter (± 26) 295 ns/iter (± 3) 1.09
time_15 596 ns/iter (± 21) 662 ns/iter (± 5) 0.90
time_20 1108 ns/iter (± 81) 1241 ns/iter (± 6) 0.89
time_40 6500 ns/iter (± 294) 7000 ns/iter (± 11) 0.93
time_5 82 ns/iter (± 3) 93 ns/iter (± 0) 0.88
time_60 13963 ns/iter (± 627) 16170 ns/iter (± 24) 0.86
total 0 ns/iter (± 0) 0 ns/iter (± 0) NaN

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.