@@ -69,6 +69,10 @@ class _DivisionMigrationVisitor extends MigrationVisitor {
69
69
/// True when the current node is expected to evaluate to a number.
70
70
var _expectsNumericResult = false ;
71
71
72
+ /// True when the current node is in calc context, so division should be
73
+ /// left unchanged.
74
+ var _inCalcContext = false ;
75
+
72
76
/// The namespaces that already exist in the current stylesheet.
73
77
Map <Uri , String ?> get _existingNamespaces =>
74
78
assertInStylesheet (__existingNamespaces, '_existingNamespaces' );
@@ -140,7 +144,7 @@ class _DivisionMigrationVisitor extends MigrationVisitor {
140
144
@override
141
145
void visitArgumentInvocation (ArgumentInvocation invocation) {
142
146
_withContext (() => super .visitArgumentInvocation (invocation),
143
- isDivisionAllowed: true );
147
+ isDivisionAllowed: true , inCalcContext : false );
144
148
}
145
149
146
150
/// If this is a division operation, migrates it.
@@ -159,6 +163,14 @@ class _DivisionMigrationVisitor extends MigrationVisitor {
159
163
}
160
164
}
161
165
166
+ /// Visits calculations with [_inCalcContext] set to true.
167
+ @override
168
+ void visitCalculationExpression (CalculationExpression node) {
169
+ _withContext (() {
170
+ super .visitCalculationExpression (node);
171
+ }, inCalcContext: true );
172
+ }
173
+
162
174
/// Allows division within a function call's arguments, with special handling
163
175
/// for new-syntax color functions.
164
176
@override
@@ -167,6 +179,15 @@ class _DivisionMigrationVisitor extends MigrationVisitor {
167
179
visitArgumentInvocation (node.arguments);
168
180
}
169
181
182
+ /// Visits interpolation with [_isDivisionAllowed] and [_inCalcContext] set
183
+ /// to false.
184
+ @override
185
+ void visitInterpolation (Interpolation node) {
186
+ _withContext (() {
187
+ super .visitInterpolation (node);
188
+ }, isDivisionAllowed: false , inCalcContext: false );
189
+ }
190
+
170
191
/// Disallows division within this list.
171
192
@override
172
193
void visitListExpression (ListExpression node) {
@@ -271,6 +292,12 @@ class _DivisionMigrationVisitor extends MigrationVisitor {
271
292
/// Returns true the `/` was migrated to either function call (indicating that
272
293
/// parentheses surrounding this operation should be removed).
273
294
bool _visitSlashOperation (BinaryOperationExpression node) {
295
+ if (_inCalcContext) {
296
+ node.left.accept (this );
297
+ node.right.accept (this );
298
+ return false ;
299
+ }
300
+
274
301
if ((! _isDivisionAllowed && _onlySlash (node)) ||
275
302
_isDefinitelyNotNumber (node)) {
276
303
// Definitely not division
@@ -446,15 +473,18 @@ class _DivisionMigrationVisitor extends MigrationVisitor {
446
473
447
474
/// Runs [operation] with the given context.
448
475
void _withContext (void operation (),
449
- {bool ? isDivisionAllowed, bool ? expectsNumericResult}) {
476
+ {bool ? isDivisionAllowed,
477
+ bool ? expectsNumericResult,
478
+ bool ? inCalcContext}) {
450
479
var previousDivisionAllowed = _isDivisionAllowed;
451
480
var previousNumericResult = _expectsNumericResult;
452
- if (isDivisionAllowed != null ) _isDivisionAllowed = isDivisionAllowed ;
453
- if (expectsNumericResult != null ) {
454
- _expectsNumericResult = expectsNumericResult;
455
- }
481
+ var previousCalcContext = _inCalcContext ;
482
+ _isDivisionAllowed = isDivisionAllowed ?? _isDivisionAllowed;
483
+ _expectsNumericResult = expectsNumericResult ?? _expectsNumericResult ;
484
+ _inCalcContext = inCalcContext ?? _inCalcContext;
456
485
operation ();
457
486
_isDivisionAllowed = previousDivisionAllowed;
458
487
_expectsNumericResult = previousNumericResult;
488
+ _inCalcContext = previousCalcContext;
459
489
}
460
490
}
0 commit comments