mirror of
https://github.com/danog/dart-sass.git
synced 2024-11-30 04:39:03 +01:00
Support url() in static declaration values.
This commit is contained in:
parent
970c63ba41
commit
c42afb4f16
@ -199,11 +199,25 @@ abstract class Parser {
|
||||
case $semicolon:
|
||||
break loop;
|
||||
|
||||
case $u:
|
||||
case $U:
|
||||
var url = tryUrl();
|
||||
if (url != null) {
|
||||
buffer.write(url);
|
||||
} else {
|
||||
buffer.writeCharCode(scanner.readChar());
|
||||
}
|
||||
wroteNewline = false;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (next == null) break loop;
|
||||
|
||||
// TODO: support url()
|
||||
buffer.writeCharCode(scanner.readChar());
|
||||
if (lookingAtIdentifier()) {
|
||||
buffer.write(identifier());
|
||||
} else {
|
||||
buffer.writeCharCode(scanner.readChar());
|
||||
}
|
||||
wroteNewline = false;
|
||||
break;
|
||||
}
|
||||
@ -213,6 +227,50 @@ abstract class Parser {
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
String tryUrl() {
|
||||
// NOTE: this logic is largely duplicated in ScssParser._tryUrlContents.
|
||||
// Most changes here should be mirrored there.
|
||||
|
||||
var start = scanner.state;
|
||||
if (!scanIdentifier("url", ignoreCase: true)) return null;
|
||||
|
||||
if (!scanner.scanChar($lparen)) {
|
||||
scanner.state = start;
|
||||
return null;
|
||||
}
|
||||
|
||||
whitespace();
|
||||
|
||||
// Match Ruby Sass's behavior: parse a raw URL() if possible, and if not
|
||||
// backtrack and re-parse as a function expression.
|
||||
var buffer = new StringBuffer()..write("url(");
|
||||
while (true) {
|
||||
var next = scanner.peekChar();
|
||||
if (next == null) {
|
||||
break;
|
||||
} else if (next == $percent ||
|
||||
next == $ampersand ||
|
||||
next == $hash ||
|
||||
(next >= $asterisk && next <= $tilde) ||
|
||||
next >= 0x0080) {
|
||||
buffer.writeCharCode(scanner.readChar());
|
||||
} else if (next == $backslash) {
|
||||
buffer.writeCharCode(escape());
|
||||
} else if (isWhitespace(next)) {
|
||||
whitespace();
|
||||
if (scanner.peekChar() != $rparen) break;
|
||||
} else if (next == $rparen) {
|
||||
buffer.writeCharCode(scanner.readChar());
|
||||
return buffer.toString();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
scanner.state = start;
|
||||
return null;
|
||||
}
|
||||
|
||||
String variableName() {
|
||||
scanner.expectChar($dollar);
|
||||
return identifier();
|
||||
|
@ -1457,6 +1457,9 @@ abstract class StylesheetParser extends Parser {
|
||||
}
|
||||
|
||||
Interpolation _tryUrlContents(LineScannerState start) {
|
||||
// NOTE: this logic is largely duplicated in ScssParser.tryUrl. Most changes
|
||||
// here should be mirrored there.
|
||||
|
||||
var start = scanner.state;
|
||||
if (!scanner.scanChar($lparen)) return null;
|
||||
whitespace();
|
||||
|
Loading…
Reference in New Issue
Block a user