From 1c7f003779fd17d3d2c372ce502cbbaabb49ed48 Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Wed, 21 Dec 2022 06:00:53 +0300 Subject: [PATCH] feat(css/prefixer): Support `overflow` (#6678) --- crates/swc_atoms/words.txt | 104 +++++++++--------- .../data/prefixes_and_browsers.json | 24 ++++ crates/swc_css_prefixer/src/prefixer.rs | 38 ++++++- .../tests/fixture/overflow/input.css | 69 +++++++++++- .../tests/fixture/overflow/output.css | 90 ++++++++++++++- .../overflow/output.defaults-not-ie-11.css | 53 ++++++++- .../tests/fixture/text-overflow/input.css | 3 + .../tests/fixture/text-overflow/output.css | 4 + .../output.defaults-not-ie-11.css | 3 + 9 files changed, 326 insertions(+), 62 deletions(-) create mode 100644 crates/swc_css_prefixer/tests/fixture/text-overflow/input.css create mode 100644 crates/swc_css_prefixer/tests/fixture/text-overflow/output.css create mode 100644 crates/swc_css_prefixer/tests/fixture/text-overflow/output.defaults-not-ie-11.css diff --git a/crates/swc_atoms/words.txt b/crates/swc_atoms/words.txt index 3460dd2b9199..e9caaf1fd916 100644 --- a/crates/swc_atoms/words.txt +++ b/crates/swc_atoms/words.txt @@ -1,4 +1,7 @@ * +* +-infinity +-moz-activehyperlinktext -moz-animation -moz-animation-delay -moz-animation-direction @@ -9,6 +12,8 @@ -moz-animation-play-state -moz-animation-timing-function -moz-any +-moz-any +-moz-any -moz-appearance -moz-backface-visibility -moz-background-origin @@ -29,7 +34,14 @@ -moz-box-pack -moz-box-shadow -moz-box-sizing +-moz-buttondefault +-moz-buttonhoverface +-moz-buttonhovertext +-moz-calc +-moz-calc -moz-calc +-moz-cellhighlight +-moz-cellhighlighttext -moz-column-count -moz-column-fill -moz-column-gap @@ -40,14 +52,48 @@ -moz-column-span -moz-column-width -moz-columns +-moz-combobox +-moz-comboboxtext +-moz-default-background-color +-moz-default-color +-moz-dialog +-moz-dialogtext +-moz-document +-moz-document -moz-document +-moz-dragtargetzone +-moz-eventreerow -moz-font-feature-settings -moz-font-language-override -moz-font-variant-ligatures +-moz-html-cellhighlight +-moz-html-cellhighlighttext +-moz-hyperlinktext -moz-hyphens -moz-keyframes +-moz-keyframes +-moz-keyframes +-moz-mac-accentdarkestshadow +-moz-mac-accentdarkshadow +-moz-mac-accentface +-moz-mac-accentlightesthighlight +-moz-mac-accentlightshadow +-moz-mac-accentregularhighlight +-moz-mac-accentregularshadow +-moz-mac-chrome-active +-moz-mac-chrome-inactive +-moz-mac-focusring +-moz-mac-menuselect +-moz-mac-menushadow +-moz-mac-menutextselect -moz-margin-end -moz-margin-start +-moz-menubarhovertext +-moz-menubartext +-moz-menuhover +-moz-menuhovertext +-moz-nativehyperlinktext +-moz-oddtreerow -moz-padding-end -moz-padding-start -moz-perspective @@ -67,6 +113,11 @@ -moz-transition-duration -moz-transition-timing-function -moz-user-select +-moz-visitedhyperlinktext +-moz-win-accentcolor +-moz-win-accentcolortext +-moz-win-communicationstext +-moz-win-mediatext -ms-appearance -ms-flex -ms-flex-align @@ -85,57 +136,6 @@ -ms-high-contrast-adjust -ms-hyphens -ms-interpolation-mode --moz-any --moz-calc --moz-document --moz-keyframes -* --infinity --moz-activehyperlinktext --moz-any --moz-buttondefault --moz-buttonhoverface --moz-buttonhovertext --moz-calc --moz-cellhighlight --moz-cellhighlighttext --moz-combobox --moz-comboboxtext --moz-default-background-color --moz-default-color --moz-dialog --moz-dialogtext --moz-document --moz-dragtargetzone --moz-eventreerow --moz-html-cellhighlight --moz-html-cellhighlighttext --moz-hyperlinktext --moz-keyframes --moz-mac-accentdarkestshadow --moz-mac-accentdarkshadow --moz-mac-accentface --moz-mac-accentlightesthighlight --moz-mac-accentlightshadow --moz-mac-accentregularhighlight --moz-mac-accentregularshadow --moz-mac-chrome-active --moz-mac-chrome-inactive --moz-mac-focusring --moz-mac-menuselect --moz-mac-menushadow --moz-mac-menutextselect --moz-menubarhovertext --moz-menubartext --moz-menuhover --moz-menuhovertext --moz-nativehyperlinktext --moz-oddtreerow --moz-visitedhyperlinktext --moz-win-accentcolor --moz-win-accentcolortext --moz-win-communicationstext --moz-win-mediatext -ms-keyframes -ms-region-fragment -ms-scroll-chaining @@ -1929,6 +1929,8 @@ overflow-block overflow-clip-margin overflow-inline overflow-wrap +overflow-x +overflow-y overline override overscroll-behavior diff --git a/crates/swc_css_prefixer/data/prefixes_and_browsers.json b/crates/swc_css_prefixer/data/prefixes_and_browsers.json index d3ad949af2f8..5ad918bc0daa 100644 --- a/crates/swc_css_prefixer/data/prefixes_and_browsers.json +++ b/crates/swc_css_prefixer/data/prefixes_and_browsers.json @@ -3955,6 +3955,30 @@ "samsung": "11.2" } ], + "overflow": [ + { + "chrome": "4", + "edge": "12", + "safari": "3.1", + "firefox": "2", + "opera": "10", + "ie": "6", + "ios": "3.2", + "samsung": "4", + "android": "2.1" + }, + { + "chrome": "67", + "edge": "17", + "safari": "13", + "firefox": "60", + "opera": "54", + "ie": "11", + "ios": "13.3", + "samsung": "14.0", + "android": "4.4.4" + } + ], "display:multi-keyword-values": [ { "chrome": "4", diff --git a/crates/swc_css_prefixer/src/prefixer.rs b/crates/swc_css_prefixer/src/prefixer.rs index b72788f9faaa..a45e2995a041 100644 --- a/crates/swc_css_prefixer/src/prefixer.rs +++ b/crates/swc_css_prefixer/src/prefixer.rs @@ -1920,7 +1920,7 @@ impl VisitMut for Prefixer { } } } else if n.value.len() == 2 - && should_prefix("display:multi-keyword-values", self.env, true) + && should_prefix("display:multi-keyword-values", self.env, false) { if let ( Some(ComponentValue::Ident(first)), @@ -2044,7 +2044,7 @@ impl VisitMut for Prefixer { } } } else if n.value.len() == 3 - && should_prefix("display:multi-keyword-values", self.env, true) + && should_prefix("display:multi-keyword-values", self.env, false) { if let ( Some(ComponentValue::Ident(first)), @@ -3390,11 +3390,41 @@ impl VisitMut for Prefixer { add_declaration!(js_word!("word-wrap"), None); } + js_word!("overflow") + if should_prefix("overflow", self.env, false) && n.value.len() == 2 => + { + if let ( + Some(left @ ComponentValue::Ident(box first)), + Some(right @ ComponentValue::Ident(box second)), + ) = (n.value.get(0), n.value.get(1)) + { + if first.value.eq_ignore_ascii_case(&second.value) { + add_declaration!( + js_word!("overflow"), + Some(Box::new(|| { vec![left.clone()] })) + ); + } else { + add_declaration!( + js_word!("overflow-x"), + Some(Box::new(|| { vec![left.clone()] })) + ); + add_declaration!( + js_word!("overflow-y"), + Some(Box::new(|| { vec![right.clone()] })) + ); + } + } + } + js_word!("tab-size") => { add_declaration!(Prefix::Moz, js_word!("-moz-tab-size"), None); add_declaration!(Prefix::O, js_word!("-o-tab-size"), None); } + js_word!("overflow-wrap") => { + add_declaration!(js_word!("word-wrap"), None); + } + js_word!("hyphens") => { add_declaration!(Prefix::Webkit, js_word!("-webkit-hyphens"), None); add_declaration!(Prefix::Moz, js_word!("-moz-hyphens"), None); @@ -3589,7 +3619,7 @@ impl VisitMut for Prefixer { add_declaration!(Prefix::Moz, js_word!("-moz-border-radius-bottomleft"), None); } - js_word!("src") if should_prefix("font-face-format-ident", self.env, true) => { + js_word!("src") if should_prefix("font-face-format-ident", self.env, false) => { let mut new_declaration = n.clone(); font_face_format_old_syntax(&mut new_declaration); @@ -3718,7 +3748,7 @@ impl VisitMut for Prefixer { })); } - if should_prefix("calc-nested", self.env, true) { + if should_prefix("calc-nested", self.env, false) { let mut value = n.value.clone(); replace_calc(&mut value, None); diff --git a/crates/swc_css_prefixer/tests/fixture/overflow/input.css b/crates/swc_css_prefixer/tests/fixture/overflow/input.css index dfe9c319f6ba..b51fe3f392ae 100644 --- a/crates/swc_css_prefixer/tests/fixture/overflow/input.css +++ b/crates/swc_css_prefixer/tests/fixture/overflow/input.css @@ -1,3 +1,68 @@ -.class { - text-overflow: clip; +html.single-overflow { + overflow: hidden; } + +html.double-overflow { + overflow: hidden auto; +} + +html.double-overflow { + overflow: auto auto; +} + +html.double-overflow { + overflow: hidden /* a comment */ auto; +} + +html.double-overflow { + overflow: hidden auto; +} + +html.double-overflow { + overflow: hidden auto; +} + +.order-0 { + -webkit-overflow: hidden auto; +} + +.order-1 { + -moz-overflow: hidden auto; +} + +.order-2 { + -ms-overflow: hidden auto; +} + +.order-3 { + -o-overflow: hidden auto; +} + +.order-4 { + --overflow: hidden auto; +} + +.order-5 { + foo-overflow: hidden auto; +} + +/* overflow: hidden auto; */ + +.content { + content: 'overflow: hidden auto;'; +} + +.important { + overflow: hidden auto !important; +} + +@supports (overflow: hidden auto) { + .support { + overflow: hidden auto; + } +} +@keyframes KEYFRAMES { + 50% { + overflow: hidden auto; + } +} \ No newline at end of file diff --git a/crates/swc_css_prefixer/tests/fixture/overflow/output.css b/crates/swc_css_prefixer/tests/fixture/overflow/output.css index c8289155b0cc..36ca665bd386 100644 --- a/crates/swc_css_prefixer/tests/fixture/overflow/output.css +++ b/crates/swc_css_prefixer/tests/fixture/overflow/output.css @@ -1,4 +1,88 @@ -.class { - -o-text-overflow: clip; - text-overflow: clip; +html.single-overflow { + overflow: hidden; +} +html.double-overflow { + overflow-x: hidden; + overflow-y: auto; + overflow: hidden auto; +} +html.double-overflow { + overflow: auto; + overflow: auto auto; +} +html.double-overflow { + overflow-x: hidden; + overflow-y: auto; + overflow: hidden auto; +} +html.double-overflow { + overflow-x: hidden; + overflow-y: auto; + overflow: hidden auto; +} +html.double-overflow { + overflow-x: hidden; + overflow-y: auto; + overflow: hidden auto; +} +.order-0 { + -webkit-overflow: hidden auto; +} +.order-1 { + -moz-overflow: hidden auto; +} +.order-2 { + -ms-overflow: hidden auto; +} +.order-3 { + -o-overflow: hidden auto; +} +.order-4 { + --overflow: hidden auto; +} +.order-5 { + foo-overflow: hidden auto; +} +.content { + content: 'overflow: hidden auto;'; +} +.important { + overflow-x: hidden !important; + overflow-y: auto !important; + overflow: hidden auto !important; +} +@supports ((overflow: hidden auto) or (overflow-x: hidden) or (overflow-y: auto)) { + .support { + overflow-x: hidden; + overflow-y: auto; + overflow: hidden auto; + } +} +@-webkit-keyframes KEYFRAMES { + 50% { + overflow-x: hidden; + overflow-y: auto; + overflow: hidden auto; + } +} +@-moz-keyframes KEYFRAMES { + 50% { + overflow-x: hidden; + overflow-y: auto; + overflow: hidden auto; + } +} +@-o-keyframes KEYFRAMES { + 50% { + overflow-x: hidden; + overflow-y: auto; + overflow: hidden auto; + } +} +@keyframes KEYFRAMES { + 50% { + overflow-x: hidden; + overflow-y: auto; + overflow: hidden auto; + } } diff --git a/crates/swc_css_prefixer/tests/fixture/overflow/output.defaults-not-ie-11.css b/crates/swc_css_prefixer/tests/fixture/overflow/output.defaults-not-ie-11.css index fc829ddc9cb5..c8f6e2acd16d 100644 --- a/crates/swc_css_prefixer/tests/fixture/overflow/output.defaults-not-ie-11.css +++ b/crates/swc_css_prefixer/tests/fixture/overflow/output.defaults-not-ie-11.css @@ -1,3 +1,52 @@ -.class { - text-overflow: clip; +html.single-overflow { + overflow: hidden; +} +html.double-overflow { + overflow: hidden auto; +} +html.double-overflow { + overflow: auto auto; +} +html.double-overflow { + overflow: hidden auto; +} +html.double-overflow { + overflow: hidden auto; +} +html.double-overflow { + overflow: hidden auto; +} +.order-0 { + -webkit-overflow: hidden auto; +} +.order-1 { + -moz-overflow: hidden auto; +} +.order-2 { + -ms-overflow: hidden auto; +} +.order-3 { + -o-overflow: hidden auto; +} +.order-4 { + --overflow: hidden auto; +} +.order-5 { + foo-overflow: hidden auto; +} +.content { + content: 'overflow: hidden auto;'; +} +.important { + overflow: hidden auto !important; +} +@supports (overflow: hidden auto) { + .support { + overflow: hidden auto; + } +} +@keyframes KEYFRAMES { + 50% { + overflow: hidden auto; + } } diff --git a/crates/swc_css_prefixer/tests/fixture/text-overflow/input.css b/crates/swc_css_prefixer/tests/fixture/text-overflow/input.css new file mode 100644 index 000000000000..dfe9c319f6ba --- /dev/null +++ b/crates/swc_css_prefixer/tests/fixture/text-overflow/input.css @@ -0,0 +1,3 @@ +.class { + text-overflow: clip; +} diff --git a/crates/swc_css_prefixer/tests/fixture/text-overflow/output.css b/crates/swc_css_prefixer/tests/fixture/text-overflow/output.css new file mode 100644 index 000000000000..c8289155b0cc --- /dev/null +++ b/crates/swc_css_prefixer/tests/fixture/text-overflow/output.css @@ -0,0 +1,4 @@ +.class { + -o-text-overflow: clip; + text-overflow: clip; +} diff --git a/crates/swc_css_prefixer/tests/fixture/text-overflow/output.defaults-not-ie-11.css b/crates/swc_css_prefixer/tests/fixture/text-overflow/output.defaults-not-ie-11.css new file mode 100644 index 000000000000..fc829ddc9cb5 --- /dev/null +++ b/crates/swc_css_prefixer/tests/fixture/text-overflow/output.defaults-not-ie-11.css @@ -0,0 +1,3 @@ +.class { + text-overflow: clip; +}