Skip to content

Commit

Permalink
disallow multiple selectors inside :global() (#6428)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau authored Jun 22, 2021
1 parent cba92ad commit bbcc1e7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/compiler/compile/css/Selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,19 @@ 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)) {
component.error(selector, {
code: 'css-invalid-global-selector',
message: ':global(...) must contain a single selector'
});
}
}
}
}
}

get_amount_class_specificity_increased() {
Expand Down
17 changes: 17 additions & 0 deletions test/validator/samples/css-invalid-global-selector/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": 58
},
"end": {
"line": 5,
"column": 24,
"character": 77
},
"pos": 58
}
]
12 changes: 12 additions & 0 deletions test/validator/samples/css-invalid-global-selector/input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<style>
div :global(.h1\,h2\,h3) {
color: red;
}
div :global(h1, h2, h3) {
color: red;
}
</style>

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

0 comments on commit bbcc1e7

Please sign in to comment.