Support url() in static declaration values.

This commit is contained in:
Natalie Weizenbaum 2016-10-03 00:07:09 -07:00 committed by Natalie Weizenbaum
parent 970c63ba41
commit c42afb4f16
2 changed files with 63 additions and 2 deletions

View File

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

View File

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