Skip to content

Commit 091f02c

Browse files
committed
feat: migrate css :id, :where:not and :has
1 parent 86ef181 commit 091f02c

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

.changeset/sour-feet-carry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': minor
3+
---
4+
5+
feat: migrate css `:id`, `:where``:not` and `:has`

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,15 @@ export function migrate(source, { filename } = {}) {
317317
if (!parsed.instance && need_script) {
318318
str.appendRight(insertion_point, '\n</script>\n\n');
319319
}
320-
return { code: str.toString() };
320+
return {
321+
code: str
322+
.toString()
323+
// for some reason replacing the magic string doesn't work
324+
.replaceAll(
325+
/(?<=<style[^>]*>[\s\S]*?:(?:is|not|where|has)\()([^)]+)(?=[\s\S]*?<\/style>)/gm,
326+
':global($1)'
327+
)
328+
};
321329
} catch (e) {
322330
if (!(e instanceof MigrationError)) {
323331
// eslint-disable-next-line no-console
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<style lang="postcss">
2+
div:has(span){}
3+
div > :not(span){}
4+
div > :is(span){}
5+
div > :where(span){}
6+
7+
div:has(:is(span)){}
8+
div > :not(:is(span)){}
9+
div > :is(:is(span)){}
10+
div > :where(:is(span)){}
11+
12+
div{
13+
p:has(&){
14+
15+
}
16+
:not(span > *){
17+
:where(form){}
18+
}
19+
}
20+
</style>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<style lang="postcss">
2+
div:has(:global(span)){}
3+
div > :not(:global(span)){}
4+
div > :is(:global(span)){}
5+
div > :where(:global(span)){}
6+
7+
div:has(:global(:is(span))){}
8+
div > :not(:global(:is(span))){}
9+
div > :is(:global(:is(span))){}
10+
div > :where(:global(:is(span))){}
11+
12+
div{
13+
p:has(:global(&)){
14+
15+
}
16+
:not(:global(span > *)){
17+
:where(:global(form)){}
18+
}
19+
}
20+
</style>

0 commit comments

Comments
 (0)