Skip to content

Commit 0c43bc6

Browse files
committed
! wip
1 parent f339e4a commit 0c43bc6

File tree

8 files changed

+67
-29
lines changed

8 files changed

+67
-29
lines changed

src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -87,39 +87,41 @@ export default class InlineComponentWrapper extends Wrapper {
8787
const slot_template = new SlotTemplateWrapper(renderer, block, this, child, strip_whitespace, next_sibling);
8888
this.children.push(slot_template);
8989
children.splice(i, 1);
90-
continue;
9190
}
9291

9392
i--;
9493
}
9594

96-
if (this.slots.has('default') && children.filter(node => !(node.type === 'Text' && node.data.trim() === ''))) {
97-
throw new Error('Found elements without slot attribute when using slot="default"');
98-
}
99-
100-
const default_slot = block.child({
101-
comment: create_debugging_comment(node, renderer.component),
102-
name: renderer.component.get_unique_name(`create_default_slot`),
103-
type: 'slot'
104-
});
95+
if (this.slots.has('default')) {
96+
if (children.find(node => !(node.type === 'Text' && node.data.trim() === ''))) {
97+
throw new Error('Found elements without slot attribute when using slot="default"');
98+
}
99+
} else if (children.length) {
100+
this.children.push(new SlotTemplateWrapper(renderer, block, this, ))
101+
const default_slot = block.child({
102+
comment: create_debugging_comment(node, renderer.component),
103+
name: renderer.component.get_unique_name(`create_default_slot`),
104+
type: 'slot'
105+
});
105106

106-
this.renderer.blocks.push(default_slot);
107-
this.default_slot_block = default_slot;
107+
this.renderer.blocks.push(default_slot);
108+
this.default_slot_block = default_slot;
108109

109-
this.slots.set('default', get_slot_definition(default_slot, this.node.scope, this.node.lets));
110-
const fragment = new FragmentWrapper(renderer, default_slot, children, this, strip_whitespace, next_sibling);
111-
this.children.push(fragment);
110+
this.slots.set('default', get_slot_definition(default_slot, this.node.scope, this.node.lets));
111+
const fragment = new FragmentWrapper(renderer, default_slot, children, this, strip_whitespace, next_sibling);
112+
this.children.push(fragment);
112113

113-
const dependencies: Set<string> = new Set();
114+
const dependencies: Set<string> = new Set();
114115

115-
// TODO is this filtering necessary? (I *think* so)
116-
default_slot.dependencies.forEach(name => {
117-
if (!this.node.scope.is_let(name)) {
118-
dependencies.add(name);
119-
}
120-
});
116+
// TODO is this filtering necessary? (I *think* so)
117+
default_slot.dependencies.forEach(name => {
118+
if (!this.node.scope.is_let(name)) {
119+
dependencies.add(name);
120+
}
121+
});
121122

122-
block.add_dependencies(dependencies);
123+
block.add_dependencies(dependencies);
124+
}
123125
}
124126

125127
block.add_outro();

test/runtime/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as glob from 'tiny-glob/sync.js';
77
import { clear_loops, flush, set_now, set_raf } from "../../internal";
88

99
import {
10-
showOutput,
10+
// showOutput,
1111
loadConfig,
1212
loadSvelte,
1313
cleanRequireCache,
@@ -142,7 +142,7 @@ describe("runtime", () => {
142142
mod = require(`./samples/${dir}/main.svelte`);
143143
SvelteComponent = mod.default;
144144
} catch (err) {
145-
showOutput(cwd, compileOptions, compile); // eslint-disable-line no-console
145+
// showOutput(cwd, compileOptions, compile); // eslint-disable-line no-console
146146
throw err;
147147
}
148148

@@ -223,7 +223,7 @@ describe("runtime", () => {
223223
}
224224
}).catch(err => {
225225
failed.add(dir);
226-
showOutput(cwd, compileOptions, compile); // eslint-disable-line no-console
226+
// showOutput(cwd, compileOptions, compile); // eslint-disable-line no-console
227227
throw err;
228228
})
229229
.catch(err => {
@@ -233,7 +233,7 @@ describe("runtime", () => {
233233
})
234234
.then(() => {
235235
if (config.show) {
236-
showOutput(cwd, compileOptions, compile);
236+
// showOutput(cwd, compileOptions, compile);
237237
}
238238

239239
flush();
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script>
2+
import Nested from './Nested.svelte';
3+
</script>
4+
5+
<Nested>
6+
<svelte:fragment slot="name">
7+
<slot />
8+
</svelte:fragment>
9+
</Nested>
10+
11+
<Nested>
12+
<svelte:fragment slot="name">
13+
<slot name="b" />
14+
</svelte:fragment>
15+
</Nested>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<slot name="name"></slot>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
html: `
3+
4+
`,
5+
solo: true,
6+
skip_if_ssr: true,
7+
skip_if_hydrate: true,
8+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<script>
2+
import Child from './Child.svelte';
3+
</script>
4+
5+
<Child>
6+
<svelte:fragment>
7+
Default
8+
</svelte:fragment>
9+
<svelte:fragment slot="b">
10+
<p>B slot</p>
11+
</svelte:fragment>
12+
</Child>

test/validator/samples/svelte-slot-placement-2/errors.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"code": "invalid-slotted-content",
44
"message": "<svelte:fragment> must be a child of a component",
55
"start": { "line": 5, "column": 0, "character": 59 },
6-
"end": { "line": 7, "column": 14, "character": 104 },
6+
"end": { "line": 7, "column": 18, "character": 122 },
77
"pos": 59
88
}
99
]

test/validator/samples/svelte-slot-placement/errors.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"code": "invalid-slotted-content",
44
"message": "<svelte:fragment> must be a child of a component",
55
"start": { "line": 7, "column": 2, "character": 77 },
6-
"end": { "line": 9, "column": 16, "character": 126 },
6+
"end": { "line": 9, "column": 20, "character": 134 },
77
"pos": 77
88
}
99
]

0 commit comments

Comments
 (0)