Skip to content

Commit d2b2ded

Browse files
Fix operators regex to remove unnecessary parenthesis in SCSS variables. (#254)
1 parent 6d08f6d commit d2b2ded

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 2.0.2
2+
3+
### Calc Functions Interpolation Migrator
4+
5+
* Fix the interpretation of a dash in a variable name as a minus sign.
6+
17
## 2.0.1
28

39
### Calc Functions Interpolation Migrator

lib/src/migrators/calc_interpolation.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class _CalculationInterpolationVisitor extends MigrationVisitor {
3636
void visitFunctionExpression(FunctionExpression node) {
3737
const calcFunctions = ['calc', 'clamp', 'min', 'max'];
3838
final interpolation = RegExp(r'\#{\s*[^}]+\s*}');
39-
final hasOperation = RegExp(r'[-+*/]+');
39+
final hasOperation = RegExp(r'\s+[-+*/]+\s+');
4040
final isVarFunc = RegExp(
4141
r'var\(#{[a-zA-Z0-9#{$}-]+}\)|var\(\-\-[a-zA-Z0-9\$\#\{\}\-]+\)');
4242
if (calcFunctions.contains(node.name)) {

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: sass_migrator
2-
version: 2.0.1
2+
version: 2.0.2
33
description: A tool for running migrations on Sass files
44
homepage: https://github.com/sass/migrator
55

test/migrators/calc_interpolation/calc_remove_interpolation.hrx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<==> input/entrypoint.scss
2+
$a-b: 5;
23
$b: 10;
34
$c: 1;
45
$d: 5;
@@ -9,14 +10,14 @@ $d: 5;
910
// More than one interpolations
1011
.a {
1112
.b: calc($b - #{$c + 1} + #{$d});
12-
.c: calc(100% - #{$table_title_height + 2px});
13+
.c: calc(100% - #{$TABLE_TITLE + 2px});
1314
}
1415

1516
// Nested
1617
.a { .b: calc(3 + max(#{$c, 2})); }
1718

1819
// Nested and more interpolations
19-
.a { .b: calc(#{$b} + max(#{$c, 2})); }
20+
.a { .b: calc(#{$a-b} + max(#{$c, 2})); }
2021

2122
// CSS Custom properties keep interpolation
2223
.a { --test: calc(#{$b} + 1);}
@@ -25,6 +26,7 @@ $d: 5;
2526
.a { .b: calc(var(#{$b}) + #{$c + 2} + var(--a-#{$d}-b)); }
2627

2728
<==> output/entrypoint.scss
29+
$a-b: 5;
2830
$b: 10;
2931
$c: 1;
3032
$d: 5;
@@ -35,14 +37,14 @@ $d: 5;
3537
// More than one interpolations
3638
.a {
3739
.b: calc($b - ($c + 1) + $d);
38-
.c: calc(100% - ($table-title-height + 2px));
40+
.c: calc(100% - ($TABLE-TITLE + 2px));
3941
}
4042

4143
// Nested
4244
.a { .b: calc(3 + max($c, 2)); }
4345

4446
// Nested and more interpolations
45-
.a { .b: calc($b + max($c, 2)); }
47+
.a { .b: calc($a-b + max($c, 2)); }
4648

4749
// CSS Custom properties keep interpolation
4850
.a { --test: calc(#{$b} + 1);}

0 commit comments

Comments
 (0)