Merge pull request #240 from sass/indented-loud-comment

Fix loud comment parsing in the indented syntax
This commit is contained in:
Natalie Weizenbaum 2018-03-01 15:58:44 -08:00 committed by GitHub
commit 0cbbb9128d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 5 deletions

View File

@ -1,3 +1,15 @@
## 1.0.0-beta.5.3
* Don't deadlock on `/*` comments in the indented syntax.
* 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 `/*`.
* Preserve empty lines in `/*` comments in the indented syntax.
## 1.0.0-beta.5.2
* Fix a bug where some colors would crash `compressed` mode.

View File

@ -23,6 +23,9 @@ class InterpolationBuffer implements StringSink {
/// Returns whether this buffer has no contents.
bool get isEmpty => _contents.isEmpty && _text.isEmpty;
/// Returns the substring of the buffer string after the last interpolation.
String get trailingString => _text.toString();
/// Empties this buffer.
void clear() {
_contents.clear();

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(" * ");
}
@ -218,13 +228,14 @@ class SassParser extends StylesheetParser {
buffer.writeCharCode($space);
}
loop:
while (!scanner.isDone) {
var next = scanner.peekChar();
switch (next) {
case $lf:
case $cr:
case $ff:
break;
break loop;
case $hash:
if (scanner.peekChar(1) == $lbrace) {
@ -241,9 +252,17 @@ class SassParser extends StylesheetParser {
}
if (_peekIndentation() <= parentIndentation) break;
// Preserve empty lines.
while (isNewline(scanner.peekChar(1))) {
scanner.readChar();
buffer.writeln();
buffer.write(" *");
}
_readIndentation();
}
buffer.write(" */");
if (!buffer.trailingString.trimRight().endsWith("*/")) buffer.write(" */");
return new LoudComment(buffer.interpolation(scanner.spanFrom(start)));
}

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);

View File

@ -1,5 +1,5 @@
name: sass
version: 1.0.0-beta.5.2
version: 1.0.0-dev
description: A Sass implementation in Dart.
author: Dart Team <misc@dartlang.org>
homepage: https://github.com/sass/dart-sass