Fix /* formatting to match Ruby Sass

This commit is contained in:
Natalie Weizenbaum 2018-02-23 17:02:22 -08:00
parent 7454a1b57f
commit b404e32c46
4 changed files with 26 additions and 2 deletions

View File

@ -5,6 +5,9 @@
* Don't add an extra `*/` to comments in the indented syntax that already have
it.
* Improve the formatting of comments that don't start on the same line as the
opening `/*`.
## 1.0.0-beta.5.2
* Fix a bug where some colors would crash `compressed` mode.

View File

@ -48,6 +48,14 @@ abstract class Parser {
}
}
/// Consumes spaces and tabs.
@protected
void spaces() {
while (!scanner.isDone && isSpaceOrTab(scanner.peekChar())) {
scanner.readChar();
}
}
/// Consumes and ignores a comment if possible.
///
/// Returns whether the comment was consumed.

View File

@ -208,7 +208,17 @@ class SassParser extends StylesheetParser {
var buffer = new InterpolationBuffer()..write("/*");
var parentIndentation = currentIndentation;
while (true) {
if (!first) {
if (first) {
// If the first line is empty, ignore it.
var beginningOfComment = scanner.position;
spaces();
if (isNewline(scanner.peekChar())) {
_readIndentation();
buffer.writeCharCode($space);
} else {
buffer.write(scanner.substring(beginningOfComment));
}
} else {
buffer.writeln();
buffer.write(" * ");
}

View File

@ -12,12 +12,15 @@ const _asciiCaseBit = 0x20;
/// Returns whether [character] is an ASCII whitespace character.
bool isWhitespace(int character) =>
character == $space || character == $tab || isNewline(character);
isSpaceOrTab(character) || isNewline(character);
/// Returns whether [character] is an ASCII newline.
bool isNewline(int character) =>
character == $lf || character == $cr || character == $ff;
/// Returns whether [character] is a space or a tab character.
bool isSpaceOrTab(int character) => character == $space || character == $tab;
/// Returns whether [character] is a letter or number.
bool isAlphanumeric(int character) =>
isAlphabetic(character) || isDigit(character);