diff --git a/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts b/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts index 10e934647f33..f3c2a2de93f8 100644 --- a/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts +++ b/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts @@ -87,39 +87,41 @@ export default class InlineComponentWrapper extends Wrapper { const slot_template = new SlotTemplateWrapper(renderer, block, this, child, strip_whitespace, next_sibling); this.children.push(slot_template); children.splice(i, 1); - continue; } i--; } - if (this.slots.has('default') && children.filter(node => !(node.type === 'Text' && node.data.trim() === ''))) { - throw new Error('Found elements without slot attribute when using slot="default"'); - } - - const default_slot = block.child({ - comment: create_debugging_comment(node, renderer.component), - name: renderer.component.get_unique_name(`create_default_slot`), - type: 'slot' - }); + if (this.slots.has('default')) { + if (children.find(node => !(node.type === 'Text' && node.data.trim() === ''))) { + throw new Error('Found elements without slot attribute when using slot="default"'); + } + } else if (children.length) { + this.children.push(new SlotTemplateWrapper(renderer, block, this, )) + const default_slot = block.child({ + comment: create_debugging_comment(node, renderer.component), + name: renderer.component.get_unique_name(`create_default_slot`), + type: 'slot' + }); - this.renderer.blocks.push(default_slot); - this.default_slot_block = default_slot; + this.renderer.blocks.push(default_slot); + this.default_slot_block = default_slot; - this.slots.set('default', get_slot_definition(default_slot, this.node.scope, this.node.lets)); - const fragment = new FragmentWrapper(renderer, default_slot, children, this, strip_whitespace, next_sibling); - this.children.push(fragment); + this.slots.set('default', get_slot_definition(default_slot, this.node.scope, this.node.lets)); + const fragment = new FragmentWrapper(renderer, default_slot, children, this, strip_whitespace, next_sibling); + this.children.push(fragment); - const dependencies: Set = new Set(); + const dependencies: Set = new Set(); - // TODO is this filtering necessary? (I *think* so) - default_slot.dependencies.forEach(name => { - if (!this.node.scope.is_let(name)) { - dependencies.add(name); - } - }); + // TODO is this filtering necessary? (I *think* so) + default_slot.dependencies.forEach(name => { + if (!this.node.scope.is_let(name)) { + dependencies.add(name); + } + }); - block.add_dependencies(dependencies); + block.add_dependencies(dependencies); + } } block.add_outro(); diff --git a/test/runtime/index.js b/test/runtime/index.js index 65157196c9d7..c59dc92b7ed8 100644 --- a/test/runtime/index.js +++ b/test/runtime/index.js @@ -7,7 +7,7 @@ import * as glob from 'tiny-glob/sync.js'; import { clear_loops, flush, set_now, set_raf } from "../../internal"; import { - showOutput, + // showOutput, loadConfig, loadSvelte, cleanRequireCache, @@ -142,7 +142,7 @@ describe("runtime", () => { mod = require(`./samples/${dir}/main.svelte`); SvelteComponent = mod.default; } catch (err) { - showOutput(cwd, compileOptions, compile); // eslint-disable-line no-console + // showOutput(cwd, compileOptions, compile); // eslint-disable-line no-console throw err; } @@ -223,7 +223,7 @@ describe("runtime", () => { } }).catch(err => { failed.add(dir); - showOutput(cwd, compileOptions, compile); // eslint-disable-line no-console + // showOutput(cwd, compileOptions, compile); // eslint-disable-line no-console throw err; }) .catch(err => { @@ -233,7 +233,7 @@ describe("runtime", () => { }) .then(() => { if (config.show) { - showOutput(cwd, compileOptions, compile); + // showOutput(cwd, compileOptions, compile); } flush(); diff --git a/test/runtime/samples/component-svelte-slot-nested/Child.svelte b/test/runtime/samples/component-svelte-slot-nested/Child.svelte new file mode 100644 index 000000000000..3f87a7dbf252 --- /dev/null +++ b/test/runtime/samples/component-svelte-slot-nested/Child.svelte @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/runtime/samples/component-svelte-slot-nested/Nested.svelte b/test/runtime/samples/component-svelte-slot-nested/Nested.svelte new file mode 100644 index 000000000000..a94392ce5d82 --- /dev/null +++ b/test/runtime/samples/component-svelte-slot-nested/Nested.svelte @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/runtime/samples/component-svelte-slot-nested/_config.js b/test/runtime/samples/component-svelte-slot-nested/_config.js new file mode 100644 index 000000000000..f7ac871e2028 --- /dev/null +++ b/test/runtime/samples/component-svelte-slot-nested/_config.js @@ -0,0 +1,8 @@ +export default { + html: ` + + `, + solo: true, + skip_if_ssr: true, + skip_if_hydrate: true, +}; diff --git a/test/runtime/samples/component-svelte-slot-nested/main.svelte b/test/runtime/samples/component-svelte-slot-nested/main.svelte new file mode 100644 index 000000000000..e5b3e2f84afb --- /dev/null +++ b/test/runtime/samples/component-svelte-slot-nested/main.svelte @@ -0,0 +1,12 @@ + + + + + Default + + +

B slot

+
+
diff --git a/test/validator/samples/svelte-slot-placement-2/errors.json b/test/validator/samples/svelte-slot-placement-2/errors.json index 6a35d97f66ec..a9ed207c6c01 100644 --- a/test/validator/samples/svelte-slot-placement-2/errors.json +++ b/test/validator/samples/svelte-slot-placement-2/errors.json @@ -3,7 +3,7 @@ "code": "invalid-slotted-content", "message": " must be a child of a component", "start": { "line": 5, "column": 0, "character": 59 }, - "end": { "line": 7, "column": 14, "character": 104 }, + "end": { "line": 7, "column": 18, "character": 122 }, "pos": 59 } ] diff --git a/test/validator/samples/svelte-slot-placement/errors.json b/test/validator/samples/svelte-slot-placement/errors.json index 9e960a263c69..ce825243f04e 100644 --- a/test/validator/samples/svelte-slot-placement/errors.json +++ b/test/validator/samples/svelte-slot-placement/errors.json @@ -3,7 +3,7 @@ "code": "invalid-slotted-content", "message": " must be a child of a component", "start": { "line": 7, "column": 2, "character": 77 }, - "end": { "line": 9, "column": 16, "character": 126 }, + "end": { "line": 9, "column": 20, "character": 134 }, "pos": 77 } ]