From ffa3c559e9afb00b042b6f551c126deeb2f7fd9a Mon Sep 17 00:00:00 2001 From: Roy Choo Date: Mon, 10 May 2021 03:03:08 +0800 Subject: [PATCH 1/2] fix: global with pseudo element should be considered as global --- src/compiler/compile/css/Selector.ts | 4 ++-- .../css-invalid-global-placement-2/errors.json | 15 +++++++++++++++ .../css-invalid-global-placement-2/input.svelte | 5 +++++ 3 files changed, 22 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 14b6f95a4ec3..73f8dedfa125 100644 --- a/src/compiler/compile/css/Selector.ts +++ b/src/compiler/compile/css/Selector.ts @@ -594,9 +594,9 @@ class Block { get global() { return ( - this.selectors.length === 1 && this.selectors[0].type === 'PseudoClassSelector' && - this.selectors[0].name === 'global' + this.selectors[0].name === 'global' && + !this.selectors.some((selector) => selector.type === 'ClassSelector') ); } } 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 @@ + From f47b8391554d49045d41a6db918f26c4f2f00903 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Tue, 22 Jun 2021 10:55:42 -0400 Subject: [PATCH 2/2] adjust test for global selector --- src/compiler/compile/css/Selector.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/compile/css/Selector.ts b/src/compiler/compile/css/Selector.ts index 73f8dedfa125..50c2738da030 100644 --- a/src/compiler/compile/css/Selector.ts +++ b/src/compiler/compile/css/Selector.ts @@ -594,9 +594,10 @@ class Block { get global() { return ( + this.selectors.length >= 1 && this.selectors[0].type === 'PseudoClassSelector' && this.selectors[0].name === 'global' && - !this.selectors.some((selector) => selector.type === 'ClassSelector') + this.selectors.every((selector) => selector.type === 'PseudoClassSelector') ); } }