mirror of
https://github.com/danog/dart-sass.git
synced 2024-11-30 04:39:03 +01:00
Merge pull request #240 from sass/indented-loud-comment
Fix loud comment parsing in the indented syntax
This commit is contained in:
commit
0cbbb9128d
12
CHANGELOG.md
12
CHANGELOG.md
@ -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.
|
||||
|
@ -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();
|
||||
|
@ -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.
|
||||
|
@ -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)));
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user