mirror of
https://github.com/danog/dart-sass.git
synced 2024-12-03 10:08:01 +01:00
Fix a unit conversion bug.
This commit is contained in:
parent
8969fc75f2
commit
98f1c7dca3
@ -497,18 +497,20 @@ class SassNumber extends Value {
|
|||||||
List<String> denominators2) {
|
List<String> denominators2) {
|
||||||
// Short-circuit without allocating any new unit lists if possible.
|
// Short-circuit without allocating any new unit lists if possible.
|
||||||
if (numerators1.isEmpty) {
|
if (numerators1.isEmpty) {
|
||||||
if (denominators1.isEmpty) {
|
if (denominators2.isEmpty) {
|
||||||
return new SassNumber.withUnits(value,
|
|
||||||
numeratorUnits: numerators2, denominatorUnits: denominators2);
|
|
||||||
} else if (denominators2.isEmpty) {
|
|
||||||
return new SassNumber.withUnits(value,
|
return new SassNumber.withUnits(value,
|
||||||
numeratorUnits: numerators2, denominatorUnits: denominators1);
|
numeratorUnits: numerators2, denominatorUnits: denominators1);
|
||||||
|
} else if (denominators1.isEmpty &&
|
||||||
|
!_areAnyConvertible(numerators1, denominators2)) {
|
||||||
|
return new SassNumber.withUnits(value,
|
||||||
|
numeratorUnits: numerators2, denominatorUnits: denominators2);
|
||||||
}
|
}
|
||||||
} else if (numerators2.isEmpty) {
|
} else if (numerators2.isEmpty) {
|
||||||
if (denominators1.isEmpty) {
|
if (denominators2.isEmpty) {
|
||||||
return new SassNumber.withUnits(value,
|
return new SassNumber.withUnits(value,
|
||||||
numeratorUnits: numerators1, denominatorUnits: denominators2);
|
numeratorUnits: numerators1, denominatorUnits: denominators2);
|
||||||
} else if (denominators2.isEmpty) {
|
} else if (denominators1.isEmpty &&
|
||||||
|
!_areAnyConvertible(numerators1, denominators2)) {
|
||||||
return new SassNumber.withUnits(value,
|
return new SassNumber.withUnits(value,
|
||||||
numeratorUnits: numerators1, denominatorUnits: denominators2);
|
numeratorUnits: numerators1, denominatorUnits: denominators2);
|
||||||
}
|
}
|
||||||
@ -526,6 +528,7 @@ class SassNumber extends Value {
|
|||||||
var factor = _conversionFactor(numerator, denominator);
|
var factor = _conversionFactor(numerator, denominator);
|
||||||
if (factor == null) return false;
|
if (factor == null) return false;
|
||||||
value *= factor;
|
value *= factor;
|
||||||
|
return true;
|
||||||
}, orElse: () {
|
}, orElse: () {
|
||||||
newNumerators.add(numerator);
|
newNumerators.add(numerator);
|
||||||
});
|
});
|
||||||
@ -552,6 +555,16 @@ class SassNumber extends Value {
|
|||||||
denominatorUnits: mutableDenominators1..addAll(mutableDenominators2));
|
denominatorUnits: mutableDenominators1..addAll(mutableDenominators2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns whether there exists a unit in [units1] that can be converted to a
|
||||||
|
/// unit in [units2].
|
||||||
|
bool _areAnyConvertible(List<String> units1, List<String> units2) {
|
||||||
|
return units1.any((unit1) {
|
||||||
|
if (!_isConvertable(unit1)) return false;
|
||||||
|
var innerMap = _conversions[unit1];
|
||||||
|
return units2.any(innerMap.containsKey);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns whether [unit] can be converted to or from any other units.
|
/// Returns whether [unit] can be converted to or from any other units.
|
||||||
bool _isConvertable(String unit) => _conversions.containsKey(unit);
|
bool _isConvertable(String unit) => _conversions.containsKey(unit);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user