Skip to content

Commit

Permalink
Merge 96d9ded into 593bf37
Browse files Browse the repository at this point in the history
  • Loading branch information
bramus committed Dec 15, 2022
2 parents 593bf37 + 96d9ded commit 9044035
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 13 deletions.
16 changes: 16 additions & 0 deletions fixtures/ast/selector/functional-pseudo/has.json
Expand Up @@ -22,6 +22,22 @@
]
}
},
"no argument": {
"source": ":has",
"ast": {
"type": "PseudoClassSelector",
"name": "has",
"children": null
}
},
"empty argument": {
"source": ":has()",
"ast": {
"type": "PseudoClassSelector",
"name": "has",
"children": []
}
},
"negation with selector group": {
"source": ":has(.a,.b.c)",
"ast": {
Expand Down
16 changes: 16 additions & 0 deletions fixtures/ast/selector/functional-pseudo/host-context.json
Expand Up @@ -17,6 +17,22 @@
]
}
},
"no argument": {
"source": ":host-context",
"ast": {
"type": "PseudoClassSelector",
"name": "host-context",
"children": null
}
},
"empty argument": {
"source": ":host-context()",
"ast": {
"type": "PseudoClassSelector",
"name": "host-context",
"children": []
}
},
"spaces around selector": {
"source": ":host-context( .a.b )",
"generate": ":host-context(.a.b)",
Expand Down
13 changes: 8 additions & 5 deletions fixtures/ast/selector/functional-pseudo/host.json
Expand Up @@ -25,6 +25,14 @@
"children": null
}
},
"empty argument": {
"source": ":host()",
"ast": {
"type": "PseudoClassSelector",
"name": "host",
"children": []
}
},
"spaces around selector": {
"source": ":host( .a.b )",
"generate": ":host(.a.b)",
Expand Down Expand Up @@ -67,11 +75,6 @@
}
},
"error": [
{
"source": ":host()",
"offset": " ^",
"error": "Selector is expected"
},
{
"source": ":host(.a{)",
"offset": " ^",
Expand Down
16 changes: 16 additions & 0 deletions fixtures/ast/selector/functional-pseudo/slotted.json
Expand Up @@ -17,6 +17,22 @@
]
}
},
"no argument": {
"source": "::slotted",
"ast": {
"type": "PseudoElementSelector",
"name": "slotted",
"children": null
}
},
"empty argument": {
"source": "::slotted()",
"ast": {
"type": "PseudoElementSelector",
"name": "slotted",
"children": []
}
},
"spaces around selector": {
"source": "::slotted( .a.b )",
"generate": "::slotted(.a.b)",
Expand Down
14 changes: 8 additions & 6 deletions lib/__tests/parse.js
Expand Up @@ -60,13 +60,15 @@ describe('parse', () => {
});
});

fixture.invalid.forEach(value =>
it(value, () =>
assert.throws(
() => parse(':nth-child(' + value + ')', { context: 'selector' })
fixture.invalid
.filter(value => value !== '')
.forEach(value =>
it(value, () =>
assert.throws(
() => parse(':nth-child(' + value + ')', { context: 'selector' })
)
)
)
);
);
});

describe('UnicodeRange', () => {
Expand Down
4 changes: 3 additions & 1 deletion lib/syntax/node/PseudoClassSelector.js
Expand Up @@ -26,7 +26,9 @@ export function parse() {
name = this.consumeFunctionName();
nameLowerCase = name.toLowerCase();

if (hasOwnProperty.call(this.pseudo, nameLowerCase)) {
if (this.lookupNonWSType(0) == RightParenthesis) {
children = this.createList();
} else if (hasOwnProperty.call(this.pseudo, nameLowerCase)) {
this.skipSC();
children = this.pseudo[nameLowerCase].call(this);
this.skipSC();
Expand Down
4 changes: 3 additions & 1 deletion lib/syntax/node/PseudoElementSelector.js
Expand Up @@ -26,7 +26,9 @@ export function parse() {
name = this.consumeFunctionName();
nameLowerCase = name.toLowerCase();

if (hasOwnProperty.call(this.pseudo, nameLowerCase)) {
if (this.lookupNonWSType(0) == RightParenthesis) {
children = this.createList();
} else if (hasOwnProperty.call(this.pseudo, nameLowerCase)) {
this.skipSC();
children = this.pseudo[nameLowerCase].call(this);
this.skipSC();
Expand Down

0 comments on commit 9044035

Please sign in to comment.