Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(css/minifier): fix timing functions #6618

Merged
merged 2 commits into from Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 34 additions & 14 deletions crates/swc_css_minifier/src/compressor/easing_function.rs
Expand Up @@ -14,41 +14,61 @@ impl Compressor {
&& function_value.len() == 7 =>
{
if let (
ComponentValue::Number(box Number { value: first, .. }),
ComponentValue::Number(box Number { value: second, .. }),
ComponentValue::Number(box Number { value: third, .. }),
ComponentValue::Number(box Number { value: fourth, .. }),
first,
second,
third,
ComponentValue::Integer(box Integer { value: fourth, .. }),
) = (
&function_value[0],
&function_value[2],
&function_value[4],
&function_value[6],
) {
if *first == 0.0 && *second == 0.0 && *third == 1.0 && *fourth == 1.0 {
if matches!(first, ComponentValue::Integer(box Integer { value, .. }) if *value == 0)
&& matches!(second, ComponentValue::Integer(box Integer { value, .. }) if *value == 0)
&& matches!(third, ComponentValue::Integer(box Integer { value, .. }) if *value == 1)
&& *fourth == 1
{
*component_value = ComponentValue::Ident(Box::new(Ident {
span: *span,
value: js_word!("linear"),
raw: None,
}))
} else if *first == 0.25 && *second == 0.1 && *third == 0.25 && *fourth == 1.0 {
} else if matches!(first, ComponentValue::Number(box Number { value, .. }) if *value == 0.25)
&& matches!(second, ComponentValue::Number(box Number { value, .. }) if *value == 0.1)
&& matches!(third, ComponentValue::Number(box Number { value, .. }) if *value == 0.25)
&& *fourth == 1
{
*component_value = ComponentValue::Ident(Box::new(Ident {
span: *span,
value: js_word!("ease"),
raw: None,
}))
} else if *first == 0.42 && *second == 0.0 && *third == 1.0 && *fourth == 1.0 {
} else if matches!(first, ComponentValue::Number(box Number { value: first, .. }) if *first == 0.42)
&& matches!(second, ComponentValue::Integer(box Integer { value, .. }) if *value == 0)
&& matches!(third, ComponentValue::Integer(box Integer { value, .. }) if *value == 1)
&& *fourth == 1
{
*component_value = ComponentValue::Ident(Box::new(Ident {
span: *span,
value: js_word!("ease-in"),
raw: None,
}))
} else if *first == 0.0 && *second == 0.0 && *third == 0.58 && *fourth == 1.0 {
} else if matches!(first, ComponentValue::Integer(box Integer { value: first, .. }) if *first == 0)
&& matches!(second, ComponentValue::Integer(box Integer { value, .. }) if *value == 0)
&& matches!(third, ComponentValue::Number(box Number { value, .. }) if *value == 0.58)
&& *fourth == 1
{
*component_value = ComponentValue::Ident(Box::new(Ident {
span: *span,
value: js_word!("ease-out"),
raw: None,
}))
} else if *first == 0.42 && *second == 0.0 && *third == 0.58 && *fourth == 1.0 {
} else if matches!(first, ComponentValue::Number(box Number { value: first, .. }) if *first == 0.42)
&& matches!(second, ComponentValue::Integer(box Integer { value, .. }) if *value == 0)
&& matches!(third, ComponentValue::Number(box Number { value, .. }) if *value == 0.58)
&& *fourth == 1
{
*component_value = ComponentValue::Ident(Box::new(Ident {
span: *span,
value: js_word!("ease-in-out"),
Expand All @@ -66,14 +86,14 @@ impl Compressor {
{
match (&function_value[0], &function_value[2]) {
(
ComponentValue::Number(box Number {
ComponentValue::Integer(box Integer {
value: number_value,
..
}),
ComponentValue::Ident(box Ident {
value: ident_value, ..
}),
) if *number_value == 1.0 => match ident_value.to_ascii_lowercase() {
) if *number_value == 1 => match ident_value.to_ascii_lowercase() {
js_word!("start") | js_word!("jump-start") => {
*component_value = ComponentValue::Ident(Box::new(Ident {
span: *span,
Expand All @@ -91,7 +111,7 @@ impl Compressor {
_ => {}
},
(
ComponentValue::Number(box Number { .. }),
ComponentValue::Integer(box Integer { .. }),
ComponentValue::Ident(box Ident {
value: ident_value, ..
}),
Expand All @@ -103,13 +123,13 @@ impl Compressor {
}))
}
(
ComponentValue::Number(number),
ComponentValue::Integer(number),
ComponentValue::Ident(box Ident {
value: ident_value, ..
}),
) => match ident_value.to_ascii_lowercase() {
js_word!("end") | js_word!("jump-end") => {
*function_value = vec![ComponentValue::Number(number.clone())];
*function_value = vec![ComponentValue::Integer(number.clone())];
}
_ => {}
},
Expand Down

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