-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat(css/minifier) Remove useless zeroes #6196
base: main
Are you sure you want to change the base?
Conversation
@@ -93,6 +93,7 @@ struct CalcSumContext { | |||
impl CalcSumContext { | |||
pub fn fold(&mut self, calc_sum: &mut CalcSum) { | |||
self.nested_fold(None, calc_sum); | |||
self.remove_zeroes(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we need extra loop? Can we solve it in nested_fold
, because it is just sum with another sign, don't forget we should implement logic looking at all future math functions (not only calc)
self.expressions.remove(term_index - 1); | ||
true | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please read my comment above, we should not add extra loops, these things can be solved in one loop and expression, any plus or minus with 0
just return value itself or value with anither sign
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should refactor out internal logic, no need extra loops, please read a spec - https://www.w3.org/TR/css-values-4/#calc-simplification, finally we should refactor our logic to this
|
||
.class10 { | ||
width: calc(0 - (pi * 3px) - 0px - 4em); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think calc(0 - 0px)
is an invaild value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, we should have something like calc(0q - (pi * 3px) - 0px - 4em)
@alexander-akait do you mean we should refactor the code to strictly follow the spec (and create structures like "Invert" and "Negate" in an intermediate step as defined in the spec, by wrapping the matching AST node)? Or "just" refactor the code to follow the spec as much as possible with our current AST nodes without intermediate transformation ? |
I am fine with it, too But will be great if you try to, but we can postpone it:
Not at the parser level, just like PoC (i know it can take a time), because it may turn out that it is faster and more convenient. |
@alexander-akait btw, i just read this from the spec:
Do you think it's relevant in our case? |
@ghostd And yes and no, look at example: https://tomhodgins.com/demo/cssom/ and put the code: .class {
width: calc(20px + 0px);
}
.class {
width: calc(20px + 0%);
} you will see how it works |
Ok, i'll give a try (in an other poc-branch) to refactor our current implementation like this:
Is that ok for you? |
Thanks for the pointer. So i understood the spec correctly, and this PR is wrong since it transforms |
@ghostd Yes, that is ideal solution ⭐ I think we need more |
@ghostd Would you mind if I take on this? |
Thank you! |
Description:
Remove useless zeroes:
calc(3px + 10em -3px)
=>10em
BREAKING CHANGE:
Related issue (if exists):