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

only check selector that are direct children of :global #6435

Merged
merged 10 commits into from
Jun 29, 2021
2 changes: 1 addition & 1 deletion src/compiler/compile/css/Selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default class Selector {
for (const block of this.blocks) {
for (const selector of block.selectors) {
if (selector.type === 'PseudoClassSelector' && selector.name === 'global') {
if (/[^\\],/.test(selector.children[0].value)) {
if (/[^\\],(?![^([]+(?:\)|\]))/.test(selector.children[0].value)) {
tanhauhau marked this conversation as resolved.
Show resolved Hide resolved
component.error(selector, {
code: 'css-invalid-global-selector',
message: ':global(...) must contain a single selector'
Expand Down
17 changes: 17 additions & 0 deletions test/validator/samples/css-invalid-global-selector-2/errors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{
"code": "css-invalid-global-selector",
"message": ":global(...) must contain a single selector",
"start": {
"line": 11,
"column": 5,
"character": 156
},
"end": {
"line": 11,
"column": 29,
"character": 180
},
"pos": 156
}
]
18 changes: 18 additions & 0 deletions test/validator/samples/css-invalid-global-selector-2/input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<style>
div :global(:is(h1, h2)) {
color: red;
}
div :global(:where(h1, h2)) {
color: red;
}
div :global(h1 ~ :is(h2, h3)) {
color: red;
}
div :global(:is(h1, h2), h3) {
color: red;
}
</style>

<div>
<h1>hello world</h1>
</div>
17 changes: 17 additions & 0 deletions test/validator/samples/css-invalid-global-selector-3/errors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{
"code": "css-invalid-global-selector",
"message": ":global(...) must contain a single selector",
"start": {
"line": 5,
"column": 5,
"character": 77
},
"end": {
"line": 5,
"column": 44,
"character": 116
},
"pos": 77
}
]
12 changes: 12 additions & 0 deletions test/validator/samples/css-invalid-global-selector-3/input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<style>
div :global(h1[data-title="Hello, world!"]) {
color: red;
}
div :global(h1[attribute], video[autoplay]) {
color: red;
}
</style>

<div>
<h1>hello world</h1>
</div>