-
-
Notifications
You must be signed in to change notification settings - Fork 78.9k
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
Handle complex expressions in add()
& subtract()
#34047
Conversation
Thanks @XhmikosR :) |
add()
& subtract()
Hi
In other words the |
@ffoodd can you have a look at the above comment please? |
Back to this, I'm opened for suggestion @oliwerAR but I don't think there's a way to both solve the initial issue and prevent unnecessary brackets. This is not overdone since it's the most basic check we can do: number or not, and if not wrap into brackets. Tell me if I'm wrong but all of your examples are working fine, aren't they? |
@ffoodd Yes, the examples are working but most of the brackets are useless. @function add($value1, $value2, $return-calc: true) {
@if $value1 == null {
@return $value2;
}
@if $value2 == null {
@return $value1;
}
@if type-of($value1) == number and type-of($value2) == number and comparable($value1, $value2) {
@return $value1 + $value2;
}
@return if($return-calc == true, calc(#{$value1} + #{$value2}), $value1 + unquote(" + ") + $value2);
}
@function subtract($value1, $value2, $return-calc: true) {
@if $value1 == null and $value2 == null {
@return null;
}
@if $value1 == null {
@return -$value2;
}
@if $value2 == null {
@return $value1;
}
@if type-of($value1) == number and type-of($value2) == number and comparable($value1, $value2) {
@return $value1 - $value2;
}
@if type-of($value2) != number {
$value2: unquote("(") + $value2 + unquote(")");
}
@return if($return-calc == true, calc(#{$value1} - #{$value2}), $value1 + unquote(" - ") + $value2);
} |
So basically only keeping |
@ffoodd Exactly. It's the only thing that is negated, changes the sign - that was the problem in the initial issue. |
Fixes #33953
I don't expect any regression, but who knows :D Need to consider about backporting this to v4, if this gets merged.
SassMeister demoing this: https://www.sassmeister.com/gist/daceb834e14e092919b5c6ebaedf317b