From 649438b76a8ea61f2ddb2160a212d318d9d05267 Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Thu, 15 Dec 2022 09:55:22 +0300 Subject: [PATCH] feat(css/parser): Normalize selector AST (#6657) --- crates/swc_atoms/words.txt | 12 ++ .../pseudo-class/an_plus_b/output.min.css | 2 +- crates/swc_css_minifier/src/compressor/mod.rs | 18 +- .../src/compressor/selector.rs | 36 +--- .../tests/fixture/compress-selector/input.css | 5 +- .../fixture/compress-selector/output.min.css | 2 +- .../tests/fixture/url/url.transform.json | 16 +- .../src/parser/selectors/mod.rs | 73 ++++--- .../fixture/selector/attribute/output.json | 4 +- .../pseudo-class/an-plus-b/output.json | 12 +- .../selector/pseudo-class/basic/output.json | 4 +- .../selector/pseudo-class/dir/input.css | 1 + .../selector/pseudo-class/dir/output.json | 90 +++++++- .../selector/pseudo-class/dir/span.swc-stderr | 99 ++++++++- .../selector/pseudo-class/not/output.json | 4 +- .../selector/pseudo-element/basic/output.json | 2 +- .../selector/pseudo-element/slotted/input.css | 3 + .../pseudo-element/slotted/output.json | 149 ++++++++++++- .../pseudo-element/slotted/span.swc-stderr | 197 +++++++++++++++++- .../tests/fixture/selector/type/output.json | 4 +- .../misc/pOZgFOB3GdVvQ0hiAsWfpQ/output.json | 2 +- .../fixture/vendor/rome/selectors/output.json | 2 +- .../tests/recovery/hacks/output.json | 2 +- crates/swc_css_utils/src/lib.rs | 6 +- 24 files changed, 649 insertions(+), 96 deletions(-) diff --git a/crates/swc_atoms/words.txt b/crates/swc_atoms/words.txt index 8f08fcc382e3..7d2c95e95dcb 100644 --- a/crates/swc_atoms/words.txt +++ b/crates/swc_atoms/words.txt @@ -836,6 +836,9 @@ createClass createReactClass crossorigin cubic-bezier +cue +cue-region +current currentColor currentcolor cursor @@ -1022,6 +1025,7 @@ frameset from from-image function +future g get global @@ -1053,14 +1057,18 @@ h4 h5 h6 hanging-punctuation +has head header headers height hgroup +highlight historical-forms hkern horizontal-tb +host +host-context hr href hsl @@ -1306,7 +1314,9 @@ noscript not nowrap nth-child +nth-col nth-last-child +nth-last-col nth-last-of-type nth-of-type null @@ -1474,6 +1484,7 @@ paint-order panose-1 param part +past path pathLength pathlength @@ -1657,6 +1668,7 @@ skewx skewy slice slot +slotted small solid solidColor diff --git a/crates/swc_css_codegen/tests/fixture/selectors/pseudo-class/an_plus_b/output.min.css b/crates/swc_css_codegen/tests/fixture/selectors/pseudo-class/an_plus_b/output.min.css index 3111571f7a6a..7b67be3688f4 100644 --- a/crates/swc_css_codegen/tests/fixture/selectors/pseudo-class/an_plus_b/output.min.css +++ b/crates/swc_css_codegen/tests/fixture/selectors/pseudo-class/an_plus_b/output.min.css @@ -1 +1 @@ -p:nth-child(1){color:blue}p:nth-child(7){color:blue}p:nth-child(5n){color:blue}p:nth-child(n+7){color:blue}p:nth-child(3n+4){color:blue}p:nth-child(3n+4){color:blue}p:nth-child(-n+3){color:blue}p:nth-child(-n+3){color:blue}p:nth-child(n){color:blue}p:nth-child(n){color:blue}p:nth-child(-n){color:blue}p:nth-child(1){color:blue}p:nth-child(2n+1){color:blue}p:nth-child(2n+1){color:blue}p:nth-child(2n+1){color:blue}p:nth-child(-2n+1){color:blue}p:nth-child(2n+1){color:blue}p:nth-child(n+1){color:blue}p:nth-child(n+1){color:blue}p:nth-child(-n+1){color:blue}p:nth-child(0n+3){color:blue}p:nth-child(0n+3){color:blue}p:nth-child(0n+3){color:blue}p:nth-child(n+1){color:blue}p:nth-child(n+1){color:blue}p:nth-child(-n+1){color:blue}p:nth-child(even){color:blue}p:nth-child(EVEN){color:blue}p:nth-child(2n){color:blue}p:nth-child(1){color:blue}p:nth-child(0n+1){color:blue}p:nth-child(0n+1){color:blue}p:nth-child(0n+1){color:blue}p:nth-child(0n+5){color:blue}p:nth-child(0n-5){color:blue}p:nth-child(-n+3){color:blue}p:nth-child(n+3){color:blue}p:nth-child(n+3){color:blue}p:nth-child(n+3){color:blue}p:nth-child(-n+3){color:blue}p:nth-child(n+3){color:blue}p:nth-child(n-3){color:blue}p:nth-child(0n-3){color:blue}p:nth-child(0n+3){color:blue}p:nth-child(0n-3){color:blue}p:nth-child(0n-3){color:blue}p:nth-child(n+0){color:blue}p:nth-child(n+0){color:blue}p:nth-child(-n+0){color:blue}p:nth-child(5n+0){color:blue}p:nth-child(-5n+0){color:blue}p:nth-child(5n+0){color:blue}p:nth-child(-2n+1){color:blue}p:nth-of-type(2n+1){color:blue}p:nth-last-col(2n+1){color:blue}p:nth-col(2n+1){color:blue}p:nth-child(n+0){color:blue}p:nth-child(n+0){color:blue}p:nth-child(5){color:blue}p:nth-child(5){color:blue}p:nth-child(-5){color:blue} +p:nth-child(1){color:blue}p:nth-child(7){color:blue}p:nth-child(5n){color:blue}p:nth-child(n+7){color:blue}p:nth-child(3n+4){color:blue}p:nth-child(3n+4){color:blue}p:nth-child(-n+3){color:blue}p:nth-child(-n+3){color:blue}p:nth-child(n){color:blue}p:nth-child(n){color:blue}p:nth-child(-n){color:blue}p:nth-child(1){color:blue}p:nth-child(2n+1){color:blue}p:nth-child(2n+1){color:blue}p:nth-child(2n+1){color:blue}p:nth-child(-2n+1){color:blue}p:nth-child(2n+1){color:blue}p:nth-child(n+1){color:blue}p:nth-child(n+1){color:blue}p:nth-child(-n+1){color:blue}p:nth-child(0n+3){color:blue}p:nth-child(0n+3){color:blue}p:nth-child(0n+3){color:blue}p:nth-child(n+1){color:blue}p:nth-child(n+1){color:blue}p:nth-child(-n+1){color:blue}p:nth-child(even){color:blue}p:nth-child(even){color:blue}p:nth-child(2n){color:blue}p:nth-child(1){color:blue}p:nth-child(0n+1){color:blue}p:nth-child(0n+1){color:blue}p:nth-child(0n+1){color:blue}p:nth-child(0n+5){color:blue}p:nth-child(0n-5){color:blue}p:nth-child(-n+3){color:blue}p:nth-child(n+3){color:blue}p:nth-child(n+3){color:blue}p:nth-child(n+3){color:blue}p:nth-child(-n+3){color:blue}p:nth-child(n+3){color:blue}p:nth-child(n-3){color:blue}p:nth-child(0n-3){color:blue}p:nth-child(0n+3){color:blue}p:nth-child(0n-3){color:blue}p:nth-child(0n-3){color:blue}p:nth-child(n+0){color:blue}p:nth-child(n+0){color:blue}p:nth-child(-n+0){color:blue}p:nth-child(5n+0){color:blue}p:nth-child(-5n+0){color:blue}p:nth-child(5n+0){color:blue}p:nth-child(-2n+1){color:blue}p:nth-of-type(2n+1){color:blue}p:nth-last-col(2n+1){color:blue}p:nth-col(2n+1){color:blue}p:nth-child(n+0){color:blue}p:nth-child(n+0){color:blue}p:nth-child(5){color:blue}p:nth-child(5){color:blue}p:nth-child(-5){color:blue} diff --git a/crates/swc_css_minifier/src/compressor/mod.rs b/crates/swc_css_minifier/src/compressor/mod.rs index 922e895cf6ef..1a4b3e6c6c71 100644 --- a/crates/swc_css_minifier/src/compressor/mod.rs +++ b/crates/swc_css_minifier/src/compressor/mod.rs @@ -255,14 +255,14 @@ impl VisitMut for Compressor { fn visit_mut_pseudo_class_selector(&mut self, n: &mut PseudoClassSelector) { match &n.name { Ident { value, .. } - if matches_eq_ignore_ascii_case!( - value, - js_word!("not"), - js_word!("is"), - js_word!("where"), - js_word!("matches"), - js_word!("-moz-any"), - js_word!("-webkit-any") + if matches!( + *value, + js_word!("not") + | js_word!("is") + | js_word!("where") + | js_word!("matches") + | js_word!("-moz-any") + | js_word!("-webkit-any") ) => { n.visit_mut_children_with(&mut *self.with_ctx(Ctx { @@ -279,7 +279,7 @@ impl VisitMut for Compressor { fn visit_mut_selector_list(&mut self, n: &mut SelectorList) { n.visit_mut_children_with(self); - self.comrpess_selector_list(n); + self.compress_selector_list(n); } fn visit_mut_forgiving_selector_list(&mut self, n: &mut ForgivingSelectorList) { diff --git a/crates/swc_css_minifier/src/compressor/selector.rs b/crates/swc_css_minifier/src/compressor/selector.rs index a1ef73f818e7..06d113473a76 100644 --- a/crates/swc_css_minifier/src/compressor/selector.rs +++ b/crates/swc_css_minifier/src/compressor/selector.rs @@ -6,7 +6,7 @@ use super::Compressor; use crate::util::dedup; impl Compressor { - pub(super) fn comrpess_selector_list(&mut self, selector_list: &mut SelectorList) { + pub(super) fn compress_selector_list(&mut self, selector_list: &mut SelectorList) { dedup(&mut selector_list.children); } @@ -62,9 +62,7 @@ impl Compressor { }); } // `even` => `2n` - AnPlusB::Ident(Ident { value, span, .. }) - if value.eq_ignore_ascii_case(&js_word!("even")) => - { + AnPlusB::Ident(Ident { value, span, .. }) if *value == js_word!("even") => { *an_plus_b = AnPlusB::AnPlusBNotation(AnPlusBNotation { span: *span, a: Some(2), @@ -110,12 +108,12 @@ impl Compressor { pub(super) fn compress_subclass_selector(&mut self, subclass_selector: &mut SubclassSelector) { match &subclass_selector { SubclassSelector::PseudoElement(PseudoElementSelector { name, span, .. }) => { - if matches_eq_ignore_ascii_case!( + if matches!( name.value, - js_word!("before"), - js_word!("after"), - js_word!("first-letter"), - js_word!("first-line") + js_word!("before") + | js_word!("after") + | js_word!("first-letter") + | js_word!("first-line") ) { *subclass_selector = SubclassSelector::PseudoClass(PseudoClassSelector { span: *span, @@ -129,9 +127,7 @@ impl Compressor { children: Some(children), span, .. - }) if name.value.eq_ignore_ascii_case(&js_word!("nth-child")) - && children.len() == 1 => - { + }) if name.value == js_word!("nth-child") && children.len() == 1 => { match children.get(0) { Some(PseudoClassSelectorChildren::AnPlusB(AnPlusB::AnPlusBNotation( AnPlusBNotation { @@ -158,11 +154,7 @@ impl Compressor { children: Some(children), span, .. - }) if name - .value - .eq_str_ignore_ascii_case(&js_word!("nth-last-child")) - && children.len() == 1 => - { + }) if name.value == js_word!("nth-last-child") && children.len() == 1 => { match children.get(0) { Some(PseudoClassSelectorChildren::AnPlusB(AnPlusB::AnPlusBNotation( AnPlusBNotation { @@ -189,9 +181,7 @@ impl Compressor { children: Some(children), span, .. - }) if name.value.eq_ignore_ascii_case(&js_word!("nth-of-type")) - && children.len() == 1 => - { + }) if name.value == js_word!("nth-of-type") && children.len() == 1 => { match children.get(0) { Some(PseudoClassSelectorChildren::AnPlusB(AnPlusB::AnPlusBNotation( AnPlusBNotation { @@ -218,11 +208,7 @@ impl Compressor { children: Some(children), span, .. - }) if name - .value - .eq_ignore_ascii_case(&js_word!("nth-last-of-type")) - && children.len() == 1 => - { + }) if name.value == js_word!("nth-last-of-type") && children.len() == 1 => { match children.get(0) { Some(PseudoClassSelectorChildren::AnPlusB(AnPlusB::AnPlusBNotation( AnPlusBNotation { diff --git a/crates/swc_css_minifier/tests/fixture/compress-selector/input.css b/crates/swc_css_minifier/tests/fixture/compress-selector/input.css index 87df901205fa..b8a3392d6759 100644 --- a/crates/swc_css_minifier/tests/fixture/compress-selector/input.css +++ b/crates/swc_css_minifier/tests/fixture/compress-selector/input.css @@ -186,4 +186,7 @@ a:has(> a, > a) {color:red} .alpha > .beta {& + & {order: 2}} a {& *.bar {color: red}} a {&*.bar {color: red}} -.class {&*.bar {color: red}} \ No newline at end of file +.class {&*.bar {color: red}} + +h1,H1{color:red} +*:NOT(H1, H1) {color: blue} \ No newline at end of file diff --git a/crates/swc_css_minifier/tests/fixture/compress-selector/output.min.css b/crates/swc_css_minifier/tests/fixture/compress-selector/output.min.css index 19819fb03810..b4a0bc8201ae 100644 --- a/crates/swc_css_minifier/tests/fixture/compress-selector/output.min.css +++ b/crates/swc_css_minifier/tests/fixture/compress-selector/output.min.css @@ -1 +1 @@ -a[color=blue],a[color=""],a[color="-"],a[color="."],a[color=" "],a[color=" a "],a[color=" a"],a[color="a "],a[color='"'],a[color="B&W?"],a[color=G],a[color=😂],a[color=👩‍🦼],a[color="1"],a[color=--],a[color="-1"],a[color="-404"],a[color=-x]{color:blue}a[color=blue i]{color:blue}a[class="woop woop woop"],a[class=woop_woop_woop],h1[class=" *.js "]+.js{color:blue}h1:before{color:blue}h1:before{color:blue}h1:after{color:blue}h1:first-letter{color:blue}h1:first-line{color:blue}*,[hreflang|=en],.warning,#myid{color:blue}:before{content:"test";color:blue}.class[hreflang|=en],foo|*[hreflang|=en],*|*[hreflang|=en]{color:blue}div{& [hreflang|=en],&[hreflang|=en],&div,&*,&,&.class{color:blue}}*|*:is(:hover,:focus){color:blue}*|*:is(*:hover,*:focus){color:blue}*|*:has(:not(h1,h2,h3,h4,h5,h6)){color:blue}div :first-child{color:blue}legend+*,*+legend,*+*{color:blue}p:first-child{color:blue}p:first-child{color:blue}p:nth-child(odd){color:blue}p:nth-child(odd){color:blue}p:nth-child(2n){color:blue}p:nth-child(2n){color:blue}p:nth-child(2n){color:blue}p:first-child{color:blue}p:first-child{color:blue}p:first-child{color:blue}p:first-child{color:blue}p:nth-child(5){color:blue}p:nth-child(-5){color:blue}p:nth-child(-5){color:blue}p:nth-child(-5){color:blue}p:nth-child(-n+3){color:blue}p:nth-child(n+3){color:blue}p:nth-child(n+3){color:blue}p:nth-child(n+3){color:blue}p:nth-child(-n+3){color:blue}p:nth-child(n+3){color:blue}p:nth-child(n-3){color:blue}p:nth-child(-3){color:blue}p:nth-child(-3){color:blue}p:nth-child(-3){color:blue}p:nth-child(n){color:blue}p:nth-child(n){color:blue}p:nth-child(-n){color:blue}p:nth-child(5n){color:blue}p:nth-child(-5n){color:blue}p:nth-child(5n){color:blue}p:nth-child(-2n+1){color:blue}p:nth-child(n){color:blue}p:nth-child(n){color:blue}p:nth-child(-n){color:blue}p:nth-child(n){color:blue}p:nth-of-type(odd){color:blue}p:nth-last-col(odd){color:blue}p:nth-col(odd){color:blue}p:nth-child(n-2){color:blue}p:nth-child(n+2){color:blue}p:nth-child(-n+2){color:blue}p:nth-child(n){color:blue}p:nth-child(-n){color:blue}p:nth-child(n){color:blue}p:nth-child(5){color:blue}p:nth-child(n){color:blue}p:nth-child(n){color:blue}p:nth-child(-n+6){color:blue}p:nth-child(odd){color:blue}p:nth-child(2n+5){color:blue}p:nth-child(2n+4){color:blue}p:nth-child(2n+3){color:blue}p:nth-child(2n+2){color:blue}p:nth-child(odd){color:blue}p:nth-child(odd){color:blue}p:nth-child(2n){color:blue}p:nth-child(odd){color:blue}p:nth-child(2n){color:blue}p:nth-child(odd){color:blue}p:nth-child(2n){color:blue}p:nth-child(odd){color:blue}p:nth-child(2n){color:blue}p:nth-child(odd){color:blue}p:nth-child(2n){color:blue}p:nth-child(2n){color:blue}p:nth-child(2n+10){color:blue}p:nth-child(n+8):nth-child(-n+15){color:blue}p:nth-last-of-type(2n+2){color:blue}body>h2:not(:first-of-type):not(:last-of-type){color:blue}.class:first-child{color:red}.class:first-child{color:red}.class:nth-child(-1){color:red}.class:last-child{color:red}.class:last-child{color:red}.class:nth-last-child(-1){color:red}.class:first-of-type{color:red}.class:first-of-type{color:red}.class:nth-of-type(-1){color:red}.class:last-of-type{color:red}.class:last-of-type{color:red}.class:nth-last-of-type(-1){color:red}.foo.foo.foo,.class#id#id,#id#id.class,#id.class#id,#id#id#id,[attr][attr][attr],[attr].class[attr].class[attr]{color:red}h1,h2,h3,h4,h5,h6,.class,div.class{color:blue}a:is(a>b){color:red}a:is(a>b){color:red}a:is(a>b,form>label){color:red}a:has(>a){color:red}a:has(>a){color:red}.row-cols-3>*{-ms-flex:0 0 33.333333%;flex:0 0 33.333333%}*,:before,:after{box-sizing:border-box;border:1px solid#dee2e6}.foo{& *,&*{color:red}}.beta{&:hover{order:1}}.alpha>.beta{&+&{order:2}}a{& .bar,&.bar{color:red}}.class{&.bar{color:red}} +a[color=blue],a[color=""],a[color="-"],a[color="."],a[color=" "],a[color=" a "],a[color=" a"],a[color="a "],a[color='"'],a[color="B&W?"],a[color=G],a[color=😂],a[color=👩‍🦼],a[color="1"],a[color=--],a[color="-1"],a[color="-404"],a[color=-x]{color:blue}a[color=blue i]{color:blue}a[class="woop woop woop"],a[class=woop_woop_woop],h1[class=" *.js "]+.js{color:blue}h1:before{color:blue}h1:before{color:blue}h1:after{color:blue}h1:first-letter{color:blue}h1:first-line{color:blue}*,[hreflang|=en],.warning,#myid{color:blue}:before{content:"test";color:blue}.class[hreflang|=en],foo|*[hreflang|=en],*|*[hreflang|=en]{color:blue}div{& [hreflang|=en],&[hreflang|=en],&div,&*,&,&.class{color:blue}}*|*:is(:hover,:focus){color:blue}*|*:is(*:hover,*:focus){color:blue}*|*:has(:not(h1,h2,h3,h4,h5,h6)){color:blue}div :first-child{color:blue}legend+*,*+legend,*+*{color:blue}p:first-child{color:blue}p:first-child{color:blue}p:nth-child(odd){color:blue}p:nth-child(odd){color:blue}p:nth-child(2n){color:blue}p:nth-child(2n){color:blue}p:nth-child(2n){color:blue}p:first-child{color:blue}p:first-child{color:blue}p:first-child{color:blue}p:first-child{color:blue}p:nth-child(5){color:blue}p:nth-child(-5){color:blue}p:nth-child(-5){color:blue}p:nth-child(-5){color:blue}p:nth-child(-n+3){color:blue}p:nth-child(n+3){color:blue}p:nth-child(n+3){color:blue}p:nth-child(n+3){color:blue}p:nth-child(-n+3){color:blue}p:nth-child(n+3){color:blue}p:nth-child(n-3){color:blue}p:nth-child(-3){color:blue}p:nth-child(-3){color:blue}p:nth-child(-3){color:blue}p:nth-child(n){color:blue}p:nth-child(n){color:blue}p:nth-child(-n){color:blue}p:nth-child(5n){color:blue}p:nth-child(-5n){color:blue}p:nth-child(5n){color:blue}p:nth-child(-2n+1){color:blue}p:nth-child(n){color:blue}p:nth-child(n){color:blue}p:nth-child(-n){color:blue}p:nth-child(n){color:blue}p:nth-of-type(odd){color:blue}p:nth-last-col(odd){color:blue}p:nth-col(odd){color:blue}p:nth-child(n-2){color:blue}p:nth-child(n+2){color:blue}p:nth-child(-n+2){color:blue}p:nth-child(n){color:blue}p:nth-child(-n){color:blue}p:nth-child(n){color:blue}p:nth-child(5){color:blue}p:nth-child(n){color:blue}p:nth-child(n){color:blue}p:nth-child(-n+6){color:blue}p:nth-child(odd){color:blue}p:nth-child(2n+5){color:blue}p:nth-child(2n+4){color:blue}p:nth-child(2n+3){color:blue}p:nth-child(2n+2){color:blue}p:nth-child(odd){color:blue}p:nth-child(odd){color:blue}p:nth-child(2n){color:blue}p:nth-child(odd){color:blue}p:nth-child(2n){color:blue}p:nth-child(odd){color:blue}p:nth-child(2n){color:blue}p:nth-child(odd){color:blue}p:nth-child(2n){color:blue}p:nth-child(odd){color:blue}p:nth-child(2n){color:blue}p:nth-child(2n){color:blue}p:nth-child(2n+10){color:blue}p:nth-child(n+8):nth-child(-n+15){color:blue}p:nth-last-of-type(2n+2){color:blue}body>h2:not(:first-of-type):not(:last-of-type){color:blue}.class:first-child{color:red}.class:first-child{color:red}.class:nth-child(-1){color:red}.class:last-child{color:red}.class:last-child{color:red}.class:nth-last-child(-1){color:red}.class:first-of-type{color:red}.class:first-of-type{color:red}.class:nth-of-type(-1){color:red}.class:last-of-type{color:red}.class:last-of-type{color:red}.class:nth-last-of-type(-1){color:red}.foo.foo.foo,.class#id#id,#id#id.class,#id.class#id,#id#id#id,[attr][attr][attr],[attr].class[attr].class[attr]{color:red}h1,h2,h3,h4,h5,h6,.class,div.class{color:blue}a:is(a>b){color:red}a:is(a>b){color:red}a:is(a>b,form>label){color:red}a:has(>a){color:red}a:has(>a){color:red}.row-cols-3>*{-ms-flex:0 0 33.333333%;flex:0 0 33.333333%}*,:before,:after{box-sizing:border-box;border:1px solid#dee2e6}.foo{& *,&*{color:red}}.beta{&:hover{order:1}}.alpha>.beta{&+&{order:2}}a{& .bar,&.bar{color:red}}.class{&.bar{color:red}}h1{color:red}:not(h1){color:blue} diff --git a/crates/swc_css_modules/tests/fixture/url/url.transform.json b/crates/swc_css_modules/tests/fixture/url/url.transform.json index 0856c180f984..382a037ebfe3 100644 --- a/crates/swc_css_modules/tests/fixture/url/url.transform.json +++ b/crates/swc_css_modules/tests/fixture/url/url.transform.json @@ -53,10 +53,10 @@ "name": "__local__root-relative" } ], - "my-background": [ + "highlight": [ { "type": "local", - "name": "__local__my-background" + "name": "__local__highlight" } ], "aliases": [ @@ -71,6 +71,12 @@ "name": "__local__strange" } ], + "my-background": [ + { + "type": "local", + "name": "__local__my-background" + } + ], "other-test-case": [ { "type": "local", @@ -106,11 +112,5 @@ "type": "local", "name": "__local__pure-url" } - ], - "highlight": [ - { - "type": "local", - "name": "__local__highlight" - } ] } diff --git a/crates/swc_css_parser/src/parser/selectors/mod.rs b/crates/swc_css_parser/src/parser/selectors/mod.rs index 79e14373bc39..814638208e35 100644 --- a/crates/swc_css_parser/src/parser/selectors/mod.rs +++ b/crates/swc_css_parser/src/parser/selectors/mod.rs @@ -488,7 +488,9 @@ where match cur!(self) { tok!("ident") => { - let value = self.parse()?; + let mut value: Ident = self.parse()?; + + value.value = value.value.to_ascii_lowercase(); return Ok(TypeSelector::TagName(TagNameSelector { span: span!(self, span.lo), @@ -821,7 +823,9 @@ where match cur!(self) { tok!("ident") => { - let value = self.parse()?; + let mut value: Ident = self.parse()?; + + value.value = value.value.to_ascii_lowercase(); Ok(AttributeSelectorModifier { span: span!(self, span.lo), @@ -846,7 +850,7 @@ where let fn_span = self.input.cur_span(); let name = bump!(self); let names = match name { - Token::Function { value, raw } => (value, raw), + Token::Function { value, raw } => (value.to_ascii_lowercase(), raw), _ => unreachable!(), }; let state = self.input.state(); @@ -854,8 +858,8 @@ where || -> PResult> { let mut children = vec![]; - match &*names.0.to_ascii_lowercase() { - "local" | "global" if self.config.css_modules => { + match names.0 { + js_word!("local") | js_word!("global") if self.config.css_modules => { self.input.skip_ws(); let selector_list = self.parse()?; @@ -865,7 +869,7 @@ where children .push(PseudoClassSelectorChildren::ComplexSelector(selector_list)); } - "-moz-any" | "-webkit-any" => { + js_word!("-moz-any") | js_word!("-webkit-any") => { self.input.skip_ws(); let compound_selector_list = self.parse()?; @@ -876,16 +880,18 @@ where compound_selector_list, )); } - "dir" => { + js_word!("dir") => { self.input.skip_ws(); - let ident = self.parse()?; + let mut ident: Ident = self.parse()?; + + ident.value = ident.value.to_ascii_lowercase(); self.input.skip_ws(); children.push(PseudoClassSelectorChildren::Ident(ident)); } - "lang" => { + js_word!("lang") => { self.input.skip_ws(); let child = match cur!(self) { @@ -932,7 +938,7 @@ where children.push(child); } } - "current" | "past" | "future" => { + js_word!("current") | js_word!("past") | js_word!("future") => { self.input.skip_ws(); let compound_selector_list = self.parse()?; @@ -943,7 +949,7 @@ where compound_selector_list, )); } - "not" | "matches" => { + js_word!("not") | js_word!("matches") => { self.input.skip_ws(); let selector_list = self.parse()?; @@ -952,14 +958,14 @@ where children.push(PseudoClassSelectorChildren::SelectorList(selector_list)); } - "is" | "where" => { + js_word!("is") | js_word!("where") => { let forgiving_selector_list = self.parse()?; children.push(PseudoClassSelectorChildren::ForgivingSelectorList( forgiving_selector_list, )); } - "has" => { + js_word!("has") => { let forgiving_relative_selector_list = self.parse()?; children.push( @@ -968,8 +974,12 @@ where ), ); } - "nth-child" | "nth-last-child" | "nth-of-type" | "nth-last-of-type" - | "nth-col" | "nth-last-col" => { + js_word!("nth-child") + | js_word!("nth-last-child") + | js_word!("nth-of-type") + | js_word!("nth-last-of-type") + | js_word!("nth-col") + | js_word!("nth-last-col") => { self.input.skip_ws(); let an_plus_b = self.parse()?; @@ -979,7 +989,9 @@ where self.input.skip_ws(); if is!(self, "ident") { - let of = self.parse()?; + let mut of: Ident = self.parse()?; + + of.value = of.value.to_ascii_lowercase(); children.push(PseudoClassSelectorChildren::Ident(of)); @@ -993,7 +1005,7 @@ where .push(PseudoClassSelectorChildren::SelectorList(selector_list)); } } - "host" | "host-context" => { + js_word!("host") | js_word!("host-context") => { self.input.skip_ws(); let compound_selector = self.parse()?; @@ -1042,7 +1054,9 @@ where children: Some(children), }) } else if is!(self, Ident) { - let name = self.parse()?; + let mut name: Ident = self.parse()?; + + name.value = name.value.to_ascii_lowercase(); Ok(PseudoClassSelector { span: span!(self, span.lo), @@ -1074,16 +1088,17 @@ where let fn_span = self.input.cur_span(); let name = bump!(self); let names = match name { - Token::Function { value, raw } => (value, raw), + Token::Function { value, raw } => (value.to_ascii_lowercase(), raw), _ => unreachable!(), }; + let state = self.input.state(); let mut parse_pseudo_element_children = || -> PResult> { let mut children = vec![]; - match &*names.0.to_ascii_lowercase() { - "cue" | "cue-region" => { + match names.0 { + js_word!("cue") | js_word!("cue-region") => { self.input.skip_ws(); let compound_selector = self.parse()?; @@ -1094,7 +1109,7 @@ where self.input.skip_ws(); } - "part" => { + js_word!("part") => { self.input.skip_ws(); let ident = self.parse()?; @@ -1103,7 +1118,7 @@ where self.input.skip_ws(); } - "slotted" => { + js_word!("slotted") => { self.input.skip_ws(); let compound_selector = self.parse()?; @@ -1114,7 +1129,7 @@ where self.input.skip_ws(); } - "highlight" => { + js_word!("highlight") => { self.input.skip_ws(); let custom_highlight_name = self.parse()?; @@ -1163,7 +1178,9 @@ where children: Some(children), }) } else if is!(self, Ident) { - let name = self.parse()?; + let mut name: Ident = self.parse()?; + + name.value = name.value.to_ascii_lowercase(); Ok(PseudoElementSelector { span: span!(self, span.lo), @@ -1190,7 +1207,11 @@ where Token::Ident { value, .. } if matches_eq_ignore_ascii_case!(value, js_word!("odd"), js_word!("even")) => { - Ok(AnPlusB::Ident(self.parse()?)) + let mut ident: Ident = self.parse()?; + + ident.value = ident.value.to_ascii_lowercase(); + + Ok(AnPlusB::Ident(ident)) } // tok!("number") => { diff --git a/crates/swc_css_parser/tests/fixture/selector/attribute/output.json b/crates/swc_css_parser/tests/fixture/selector/attribute/output.json index 3a52c970238c..e55e54cba38d 100644 --- a/crates/swc_css_parser/tests/fixture/selector/attribute/output.json +++ b/crates/swc_css_parser/tests/fixture/selector/attribute/output.json @@ -1253,7 +1253,7 @@ "end": 232, "ctxt": 0 }, - "value": "I", + "value": "i", "raw": "I" } } @@ -1497,7 +1497,7 @@ "end": 272, "ctxt": 0 }, - "value": "S", + "value": "s", "raw": "S" } } diff --git a/crates/swc_css_parser/tests/fixture/selector/pseudo-class/an-plus-b/output.json b/crates/swc_css_parser/tests/fixture/selector/pseudo-class/an-plus-b/output.json index 1972f37badfd..5648f1d9bb0b 100644 --- a/crates/swc_css_parser/tests/fixture/selector/pseudo-class/an-plus-b/output.json +++ b/crates/swc_css_parser/tests/fixture/selector/pseudo-class/an-plus-b/output.json @@ -5723,7 +5723,7 @@ "end": 1309, "ctxt": 0 }, - "value": "Nth-Child", + "value": "nth-child", "raw": "Nth-Child" }, "children": [ @@ -5813,7 +5813,7 @@ "end": 1329, "ctxt": 0 }, - "value": "NTH-CHILD", + "value": "nth-child", "raw": "NTH-CHILD" }, "children": [ @@ -6002,7 +6002,7 @@ "end": 1373, "ctxt": 0 }, - "value": "ODD", + "value": "odd", "raw": "ODD" } ] @@ -6090,7 +6090,7 @@ "end": 1392, "ctxt": 0 }, - "value": "oDd", + "value": "odd", "raw": "oDd" } ] @@ -6266,7 +6266,7 @@ "end": 1432, "ctxt": 0 }, - "value": "eVeN", + "value": "even", "raw": "eVeN" } ] @@ -6354,7 +6354,7 @@ "end": 1452, "ctxt": 0 }, - "value": "EVEN", + "value": "even", "raw": "EVEN" } ] diff --git a/crates/swc_css_parser/tests/fixture/selector/pseudo-class/basic/output.json b/crates/swc_css_parser/tests/fixture/selector/pseudo-class/basic/output.json index 8b5b001fa494..fc3102d6f554 100644 --- a/crates/swc_css_parser/tests/fixture/selector/pseudo-class/basic/output.json +++ b/crates/swc_css_parser/tests/fixture/selector/pseudo-class/basic/output.json @@ -502,7 +502,7 @@ "end": 75, "ctxt": 0 }, - "value": "iNpUt", + "value": "input", "raw": "iNpUt" } } @@ -2373,7 +2373,7 @@ "end": 461, "ctxt": 0 }, - "value": "hOvEr", + "value": "hover", "raw": "hOvEr" }, "children": null diff --git a/crates/swc_css_parser/tests/fixture/selector/pseudo-class/dir/input.css b/crates/swc_css_parser/tests/fixture/selector/pseudo-class/dir/input.css index 8c64c4198868..9440bd0dded4 100644 --- a/crates/swc_css_parser/tests/fixture/selector/pseudo-class/dir/input.css +++ b/crates/swc_css_parser/tests/fixture/selector/pseudo-class/dir/input.css @@ -2,3 +2,4 @@ :dir( ltr ) {} :dir(rtl) {} :dir( rtl ) {} +:dir( RTL ) {} diff --git a/crates/swc_css_parser/tests/fixture/selector/pseudo-class/dir/output.json b/crates/swc_css_parser/tests/fixture/selector/pseudo-class/dir/output.json index 393c606969cf..2077a250f0bb 100644 --- a/crates/swc_css_parser/tests/fixture/selector/pseudo-class/dir/output.json +++ b/crates/swc_css_parser/tests/fixture/selector/pseudo-class/dir/output.json @@ -2,7 +2,7 @@ "type": "Stylesheet", "span": { "start": 1, - "end": 65, + "end": 84, "ctxt": 0 }, "rules": [ @@ -357,6 +357,94 @@ }, "value": [] } + }, + { + "type": "QualifiedRule", + "span": { + "start": 65, + "end": 83, + "ctxt": 0 + }, + "prelude": { + "type": "SelectorList", + "span": { + "start": 65, + "end": 80, + "ctxt": 0 + }, + "children": [ + { + "type": "ComplexSelector", + "span": { + "start": 65, + "end": 80, + "ctxt": 0 + }, + "children": [ + { + "type": "CompoundSelector", + "span": { + "start": 65, + "end": 80, + "ctxt": 0 + }, + "nestingSelector": null, + "typeSelector": null, + "subclassSelectors": [ + { + "type": "PseudoClassSelector", + "span": { + "start": 65, + "end": 80, + "ctxt": 0 + }, + "name": { + "type": "Ident", + "span": { + "start": 66, + "end": 69, + "ctxt": 0 + }, + "value": "dir", + "raw": "dir" + }, + "children": [ + { + "type": "Ident", + "span": { + "start": 73, + "end": 76, + "ctxt": 0 + }, + "value": "rtl", + "raw": "RTL" + } + ] + } + ] + } + ] + } + ] + }, + "block": { + "type": "SimpleBlock", + "span": { + "start": 81, + "end": 83, + "ctxt": 0 + }, + "name": { + "type": "PreservedToken", + "span": { + "start": 81, + "end": 82, + "ctxt": 0 + }, + "token": "LBrace" + }, + "value": [] + } } ] } diff --git a/crates/swc_css_parser/tests/fixture/selector/pseudo-class/dir/span.swc-stderr b/crates/swc_css_parser/tests/fixture/selector/pseudo-class/dir/span.swc-stderr index d9bad6ca02d8..f2a755b55e32 100644 --- a/crates/swc_css_parser/tests/fixture/selector/pseudo-class/dir/span.swc-stderr +++ b/crates/swc_css_parser/tests/fixture/selector/pseudo-class/dir/span.swc-stderr @@ -4,7 +4,8 @@ 1 | ,-> :dir(ltr) {} 2 | | :dir( ltr ) {} 3 | | :dir(rtl) {} - 4 | `-> :dir( rtl ) {} + 4 | | :dir( rtl ) {} + 5 | `-> :dir( RTL ) {} `---- x Rule @@ -288,6 +289,7 @@ 3 | :dir(rtl) {} 4 | :dir( rtl ) {} : ^^^^^^^^^^^^^^^^^^ + 5 | :dir( RTL ) {} `---- x QualifiedRule @@ -295,6 +297,7 @@ 3 | :dir(rtl) {} 4 | :dir( rtl ) {} : ^^^^^^^^^^^^^^^^^^ + 5 | :dir( RTL ) {} `---- x SelectorList @@ -302,6 +305,7 @@ 3 | :dir(rtl) {} 4 | :dir( rtl ) {} : ^^^^^^^^^^^^^^^ + 5 | :dir( RTL ) {} `---- x ComplexSelector @@ -309,6 +313,7 @@ 3 | :dir(rtl) {} 4 | :dir( rtl ) {} : ^^^^^^^^^^^^^^^ + 5 | :dir( RTL ) {} `---- x CompoundSelector @@ -316,6 +321,7 @@ 3 | :dir(rtl) {} 4 | :dir( rtl ) {} : ^^^^^^^^^^^^^^^ + 5 | :dir( RTL ) {} `---- x SubclassSelector @@ -323,6 +329,7 @@ 3 | :dir(rtl) {} 4 | :dir( rtl ) {} : ^^^^^^^^^^^^^^^ + 5 | :dir( RTL ) {} `---- x PseudoClassSelector @@ -330,6 +337,7 @@ 3 | :dir(rtl) {} 4 | :dir( rtl ) {} : ^^^^^^^^^^^^^^^ + 5 | :dir( RTL ) {} `---- x Ident @@ -337,6 +345,7 @@ 3 | :dir(rtl) {} 4 | :dir( rtl ) {} : ^^^ + 5 | :dir( RTL ) {} `---- x PseudoClassSelectorChildren @@ -344,6 +353,7 @@ 3 | :dir(rtl) {} 4 | :dir( rtl ) {} : ^^^ + 5 | :dir( RTL ) {} `---- x Ident @@ -351,6 +361,7 @@ 3 | :dir(rtl) {} 4 | :dir( rtl ) {} : ^^^ + 5 | :dir( RTL ) {} `---- x SimpleBlock @@ -358,6 +369,7 @@ 3 | :dir(rtl) {} 4 | :dir( rtl ) {} : ^^ + 5 | :dir( RTL ) {} `---- x LBrace @@ -365,4 +377,89 @@ 3 | :dir(rtl) {} 4 | :dir( rtl ) {} : ^ + 5 | :dir( RTL ) {} + `---- + + x Rule + ,-[$DIR/tests/fixture/selector/pseudo-class/dir/input.css:4:1] + 4 | :dir( rtl ) {} + 5 | :dir( RTL ) {} + : ^^^^^^^^^^^^^^^^^^ + `---- + + x QualifiedRule + ,-[$DIR/tests/fixture/selector/pseudo-class/dir/input.css:4:1] + 4 | :dir( rtl ) {} + 5 | :dir( RTL ) {} + : ^^^^^^^^^^^^^^^^^^ + `---- + + x SelectorList + ,-[$DIR/tests/fixture/selector/pseudo-class/dir/input.css:4:1] + 4 | :dir( rtl ) {} + 5 | :dir( RTL ) {} + : ^^^^^^^^^^^^^^^ + `---- + + x ComplexSelector + ,-[$DIR/tests/fixture/selector/pseudo-class/dir/input.css:4:1] + 4 | :dir( rtl ) {} + 5 | :dir( RTL ) {} + : ^^^^^^^^^^^^^^^ + `---- + + x CompoundSelector + ,-[$DIR/tests/fixture/selector/pseudo-class/dir/input.css:4:1] + 4 | :dir( rtl ) {} + 5 | :dir( RTL ) {} + : ^^^^^^^^^^^^^^^ + `---- + + x SubclassSelector + ,-[$DIR/tests/fixture/selector/pseudo-class/dir/input.css:4:1] + 4 | :dir( rtl ) {} + 5 | :dir( RTL ) {} + : ^^^^^^^^^^^^^^^ + `---- + + x PseudoClassSelector + ,-[$DIR/tests/fixture/selector/pseudo-class/dir/input.css:4:1] + 4 | :dir( rtl ) {} + 5 | :dir( RTL ) {} + : ^^^^^^^^^^^^^^^ + `---- + + x Ident + ,-[$DIR/tests/fixture/selector/pseudo-class/dir/input.css:4:1] + 4 | :dir( rtl ) {} + 5 | :dir( RTL ) {} + : ^^^ + `---- + + x PseudoClassSelectorChildren + ,-[$DIR/tests/fixture/selector/pseudo-class/dir/input.css:4:1] + 4 | :dir( rtl ) {} + 5 | :dir( RTL ) {} + : ^^^ + `---- + + x Ident + ,-[$DIR/tests/fixture/selector/pseudo-class/dir/input.css:4:1] + 4 | :dir( rtl ) {} + 5 | :dir( RTL ) {} + : ^^^ + `---- + + x SimpleBlock + ,-[$DIR/tests/fixture/selector/pseudo-class/dir/input.css:4:1] + 4 | :dir( rtl ) {} + 5 | :dir( RTL ) {} + : ^^ + `---- + + x LBrace + ,-[$DIR/tests/fixture/selector/pseudo-class/dir/input.css:4:1] + 4 | :dir( rtl ) {} + 5 | :dir( RTL ) {} + : ^ `---- diff --git a/crates/swc_css_parser/tests/fixture/selector/pseudo-class/not/output.json b/crates/swc_css_parser/tests/fixture/selector/pseudo-class/not/output.json index f1d3dc11410a..5e3150c1363b 100644 --- a/crates/swc_css_parser/tests/fixture/selector/pseudo-class/not/output.json +++ b/crates/swc_css_parser/tests/fixture/selector/pseudo-class/not/output.json @@ -682,7 +682,7 @@ "end": 83, "ctxt": 0 }, - "value": "FOO", + "value": "foo", "raw": "FOO" } } @@ -3120,7 +3120,7 @@ "end": 399, "ctxt": 0 }, - "value": "FOO", + "value": "foo", "raw": "FOO" } } diff --git a/crates/swc_css_parser/tests/fixture/selector/pseudo-element/basic/output.json b/crates/swc_css_parser/tests/fixture/selector/pseudo-element/basic/output.json index a9a7694b2447..e71132dd3e0c 100644 --- a/crates/swc_css_parser/tests/fixture/selector/pseudo-element/basic/output.json +++ b/crates/swc_css_parser/tests/fixture/selector/pseudo-element/basic/output.json @@ -1771,7 +1771,7 @@ "end": 366, "ctxt": 0 }, - "value": "bEfOrE", + "value": "before", "raw": "bEfOrE" }, "children": null diff --git a/crates/swc_css_parser/tests/fixture/selector/pseudo-element/slotted/input.css b/crates/swc_css_parser/tests/fixture/selector/pseudo-element/slotted/input.css index 84ab23fa8ece..658fcac2f6ae 100644 --- a/crates/swc_css_parser/tests/fixture/selector/pseudo-element/slotted/input.css +++ b/crates/swc_css_parser/tests/fixture/selector/pseudo-element/slotted/input.css @@ -1,3 +1,6 @@ ::slotted(*) {} ::slotted(span) {} ::slotted( span ) {} +::SLOTTED(SPAN) { + font-weight: bold; +} diff --git a/crates/swc_css_parser/tests/fixture/selector/pseudo-element/slotted/output.json b/crates/swc_css_parser/tests/fixture/selector/pseudo-element/slotted/output.json index 99d6a8f95f1f..7ccd73815322 100644 --- a/crates/swc_css_parser/tests/fixture/selector/pseudo-element/slotted/output.json +++ b/crates/swc_css_parser/tests/fixture/selector/pseudo-element/slotted/output.json @@ -2,7 +2,7 @@ "type": "Stylesheet", "span": { "start": 1, - "end": 61, + "end": 104, "ctxt": 0 }, "rules": [ @@ -332,6 +332,153 @@ }, "value": [] } + }, + { + "type": "QualifiedRule", + "span": { + "start": 61, + "end": 103, + "ctxt": 0 + }, + "prelude": { + "type": "SelectorList", + "span": { + "start": 61, + "end": 76, + "ctxt": 0 + }, + "children": [ + { + "type": "ComplexSelector", + "span": { + "start": 61, + "end": 76, + "ctxt": 0 + }, + "children": [ + { + "type": "CompoundSelector", + "span": { + "start": 61, + "end": 76, + "ctxt": 0 + }, + "nestingSelector": null, + "typeSelector": null, + "subclassSelectors": [ + { + "type": "PseudoElementSelector", + "span": { + "start": 61, + "end": 76, + "ctxt": 0 + }, + "name": { + "type": "Ident", + "span": { + "start": 63, + "end": 70, + "ctxt": 0 + }, + "value": "slotted", + "raw": "SLOTTED" + }, + "children": [ + { + "type": "CompoundSelector", + "span": { + "start": 71, + "end": 75, + "ctxt": 0 + }, + "nestingSelector": null, + "typeSelector": { + "type": "TagNameSelector", + "span": { + "start": 71, + "end": 75, + "ctxt": 0 + }, + "name": { + "type": "WqName", + "span": { + "start": 71, + "end": 75, + "ctxt": 0 + }, + "prefix": null, + "value": { + "type": "Ident", + "span": { + "start": 71, + "end": 75, + "ctxt": 0 + }, + "value": "span", + "raw": "SPAN" + } + } + }, + "subclassSelectors": [] + } + ] + } + ] + } + ] + } + ] + }, + "block": { + "type": "SimpleBlock", + "span": { + "start": 77, + "end": 103, + "ctxt": 0 + }, + "name": { + "type": "PreservedToken", + "span": { + "start": 77, + "end": 78, + "ctxt": 0 + }, + "token": "LBrace" + }, + "value": [ + { + "type": "Declaration", + "span": { + "start": 83, + "end": 100, + "ctxt": 0 + }, + "name": { + "type": "Ident", + "span": { + "start": 83, + "end": 94, + "ctxt": 0 + }, + "value": "font-weight", + "raw": "font-weight" + }, + "value": [ + { + "type": "Ident", + "span": { + "start": 96, + "end": 100, + "ctxt": 0 + }, + "value": "bold", + "raw": "bold" + } + ], + "important": null + } + ] + } } ] } diff --git a/crates/swc_css_parser/tests/fixture/selector/pseudo-element/slotted/span.swc-stderr b/crates/swc_css_parser/tests/fixture/selector/pseudo-element/slotted/span.swc-stderr index 71f05b6ffebc..42cdd43ecc12 100644 --- a/crates/swc_css_parser/tests/fixture/selector/pseudo-element/slotted/span.swc-stderr +++ b/crates/swc_css_parser/tests/fixture/selector/pseudo-element/slotted/span.swc-stderr @@ -3,7 +3,10 @@ ,-[$DIR/tests/fixture/selector/pseudo-element/slotted/input.css:1:1] 1 | ,-> ::slotted(*) {} 2 | | ::slotted(span) {} - 3 | `-> ::slotted( span ) {} + 3 | | ::slotted( span ) {} + 4 | | ::SLOTTED(SPAN) { + 5 | | font-weight: bold; + 6 | `-> } `---- x Rule @@ -237,6 +240,7 @@ 2 | ::slotted(span) {} 3 | ::slotted( span ) {} : ^^^^^^^^^^^^^^^^^^^^^^^^ + 4 | ::SLOTTED(SPAN) { `---- x QualifiedRule @@ -244,6 +248,7 @@ 2 | ::slotted(span) {} 3 | ::slotted( span ) {} : ^^^^^^^^^^^^^^^^^^^^^^^^ + 4 | ::SLOTTED(SPAN) { `---- x SelectorList @@ -251,6 +256,7 @@ 2 | ::slotted(span) {} 3 | ::slotted( span ) {} : ^^^^^^^^^^^^^^^^^^^^^ + 4 | ::SLOTTED(SPAN) { `---- x ComplexSelector @@ -258,6 +264,7 @@ 2 | ::slotted(span) {} 3 | ::slotted( span ) {} : ^^^^^^^^^^^^^^^^^^^^^ + 4 | ::SLOTTED(SPAN) { `---- x CompoundSelector @@ -265,6 +272,7 @@ 2 | ::slotted(span) {} 3 | ::slotted( span ) {} : ^^^^^^^^^^^^^^^^^^^^^ + 4 | ::SLOTTED(SPAN) { `---- x SubclassSelector @@ -272,6 +280,7 @@ 2 | ::slotted(span) {} 3 | ::slotted( span ) {} : ^^^^^^^^^^^^^^^^^^^^^ + 4 | ::SLOTTED(SPAN) { `---- x PseudoElementSelector @@ -279,6 +288,7 @@ 2 | ::slotted(span) {} 3 | ::slotted( span ) {} : ^^^^^^^^^^^^^^^^^^^^^ + 4 | ::SLOTTED(SPAN) { `---- x Ident @@ -286,6 +296,7 @@ 2 | ::slotted(span) {} 3 | ::slotted( span ) {} : ^^^^^^^ + 4 | ::SLOTTED(SPAN) { `---- x PseudoElementSelectorChildren @@ -293,6 +304,7 @@ 2 | ::slotted(span) {} 3 | ::slotted( span ) {} : ^^^^ + 4 | ::SLOTTED(SPAN) { `---- x CompoundSelector @@ -300,6 +312,7 @@ 2 | ::slotted(span) {} 3 | ::slotted( span ) {} : ^^^^ + 4 | ::SLOTTED(SPAN) { `---- x TypeSelector @@ -307,6 +320,7 @@ 2 | ::slotted(span) {} 3 | ::slotted( span ) {} : ^^^^ + 4 | ::SLOTTED(SPAN) { `---- x TagNameSelector @@ -314,6 +328,7 @@ 2 | ::slotted(span) {} 3 | ::slotted( span ) {} : ^^^^ + 4 | ::SLOTTED(SPAN) { `---- x WqName @@ -321,6 +336,7 @@ 2 | ::slotted(span) {} 3 | ::slotted( span ) {} : ^^^^ + 4 | ::SLOTTED(SPAN) { `---- x Ident @@ -328,6 +344,7 @@ 2 | ::slotted(span) {} 3 | ::slotted( span ) {} : ^^^^ + 4 | ::SLOTTED(SPAN) { `---- x SimpleBlock @@ -335,6 +352,7 @@ 2 | ::slotted(span) {} 3 | ::slotted( span ) {} : ^^ + 4 | ::SLOTTED(SPAN) { `---- x LBrace @@ -342,4 +360,181 @@ 2 | ::slotted(span) {} 3 | ::slotted( span ) {} : ^ + 4 | ::SLOTTED(SPAN) { + `---- + + x Rule + ,-[$DIR/tests/fixture/selector/pseudo-element/slotted/input.css:3:1] + 3 | ::slotted( span ) {} + 4 | ,-> ::SLOTTED(SPAN) { + 5 | | font-weight: bold; + 6 | `-> } + `---- + + x QualifiedRule + ,-[$DIR/tests/fixture/selector/pseudo-element/slotted/input.css:3:1] + 3 | ::slotted( span ) {} + 4 | ,-> ::SLOTTED(SPAN) { + 5 | | font-weight: bold; + 6 | `-> } + `---- + + x SelectorList + ,-[$DIR/tests/fixture/selector/pseudo-element/slotted/input.css:3:1] + 3 | ::slotted( span ) {} + 4 | ::SLOTTED(SPAN) { + : ^^^^^^^^^^^^^^^ + 5 | font-weight: bold; + `---- + + x ComplexSelector + ,-[$DIR/tests/fixture/selector/pseudo-element/slotted/input.css:3:1] + 3 | ::slotted( span ) {} + 4 | ::SLOTTED(SPAN) { + : ^^^^^^^^^^^^^^^ + 5 | font-weight: bold; + `---- + + x CompoundSelector + ,-[$DIR/tests/fixture/selector/pseudo-element/slotted/input.css:3:1] + 3 | ::slotted( span ) {} + 4 | ::SLOTTED(SPAN) { + : ^^^^^^^^^^^^^^^ + 5 | font-weight: bold; + `---- + + x SubclassSelector + ,-[$DIR/tests/fixture/selector/pseudo-element/slotted/input.css:3:1] + 3 | ::slotted( span ) {} + 4 | ::SLOTTED(SPAN) { + : ^^^^^^^^^^^^^^^ + 5 | font-weight: bold; + `---- + + x PseudoElementSelector + ,-[$DIR/tests/fixture/selector/pseudo-element/slotted/input.css:3:1] + 3 | ::slotted( span ) {} + 4 | ::SLOTTED(SPAN) { + : ^^^^^^^^^^^^^^^ + 5 | font-weight: bold; + `---- + + x Ident + ,-[$DIR/tests/fixture/selector/pseudo-element/slotted/input.css:3:1] + 3 | ::slotted( span ) {} + 4 | ::SLOTTED(SPAN) { + : ^^^^^^^ + 5 | font-weight: bold; + `---- + + x PseudoElementSelectorChildren + ,-[$DIR/tests/fixture/selector/pseudo-element/slotted/input.css:3:1] + 3 | ::slotted( span ) {} + 4 | ::SLOTTED(SPAN) { + : ^^^^ + 5 | font-weight: bold; + `---- + + x CompoundSelector + ,-[$DIR/tests/fixture/selector/pseudo-element/slotted/input.css:3:1] + 3 | ::slotted( span ) {} + 4 | ::SLOTTED(SPAN) { + : ^^^^ + 5 | font-weight: bold; + `---- + + x TypeSelector + ,-[$DIR/tests/fixture/selector/pseudo-element/slotted/input.css:3:1] + 3 | ::slotted( span ) {} + 4 | ::SLOTTED(SPAN) { + : ^^^^ + 5 | font-weight: bold; + `---- + + x TagNameSelector + ,-[$DIR/tests/fixture/selector/pseudo-element/slotted/input.css:3:1] + 3 | ::slotted( span ) {} + 4 | ::SLOTTED(SPAN) { + : ^^^^ + 5 | font-weight: bold; + `---- + + x WqName + ,-[$DIR/tests/fixture/selector/pseudo-element/slotted/input.css:3:1] + 3 | ::slotted( span ) {} + 4 | ::SLOTTED(SPAN) { + : ^^^^ + 5 | font-weight: bold; + `---- + + x Ident + ,-[$DIR/tests/fixture/selector/pseudo-element/slotted/input.css:3:1] + 3 | ::slotted( span ) {} + 4 | ::SLOTTED(SPAN) { + : ^^^^ + 5 | font-weight: bold; + `---- + + x SimpleBlock + ,-[$DIR/tests/fixture/selector/pseudo-element/slotted/input.css:3:1] + 3 | ::slotted( span ) {} + 4 | ,-> ::SLOTTED(SPAN) { + 5 | | font-weight: bold; + 6 | `-> } + `---- + + x LBrace + ,-[$DIR/tests/fixture/selector/pseudo-element/slotted/input.css:3:1] + 3 | ::slotted( span ) {} + 4 | ::SLOTTED(SPAN) { + : ^ + 5 | font-weight: bold; + `---- + + x ComponentValue + ,-[$DIR/tests/fixture/selector/pseudo-element/slotted/input.css:4:1] + 4 | ::SLOTTED(SPAN) { + 5 | font-weight: bold; + : ^^^^^^^^^^^^^^^^^ + 6 | } + `---- + + x Declaration + ,-[$DIR/tests/fixture/selector/pseudo-element/slotted/input.css:4:1] + 4 | ::SLOTTED(SPAN) { + 5 | font-weight: bold; + : ^^^^^^^^^^^^^^^^^ + 6 | } + `---- + + x DeclarationName + ,-[$DIR/tests/fixture/selector/pseudo-element/slotted/input.css:4:1] + 4 | ::SLOTTED(SPAN) { + 5 | font-weight: bold; + : ^^^^^^^^^^^ + 6 | } + `---- + + x Ident + ,-[$DIR/tests/fixture/selector/pseudo-element/slotted/input.css:4:1] + 4 | ::SLOTTED(SPAN) { + 5 | font-weight: bold; + : ^^^^^^^^^^^ + 6 | } + `---- + + x ComponentValue + ,-[$DIR/tests/fixture/selector/pseudo-element/slotted/input.css:4:1] + 4 | ::SLOTTED(SPAN) { + 5 | font-weight: bold; + : ^^^^ + 6 | } + `---- + + x Ident + ,-[$DIR/tests/fixture/selector/pseudo-element/slotted/input.css:4:1] + 4 | ::SLOTTED(SPAN) { + 5 | font-weight: bold; + : ^^^^ + 6 | } `---- diff --git a/crates/swc_css_parser/tests/fixture/selector/type/output.json b/crates/swc_css_parser/tests/fixture/selector/type/output.json index 16351a982dc6..2f05a0de8183 100644 --- a/crates/swc_css_parser/tests/fixture/selector/type/output.json +++ b/crates/swc_css_parser/tests/fixture/selector/type/output.json @@ -941,7 +941,7 @@ "end": 100, "ctxt": 0 }, - "value": "foreignObject", + "value": "foreignobject", "raw": "foreignObject" } } @@ -1070,7 +1070,7 @@ "end": 117, "ctxt": 0 }, - "value": "textPath", + "value": "textpath", "raw": "textPath" } } diff --git a/crates/swc_css_parser/tests/fixture/vendor/esbuild/misc/pOZgFOB3GdVvQ0hiAsWfpQ/output.json b/crates/swc_css_parser/tests/fixture/vendor/esbuild/misc/pOZgFOB3GdVvQ0hiAsWfpQ/output.json index 5e57b9faae10..54c2f5b36c53 100644 --- a/crates/swc_css_parser/tests/fixture/vendor/esbuild/misc/pOZgFOB3GdVvQ0hiAsWfpQ/output.json +++ b/crates/swc_css_parser/tests/fixture/vendor/esbuild/misc/pOZgFOB3GdVvQ0hiAsWfpQ/output.json @@ -98,7 +98,7 @@ "end": 11, "ctxt": 0 }, - "value": "I", + "value": "i", "raw": "I" } } diff --git a/crates/swc_css_parser/tests/fixture/vendor/rome/selectors/output.json b/crates/swc_css_parser/tests/fixture/vendor/rome/selectors/output.json index 1fe94063a3fd..cf1a94418edf 100644 --- a/crates/swc_css_parser/tests/fixture/vendor/rome/selectors/output.json +++ b/crates/swc_css_parser/tests/fixture/vendor/rome/selectors/output.json @@ -1181,7 +1181,7 @@ "end": 239, "ctxt": 0 }, - "value": "S", + "value": "s", "raw": "S" } } diff --git a/crates/swc_css_parser/tests/recovery/hacks/output.json b/crates/swc_css_parser/tests/recovery/hacks/output.json index de9c52011fc2..424f80923d1e 100644 --- a/crates/swc_css_parser/tests/recovery/hacks/output.json +++ b/crates/swc_css_parser/tests/recovery/hacks/output.json @@ -5942,7 +5942,7 @@ "end": 1980, "ctxt": 0 }, - "value": "-IE7", + "value": "-ie7", "raw": "-IE7" }, "children": null diff --git a/crates/swc_css_utils/src/lib.rs b/crates/swc_css_utils/src/lib.rs index f64bc237a8ca..aa1636bf1d1d 100644 --- a/crates/swc_css_utils/src/lib.rs +++ b/crates/swc_css_utils/src/lib.rs @@ -64,7 +64,7 @@ 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.eq_str_ignore_ascii_case(self.from) { + if &*n.name.value == self.from { n.name.value = self.to.into(); n.name.raw = None; } @@ -87,7 +87,7 @@ 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.eq_str_ignore_ascii_case(self.from) { + if &*n.name.value == self.from { n.name.value = self.to.into(); n.name.raw = None; } @@ -112,7 +112,7 @@ impl VisitMut for PseudoElementOnPseudoClassReplacer<'_> { match n { SubclassSelector::PseudoElement(PseudoElementSelector { name, span, .. }) - if name.value.eq_str_ignore_ascii_case(self.from) => + if &*name.value == self.from => { *n = SubclassSelector::PseudoClass(PseudoClassSelector { span: *span,