From 5c7fdf4ad2cb8a848874b754f621c3058c9b62c1 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sun, 17 Feb 2019 14:16:22 -0500 Subject: [PATCH] assign elements to correct block when slots are involved - fixes #2031 --- src/compile/render-dom/wrappers/Element/index.ts | 10 +++++++--- .../component-slot-nested-in-element/One.svelte | 11 +++++++++++ .../component-slot-nested-in-element/Two.svelte | 1 + .../component-slot-nested-in-element/_config.js | 9 +++++++++ .../component-slot-nested-in-element/main.svelte | 7 +++++++ 5 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 test/runtime/samples/component-slot-nested-in-element/One.svelte create mode 100644 test/runtime/samples/component-slot-nested-in-element/Two.svelte create mode 100644 test/runtime/samples/component-slot-nested-in-element/_config.js create mode 100644 test/runtime/samples/component-slot-nested-in-element/main.svelte diff --git a/src/compile/render-dom/wrappers/Element/index.ts b/src/compile/render-dom/wrappers/Element/index.ts index 4a30232fcc..fea7737671 100644 --- a/src/compile/render-dom/wrappers/Element/index.ts +++ b/src/compile/render-dom/wrappers/Element/index.ts @@ -203,6 +203,10 @@ export default class ElementWrapper extends Wrapper { if (this.slot_block) { block.parent.addDependencies(block.dependencies); + + // appalling hack + block.wrappers.splice(block.wrappers.indexOf(this), 1); + this.slot_block.wrappers.push(this); } } @@ -216,13 +220,13 @@ export default class ElementWrapper extends Wrapper { if (this.node.name === 'noscript') return; - const node = this.var; - const nodes = parentNodes && block.getUniqueName(`${this.var}_nodes`) // if we're in unclaimable territory, i.e. , parentNodes is null - if (this.slot_block) { block = this.slot_block; } + const node = this.var; + const nodes = parentNodes && block.getUniqueName(`${this.var}_nodes`) // if we're in unclaimable territory, i.e. , parentNodes is null + block.addVariable(node); const renderStatement = this.getRenderStatement(); block.builders.create.addLine( diff --git a/test/runtime/samples/component-slot-nested-in-element/One.svelte b/test/runtime/samples/component-slot-nested-in-element/One.svelte new file mode 100644 index 0000000000..ec1e06a598 --- /dev/null +++ b/test/runtime/samples/component-slot-nested-in-element/One.svelte @@ -0,0 +1,11 @@ + + + +
+
+ +
+
+
\ No newline at end of file diff --git a/test/runtime/samples/component-slot-nested-in-element/Two.svelte b/test/runtime/samples/component-slot-nested-in-element/Two.svelte new file mode 100644 index 0000000000..e3842479c5 --- /dev/null +++ b/test/runtime/samples/component-slot-nested-in-element/Two.svelte @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/runtime/samples/component-slot-nested-in-element/_config.js b/test/runtime/samples/component-slot-nested-in-element/_config.js new file mode 100644 index 0000000000..bbdd8793c7 --- /dev/null +++ b/test/runtime/samples/component-slot-nested-in-element/_config.js @@ -0,0 +1,9 @@ +export default { + html: ` +
+
+
a
+
+
+ ` +}; diff --git a/test/runtime/samples/component-slot-nested-in-element/main.svelte b/test/runtime/samples/component-slot-nested-in-element/main.svelte new file mode 100644 index 0000000000..32f5ddc312 --- /dev/null +++ b/test/runtime/samples/component-slot-nested-in-element/main.svelte @@ -0,0 +1,7 @@ + + + +
a
+
\ No newline at end of file