Merge pull request #219 from sass/fix-conversion-error

Fix some unit math issues
This commit is contained in:
Natalie Weizenbaum 2018-01-23 14:51:31 -08:00 committed by GitHub
commit 2f1e40eb35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -13,6 +13,12 @@
* Fix some cases where equivalent numbers wouldn't count as the same keys in
maps.
* Fix a bug where multiplication like `(1/1px) * (1px/1)` wouldn't properly
cancel out units.
* Fix a bug where dividing by a compatible unit would produce an invalid
result.
### Dart API
* Add a `functions` parameter to `compile()`, `compleString()`,

View File

@ -407,11 +407,11 @@ class SassNumber extends Value implements ext.SassNumber {
List<String> denominators2) {
// Short-circuit without allocating any new unit lists if possible.
if (numerators1.isEmpty) {
if (denominators2.isEmpty) {
if (denominators2.isEmpty &&
!_areAnyConvertible(denominators1, numerators2)) {
return new SassNumber.withUnits(value,
numeratorUnits: numerators2, denominatorUnits: denominators1);
} else if (denominators1.isEmpty &&
!_areAnyConvertible(numerators1, denominators2)) {
} else if (denominators1.isEmpty) {
return new SassNumber.withUnits(value,
numeratorUnits: numerators2, denominatorUnits: denominators2);
}
@ -444,7 +444,7 @@ class SassNumber extends Value implements ext.SassNumber {
removeFirstWhere<String>(mutableDenominators1, (denominator) {
var factor = _conversionFactor(numerator, denominator);
if (factor == null) return false;
value *= factor;
value /= factor;
return true;
}, orElse: () {
newNumerators.add(numerator);