Skip to content

Commit

Permalink
Fix isTrailingComment to handle mixins that include loud comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbehrens committed Nov 9, 2019
1 parent fd276e7 commit 6357642
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/src/visitor/serialize.dart
Expand Up @@ -1143,6 +1143,16 @@ class _SerializeVisitor
// a simple forward search of the previousSpan.text as that might contain
// other left braces.
var searchFrom = node.span.start.offset - previousSpan.start.offset - 1;
if (searchFrom < 0) {
// This can happen when the loud comment is the first statement in a
// mixin that's later included. In that case, node.span.start.offset
// (representing the loud comment in the mixin) will be less than
// previousSpan.start.offset (representing the statement where the
// mixin is later included) ==> the loud comment cannot possibly be
// trailing.
return false;
}

var endOffset = previousSpan.text.lastIndexOf("{", searchFrom);
endOffset = math.max(0, endOffset);
previousSpan = previousSpan.file.span(
Expand Down
11 changes: 11 additions & 0 deletions test/output_test.dart
Expand Up @@ -162,5 +162,16 @@ selector[href*=\"{\"] { /* please don't move me */ }
@rule3;"""));
});

test("loud comments in mixin", () {
expect(compileString("""
@mixin loudComment {
/* ... */
}
selector {
@include loudComment;
}"""), "selector {\n /* ... */\n}");
});
});
}

0 comments on commit 6357642

Please sign in to comment.