operateInternal static method
- @internal
- CalculationOperator operator,
- Object left,
- Object right, {
- required bool inLegacySassFunction,
- required bool simplify,
Like operate, but with the internal-only inLegacySassFunction
parameter.
If inLegacySassFunction
is true
, this allows unitless numbers to be added and
subtracted with numbers with units, for backwards-compatibility with the
old global min()
and max()
functions.
If simplify
is false
, no simplification will be done.
Implementation
@internal
static Object operateInternal(
CalculationOperator operator, Object left, Object right,
{required bool inLegacySassFunction, required bool simplify}) {
if (!simplify) return CalculationOperation._(operator, left, right);
left = _simplify(left);
right = _simplify(right);
if (operator case CalculationOperator.plus || CalculationOperator.minus) {
if (left is SassNumber &&
right is SassNumber &&
(inLegacySassFunction
? left.isComparableTo(right)
: left.hasCompatibleUnits(right))) {
return operator == CalculationOperator.plus
? left.plus(right)
: left.minus(right);
}
_verifyCompatibleNumbers([left, right]);
if (right is SassNumber && number_lib.fuzzyLessThan(right.value, 0)) {
right = right.times(SassNumber(-1));
operator = operator == CalculationOperator.plus
? CalculationOperator.minus
: CalculationOperator.plus;
}
return CalculationOperation._(operator, left, right);
} else if (left is SassNumber && right is SassNumber) {
return operator == CalculationOperator.times
? left.times(right)
: left.dividedBy(right);
} else {
return CalculationOperation._(operator, left, right);
}
}