Skip to content

Commit

Permalink
Fix operators regex to remove unnecessary parenthesis in SCSS variabl…
Browse files Browse the repository at this point in the history
…es. (#254)
  • Loading branch information
pamelalozano16 authored Jan 16, 2024
1 parent 6d08f6d commit d2b2ded
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2.0.2

### Calc Functions Interpolation Migrator

* Fix the interpretation of a dash in a variable name as a minus sign.

## 2.0.1

### Calc Functions Interpolation Migrator
Expand Down
2 changes: 1 addition & 1 deletion lib/src/migrators/calc_interpolation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class _CalculationInterpolationVisitor extends MigrationVisitor {
void visitFunctionExpression(FunctionExpression node) {
const calcFunctions = ['calc', 'clamp', 'min', 'max'];
final interpolation = RegExp(r'\#{\s*[^}]+\s*}');
final hasOperation = RegExp(r'[-+*/]+');
final hasOperation = RegExp(r'\s+[-+*/]+\s+');
final isVarFunc = RegExp(
r'var\(#{[a-zA-Z0-9#{$}-]+}\)|var\(\-\-[a-zA-Z0-9\$\#\{\}\-]+\)');
if (calcFunctions.contains(node.name)) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: sass_migrator
version: 2.0.1
version: 2.0.2
description: A tool for running migrations on Sass files
homepage: https://github.com/sass/migrator

Expand Down
10 changes: 6 additions & 4 deletions test/migrators/calc_interpolation/calc_remove_interpolation.hrx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<==> input/entrypoint.scss
$a-b: 5;
$b: 10;
$c: 1;
$d: 5;
Expand All @@ -9,14 +10,14 @@ $d: 5;
// More than one interpolations
.a {
.b: calc($b - #{$c + 1} + #{$d});
.c: calc(100% - #{$table_title_height + 2px});
.c: calc(100% - #{$TABLE_TITLE + 2px});
}

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

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

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

<==> output/entrypoint.scss
$a-b: 5;
$b: 10;
$c: 1;
$d: 5;
Expand All @@ -35,14 +37,14 @@ $d: 5;
// More than one interpolations
.a {
.b: calc($b - ($c + 1) + $d);
.c: calc(100% - ($table-title-height + 2px));
.c: calc(100% - ($TABLE-TITLE + 2px));
}

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

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

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

0 comments on commit d2b2ded

Please sign in to comment.