From 015e6958ce97e625ecfe0004f57eb8a18e5fe875 Mon Sep 17 00:00:00 2001 From: Albert Date: Thu, 8 Feb 2024 12:31:42 +1030 Subject: [PATCH] Clean some logic --- .../compiler/phases/2-analyze/css/Selector.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/svelte/src/compiler/phases/2-analyze/css/Selector.js b/packages/svelte/src/compiler/phases/2-analyze/css/Selector.js index b68d303aeb..f72133d4d8 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/css/Selector.js +++ b/packages/svelte/src/compiler/phases/2-analyze/css/Selector.js @@ -1071,14 +1071,14 @@ function get_parent_selectors(parent_complex_selector) { */ function nest_fake_parents(children, parent_complex_selector) { let nested_selector_index = children.findIndex(child => child.type === 'NestingSelector'); - let had_ampersand = false; + let used_ampersand = false; // TODO: Handle multiple nesting selectors? // eg: &&& {...} or .bar & .foo {...} if (nested_selector_index === -1) { nested_selector_index = 0; // insert the parent selectors at the beginning of the children array } else { - had_ampersand = true; + used_ampersand = true; children.splice(nested_selector_index, 1); // remove the nesting selector, so we can insert there } @@ -1108,12 +1108,12 @@ function nest_fake_parents(children, parent_complex_selector) { } - if(child_before?.type !== "Combinator") { - if (child_after?.type !== 'Combinator') { - if(!had_ampersand) { - children.splice(nested_selector_index, 0, FakeCombinator); - } - } + if( + child_before?.type !== "Combinator" + && child_after?.type !== "Combinator" + && !used_ampersand + ) { + children.splice(nested_selector_index, 0, FakeCombinator); } } // Finally, insert the parent selectors into the children array