standalone :global() with multiple selectors shouldn't be treated as error ()

pull/6509/head
Tan Li Hau 4 years ago committed by GitHub
parent 64c162c6b7
commit f60cb22a9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -142,6 +142,15 @@ export default class Selector {
} }
} }
this.validate_global_with_multiple_selectors(component);
}
validate_global_with_multiple_selectors(component: Component) {
if (this.blocks.length === 1 && this.blocks[0].selectors.length === 1) {
// standalone :global() with multiple selectors is OK
return;
}
for (const block of this.blocks) { for (const block of this.blocks) {
for (const selector of block.selectors) { for (const selector of block.selectors) {
if (selector.type === 'PseudoClassSelector' && selector.name === 'global') { if (selector.type === 'PseudoClassSelector' && selector.name === 'global') {

@ -0,0 +1,17 @@
[
{
"code": "css-invalid-global-selector",
"message": ":global(...) must contain a single selector",
"start": {
"line": 5,
"column": 1,
"character": 54
},
"end": {
"line": 5,
"column": 20,
"character": 73
},
"pos": 54
}
]

@ -0,0 +1,12 @@
<style>
:global(h1, h2, h3), div {
color: red;
}
:global(h1, h2, h3) div {
color: red;
}
</style>
<div>
<h1>hello world</h1>
</div>

@ -0,0 +1,17 @@
[
{
"code": "css-invalid-global-selector",
"message": ":global(...) must contain a single selector",
"start": {
"line": 5,
"column": 1,
"character": 54
},
"end": {
"line": 5,
"column": 20,
"character": 73
},
"pos": 54
}
]

@ -0,0 +1,12 @@
<style>
:global(.h1\,h2\,h3).foo {
color: red;
}
:global(h1, h2, h3).foo {
color: red;
}
</style>
<div>
<h1>hello world</h1>
</div>

@ -3,15 +3,15 @@
"code": "css-invalid-global-selector", "code": "css-invalid-global-selector",
"message": ":global(...) must contain a single selector", "message": ":global(...) must contain a single selector",
"start": { "start": {
"line": 5, "line": 11,
"column": 5, "column": 5,
"character": 58 "character": 143
}, },
"end": { "end": {
"line": 5, "line": 11,
"column": 24, "column": 24,
"character": 77 "character": 162
}, },
"pos": 58 "pos": 143
} }
] ]

@ -2,6 +2,12 @@
div :global(.h1\,h2\,h3) { div :global(.h1\,h2\,h3) {
color: red; color: red;
} }
:global(h1, h2, h3) {
color: red;
}
div, :global(h1, h2, h3) {
color: red;
}
div :global(h1, h2, h3) { div :global(h1, h2, h3) {
color: red; color: red;
} }

Loading…
Cancel
Save