Skip to content

Commit

Permalink
Only ignore comments when finding insertion point (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
jathak authored Jun 7, 2021
1 parent 92fe5ec commit acc3539
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 1.4.4

### Division Migrator

* Fix a bug where `@use "sass:math"` would sometimes be incorrectly inserted
after other rules.

## 1.4.3

### Division Migrator
Expand Down
7 changes: 3 additions & 4 deletions lib/src/migrators/division.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ class _DivisionMigrationVisitor extends MigrationVisitor {
var useRules = _useRulesToInsert.join('\n');
var insertionPoint = node.span.start;
for (var child in node.children) {
if (child is UseRule || child is ForwardRule || child is ImportRule) {
insertionPoint = child.span.start;
break;
}
if (child is LoudComment || child is SilentComment) continue;
insertionPoint = child.span.start;
break;
}
addPatch(Patch.insert(insertionPoint, '$useRules\n\n'));
}
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: 1.4.3
version: 1.4.4
description: A tool for running migrations on Sass files
author: Jennifer Thakar <[email protected]>
homepage: https://github.com/sass/migrator
Expand Down
22 changes: 22 additions & 0 deletions test/migrators/division/insert_before_style_rules.hrx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<==> input/entrypoint.scss
// Comment

a {
b: 3 / $x;
c: (six / three);
}

@import "other";

<==> output/entrypoint.scss
// Comment

@use "sass:math";
@use "sass:list";

a {
b: math.div(3, $x);
c: list.slash(six, three);
}

@import "other";

0 comments on commit acc3539

Please sign in to comment.