Skip to content

Commit ecff925

Browse files
committed
move
1 parent 36123fc commit ecff925

File tree

1 file changed

+18
-22
lines changed
  • packages/svelte/src/compiler/phases/2-analyze/css

1 file changed

+18
-22
lines changed

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

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,7 @@ export default class Selector {
4848
this.node = node;
4949
this.stylesheet = stylesheet;
5050

51-
let parent_selector_list = null;
52-
53-
if (parent.parent instanceof Rule) {
54-
parent_selector_list = parent.parent.selectors
55-
.map((selector) => selector.selector_list)
56-
.flat();
57-
}
58-
59-
this.selector_list = group_selectors(node, parent_selector_list);
51+
this.selector_list = group_selectors(node, parent);
6052

6153
this.local_selector_list = this.selector_list.map((complex_selector) => {
6254
const i = complex_selector.findLastIndex((block) => !block.can_ignore());
@@ -943,23 +935,27 @@ class CompoundSelector {
943935
* Groups selectors and inserts parent blocks into nested rules.
944936
*
945937
* @param {import('#compiler').Css.Selector} selector - The selector to group and analyze.
946-
* @param {SelectorList | null} parent_selector_list - The parent blocks group to insert into nested rules.
938+
* @param {Rule} rule
947939
* @returns {SelectorList} - The grouped selectors with parent's blocks inserted if nested.
948940
*/
949-
function group_selectors(selector, parent_selector_list) {
950-
// If it isn't a nested rule, then we add an empty block group
951-
if (parent_selector_list === null) {
952-
return [selector_to_blocks([...selector.children], null)];
953-
}
941+
function group_selectors(selector, rule) {
942+
// TODO this logic isn't quite right, as it doesn't properly account for atrules
943+
if (rule.parent instanceof Rule) {
944+
const parent_selector_list = rule.parent.selectors
945+
.map((selector) => selector.selector_list)
946+
.flat();
947+
948+
return parent_selector_list.map((parent_complex_selector) => {
949+
const block_group = selector_to_blocks(
950+
[...selector.children],
951+
[...parent_complex_selector] // Clone the parent's blocks to avoid modifying the original array
952+
);
954953

955-
return parent_selector_list.map((parent_complex_selector) => {
956-
const block_group = selector_to_blocks(
957-
[...selector.children],
958-
[...parent_complex_selector] // Clone the parent's blocks to avoid modifying the original array
959-
);
954+
return block_group;
955+
});
956+
}
960957

961-
return block_group;
962-
});
958+
return [selector_to_blocks([...selector.children], null)];
963959
}
964960

965961
/**

0 commit comments

Comments
 (0)