From d7a0524fb64c97facf067281ae3a2fc4afae68fe Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Tue, 20 Dec 2022 07:35:14 +0300 Subject: [PATCH] feat(css/parser): Normalize keyframe selectors (#6688) --- crates/swc_css_minifier/src/compressor/keyframes.rs | 2 +- crates/swc_css_parser/src/parser/at_rules/mod.rs | 7 ++++--- .../tests/fixture/at-rule/keyframe/output.json | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/swc_css_minifier/src/compressor/keyframes.rs b/crates/swc_css_minifier/src/compressor/keyframes.rs index e52f5d03d92c..bd34e12bd5b8 100644 --- a/crates/swc_css_minifier/src/compressor/keyframes.rs +++ b/crates/swc_css_minifier/src/compressor/keyframes.rs @@ -34,7 +34,7 @@ impl Compressor { pub(super) fn compress_keyframe_selector(&mut self, keyframe_selector: &mut KeyframeSelector) { match keyframe_selector { - KeyframeSelector::Ident(i) if i.value.eq_ignore_ascii_case(&js_word!("from")) => { + KeyframeSelector::Ident(i) if i.value == js_word!("from") => { *keyframe_selector = KeyframeSelector::Percentage(Percentage { span: i.span, value: Number { diff --git a/crates/swc_css_parser/src/parser/at_rules/mod.rs b/crates/swc_css_parser/src/parser/at_rules/mod.rs index 2248511d2759..e64e59123ad9 100644 --- a/crates/swc_css_parser/src/parser/at_rules/mod.rs +++ b/crates/swc_css_parser/src/parser/at_rules/mod.rs @@ -896,10 +896,11 @@ where fn parse(&mut self) -> PResult { match cur!(self) { tok!("ident") => { - let ident: Ident = self.parse()?; - let normalized_ident_value = ident.value.to_ascii_lowercase(); + let mut ident: Ident = self.parse()?; - if &*normalized_ident_value != "from" && &*normalized_ident_value != "to" { + ident.value = ident.value.to_ascii_lowercase(); + + if ident.value != js_word!("from") && ident.value != js_word!("to") { return Err(Error::new( ident.span, ErrorKind::Expected("'from' or 'to' idents"), diff --git a/crates/swc_css_parser/tests/fixture/at-rule/keyframe/output.json b/crates/swc_css_parser/tests/fixture/at-rule/keyframe/output.json index 3df6f83876ea..870904bc1efd 100644 --- a/crates/swc_css_parser/tests/fixture/at-rule/keyframe/output.json +++ b/crates/swc_css_parser/tests/fixture/at-rule/keyframe/output.json @@ -1513,7 +1513,7 @@ "end": 686, "ctxt": 0 }, - "value": "fRoM", + "value": "from", "raw": "fRoM" } ], @@ -1611,7 +1611,7 @@ "end": 737, "ctxt": 0 }, - "value": "tO", + "value": "to", "raw": "tO" } ],