From 37033b26e01706f6923068ccd047a2fba9b578e3 Mon Sep 17 00:00:00 2001 From: Pamela Lozano Date: Tue, 16 Jan 2024 15:30:23 -0800 Subject: [PATCH] Fix operators regex to remove unnecessary parenthesis in SCSS variables. --- CHANGELOG.md | 6 ++++++ lib/src/migrators/calc_interpolation.dart | 2 +- pubspec.yaml | 2 +- .../calc_interpolation/calc_remove_interpolation.hrx | 8 ++++---- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bae9b32..3186d3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.0.2 + +### Calc Functions Interpolation Migrator + +* Fix operators regex to remove unnecessary parenthesis in SCSS variables. + ## 2.0.1 ### Calc Functions Interpolation Migrator diff --git a/lib/src/migrators/calc_interpolation.dart b/lib/src/migrators/calc_interpolation.dart index 8cdc57b..d72891b 100644 --- a/lib/src/migrators/calc_interpolation.dart +++ b/lib/src/migrators/calc_interpolation.dart @@ -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)) { diff --git a/pubspec.yaml b/pubspec.yaml index e0e1fed..b93b73c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 diff --git a/test/migrators/calc_interpolation/calc_remove_interpolation.hrx b/test/migrators/calc_interpolation/calc_remove_interpolation.hrx index 50a3f34..47f62a3 100644 --- a/test/migrators/calc_interpolation/calc_remove_interpolation.hrx +++ b/test/migrators/calc_interpolation/calc_remove_interpolation.hrx @@ -9,14 +9,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);} @@ -35,14 +35,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);}