Supports mixing /* */ and <!-- --> comments (#53)
The tokenizer had no context of which kind of comment it was processing and
would terminate upon seeing any comment ending.
Fixes failing test added in #51.
diff --git a/lib/src/tokenizer.dart b/lib/src/tokenizer.dart
index d7677f9..0b0661a 100644
--- a/lib/src/tokenizer.dart
+++ b/lib/src/tokenizer.dart
@@ -149,7 +149,7 @@
if (_maybeEatChar(TokenChar.BANG)) {
if (_maybeEatChar(TokenChar.MINUS) &&
_maybeEatChar(TokenChar.MINUS)) {
- return finishMultiLineComment();
+ return finishHtmlComment();
} else if (_maybeEatChar(TokenChar.LBRACK) &&
_maybeEatChar(CDATA_NAME[0]) &&
_maybeEatChar(CDATA_NAME[1]) &&
@@ -393,6 +393,26 @@
return _finishToken(TokenKind.HEX_RANGE);
}
+ Token finishHtmlComment() {
+ while (true) {
+ int ch = _nextChar();
+ if (ch == 0) {
+ return _finishToken(TokenKind.INCOMPLETE_COMMENT);
+ } else if (ch == TokenChar.MINUS) {
+ /* Check if close part of Comment Definition --> (CDC). */
+ if (_maybeEatChar(TokenChar.MINUS)) {
+ if (_maybeEatChar(TokenChar.GREATER)) {
+ if (_inString) {
+ return next();
+ } else {
+ return _finishToken(TokenKind.HTML_COMMENT);
+ }
+ }
+ }
+ }
+ }
+ }
+
Token finishMultiLineComment() {
while (true) {
int ch = _nextChar();
@@ -406,17 +426,6 @@
return _finishToken(TokenKind.COMMENT);
}
}
- } else if (ch == TokenChar.MINUS) {
- /* Check if close part of Comment Definition --> (CDC). */
- if (_maybeEatChar(TokenChar.MINUS)) {
- if (_maybeEatChar(TokenChar.GREATER)) {
- if (_inString) {
- return next();
- } else {
- return _finishToken(TokenKind.HTML_COMMENT);
- }
- }
- }
}
}
}
diff --git a/test/declaration_test.dart b/test/declaration_test.dart
index af6fdef..782c33c 100644
--- a/test/declaration_test.dart
+++ b/test/declaration_test.dart
@@ -1260,6 +1260,16 @@
expect((decl as Declaration).expression.span.text, '50px');
}
+void testComments() {
+ final css = '''/* This comment has a nested HTML comment...
+* <html>
+* <!-- Nested HTML comment... -->
+* <div></div>
+* </html>
+*/''';
+ expectCss(css, '');
+}
+
void simpleCalc() {
final input = r'''.foo { height: calc(100% - 55px); }''';
var stylesheet = parseCss(input);
@@ -1351,6 +1361,7 @@
test('Expression spans', testExpressionSpans,
skip: 'expression spans are broken'
' (https://github.com/dart-lang/csslib/issues/15)');
+ test('Comments', testComments);
group('calc function', () {
test('simple calc', simpleCalc);
test('single complex', complexCalc);