Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix erroneous trailing combinators in pseudos #294

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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