Skip to content

Commit 60fb2b5

Browse files
committed
fix: handle already global selectors
1 parent 68f71c9 commit 60fb2b5

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

packages/svelte/src/compiler/migrate/index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,16 @@ function migrate_css(state) {
5454
code.startsWith(':is') ||
5555
code.startsWith(':where')
5656
) {
57-
let parenthesis = 1;
5857
let start = code.indexOf('(') + 1;
58+
let is_global = false;
59+
const global_str = ':global';
60+
const next_global = code.indexOf(global_str);
61+
const str_between = code.substring(start, next_global);
62+
if (!str_between.trim()) {
63+
is_global = true;
64+
start += global_str.length;
65+
}
66+
let parenthesis = 1;
5967
let end = start;
6068
let char = code[end];
6169
// find the closing parenthesis
@@ -66,8 +74,10 @@ function migrate_css(state) {
6674
char = code[end];
6775
}
6876
if (start && end) {
69-
str.prependLeft(starting + start, ':global(');
70-
str.appendRight(starting + end - 1, ')');
77+
if (!is_global) {
78+
str.prependLeft(starting + start, ':global(');
79+
str.appendRight(starting + end - 1, ')');
80+
}
7181
starting += end - 1;
7282
code = code.substring(end - 1);
7383
continue;

packages/svelte/tests/migrate/samples/is-not-where-has/input.svelte

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ what if i'm talking about `:has()` in my blog?
4141
div :where(.class:is(span:has(* > *))){}
4242
div :is(.class:is(span:is(:hover)), .x){}
4343
44+
div :has( :global(.class:is(span:where(:focus)))){}
45+
div :not(:global(.class:is(span:where(:focus-within)))){}
46+
div :is(:global(.class:is(span:is(:hover)))){}
47+
div :where(:global(.class:is(span:has(* > *)))){}
48+
div :is(:global(.class:is(span:is(:hover)), .x)){}
49+
4450
div{
4551
p:has(&){
4652

packages/svelte/tests/migrate/samples/is-not-where-has/output.svelte

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ what if i'm talking about `:has()` in my blog?
4141
div :where(:global(.class:is(span:has(* > *)))){}
4242
div :is(:global(.class:is(span:is(:hover)), .x)){}
4343
44+
div :has( :global(.class:is(span:where(:focus)))){}
45+
div :not(:global(.class:is(span:where(:focus-within)))){}
46+
div :is(:global(.class:is(span:is(:hover)))){}
47+
div :where(:global(.class:is(span:has(* > *)))){}
48+
div :is(:global(.class:is(span:is(:hover)), .x)){}
49+
4450
div{
4551
p:has(:global(&)){
4652

0 commit comments

Comments
 (0)