@@ -6,6 +6,7 @@ import 'dart:math' as math;
6
6
import 'dart:typed_data' ;
7
7
8
8
import 'package:charcode/charcode.dart' ;
9
+ import 'package:collection/collection.dart' ;
9
10
import 'package:source_maps/source_maps.dart' ;
10
11
import 'package:string_scanner/string_scanner.dart' ;
11
12
@@ -492,7 +493,35 @@ class _SerializeVisitor
492
493
}
493
494
494
495
void _writeCalculationValue (Object value) {
495
- if (value is Value ) {
496
+ if (value is SassNumber && ! value.value.isFinite) {
497
+ if (value.numeratorUnits.length > 1 ||
498
+ value.denominatorUnits.isNotEmpty) {
499
+ if (! _inspect) {
500
+ throw SassScriptException ("$value isn't a valid CSS value." );
501
+ }
502
+
503
+ _writeNumber (value.value);
504
+ _buffer.write (value.unitString);
505
+ return ;
506
+ }
507
+
508
+ if (value.value == double .infinity) {
509
+ _buffer.write ('infinity' );
510
+ } else if (value.value == double .negativeInfinity) {
511
+ _buffer.write ('-infinity' );
512
+ } else if (value.value.isNaN) {
513
+ _buffer.write ('NaN' );
514
+ }
515
+
516
+ var unit = value.numeratorUnits.firstOrNull;
517
+ if (unit != null ) {
518
+ _writeOptionalSpace ();
519
+ _buffer.writeCharCode ($asterisk);
520
+ _writeOptionalSpace ();
521
+ _buffer.writeCharCode ($1);
522
+ _buffer.write (unit);
523
+ }
524
+ } else if (value is Value ) {
496
525
value.accept (this );
497
526
} else if (value is CalculationInterpolation ) {
498
527
_buffer.write (value.value);
@@ -513,7 +542,11 @@ class _SerializeVisitor
513
542
var right = value.right;
514
543
var parenthesizeRight = right is CalculationInterpolation ||
515
544
(right is CalculationOperation &&
516
- _parenthesizeCalculationRhs (value.operator , right.operator ));
545
+ _parenthesizeCalculationRhs (value.operator , right.operator )) ||
546
+ (value.operator == CalculationOperator .dividedBy &&
547
+ right is SassNumber &&
548
+ ! right.value.isFinite &&
549
+ right.hasUnits);
517
550
if (parenthesizeRight) _buffer.writeCharCode ($lparen);
518
551
_writeCalculationValue (right);
519
552
if (parenthesizeRight) _buffer.writeCharCode ($rparen);
@@ -760,6 +793,11 @@ class _SerializeVisitor
760
793
return ;
761
794
}
762
795
796
+ if (! value.value.isFinite) {
797
+ visitCalculation (SassCalculation .unsimplified ('calc' , [value]));
798
+ return ;
799
+ }
800
+
763
801
_writeNumber (value.value);
764
802
765
803
if (! _inspect) {
0 commit comments