mirror of
https://github.com/danog/dart-sass.git
synced 2024-12-02 09:37:49 +01:00
Support explicit @charset.
This commit is contained in:
parent
dd4a9165a2
commit
c8f0126f0b
@ -86,10 +86,12 @@ class StringExpression implements Expression {
|
||||
int _bestQuote() {
|
||||
var containsDoubleQuote = false;
|
||||
for (var value in text.contents) {
|
||||
for (var i = 0; i < value.length; i++) {
|
||||
var codeUnit = value.codeUnitAt(i);
|
||||
if (codeUnit == $single_quote) return $double_quote;
|
||||
if (codeUnit == $double_quote) containsDoubleQuote = true;
|
||||
if (value is String) {
|
||||
for (var i = 0; i < value.length; i++) {
|
||||
var codeUnit = value.codeUnitAt(i);
|
||||
if (codeUnit == $single_quote) return $double_quote;
|
||||
if (codeUnit == $double_quote) containsDoubleQuote = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return containsDoubleQuote ? $single_quote : $double_quote;
|
||||
|
@ -79,7 +79,8 @@ class SassParser extends StylesheetParser {
|
||||
|
||||
var statements = <Statement>[];
|
||||
while (!scanner.isDone) {
|
||||
statements.add(_child(statement));
|
||||
var child = _child(statement);
|
||||
if (child != null) statements.add(child);
|
||||
var indentation = _readIndentation();
|
||||
assert(indentation == 0);
|
||||
}
|
||||
|
@ -92,7 +92,8 @@ class ScssParser extends StylesheetParser {
|
||||
statements.add(_loudComment());
|
||||
break;
|
||||
default:
|
||||
statements.add(statement());
|
||||
var child = statement();
|
||||
if (child != null) statements.add(child);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -103,7 +104,8 @@ class ScssParser extends StylesheetParser {
|
||||
break;
|
||||
|
||||
default:
|
||||
statements.add(statement());
|
||||
var child = statement();
|
||||
if (child != null) statements.add(child);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,8 @@ abstract class StylesheetParser extends Parser {
|
||||
|
||||
/// Consumes a statement that's allowed at the top level of the stylesheet.
|
||||
Statement _topLevelStatement() {
|
||||
if (scanner.peekChar() == $at) return _atRule(_topLevelStatement);
|
||||
if (scanner.peekChar() == $at)
|
||||
return _atRule(_topLevelStatement, root: true);
|
||||
return _styleRule();
|
||||
}
|
||||
|
||||
@ -301,13 +302,20 @@ abstract class StylesheetParser extends Parser {
|
||||
/// This consumes at-rules that are allowed at all levels of the document; the
|
||||
/// [child] parameter is called to consume any at-rules that are specifically
|
||||
/// allowed in the caller's context.
|
||||
Statement _atRule(Statement child()) {
|
||||
///
|
||||
/// If [root] is `true`, this parses at-rules that are allowed only at the
|
||||
/// root of the stylesheet.
|
||||
Statement _atRule(Statement child(), {bool root: false}) {
|
||||
var start = scanner.state;
|
||||
var name = _atRuleName();
|
||||
|
||||
switch (name) {
|
||||
case "at-root":
|
||||
return _atRootRule(start);
|
||||
case "charset":
|
||||
if (!root) _disallowedAtRule(start);
|
||||
string();
|
||||
return null;
|
||||
case "content":
|
||||
return _contentRule(start);
|
||||
case "debug":
|
||||
@ -2193,5 +2201,8 @@ abstract class StylesheetParser extends Parser {
|
||||
List<Statement> children(Statement child());
|
||||
|
||||
/// Consumes top-level statements.
|
||||
///
|
||||
/// The [statement] callback may return `null`, indicating that a statement
|
||||
/// was consumed that shouldn't be added to the AST.
|
||||
List<Statement> statements(Statement statement());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user