Skip to content

Commit

Permalink
fix: erroneous trailing combinators in pseudos
Browse files Browse the repository at this point in the history
  • Loading branch information
romainmenke committed Aug 12, 2024
1 parent 5c6260c commit fb38876
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/__tests__/comments.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,37 @@ test('multiple comments and other things', 'h1/*test*/h2/*test*/.test/*test*/',
});

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

test('ending in comment and whitespace', ".bar /* comment 3 */ ", (t, tree) => {
t.is(tree.nodes[0].nodes.length, 1);
let classname = tree.nodes[0].nodes[0];
t.deepEqual(classname.type, 'class', 'should have a tag');
t.deepEqual(classname.spaces.after, ' ');
t.deepEqual(classname.raws.spaces.after, ' /* comment 3 */ ');
});

test('ending in comment in a pseudo', ":is(.bar /* comment 3 */)", (t, tree) => {
t.is(tree.nodes[0].nodes[0].nodes[0].nodes.length, 1);
let classname = tree.nodes[0].nodes[0].nodes[0].nodes[0];
t.deepEqual(classname.type, 'class', 'should have a tag');
t.deepEqual(classname.spaces.after, ' ');
t.deepEqual(classname.raws.spaces.after, ' /* comment 3 */');
});

test('ending in comment and whitespace in a pseudo', ":is(.bar /* comment 3 */ )", (t, tree) => {
t.is(tree.nodes[0].nodes[0].nodes[0].nodes.length, 1);
let classname = tree.nodes[0].nodes[0].nodes[0].nodes[0];
t.deepEqual(classname.type, 'class', 'should have a tag');
t.deepEqual(classname.spaces.after, ' ');
t.deepEqual(classname.raws.spaces.after, ' /* comment 3 */ ');
});

test('comments in selector list', 'h2, /*test*/ h4', (t, tree) => {
t.deepEqual(tree.nodes[0].nodes[0].type, 'tag');
t.deepEqual(tree.nodes[0].nodes[0].value, 'h2');
Expand Down
2 changes: 1 addition & 1 deletion src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ export default class Parser {
// We need to decide between a space that's a descendant combinator and meaningless whitespace at the end of a selector.
let nextSigTokenPos = this.locateNextMeaningfulToken(this.position);

if (nextSigTokenPos < 0 || this.tokens[nextSigTokenPos][TOKEN.TYPE] === tokens.comma) {
if (nextSigTokenPos < 0 || this.tokens[nextSigTokenPos][TOKEN.TYPE] === tokens.comma || this.tokens[nextSigTokenPos][TOKEN.TYPE] === tokens.closeParenthesis) {
let nodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
if (nodes.length > 0) {
let last = this.current.last;
Expand Down

0 comments on commit fb38876

Please sign in to comment.