Skip to content

Commit

Permalink
! wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau committed Jun 29, 2020
1 parent f339e4a commit 0c43bc6
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 29 deletions.
48 changes: 25 additions & 23 deletions src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> = new Set();
const dependencies: Set<string> = 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();
Expand Down
8 changes: 4 additions & 4 deletions test/runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 => {
Expand All @@ -233,7 +233,7 @@ describe("runtime", () => {
})
.then(() => {
if (config.show) {
showOutput(cwd, compileOptions, compile);
// showOutput(cwd, compileOptions, compile);
}

flush();
Expand Down
15 changes: 15 additions & 0 deletions test/runtime/samples/component-svelte-slot-nested/Child.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script>
import Nested from './Nested.svelte';
</script>

<Nested>
<svelte:fragment slot="name">
<slot />
</svelte:fragment>
</Nested>

<Nested>
<svelte:fragment slot="name">
<slot name="b" />
</svelte:fragment>
</Nested>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<slot name="name"></slot>
8 changes: 8 additions & 0 deletions test/runtime/samples/component-svelte-slot-nested/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
html: `
`,
solo: true,
skip_if_ssr: true,
skip_if_hydrate: true,
};
12 changes: 12 additions & 0 deletions test/runtime/samples/component-svelte-slot-nested/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script>
import Child from './Child.svelte';
</script>

<Child>
<svelte:fragment>
Default
</svelte:fragment>
<svelte:fragment slot="b">
<p>B slot</p>
</svelte:fragment>
</Child>
2 changes: 1 addition & 1 deletion test/validator/samples/svelte-slot-placement-2/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"code": "invalid-slotted-content",
"message": "<svelte:fragment> 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
}
]
2 changes: 1 addition & 1 deletion test/validator/samples/svelte-slot-placement/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"code": "invalid-slotted-content",
"message": "<svelte:fragment> 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
}
]

0 comments on commit 0c43bc6

Please sign in to comment.