mirror of https://github.com/sveltejs/svelte
parent
54f65696cb
commit
58ddbde888
@ -0,0 +1,7 @@
|
||||
<script>
|
||||
export let constant;
|
||||
</script>
|
||||
|
||||
<slot name="top" {constant} />
|
||||
<hr />
|
||||
<slot name="bottom" {constant} />
|
||||
@ -0,0 +1,55 @@
|
||||
export default {
|
||||
html: `
|
||||
3 ~ 15
|
||||
<hr>
|
||||
<div>sum: 7 product: 2 all: 14</div>
|
||||
`,
|
||||
test({ assert, component, target }) {
|
||||
component.top = { a: 5, b: 6 };
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
11 ~ 55
|
||||
<hr>
|
||||
<div>sum: 7 product: 30 all: 42</div>
|
||||
`);
|
||||
|
||||
component.main_constant = 3;
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
11 ~ 165
|
||||
<hr>
|
||||
<div>sum: 7 product: 90 all: 102</div>
|
||||
`);
|
||||
|
||||
component.top = false;
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<hr>
|
||||
<div>sum: 7 all: 12</div>
|
||||
`);
|
||||
|
||||
component.bottom = false;
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<hr>
|
||||
<div>35</div>
|
||||
`);
|
||||
|
||||
component.top = { a: 2, b: 3 };
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
5 ~ 75
|
||||
<hr>
|
||||
<div>35</div>
|
||||
`);
|
||||
|
||||
component.main_constant = 1;
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
5 ~ 25
|
||||
<hr>
|
||||
<div>15</div>
|
||||
`);
|
||||
|
||||
component.foo_constant = 3;
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
5 ~ 15
|
||||
<hr>
|
||||
<div>9</div>
|
||||
`);
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,38 @@
|
||||
<script>
|
||||
import Foo from "./Foo.svelte";
|
||||
export let main_constant = 1;
|
||||
export let foo_constant = 5;
|
||||
export let top = { a: 1, b: 2 };
|
||||
export let bottom = { a: 3, b: 4 };
|
||||
</script>
|
||||
|
||||
<Foo constant={foo_constant}>
|
||||
{#if top}
|
||||
{@const sum = top.a + top.b}
|
||||
<svelte:fragment slot="top" let:constant>
|
||||
{@const csum = sum * constant * main_constant}
|
||||
{sum} ~ {csum}
|
||||
</svelte:fragment>
|
||||
{/if}
|
||||
{#if bottom}
|
||||
{@const sum = bottom.a + bottom.b}
|
||||
{#if top}
|
||||
{@const product = top.a * top.b * main_constant}
|
||||
<svelte:fragment slot="bottom" let:constant>
|
||||
{@const all = constant + product + sum}
|
||||
<div>sum: {sum} product: {product} all: {all}</div>
|
||||
</svelte:fragment>
|
||||
{:else}
|
||||
<svelte:fragment slot="bottom" let:constant>
|
||||
{@const all = constant + sum}
|
||||
<div>sum: {sum} all: {all}</div>
|
||||
</svelte:fragment>
|
||||
{/if}
|
||||
{:else}
|
||||
{@const product = foo_constant + foo_constant}
|
||||
<svelte:fragment slot="bottom" let:constant>
|
||||
{@const all = constant + product * main_constant}
|
||||
<div>{all}</div>
|
||||
</svelte:fragment>
|
||||
{/if}
|
||||
</Foo>
|
||||
@ -0,0 +1,11 @@
|
||||
<script>
|
||||
export let value;
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<slot name="child" {value}>fallback {value * 2}</slot>
|
||||
{#if $$slots.alert}
|
||||
<hr>
|
||||
<slot name="alert" />
|
||||
{/if}
|
||||
</div>
|
||||
@ -0,0 +1,76 @@
|
||||
export default {
|
||||
html: `
|
||||
<div>
|
||||
<span>2 ~ 3</span>
|
||||
<div>
|
||||
<span>3 ~ 5</span>
|
||||
<div>
|
||||
<span>5 ~ 8</span>
|
||||
<hr>
|
||||
#2 > 5
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
test({ assert, component, target }) {
|
||||
component.array = [3, 5, 8];
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<div>
|
||||
<span>2 ~ 5</span>
|
||||
<div>
|
||||
<span>5 ~ 10</span>
|
||||
<div>
|
||||
<span>10 ~ 18</span>
|
||||
<hr>
|
||||
#2 > 5
|
||||
</div>
|
||||
<hr>
|
||||
#1 > 5
|
||||
</div>
|
||||
</div>
|
||||
`);
|
||||
|
||||
component.value = 8;
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<div>
|
||||
<span>8 ~ 11</span>
|
||||
<div>
|
||||
<span>11 ~ 16</span>
|
||||
<div>
|
||||
<span>16 ~ 24</span>
|
||||
<hr>
|
||||
#2 > 5
|
||||
</div>
|
||||
<hr>
|
||||
#1 > 5
|
||||
</div>
|
||||
<hr>
|
||||
#0 > 5
|
||||
</div>
|
||||
`);
|
||||
|
||||
component.array = [1, 3];
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<div>
|
||||
<span>8 ~ 9</span>
|
||||
<div>
|
||||
<span>9 ~ 12</span>
|
||||
<div>
|
||||
fallback 24
|
||||
</div>
|
||||
<hr>
|
||||
#1 > 5
|
||||
</div>
|
||||
<hr>
|
||||
#0 > 5
|
||||
</div>
|
||||
`);
|
||||
|
||||
component.array = [];
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<div>
|
||||
fallback 16
|
||||
</div>
|
||||
`);
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,39 @@
|
||||
<script>
|
||||
import Foo from "./Foo.svelte";
|
||||
export let value = 2;
|
||||
export let array = [1, 2, 3];
|
||||
</script>
|
||||
|
||||
<Foo {value}>
|
||||
{#if array[0]}
|
||||
{@const sum = array[0] + value}
|
||||
{#if sum > 5}
|
||||
<svelte:fragment slot="alert">#0 > 5</svelte:fragment>
|
||||
{/if}
|
||||
<svelte:fragment slot="child" let:value>
|
||||
<span>{value} ~ {sum}</span>
|
||||
<Foo value={sum}>
|
||||
{#if array[1]}
|
||||
{@const sum1 = array[1] + sum}
|
||||
{#if sum1 > 5}
|
||||
<svelte:fragment slot="alert">#1 > 5</svelte:fragment>
|
||||
{/if}
|
||||
<svelte:fragment slot="child" let:value>
|
||||
<span>{value} ~ {sum1}</span>
|
||||
<Foo value={sum1}>
|
||||
{#if array[2]}
|
||||
{@const sum2 = array[2] + sum1}
|
||||
{#if sum2 > 5}
|
||||
<svelte:fragment slot="alert">#2 > 5</svelte:fragment>
|
||||
{/if}
|
||||
<svelte:fragment slot="child" let:value>
|
||||
<span>{value} ~ {sum2}</span>
|
||||
</svelte:fragment>
|
||||
{/if}
|
||||
</Foo>
|
||||
</svelte:fragment>
|
||||
{/if}
|
||||
</Foo>
|
||||
</svelte:fragment>
|
||||
{/if}
|
||||
</Foo>
|
||||
@ -0,0 +1,11 @@
|
||||
<script>
|
||||
export let value;
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<slot name="child" {value}>fallback {value * 2}</slot>
|
||||
{#if $$slots.alert}
|
||||
<hr>
|
||||
<slot name="alert" />
|
||||
{/if}
|
||||
</div>
|
||||
@ -0,0 +1,76 @@
|
||||
export default {
|
||||
html: `
|
||||
<div>
|
||||
<span>2 ~ 3</span>
|
||||
<div>
|
||||
<span>3 ~ 5</span>
|
||||
<div>
|
||||
<span>5 ~ 8</span>
|
||||
<hr>
|
||||
#2 > 5
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
test({ assert, component, target }) {
|
||||
component.array = [3, 5, 8];
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<div>
|
||||
<span>2 ~ 5</span>
|
||||
<div>
|
||||
<span>5 ~ 10</span>
|
||||
<div>
|
||||
<span>10 ~ 18</span>
|
||||
<hr>
|
||||
#2 > 5
|
||||
</div>
|
||||
<hr>
|
||||
#1 > 5
|
||||
</div>
|
||||
</div>
|
||||
`);
|
||||
|
||||
component.value = 8;
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<div>
|
||||
<span>8 ~ 11</span>
|
||||
<div>
|
||||
<span>11 ~ 16</span>
|
||||
<div>
|
||||
<span>16 ~ 24</span>
|
||||
<hr>
|
||||
#2 > 5
|
||||
</div>
|
||||
<hr>
|
||||
#1 > 5
|
||||
</div>
|
||||
<hr>
|
||||
#0 > 5
|
||||
</div>
|
||||
`);
|
||||
|
||||
component.array = [1, 3];
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<div>
|
||||
<span>8 ~ 9</span>
|
||||
<div>
|
||||
<span>9 ~ 12</span>
|
||||
<div>
|
||||
fallback 24
|
||||
</div>
|
||||
<hr>
|
||||
#1 > 5
|
||||
</div>
|
||||
<hr>
|
||||
#0 > 5
|
||||
</div>
|
||||
`);
|
||||
|
||||
component.array = [];
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<div>
|
||||
fallback 16
|
||||
</div>
|
||||
`);
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,39 @@
|
||||
<script>
|
||||
import Foo from "./Foo.svelte";
|
||||
export let value = 2;
|
||||
export let array = [1, 2, 3];
|
||||
</script>
|
||||
|
||||
<Foo {value}>
|
||||
{#if array[0]}
|
||||
{@const sum = array[0] + value}
|
||||
{#if sum > 5}
|
||||
<svelte:fragment slot="alert">#0 > 5</svelte:fragment>
|
||||
{/if}
|
||||
<svelte:fragment slot="child" let:value>
|
||||
<span>{value} ~ {sum}</span>
|
||||
<Foo value={sum}>
|
||||
{#if array[1]}
|
||||
{@const sum = array[0] + array[1] + value}
|
||||
{#if sum > 5}
|
||||
<svelte:fragment slot="alert">#1 > 5</svelte:fragment>
|
||||
{/if}
|
||||
<svelte:fragment slot="child" let:value>
|
||||
<span>{value} ~ {sum}</span>
|
||||
<Foo value={sum}>
|
||||
{#if array[2]}
|
||||
{@const sum = array[1] + array[2] + value}
|
||||
{#if sum > 5}
|
||||
<svelte:fragment slot="alert">#2 > 5</svelte:fragment>
|
||||
{/if}
|
||||
<svelte:fragment slot="child" let:value>
|
||||
<span>{value} ~ {sum}</span>
|
||||
</svelte:fragment>
|
||||
{/if}
|
||||
</Foo>
|
||||
</svelte:fragment>
|
||||
{/if}
|
||||
</Foo>
|
||||
</svelte:fragment>
|
||||
{/if}
|
||||
</Foo>
|
||||
@ -1,4 +1,3 @@
|
||||
export default {
|
||||
solo:true,
|
||||
html: '<div><span>lol</span></div>'
|
||||
};
|
||||
|
||||
Loading…
Reference in new issue