Skip to content

Commit fb38876

Browse files
authored
fix: erroneous trailing combinators in pseudos
1 parent 5c6260c commit fb38876

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/__tests__/comments.mjs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,37 @@ test('multiple comments and other things', 'h1/*test*/h2/*test*/.test/*test*/',
3333
});
3434

3535
test('ending in comment', ".bar /* comment 3 */", (t, tree) => {
36+
t.is(tree.nodes[0].nodes.length, 1);
3637
let classname = tree.nodes[0].nodes[0];
3738
t.deepEqual(classname.type, 'class', 'should have a tag');
3839
t.deepEqual(classname.spaces.after, ' ');
3940
t.deepEqual(classname.raws.spaces.after, ' /* comment 3 */');
4041
});
4142

43+
test('ending in comment and whitespace', ".bar /* comment 3 */ ", (t, tree) => {
44+
t.is(tree.nodes[0].nodes.length, 1);
45+
let classname = tree.nodes[0].nodes[0];
46+
t.deepEqual(classname.type, 'class', 'should have a tag');
47+
t.deepEqual(classname.spaces.after, ' ');
48+
t.deepEqual(classname.raws.spaces.after, ' /* comment 3 */ ');
49+
});
50+
51+
test('ending in comment in a pseudo', ":is(.bar /* comment 3 */)", (t, tree) => {
52+
t.is(tree.nodes[0].nodes[0].nodes[0].nodes.length, 1);
53+
let classname = tree.nodes[0].nodes[0].nodes[0].nodes[0];
54+
t.deepEqual(classname.type, 'class', 'should have a tag');
55+
t.deepEqual(classname.spaces.after, ' ');
56+
t.deepEqual(classname.raws.spaces.after, ' /* comment 3 */');
57+
});
58+
59+
test('ending in comment and whitespace in a pseudo', ":is(.bar /* comment 3 */ )", (t, tree) => {
60+
t.is(tree.nodes[0].nodes[0].nodes[0].nodes.length, 1);
61+
let classname = tree.nodes[0].nodes[0].nodes[0].nodes[0];
62+
t.deepEqual(classname.type, 'class', 'should have a tag');
63+
t.deepEqual(classname.spaces.after, ' ');
64+
t.deepEqual(classname.raws.spaces.after, ' /* comment 3 */ ');
65+
});
66+
4267
test('comments in selector list', 'h2, /*test*/ h4', (t, tree) => {
4368
t.deepEqual(tree.nodes[0].nodes[0].type, 'tag');
4469
t.deepEqual(tree.nodes[0].nodes[0].value, 'h2');

src/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ export default class Parser {
525525
// We need to decide between a space that's a descendant combinator and meaningless whitespace at the end of a selector.
526526
let nextSigTokenPos = this.locateNextMeaningfulToken(this.position);
527527

528-
if (nextSigTokenPos < 0 || this.tokens[nextSigTokenPos][TOKEN.TYPE] === tokens.comma) {
528+
if (nextSigTokenPos < 0 || this.tokens[nextSigTokenPos][TOKEN.TYPE] === tokens.comma || this.tokens[nextSigTokenPos][TOKEN.TYPE] === tokens.closeParenthesis) {
529529
let nodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
530530
if (nodes.length > 0) {
531531
let last = this.current.last;

0 commit comments

Comments
 (0)