fix(css-parser): handle multiline comments
MODIFY
internal/css-parser/index.ts
internal/css-parser/index.ts
@@ -37,9 +37,9 @@ export const cssParser = createParser<CSSParserTypes>({
index = index.add(2);
let value = "";
while (
- parser.getInputCharOnly(index) !== "*" &&
- parser.getInputCharOnly(index.increment()) !== "/" &&
- !parser.isEOF(index)
+ !((parser.getInputCharOnly(index) === "*" &&
+ parser.getInputCharOnly(index.increment()) === "/") ||
+ parser.isEOF(index))
) {
value += parser.getInputCharOnly(index);
index = index.add(1);

MODIFY
internal/css-parser/test-fixtures/comment/input.css
internal/css-parser/test-fixtures/comment/input.css
+/*
+ * comments
+ */
+
a {
color: white; /* comment */
}

MODIFY
internal/css-parser/test-fixtures/comment/input.test.md
internal/css-parser/test-fixtures/comment/input.test.md
@@ -9,35 +9,43 @@ CSSRoot {
corrupt: false
diagnostics: Array []
integrity: undefined
- loc: SourceLocation comment/input.css 1:0-11:1
+ loc: SourceLocation comment/input.css 1:0-15:1
path: RelativePath<comment/input.css>
comments: Array [
CommentBlock {
id: "0"
- value: " comment "
- loc: SourceLocation comment/input.css 2:15-2:28
+ value: "\n * comments\n "
+ loc: SourceLocation comment/input.css 1:0-3:3
}
CommentBlock {
id: "1"
value: " comment "
- loc: SourceLocation comment/input.css 6:8-6:21
+ loc: SourceLocation comment/input.css 6:15-6:28
}
CommentBlock {
id: "2"
value: " comment "
- loc: SourceLocation comment/input.css 9:2-9:15
+ loc: SourceLocation comment/input.css 10:8-10:21
+ }
+ CommentBlock {
+ id: "3"
+ value: " comment "
+ loc: SourceLocation comment/input.css 13:2-13:15
}
]
body: Array [
CSSRule {
- loc: SourceLocation comment/input.css 1:0-3:1
+ leadingComments: Array ["0"]
+ loc: SourceLocation comment/input.css 5:0-7:1
prelude: Array [
CSSSelector {
- loc: SourceLocation comment/input.css 1:0-1:2
+ leadingComments: undefined
+ loc: SourceLocation comment/input.css 5:0-5:2
patterns: Array [
CSSTypeSelector {
value: "a"
- loc: SourceLocation comment/input.css 1:0-1:1
+ leadingComments: undefined
+ loc: SourceLocation comment/input.css 5:0-5:1
}
]
}
@@ -49,26 +57,26 @@ CSSRoot {
value: Array [
CSSIdentifier {
value: "white"
- loc: SourceLocation comment/input.css 2:8-2:13
+ loc: SourceLocation comment/input.css 6:8-6:13
}
]
important: false
- loc: SourceLocation comment/input.css 2:1-2:13
+ loc: SourceLocation comment/input.css 6:1-6:13
}
]
startingTokenValue: "{"
- loc: SourceLocation comment/input.css 1:2-3:1
+ loc: SourceLocation comment/input.css 5:2-7:1
}
}
CSSRule {
- loc: SourceLocation comment/input.css 5:0-7:1
+ loc: SourceLocation comment/input.css 9:0-11:1
prelude: Array [
CSSSelector {
- loc: SourceLocation comment/input.css 5:0-5:2
+ loc: SourceLocation comment/input.css 9:0-9:2
patterns: Array [
CSSTypeSelector {
value: "a"
- loc: SourceLocation comment/input.css 5:0-5:1
+ loc: SourceLocation comment/input.css 9:0-9:1
}
]
}
@@ -80,27 +88,27 @@ CSSRoot {
value: Array [
CSSIdentifier {
value: "white"
- leadingComments: Array ["1"]
- loc: SourceLocation comment/input.css 6:22-6:27
+ leadingComments: Array ["2"]
+ loc: SourceLocation comment/input.css 10:22-10:27
}
]
important: false
- loc: SourceLocation comment/input.css 6:1-6:27
+ loc: SourceLocation comment/input.css 10:1-10:27
}
]
startingTokenValue: "{"
- loc: SourceLocation comment/input.css 5:2-7:1
+ loc: SourceLocation comment/input.css 9:2-11:1
}
}
CSSRule {
- loc: SourceLocation comment/input.css 9:0-11:1
+ loc: SourceLocation comment/input.css 13:0-15:1
prelude: Array [
CSSSelector {
- loc: SourceLocation comment/input.css 9:0-9:16
+ loc: SourceLocation comment/input.css 13:0-13:16
patterns: Array [
CSSTypeSelector {
value: "a"
- loc: SourceLocation comment/input.css 9:0-9:1
+ loc: SourceLocation comment/input.css 13:0-13:1
}
]
}
@@ -112,15 +120,15 @@ CSSRoot {
value: Array [
CSSIdentifier {
value: "white"
- loc: SourceLocation comment/input.css 10:8-10:13
+ loc: SourceLocation comment/input.css 14:8-14:13
}
]
important: false
- loc: SourceLocation comment/input.css 10:1-10:13
+ loc: SourceLocation comment/input.css 14:1-14:13
}
]
startingTokenValue: "{"
- loc: SourceLocation comment/input.css 9:16-11:1
+ loc: SourceLocation comment/input.css 13:16-15:1
}
}
]

fix(css-parser): handle multiline comments (#1373)