Skip to content

Commit

Permalink
refactor(css/ast): Refactor dashed ident (#6198)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Oct 19, 2022
1 parent 14a6124 commit 6c170e5
Show file tree
Hide file tree
Showing 29 changed files with 1,504 additions and 907 deletions.
1 change: 1 addition & 0 deletions crates/swc_atoms/words.txt
Expand Up @@ -726,6 +726,7 @@ counter-style
createClass
createReactClass
cubic-bezier
custom-media
cursor
data
datalist
Expand Down
6 changes: 5 additions & 1 deletion crates/swc_css_codegen/src/lib.rs
Expand Up @@ -1140,7 +1140,7 @@ where
})) => false,
_ => !self.config.minify,
},
ComponentValue::Ident(_) => match next {
ComponentValue::Ident(_) | ComponentValue::DashedIdent(_) => match next {
Some(ComponentValue::SimpleBlock(SimpleBlock { name, .. })) => {
if name.token == Token::LParen {
true
Expand Down Expand Up @@ -1509,12 +1509,16 @@ where
#[emitter]
fn emit_dashed_ident(&mut self, n: &DashedIdent) -> Result {
if self.config.minify {
write_raw!(self, lo_span_offset!(n.span, 2), "--");

let serialized = serialize_ident(&n.value, n.raw.as_deref(), true);

write_raw!(self, n.span, &serialized);
} else if let Some(raw) = &n.raw {
write_raw!(self, n.span, raw);
} else {
write_raw!(self, lo_span_offset!(n.span, 2), "--");

let serialized = serialize_ident(&n.value, n.raw.as_deref(), false);

write_raw!(self, n.span, &serialized);
Expand Down
Expand Up @@ -69,7 +69,7 @@ div {
@supports ( . --x : y , z ) { a { color: red; } }

* {
counter-reset: -- --a -a;
counter-reset: --a --a -a;
--dash:-;
}

Expand Down Expand Up @@ -102,3 +102,7 @@ div {
counter-increment: -a;
content: counter(-a);
}

* {
counter-reset: --a "string";
}
Expand Up @@ -161,7 +161,7 @@ div {
}
}
* {
counter-reset: -- --a -a;
counter-reset: --a --a -a;
--dash: -;
}
#test_1 span::before {
Expand All @@ -188,3 +188,6 @@ div {
counter-increment: -a;
content: counter(-a);
}
* {
counter-reset: --a "string";
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -51,7 +51,7 @@ impl Visit for CustomPropertyNoMissingVarFunction {
self.ctx.report(
dashed_ident,
format!(
"Unexpected missing var function for '{}'.",
"Unexpected missing var function for '--{}'.",
dashed_ident.value
),
);
Expand Down

1 comment on commit 6c170e5

@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: 6c170e5 Previous: 3546632 Ratio
es/full/minify/libraries/antd 1871640101 ns/iter (± 70308367) 1849917683 ns/iter (± 47011429) 1.01
es/full/minify/libraries/d3 422338956 ns/iter (± 25431013) 387977118 ns/iter (± 15675250) 1.09
es/full/minify/libraries/echarts 1613614313 ns/iter (± 52659089) 1528868284 ns/iter (± 69666641) 1.06
es/full/minify/libraries/jquery 104439031 ns/iter (± 7999130) 103306798 ns/iter (± 6055879) 1.01
es/full/minify/libraries/lodash 112544652 ns/iter (± 6291418) 115854563 ns/iter (± 6276858) 0.97
es/full/minify/libraries/moment 63216891 ns/iter (± 4901533) 64928146 ns/iter (± 4091272) 0.97
es/full/minify/libraries/react 22566100 ns/iter (± 2928107) 20943470 ns/iter (± 1033868) 1.08
es/full/minify/libraries/terser 303240878 ns/iter (± 12480765) 329252558 ns/iter (± 15074390) 0.92
es/full/minify/libraries/three 581965703 ns/iter (± 36805955) 556533983 ns/iter (± 19212745) 1.05
es/full/minify/libraries/typescript 3536690542 ns/iter (± 97397423) 3349976972 ns/iter (± 36449791) 1.06
es/full/minify/libraries/victory 873776198 ns/iter (± 22047905) 790774235 ns/iter (± 15148403) 1.10
es/full/minify/libraries/vue 143216646 ns/iter (± 18123790) 137847061 ns/iter (± 2797599) 1.04
es/full/codegen/es3 34878 ns/iter (± 3060) 33512 ns/iter (± 856) 1.04
es/full/codegen/es5 34104 ns/iter (± 1796) 33642 ns/iter (± 365) 1.01
es/full/codegen/es2015 34112 ns/iter (± 3848) 33616 ns/iter (± 738) 1.01
es/full/codegen/es2016 35161 ns/iter (± 4884) 33606 ns/iter (± 372) 1.05
es/full/codegen/es2017 34031 ns/iter (± 4156) 33577 ns/iter (± 619) 1.01
es/full/codegen/es2018 33898 ns/iter (± 1360) 33448 ns/iter (± 1081) 1.01
es/full/codegen/es2019 33557 ns/iter (± 558) 33287 ns/iter (± 1337) 1.01
es/full/codegen/es2020 35259 ns/iter (± 24656) 33537 ns/iter (± 1927) 1.05
es/full/all/es3 205224636 ns/iter (± 24947343) 195932333 ns/iter (± 12192370) 1.05
es/full/all/es5 216246319 ns/iter (± 21942223) 194670157 ns/iter (± 14681394) 1.11
es/full/all/es2015 155835227 ns/iter (± 10432809) 160191742 ns/iter (± 13158160) 0.97
es/full/all/es2016 155873937 ns/iter (± 17805694) 143206486 ns/iter (± 6330463) 1.09
es/full/all/es2017 151297160 ns/iter (± 9441285) 147262853 ns/iter (± 11797597) 1.03
es/full/all/es2018 168873083 ns/iter (± 17035204) 155132294 ns/iter (± 10557820) 1.09
es/full/all/es2019 153457456 ns/iter (± 17016914) 140720254 ns/iter (± 11293203) 1.09
es/full/all/es2020 144586437 ns/iter (± 13168394) 136463664 ns/iter (± 6348042) 1.06
es/full/parser 743461 ns/iter (± 29385) 712894 ns/iter (± 19205) 1.04
es/full/base/fixer 27042 ns/iter (± 1136) 26415 ns/iter (± 546) 1.02
es/full/base/resolver_and_hygiene 95534 ns/iter (± 6270) 89639 ns/iter (± 3041) 1.07
serialization of ast node 217 ns/iter (± 3) 229 ns/iter (± 8) 0.95
serialization of serde 217 ns/iter (± 6) 228 ns/iter (± 4) 0.95

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

Please sign in to comment.