From 228832c9a3a6fdb8c11cdbb942444734686a04f6 Mon Sep 17 00:00:00 2001 From: Roy Choo Date: Tue, 22 Jun 2021 23:03:08 +0800 Subject: [PATCH] fix: :global(...):some-pseudoclass should be considered global (#6317) --- src/compiler/compile/css/Selector.ts | 5 +++-- .../css-invalid-global-placement-2/errors.json | 15 +++++++++++++++ .../css-invalid-global-placement-2/input.svelte | 5 +++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 test/validator/samples/css-invalid-global-placement-2/errors.json create mode 100644 test/validator/samples/css-invalid-global-placement-2/input.svelte diff --git a/src/compiler/compile/css/Selector.ts b/src/compiler/compile/css/Selector.ts index d7e80f5499a2..49ba5e71e587 100644 --- a/src/compiler/compile/css/Selector.ts +++ b/src/compiler/compile/css/Selector.ts @@ -607,9 +607,10 @@ class Block { get global() { return ( - this.selectors.length === 1 && + this.selectors.length >= 1 && this.selectors[0].type === 'PseudoClassSelector' && - this.selectors[0].name === 'global' + this.selectors[0].name === 'global' && + this.selectors.every((selector) => selector.type === 'PseudoClassSelector') ); } } diff --git a/test/validator/samples/css-invalid-global-placement-2/errors.json b/test/validator/samples/css-invalid-global-placement-2/errors.json new file mode 100644 index 000000000000..4594469cc21b --- /dev/null +++ b/test/validator/samples/css-invalid-global-placement-2/errors.json @@ -0,0 +1,15 @@ +[{ + "code": "css-invalid-global", + "message": ":global(...) can be at the start or end of a selector sequence, but not in the middle", + "start": { + "line": 2, + "column": 6, + "character": 14 + }, + "end": { + "line": 2, + "column": 19, + "character": 27 + }, + "pos": 14 +}] diff --git a/test/validator/samples/css-invalid-global-placement-2/input.svelte b/test/validator/samples/css-invalid-global-placement-2/input.svelte new file mode 100644 index 000000000000..75bd7b66e1d0 --- /dev/null +++ b/test/validator/samples/css-invalid-global-placement-2/input.svelte @@ -0,0 +1,5 @@ +