Skip to content

Commit

Permalink
refactor: rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Dec 20, 2022
1 parent 8f6a9cf commit 90fd03b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 30 deletions.
14 changes: 7 additions & 7 deletions crates/swc_css_compat/src/compiler/color_hwb.rs
@@ -1,7 +1,7 @@
use swc_atoms::js_word;
use swc_css_ast::{
AbsoluteColorBase, AlphaValue, Angle, ComponentValue, Delimiter, DelimiterValue, Hue, Ident,
Number, Percentage,
AbsoluteColorBase, AlphaValue, Angle, ComponentValue, Delimiter, DelimiterValue, FunctionName,
Hue, Ident, Number, Percentage,
};
use swc_css_utils::{angle_to_deg, hwb_to_rgb, to_rgb255};

Expand Down Expand Up @@ -95,7 +95,7 @@ impl Compiler {

pub(crate) fn process_color_hwb(&mut self, n: &mut AbsoluteColorBase) {
if let AbsoluteColorBase::Function(function) = n {
if function.name.value != js_word!("hwb") {
if function.name != js_word!("hwb") {
return;
}

Expand All @@ -120,11 +120,11 @@ impl Compiler {

if a == 1.0 {
*n = AbsoluteColorBase::Function(swc_css_ast::Function {
name: Ident {
name: FunctionName::Ident(Ident {
value: js_word!("rgb"),
span: Default::default(),
raw: None,
},
}),
value: vec![
ComponentValue::Number(Box::new(Number {
value: rgb[0].round(),
Expand Down Expand Up @@ -154,11 +154,11 @@ impl Compiler {
});
} else {
*n = AbsoluteColorBase::Function(swc_css_ast::Function {
name: Ident {
name: FunctionName::Ident(Ident {
value: js_word!("rgba"),
span: Default::default(),
raw: None,
},
}),
value: vec![
ComponentValue::Number(Box::new(Number {
value: rgb[0].round(),
Expand Down
3 changes: 1 addition & 2 deletions crates/swc_css_compat/src/compiler/legacy_rgb_and_hsl.rs
@@ -1,11 +1,10 @@
use std::f64::consts::PI;

use swc_atoms::js_word;
use swc_css_ast::{AbsoluteColorBase, AlphaValue, Angle, ComponentValue, Hue, Number, Percentage};
use swc_css_utils::{clamp_unit_f64, round_alpha};
use swc_css_ast::{
matches_eq, AbsoluteColorBase, AlphaValue, Angle, ComponentValue, Hue, Number, Percentage,
};
use swc_css_utils::{clamp_unit_f64, round_alpha};

use crate::compiler::Compiler;

Expand Down
17 changes: 1 addition & 16 deletions crates/swc_css_minifier/src/compressor/color.rs
Expand Up @@ -465,23 +465,8 @@ impl Compressor {
name,
value,
..
})) if matches!(&*name.value, "hwb") => {
let h = match self.get_hue(value.get(0).as_ref()) {
})) if name == &js_word!("hwb") => {
let hsla: Vec<_> = value
.iter()
.filter(|n| {
!matches!(
n,
ComponentValue::Delimiter(box Delimiter {
value: DelimiterValue::Comma | DelimiterValue::Solidus,
..
})
)
})
.collect();

let h = match self.get_hue(hsla.get(0)) {
let h = match self.get_hue(value.get(0).as_ref()) {
Some(value) => value,
_ => return,
};
Expand Down
9 changes: 4 additions & 5 deletions crates/swc_css_prefixer/src/prefixer.rs
Expand Up @@ -2547,11 +2547,10 @@ impl VisitMut for Prefixer {
}
}

js_word!("filter") => match &n.value[0] {
ComponentValue::PreservedToken(_) => {}
ComponentValue::Function(function)
if function.name.value.eq_ignore_ascii_case(&js_word!("alpha")) => {}
ComponentValue::Function(function) if function.name == js_word!("alpha") => {}
js_word!("filter") => match &n.value.get(0) {
Some(ComponentValue::PreservedToken(_)) => {}
Some(ComponentValue::Function(function)) if function.name == js_word!("alpha") => {}
None => {}
_ => {
add_declaration!(Prefix::Webkit, js_word!("-webkit-filter"), None);
}
Expand Down

0 comments on commit 90fd03b

Please sign in to comment.