From 451612141d62539d008757535ba1a29400e2d959 Mon Sep 17 00:00:00 2001 From: Nguyen Tran Date: Sat, 25 Mar 2023 17:47:16 -0400 Subject: [PATCH] Fix issue where we can't find previous sibling because of nested slots --- src/compiler/compile/css/Selector.ts | 8 ++++---- .../expected.css | 1 + .../input.svelte | 7 +++++++ .../expected.css | 1 + .../input.svelte | 7 +++++++ 5 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 test/css/samples/general-siblings-combinator-nested-slots-flattened/expected.css create mode 100644 test/css/samples/general-siblings-combinator-nested-slots-flattened/input.svelte create mode 100644 test/css/samples/siblings-combinator-nested-slots-flattened/expected.css create mode 100644 test/css/samples/siblings-combinator-nested-slots-flattened/input.svelte diff --git a/src/compiler/compile/css/Selector.ts b/src/compiler/compile/css/Selector.ts index f2839ba36a..19fac1f314 100644 --- a/src/compiler/compile/css/Selector.ts +++ b/src/compiler/compile/css/Selector.ts @@ -483,11 +483,11 @@ function find_previous_sibling_ignoring_slots(node: INode): INode { } // @ts-ignore - if (!current_node.prev && current_node.parent.type === 'Slot') { - current_node = current_node.parent.prev; - } else { - current_node = current_node.prev; + while (!current_node.prev && current_node.parent && current_node.parent.type === 'Slot') { + current_node = current_node.parent; } + current_node = current_node.prev; + // @ts-ignore } while (current_node && current_node.type === 'Slot'); diff --git a/test/css/samples/general-siblings-combinator-nested-slots-flattened/expected.css b/test/css/samples/general-siblings-combinator-nested-slots-flattened/expected.css new file mode 100644 index 0000000000..f365e3dc24 --- /dev/null +++ b/test/css/samples/general-siblings-combinator-nested-slots-flattened/expected.css @@ -0,0 +1 @@ +h1.svelte-xyz~p.svelte-xyz{color:red} \ No newline at end of file diff --git a/test/css/samples/general-siblings-combinator-nested-slots-flattened/input.svelte b/test/css/samples/general-siblings-combinator-nested-slots-flattened/input.svelte new file mode 100644 index 0000000000..0d521b8385 --- /dev/null +++ b/test/css/samples/general-siblings-combinator-nested-slots-flattened/input.svelte @@ -0,0 +1,7 @@ +

Heading 1

Span 1Span 2

Paragraph 2

+ + diff --git a/test/css/samples/siblings-combinator-nested-slots-flattened/expected.css b/test/css/samples/siblings-combinator-nested-slots-flattened/expected.css new file mode 100644 index 0000000000..d523f1d533 --- /dev/null +++ b/test/css/samples/siblings-combinator-nested-slots-flattened/expected.css @@ -0,0 +1 @@ +h1.svelte-xyz+span.svelte-xyz{color:red} \ No newline at end of file diff --git a/test/css/samples/siblings-combinator-nested-slots-flattened/input.svelte b/test/css/samples/siblings-combinator-nested-slots-flattened/input.svelte new file mode 100644 index 0000000000..475aa85426 --- /dev/null +++ b/test/css/samples/siblings-combinator-nested-slots-flattened/input.svelte @@ -0,0 +1,7 @@ +

test

Hello + +