Skip to content

Commit cd25065

Browse files
authored
feat: leave view transition pseudo selectors untouched (#11375)
* feat: leave view transition pseudo selectors untouched view transition pseude selectors are global-like, i.e. they shouldn't be scoped or treated as unused. In the process of adding support for this, is_root and is_host were consolidated into is_global_like because their usage locations didn't need any differentiation between them (same for the new view transition treatment) closes #9127 * regenerate types
1 parent de315d8 commit cd25065

File tree

8 files changed

+62
-15
lines changed

8 files changed

+62
-15
lines changed

.changeset/moody-ghosts-buy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
feat: leave view transition pseudo selectors untouched

packages/svelte/src/compiler/phases/1-parse/read/style.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ function read_selector(parser, inside_pseudo_class = false) {
182182
end: -1,
183183
metadata: {
184184
is_global: false,
185-
is_host: false,
186-
is_root: false,
185+
is_global_like: false,
187186
scoped: false
188187
}
189188
};

packages/svelte/src/compiler/phases/2-analyze/css/css-analyze.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const analysis_visitors = {
4242
node.metadata.rule = context.state.rule;
4343

4444
node.metadata.used = node.children.every(
45-
({ metadata }) => metadata.is_global || metadata.is_host || metadata.is_root
45+
({ metadata }) => metadata.is_global || metadata.is_global_like
4646
);
4747
},
4848
RelativeSelector(node, context) {
@@ -57,10 +57,19 @@ const analysis_visitors = {
5757

5858
if (node.selectors.length === 1) {
5959
const first = node.selectors[0];
60-
node.metadata.is_host = first.type === 'PseudoClassSelector' && first.name === 'host';
60+
node.metadata.is_global_like ||=
61+
(first.type === 'PseudoClassSelector' && first.name === 'host') ||
62+
(first.type === 'PseudoElementSelector' &&
63+
[
64+
'view-transition',
65+
'view-transition-group',
66+
'view-transition-old',
67+
'view-transition-new',
68+
'view-transition-image-pair'
69+
].includes(first.name));
6170
}
6271

63-
node.metadata.is_root = !!node.selectors.find(
72+
node.metadata.is_global_like ||= !!node.selectors.find(
6473
(child) => child.type === 'PseudoClassSelector' && child.name === 'root'
6574
);
6675

@@ -87,7 +96,7 @@ const analysis_visitors = {
8796

8897
node.metadata.has_local_selectors = node.prelude.children.some((selector) => {
8998
return selector.children.some(
90-
({ metadata }) => !metadata.is_global && !metadata.is_host && !metadata.is_root
99+
({ metadata }) => !metadata.is_global && !metadata.is_global_like
91100
);
92101
});
93102
}

packages/svelte/src/compiler/phases/2-analyze/css/css-prune.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ const nesting_selector = {
4242
],
4343
metadata: {
4444
is_global: false,
45-
is_host: false,
46-
is_root: false,
45+
is_global_like: false,
4746
scoped: false
4847
}
4948
};
@@ -109,7 +108,7 @@ const visitors = {
109108
*/
110109
function truncate(node) {
111110
const i = node.children.findLastIndex(({ metadata }) => {
112-
return !metadata.is_global && !metadata.is_host && !metadata.is_root;
111+
return !metadata.is_global && !metadata.is_global_like;
113112
});
114113

115114
return node.children.slice(0, i + 1);
@@ -229,14 +228,14 @@ function mark(relative_selector, element) {
229228

230229
/**
231230
* Returns `true` if the relative selector is global, meaning
232-
* it's a `:global(...)` or `:host` or `:root` selector, or
231+
* it's a `:global(...)` or unscopeable selector, or
233232
* is an `:is(...)` or `:where(...)` selector that contains
234233
* a global selector
235234
* @param {import('#compiler').Css.RelativeSelector} selector
236235
* @param {import('#compiler').Css.Rule} rule
237236
*/
238237
function is_global(selector, rule) {
239-
if (selector.metadata.is_global || selector.metadata.is_host || selector.metadata.is_root) {
238+
if (selector.metadata.is_global || selector.metadata.is_global_like) {
240239
return true;
241240
}
242241

packages/svelte/src/compiler/types/css.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ export namespace Css {
5656
combinator: null | Combinator;
5757
selectors: SimpleSelector[];
5858
metadata: {
59+
/** :global(..) */
5960
is_global: boolean;
60-
is_host: boolean;
61-
is_root: boolean;
61+
/** :root, :host, ::view-transition */
62+
is_global_like: boolean;
6263
scoped: boolean;
6364
};
6465
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
::view-transition {
3+
animation-duration: 0.5s;
4+
}
5+
::view-transition-group(foo) {
6+
animation-duration: 0.5s;
7+
}
8+
::view-transition-old {
9+
animation-duration: 0.5s;
10+
}
11+
::view-transition-new {
12+
animation-duration: 0.5s;
13+
}
14+
::view-transition-image-pair {
15+
animation-duration: 0.5s;
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<style>
2+
::view-transition {
3+
animation-duration: 0.5s;
4+
}
5+
::view-transition-group(foo) {
6+
animation-duration: 0.5s;
7+
}
8+
::view-transition-old {
9+
animation-duration: 0.5s;
10+
}
11+
::view-transition-new {
12+
animation-duration: 0.5s;
13+
}
14+
::view-transition-image-pair {
15+
animation-duration: 0.5s;
16+
}
17+
</style>

packages/svelte/types/index.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,9 +1202,10 @@ declare module 'svelte/compiler' {
12021202
combinator: null | Combinator;
12031203
selectors: SimpleSelector[];
12041204
metadata: {
1205+
/** :global(..) */
12051206
is_global: boolean;
1206-
is_host: boolean;
1207-
is_root: boolean;
1207+
/** :root, :host, ::view-transition */
1208+
is_global_like: boolean;
12081209
scoped: boolean;
12091210
};
12101211
}

0 commit comments

Comments
 (0)