Skip to content

Commit

Permalink
Support :host and :host-context pseudo class selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
bramus committed Dec 12, 2022
1 parent debb7c5 commit 9438d8b
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 1 deletion.
88 changes: 88 additions & 0 deletions fixtures/ast/selector/functional-pseudo/host-context.json
@@ -0,0 +1,88 @@
{
"basic": {
"source": ":host-context(test)",
"ast": {
"type": "PseudoClassSelector",
"name": "host-context",
"children": [
{
"type": "Selector",
"children": [
{
"type": "TypeSelector",
"name": "test"
}
]
}
]
}
},
"spaces around selector": {
"source": ":host-context( .a.b )",
"generate": ":host-context(.a.b)",
"ast": {
"type": "PseudoClassSelector",
"name": "host-context",
"children": [
{
"type": "Selector",
"children": [
{
"type": "ClassSelector",
"name": "a"
},
{
"type": "ClassSelector",
"name": "b"
}
]
}
]
}
},
"should be case insensitive": {
"source": ":hOsT-cOntexT(.a)",
"ast": {
"type": "PseudoClassSelector",
"name": "hOsT-cOntexT",
"children": [
{
"type": "Selector",
"children": [
{
"type": "ClassSelector",
"name": "a"
}
]
}
]
}
},
"error": [
{
"source": ":host-context(.a{)",
"offset": " ^",
"error": "\")\" is expected"
},
{
"source": ":host-context(,.b)",
"offset": " ^",
"error": "Selector is expected"
},
{
"source": ":host-context(.a,)",
"offset": " ^",
"error": "\")\" is expected"
},
{
"source": ":host-context(var(--test))",
"offset": " ^",
"error": "Selector is expected"
},
{
"source": ":host-context(foo,bar)",
"offset": " ^",
"error": "\")\" is expected"
}
]
}
88 changes: 88 additions & 0 deletions fixtures/ast/selector/functional-pseudo/host.json
@@ -0,0 +1,88 @@
{
"basic": {
"source": ":host(test)",
"ast": {
"type": "PseudoClassSelector",
"name": "host",
"children": [
{
"type": "Selector",
"children": [
{
"type": "TypeSelector",
"name": "test"
}
]
}
]
}
},
"spaces around selector": {
"source": ":host( .a.b )",
"generate": ":host(.a.b)",
"ast": {
"type": "PseudoClassSelector",
"name": "host",
"children": [
{
"type": "Selector",
"children": [
{
"type": "ClassSelector",
"name": "a"
},
{
"type": "ClassSelector",
"name": "b"
}
]
}
]
}
},
"should be case insensitive": {
"source": ":hOsT(.a)",
"ast": {
"type": "PseudoClassSelector",
"name": "hOsT",
"children": [
{
"type": "Selector",
"children": [
{
"type": "ClassSelector",
"name": "a"
}
]
}
]
}
},
"error": [
{
"source": ":host(.a{)",
"offset": " ^",
"error": "\")\" is expected"
},
{
"source": ":host(,.b)",
"offset": " ^",
"error": "Selector is expected"
},
{
"source": ":host(.a,)",
"offset": " ^",
"error": "\")\" is expected"
},
{
"source": ":host(var(--test))",
"offset": " ^",
"error": "Selector is expected"
},
{
"source": ":host(foo,bar)",
"offset": " ^",
"error": "\")\" is expected"
}
]
}
4 changes: 3 additions & 1 deletion lib/syntax/pseudo/index.js
Expand Up @@ -44,5 +44,7 @@ export default {
'nth-last-child': nth,
'nth-last-of-type': nth,
'nth-of-type': nth,
'slotted': selector
'slotted': selector,
'host': selector,
'host-context': selector
};

0 comments on commit 9438d8b

Please sign in to comment.