Skip to content

Commit d1d99d2

Browse files
committed
check
1 parent c7273b3 commit d1d99d2

File tree

1 file changed

+14
-11
lines changed
  • packages/svelte/src/compiler/phases/2-analyze/css

1 file changed

+14
-11
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,11 @@ function apply_selector(relative_selectors, rule, element, state) {
207207
* @param {Compiler.Css.RelativeSelector} relative_selector
208208
* @param {Compiler.Css.RelativeSelector[]} parent_selectors
209209
* @param {Compiler.Css.Rule} rule
210-
* @param {Compiler.AST.RegularElement | Compiler.AST.SvelteElement} element
210+
* @param {Compiler.AST.RegularElement | Compiler.AST.SvelteElement | Compiler.AST.RenderTag | Compiler.AST.Component | Compiler.AST.SvelteComponent | Compiler.AST.SvelteSelf} node
211211
* @param {State} state
212212
* @returns {boolean}
213213
*/
214-
function apply_combinator(combinator, relative_selector, parent_selectors, rule, element, state) {
214+
function apply_combinator(combinator, relative_selector, parent_selectors, rule, node, state) {
215215
const name = combinator.name;
216216

217217
switch (name) {
@@ -220,7 +220,7 @@ function apply_combinator(combinator, relative_selector, parent_selectors, rule,
220220
let parent_matched = false;
221221
let crossed_component_boundary = false;
222222

223-
const path = element.metadata.path;
223+
const path = node.metadata.path;
224224
let i = path.length;
225225

226226
while (i--) {
@@ -261,26 +261,26 @@ function apply_combinator(combinator, relative_selector, parent_selectors, rule,
261261

262262
case '+':
263263
case '~': {
264-
const siblings = get_possible_element_siblings(element, name === '+');
264+
const siblings = get_possible_element_siblings(node, name === '+');
265265

266266
let sibling_matched = false;
267267

268268
for (const possible_sibling of siblings.keys()) {
269269
if (possible_sibling.type === 'RenderTag' || possible_sibling.type === 'SlotElement') {
270270
// `{@render foo()}<p>foo</p>` with `:global(.x) + p` is a match
271271
if (parent_selectors.length === 1 && parent_selectors[0].metadata.is_global) {
272-
mark(relative_selector, element);
272+
mark(relative_selector, node);
273273
sibling_matched = true;
274274
}
275275
} else if (apply_selector(parent_selectors, rule, possible_sibling, state)) {
276-
mark(relative_selector, element);
276+
mark(relative_selector, node);
277277
sibling_matched = true;
278278
}
279279
}
280280

281281
return (
282282
sibling_matched ||
283-
(get_element_parent(element) === null &&
283+
(get_element_parent(node) === null &&
284284
parent_selectors.every((selector) => is_global(selector, rule)))
285285
);
286286
}
@@ -295,13 +295,16 @@ function apply_combinator(combinator, relative_selector, parent_selectors, rule,
295295
* Mark both the compound selector and the node it selects as encapsulated,
296296
* for transformation in a later step
297297
* @param {Compiler.Css.RelativeSelector} relative_selector
298-
* @param {Compiler.AST.RegularElement | Compiler.AST.SvelteElement} element
298+
* @param {Compiler.AST.RegularElement | Compiler.AST.SvelteElement | Compiler.AST.RenderTag | Compiler.AST.Component | Compiler.AST.SvelteComponent | Compiler.AST.SvelteSelf} node
299299
*/
300-
function mark(relative_selector, element) {
300+
function mark(relative_selector, node) {
301301
if (!is_outer_global(relative_selector)) {
302302
relative_selector.metadata.scoped = true;
303303
}
304-
element.metadata.scoped = true;
304+
305+
if (node.type === 'RegularElement' || node.type === 'SvelteElement') {
306+
node.metadata.scoped = true;
307+
}
305308
}
306309

307310
/**
@@ -825,7 +828,7 @@ function unquote(str) {
825828
}
826829

827830
/**
828-
* @param {Compiler.AST.RegularElement | Compiler.AST.SvelteElement | Compiler.AST.RenderTag} node
831+
* @param {Compiler.AST.RegularElement | Compiler.AST.SvelteElement | Compiler.AST.RenderTag | Compiler.AST.Component | Compiler.AST.SvelteComponent | Compiler.AST.SvelteSelf} node
829832
* @returns {Compiler.AST.RegularElement | Compiler.AST.SvelteElement | null}
830833
*/
831834
function get_element_parent(node) {

0 commit comments

Comments
 (0)