update css tests

update custom-elements tests

update hydration tests

update js tests

update some tests

update some tests

update some tests

update some tests

update some tests

update some tests

update some tests

update some tests

update some tests

update some tests

update some tests

update some tests

update some tests

update some tests

update some tests

update some tests
pull/1864/head
Rich Harris 7 years ago
parent 2231a7eb19
commit 7f3cd0d655

@ -1,3 +1,7 @@
<script>
export let unknown = 'whatever';
</script>
<p class='{unknown}'>this is styled</p> <p class='{unknown}'>this is styled</p>
<p class='bar'>this is unstyled</p> <p class='bar'>this is unstyled</p>
@ -6,13 +10,3 @@
color: red; color: red;
} }
</style> </style>
<script>
export default {
data () {
return {
unknown: 'whatever'
};
}
};
</script>

@ -1,13 +1,11 @@
<p>{foo}</p> <svelte:meta tag="custom-element"/>
<script> <script>
export default { export function updateFoo(value) {
tag: 'custom-element', foo = value;
}
methods: { export let foo;
updateFoo(value) {
this.foo = value;
}
}
};
</script> </script>
<p>{foo}</p>

@ -1,3 +1,5 @@
<svelte:meta tag="custom-element"/>
<span class='icon'></span> <span class='icon'></span>
<style> <style>
@ -5,9 +7,3 @@
content: '\ff' content: '\ff'
} }
</style> </style>
<script>
export default {
tag: 'custom-element'
};
</script>

@ -1,3 +1,5 @@
<svelte:meta tag="custom-element"/>
<div> <div>
<slot> <slot>
<p>default fallback content</p> <p>default fallback content</p>
@ -7,9 +9,3 @@
<p>foo fallback content</p> <p>foo fallback content</p>
</slot> </slot>
</div> </div>
<script>
export default {
tag: 'custom-element'
};
</script>

@ -1,7 +1,7 @@
<h1>Hello {name}!</h1> <svelte:meta tag="custom-element"/>
<script> <script>
export default { export let name;
tag: 'custom-element'
};
</script> </script>
<h1>Hello {name}!</h1>

@ -1,13 +1,7 @@
<button on:click='set({ count: count + 1 })'>count: {count}</button> <svelte:meta tag="my-counter"/>
<script> <script>
export default { export let count = 0;
tag: 'my-counter',
data() {
return {
count: 0
};
}
};
</script> </script>
<button on:click='{() => count += 1}'>count: {count}</button>

@ -1,12 +1,10 @@
<Counter bind:count/> <svelte:meta tag="my-app"/>
<p>clicked {count} times</p>
<script> <script>
import Counter from './Counter.html'; import Counter from './Counter.html';
export default { export let count;
tag: 'my-app',
components: { Counter }
};
</script> </script>
<Counter bind:count/>
<p>clicked {count} times</p>

@ -1,3 +1,5 @@
<svelte:meta tag="custom-element"/>
<p>styled</p> <p>styled</p>
<style> <style>
@ -5,9 +7,3 @@
color: red; color: red;
} }
</style> </style>
<script>
export default {
tag: 'custom-element'
};
</script>

@ -1,7 +1,7 @@
<h1>Hello {name}!</h1> <svelte:meta tag="custom-element"/>
<script> <script>
export default { export let name;
tag: 'custom-element'
};
</script> </script>
<h1>Hello {name}!</h1>

@ -1,8 +1,9 @@
<p>foo: {foo}</p> <svelte:meta tag="my-app"/>
<p>bar: {bar}</p>
<script> <script>
export default { export let foo;
tag: 'my-app' export let bar;
};
</script> </script>
<p>foo: {foo}</p>
<p>bar: {bar}</p>

@ -1,9 +1,12 @@
<svelte:meta tag="my-app"/>
<script> <script>
export default { import { onmount } from 'svelte';
tag: 'my-app',
export let wasCreated;
oncreate() { onmount(() => {
this.wasCreated = true; wasCreated = true;
} });
};
</script> </script>

@ -1,15 +1,9 @@
<my-widget class="foo" {items}/> <svelte:meta tag="custom-element"/>
<script> <script>
import './my-widget.html'; import './my-widget.html';
export default { export let items = ['a', 'b', 'c'];
tag: 'custom-element',
data() {
return {
items: ['a', 'b', 'c']
};
}
};
</script> </script>
<my-widget class="foo" {items}/>

@ -1,14 +1,8 @@
<p>{items.length} items</p> <svelte:meta tag="my-widget"/>
<p>{items.join(', ')}</p>
<script> <script>
export default { export let items = [];
tag: 'my-widget',
data() {
return {
items: []
};
}
};
</script> </script>
<p>{items.length} items</p>
<p>{items.join(', ')}</p>

@ -1,13 +1,7 @@
<div>
<Nested/>
</div>
<script> <script>
import Nested from './Nested.html'; import Nested from './Nested.html';
export default {
components: {
Nested
}
};
</script> </script>
<div>
<Nested/>
</div>

@ -1,11 +1,5 @@
<Nested/>
<script> <script>
import Nested from './Nested.html'; import Nested from './Nested.html';
export default {
components: {
Nested
}
};
</script> </script>
<Nested/>

@ -1,4 +1,4 @@
<button on:click='set({ clicked: true })'>click me</button> <button on:click='{() => clicked = true}'>click me</button>
{#if clicked} {#if clicked}
<p>clicked!</p> <p>clicked!</p>

@ -1,23 +1,19 @@
<a href="#" use:link>Test</a>
<script> <script>
export default { function link(node) {
actions: {
link(node) {
function onClick(event) { function onClick(event) {
event.preventDefault(); event.preventDefault();
history.pushState(null, null, event.target.href); history.pushState(null, null, event.target.href);
} }
node.addEventListener('click', onClick); node.addEventListener('click', onClick);
return { return {
destroy() { destroy() {
node.removeEventListener('click', onClick); node.removeEventListener('click', onClick);
}
}
} }
} }
} }
</script> </script>
<a href="#" use:link>Test</a>

@ -1,3 +1,6 @@
<script>
export let foo = 42;
</script>
<!-- a --> <!-- a -->
@ -17,13 +20,7 @@
<!-- e --> <!-- e -->
<script>
export default {
data: function () {
return { foo: 42 }
}
};
</script>
<!-- f --> <!-- f -->

@ -1,9 +1,5 @@
<Nested foo={[1, 2, 3]}/>
<script> <script>
export default { const Nested = window.Nested;
components: {
Nested: window.Nested
}
};
</script> </script>
<Nested foo={[1, 2, 3]}/>

@ -1,10 +1,7 @@
<Nested foo='bar'/> <svelte:meta immutable/>
<script> <script>
export default { const Nested = window.Nested;
immutable: true,
components: {
Nested: window.Nested
}
};
</script> </script>
<Nested foo='bar'/>

@ -1,9 +1,5 @@
<Nested foo='bar'/>
<script> <script>
export default { const Nested = window.Nested;
components: {
Nested: window.Nested
}
};
</script> </script>
<Nested foo='bar'/>

@ -1,9 +1,5 @@
<Nested foo='bar'/>
<script> <script>
export default { const Nested = window.Nested;
components: {
Nested: window.Nested
}
};
</script> </script>
<Nested foo='bar'/>

@ -1,8 +1,11 @@
<script> <script>
export default { export let x;
computed: {
a: ({ x }) => x * 2, function a() {
b: ({ x }) => x * 3 return x * 2;
} }
};
function b() {
return x * 3;
}
</script> </script>

@ -1,3 +1,5 @@
<svelte:meta tag="custom-element"/>
<div>fades in</div> <div>fades in</div>
<style> <style>
@ -10,9 +12,3 @@
100% { opacity: 1; } 100% { opacity: 1; }
} }
</style> </style>
<script>
export default {
tag: 'custom-element'
};
</script>

@ -1,11 +1,9 @@
<script> <script>
export default { import { onmount } from 'svelte';
data: () => ({
foo: 'bar'
}),
oncreate() { export let foo = 'bar';
alert(JSON.stringify(data()));
} onmount(() => {
}; alert(JSON.stringify(data()));
});
</script> </script>

@ -1,12 +1,12 @@
<script>
export let foo;
function bar() {
return foo * 2;
}
</script>
<p> <p>
{Math.max(0, foo)} {Math.max(0, foo)}
{bar} {bar()}
</p> </p>
<script>
export default {
computed: {
bar: ({ foo }) => foo * 2
}
};
</script>

@ -1,9 +1 @@
<LazyLoad load="{() => import('./Foo.html')}"/> <LazyLoad load="{() => import('./Foo.html')}"/>
<script>
export default {
components: {
LazyLoad
}
};
</script>

@ -1,23 +1,21 @@
{#each things as thing (thing.id)}
<div animate:foo>{thing.name}</div>
{/each}
<script> <script>
export default { export let things;
animations: {
foo(node, animation, params) { function foo(node, animation, params) {
const dx = animation.from.left - animation.to.left; const dx = animation.from.left - animation.to.left;
const dy = animation.from.top - animation.to.top; const dy = animation.from.top - animation.to.top;
return { return {
delay: params.delay, delay: params.delay,
duration: 100, duration: 100,
tick: (t, u) => { tick: (t, u) => {
node.dx = u * dx; node.dx = u * dx;
node.dy = u * dy; node.dy = u * dy;
}
};
} }
} };
}; }
</script> </script>
{#each things as thing (thing.id)}
<div animate:foo>{thing.name}</div>
{/each}

@ -1,16 +1,13 @@
<button on:foo='foo( bar )'>foo</button>
<script> <script>
export default { export let bar;
methods: {
foo ( bar ) { function handleFoo(bar) {
console.log( bar ); console.log( bar );
} }
},
events: { function foo(node, callback) {
foo ( node, callback ) { // code goes here
// code goes here }
}
}
};
</script> </script>
<button on:foo='{() => handleFoo( bar )}'>foo</button>

@ -1,19 +1,15 @@
<div on:touchstart="handleTouchstart()">
<button on:click|stopPropagation|preventDefault="handleClick()">click me</button>
<button on:click|once|capture="handleClick()">or me</button>
<button on:click|capture="handleClick()">or me!</button>
</div>
<script> <script>
export default { function handleTouchstart() {
methods: { // ...
handleTouchstart() { }
// ...
},
handleClick() { function handleClick() {
// ... // ...
} }
}
};
</script> </script>
<div on:touchstart="{handleTouchstart}">
<button on:click|stopPropagation|preventDefault="{handleClick}">click me</button>
<button on:click|once|capture="{handleClick}">or me</button>
<button on:click|capture="{handleClick}">or me!</button>
</div>

@ -1,13 +1,6 @@
<Imported/>
<NonImported/>
<script> <script>
import Imported from 'Imported.html'; import Imported from 'Imported.html';
export default {
components: {
Imported,
NonImported
}
};
</script> </script>
<Imported/>
<NonImported/>

@ -1,18 +1,9 @@
<script scope="shared">
export const SOME_CONSTANT = 42;
</script>
<script> <script>
export default { export function foo(bar) {
methods: { console.log( bar );
foo ( bar ) { }
console.log( bar );
}
},
setup: (Component) => {
Component.SOME_CONSTANT = 42;
Component.factory = function (target) {
return new Component({
target: target
});
}
Component.prototype.foo( 'baz' );
}
};
</script> </script>

@ -1,27 +1,25 @@
<script scope="shared">
export function preload(input) {
return output;
}
</script>
<script> <script>
export default { import { ondestroy, onmount } from 'svelte';
oncreate() {
console.log('oncreate');
},
ondestroy() { onmount(() => {
console.log('ondestroy'); console.log('oncreate');
}, });
methods: { ondestroy(() => {
foo() { console.log('ondestroy');
console.log('foo'); });
}
},
events: { function foo() {
swipe(node, callback) { console.log('foo');
// TODO implement }
}
},
preload(input) { function swipe(node, callback) {
return output; // TODO implement
} }
};
</script> </script>

@ -1,5 +1,3 @@
<button use:tooltip="t(actionTransKey)">action</button>
<script> <script>
const translations = { const translations = {
perform_action: 'Perform an Action' perform_action: 'Perform an Action'
@ -9,38 +7,34 @@
return translations[key] || `{{${key}}}`; return translations[key] || `{{${key}}}`;
} }
export default { export let actionTransKey = 'perform_action';
data() {
return { t, actionTransKey: 'perform_action' }; function tooltip(node, text) {
}, let tooltip = null;
actions: { function onMouseEnter() {
tooltip(node, text) { tooltip = document.createElement('div');
let tooltip = null; tooltip.classList.add('tooltip');
tooltip.textContent = text;
function onMouseEnter() { node.parentNode.appendChild(tooltip);
tooltip = document.createElement('div'); }
tooltip.classList.add('tooltip');
tooltip.textContent = text; function onMouseLeave() {
node.parentNode.appendChild(tooltip); if (!tooltip) return;
} tooltip.remove();
tooltip = null;
function onMouseLeave() { }
if (!tooltip) return;
tooltip.remove(); node.addEventListener('mouseenter', onMouseEnter);
tooltip = null; node.addEventListener('mouseleave', onMouseLeave);
}
return {
node.addEventListener('mouseenter', onMouseEnter); destroy() {
node.addEventListener('mouseleave', onMouseLeave); node.removeEventListener('mouseenter', onMouseEnter);
node.removeEventListener('mouseleave', onMouseLeave);
return {
destroy() {
node.removeEventListener('mouseenter', onMouseEnter);
node.removeEventListener('mouseleave', onMouseLeave);
}
}
} }
} }
} }
</script> </script>
<button use:tooltip="{t(actionTransKey)}">action</button>

@ -1,21 +1,20 @@
<h1 use:insert="display ? `Hello ${target}` : ''"></h1>
<script> <script>
export default { export let display;
actions: { export let target;
insert(node, text) {
function insert(node, text) {
function onClick() { function onClick() {
node.textContent = text; node.textContent = text;
} }
node.addEventListener('click', onClick); node.addEventListener('click', onClick);
return { return {
destroy() { destroy() {
node.removeEventListener('click', onClick); node.removeEventListener('click', onClick);
}
}
} }
} }
} }
</script> </script>
<h1 use:insert="{display ? `Hello ${target}` : ''}"></h1>

@ -1,22 +1,20 @@
<button use:foo>{x}</button>
<script> <script>
export default { export let x;
actions: {
foo(node) { function foo(node) {
let x = 0; let x = 0;
const handler = () => this.set({ x: x++ }); const handler = () => x = x++;
node.addEventListener('click', handler); node.addEventListener('click', handler);
handler(); handler();
return { return {
destroy() { destroy() {
node.removeEventListener('click', handler); node.removeEventListener('click', handler);
}
};
} }
}, };
}; }
</script> </script>
<button use:foo>{x}</button>

@ -1,52 +1,44 @@
<button use:tooltip="tooltip">action</button>
<svelte:window on:keydown="checkForCtrl(event)" on:keyup="checkForCtrl(event)"/>
<script> <script>
export default { export let tooltip = 'Perform an Action';
data() {
return { tooltip: 'Perform an Action' };
},
methods: { function checkForCtrl(event) {
checkForCtrl(event) { if (event.ctrlKey) {
if (event.ctrlKey) { tooltip = 'Perform an augmented Action';
this.set({ tooltip: 'Perform an augmented Action' }); } else {
} else { tooltip = 'Perform an Action';
this.set({ tooltip: 'Perform an Action' }); }
} }
}
},
actions: { function tooltip(node, text) {
tooltip(node, text) { let tooltip = null;
let tooltip = null;
function onMouseEnter() { function onMouseEnter() {
tooltip = document.createElement('div'); tooltip = document.createElement('div');
tooltip.classList.add('tooltip'); tooltip.classList.add('tooltip');
tooltip.textContent = text; tooltip.textContent = text;
node.parentNode.appendChild(tooltip); node.parentNode.appendChild(tooltip);
} }
function onMouseLeave() { function onMouseLeave() {
if (!tooltip) return; if (!tooltip) return;
tooltip.remove(); tooltip.remove();
tooltip = null; tooltip = null;
} }
node.addEventListener('mouseenter', onMouseEnter); node.addEventListener('mouseenter', onMouseEnter);
node.addEventListener('mouseleave', onMouseLeave); node.addEventListener('mouseleave', onMouseLeave);
return { return {
update(text) { update(text) {
if (tooltip) tooltip.textContent = text; if (tooltip) tooltip.textContent = text;
}, },
destroy() { destroy() {
node.removeEventListener('mouseenter', onMouseEnter); node.removeEventListener('mouseenter', onMouseEnter);
node.removeEventListener('mouseleave', onMouseLeave); node.removeEventListener('mouseleave', onMouseLeave);
}
}
} }
} }
} }
</script> </script>
<button use:tooltip="{tooltip}">action</button>
<svelte:window on:keydown="{checkForCtrl}" on:keyup="{checkForCtrl}"/>

@ -1,34 +1,30 @@
<button use:tooltip="'Perform an Action'">action</button>
<script> <script>
export default { function tooltip(node, text) {
actions: { let tooltip = null;
tooltip(node, text) {
let tooltip = null;
function onMouseEnter() { function onMouseEnter() {
tooltip = document.createElement('div'); tooltip = document.createElement('div');
tooltip.classList.add('tooltip'); tooltip.classList.add('tooltip');
tooltip.textContent = text; tooltip.textContent = text;
node.parentNode.appendChild(tooltip); node.parentNode.appendChild(tooltip);
} }
function onMouseLeave() { function onMouseLeave() {
if (!tooltip) return; if (!tooltip) return;
tooltip.remove(); tooltip.remove();
tooltip = null; tooltip = null;
} }
node.addEventListener('mouseenter', onMouseEnter); node.addEventListener('mouseenter', onMouseEnter);
node.addEventListener('mouseleave', onMouseLeave); node.addEventListener('mouseleave', onMouseLeave);
return { return {
destroy() { destroy() {
node.removeEventListener('mouseenter', onMouseEnter); node.removeEventListener('mouseenter', onMouseEnter);
node.removeEventListener('mouseleave', onMouseLeave); node.removeEventListener('mouseleave', onMouseLeave);
}
}
} }
} }
} }
</script> </script>
<button use:tooltip="{'Perform an Action'}">action</button>

@ -1,19 +1,17 @@
{#each things as thing (thing.id)}
<div animate:flip>{thing.name}</div>
{/each}
<script> <script>
export default { export let things;
animations: {
flip(node, animation, params) { function flip(node, animation, params) {
const dx = animation.from.left - animation.to.left; const dx = animation.from.left - animation.to.left;
const dy = animation.from.top - animation.to.top; const dy = animation.from.top - animation.to.top;
return { return {
duration: 100, duration: 100,
css: (t, u) => `transform: translate(${u + dx}px, ${u * dy}px)` css: (t, u) => `transform: translate(${u + dx}px, ${u * dy}px)`
}; };
} }
}
};
</script> </script>
{#each things as thing (thing.id)}
<div animate:flip>{thing.name}</div>
{/each}

@ -1,23 +1,21 @@
{#each things as thing, i (thing.id)}
<div animate:flip="{delay: i * 10}">{thing.name}</div>
{/each}
<script> <script>
export default { export let things;
animations: {
flip(node, animation, params) { function flip(node, animation, params) {
const dx = animation.from.left - animation.to.left; const dx = animation.from.left - animation.to.left;
const dy = animation.from.top - animation.to.top; const dy = animation.from.top - animation.to.top;
return { return {
delay: params.delay, delay: params.delay,
duration: 100, duration: 100,
tick: (t, u) => { tick: (t, u) => {
node.dx = u * dx; node.dx = u * dx;
node.dy = u * dy; node.dy = u * dy;
}
};
} }
} };
}; }
</script> </script>
{#each things as thing, i (thing.id)}
<div animate:flip="{delay: i * 10}">{thing.name}</div>
{/each}

@ -1,22 +1,20 @@
{#each things as thing (thing.id)}
<div animate:flip>{thing.name}</div>
{/each}
<script> <script>
export default { export let things;
animations: {
flip(node, animation, params) { function flip(node, animation, params) {
const dx = animation.from.left - animation.to.left; const dx = animation.from.left - animation.to.left;
const dy = animation.from.top - animation.to.top; const dy = animation.from.top - animation.to.top;
return { return {
duration: 100, duration: 100,
tick: (t, u) => { tick: (t, u) => {
node.dx = u * dx; node.dx = u * dx;
node.dy = u * dy; node.dy = u * dy;
}
};
} }
} };
}; }
</script> </script>
{#each things as thing (thing.id)}
<div animate:flip>{thing.name}</div>
{/each}

@ -1,9 +1,5 @@
<div {id}/>
<script> <script>
export default { export let id = 'foo';
data: () => ({
id: 'foo'
})
};
</script> </script>
<div {id}/>

@ -1,9 +1,5 @@
<div style='color: {color};'>{color}</div>
<script> <script>
export default { export let color = 'red';
data: () => ({
color: 'red'
})
};
</script> </script>
<div style='color: {color};'>{color}</div>

@ -1,11 +1,5 @@
<Component value="10px"/>
<script> <script>
import Component from './Component.html'; import Component from './Component.html';
export default {
components: {
Component
}
};
</script> </script>
<Component value="10px"/>

@ -1,13 +1,9 @@
{#await promise then value}
<Foo {value} />
{/await}
<script> <script>
import Foo from './Foo.html'; import Foo from './Foo.html';
export default { export let promise;
components: {
Foo
}
};
</script> </script>
{#await promise then value}
<Foo {value} />
{/await}

@ -1,7 +1,7 @@
{#await thePromise} {#await thePromise}
<p>loading...</p> <p>loading...</p>
{:then theValue} {:then theValue}
<button ref:button on:click='set({ clicked: theValue })'>click me</button> <button ref:button on:click='{() => clicked = theValue}'>click me</button>
{:catch theError} {:catch theError}
<p>oh no! {theError.message}</p> <p>oh no! {theError.message}</p>
{/await} {/await}

@ -1,3 +1,9 @@
<script>
import Foo from './Foo.html';
export let thePromise;
</script>
<Foo> <Foo>
{#await thePromise} {#await thePromise}
<p>loading...</p> <p>loading...</p>
@ -7,11 +13,3 @@
<p>oh no! {theError.message}</p> <p>oh no! {theError.message}</p>
{/await} {/await}
</Foo> </Foo>
<script>
import Foo from './Foo.html';
export default {
components: { Foo }
};
</script>

@ -1,3 +1,18 @@
<script>
export let letters = [
'a',
'b',
'c'
];
export let selected = {
letter: ''
};
function uppercase() {
return letters.map(x => x.toUpperCase());
}
</script>
<select bind:value="selected.letter"> <select bind:value="selected.letter">
{#each uppercase as letter} {#each uppercase as letter}
<option value="{letter}">{letter}</option> <option value="{letter}">{letter}</option>
@ -5,23 +20,3 @@
</select> </select>
{selected.letter} {selected.letter}
<script>
export default {
data() {
return {
letters: [
'a',
'b',
'c'
],
selected: {
letter: ''
}
}
},
computed:{
uppercase: ({ letters }) => letters.map(x => x.toUpperCase())
}
};
</script>

@ -1,15 +1,13 @@
<script>
export let items;
function numCompleted() {
return items.reduce( ( total, item ) => total + ( item.completed ? 1 : 0 ), 0 );
}
</script>
{#each items as item} {#each items as item}
<div><input type='checkbox' bind:checked='item.completed'><p>{item.description}</p></div> <div><input type='checkbox' bind:checked='item.completed'><p>{item.description}</p></div>
{/each} {/each}
<p>{numCompleted} completed</p> <p>{numCompleted()} completed</p>
<script>
export default {
computed: {
numCompleted ({ items }) {
return items.reduce( ( total, item ) => total + ( item.completed ? 1 : 0 ), 0 );
}
}
};
</script>

@ -1,14 +1,11 @@
{#each cats as cat (cat.name)}
<input type="checkbox" bind:checked="cat.checked" on:change="someCheck()">
{/each}
<script> <script>
export default { export let cats;
oncreate() {},
methods: { function someCheck() {
someCheck() { console.log('Check');
console.log('Check'); }
}
},
};
</script> </script>
{#each cats as cat (cat.name)}
<input type="checkbox" bind:checked="cat.checked" on:change="{someCheck}">
{/each}

@ -1 +1 @@
<input bind:value='a' on:input='set({ b: 0 })'> <input bind:value='a' on:input='{() => b = 0}'>

@ -1,20 +1,11 @@
<script>
export let hidden = true;
export function toggle() {
hidden = !this.get().hidden;
}
</script>
{#if !hidden} {#if !hidden}
<slot></slot> <slot></slot>
{/if} {/if}
<script>
export default {
data () {
return {
hidden: true
};
},
methods: {
toggle () {
this.set({
hidden: !this.get().hidden
});
}
}
};
</script>

@ -1,3 +1,10 @@
<script>
import Modal from './Modal.html';
export let letter;
export let letters = ['a', 'b', 'c'];
</script>
<Modal ref:modal> <Modal ref:modal>
<span>{letter}</span> <span>{letter}</span>
<select bind:value='letter'> <select bind:value='letter'>
@ -6,18 +13,3 @@
{/each} {/each}
</select> </select>
</Modal> </Modal>
<script>
import Modal from './Modal.html';
export default {
data () {
return {
letters: ['a', 'b', 'c']
};
},
components: {
Modal
}
};
</script>

@ -1,15 +1,13 @@
<Two bind:foo/>
<script> <script>
import { onmount } from 'svelte';
import Two from './Two.html'; import Two from './Two.html';
export default { export let snapshot;
components: { export let foo;
Two
},
oncreate() { onmount(() => {
this.snapshot = this.get().foo; snapshot = foo;
} });
};
</script> </script>
<Two bind:foo/>

@ -1,15 +1,7 @@
<script> <script>
export default { export let bar = 1;
data() {
return {
bar: 1
};
},
computed: { function foo() {
foo({ bar }) { return bar * 2;
return bar * 2; }
}
}
};
</script> </script>

@ -1,9 +1,5 @@
<One ref:one/>
<script> <script>
import One from './One.html'; import One from './One.html';
export default {
components: { One }
};
</script> </script>
<One ref:one/>

@ -1,20 +1,12 @@
<p>bar in Foo: {bar}</p>
<p>baz in Foo: {baz}</p>
<script> <script>
export default { export let bar = 1;
data() { export let baz = 2;
return {
bar: 1,
baz: 2
};
},
methods: { export function double() {
double() { bar = bar * 2;
const { bar, baz } = this.get(); baz = baz * 2;
this.set({ bar: bar * 2, baz: baz * 2 }); }
}
}
};
</script> </script>
<p>bar in Foo: {bar}</p>
<p>baz in Foo: {baz}</p>

@ -1,12 +1,9 @@
<Foo ref:foo bind:bar bind:baz/>
<p ref:p>{bar + baz}</p>
<script> <script>
import Foo from './Foo.html'; import Foo from './Foo.html';
export default { export let bar;
components: { export let baz;
Foo
}
};
</script> </script>
<Foo ref:foo bind:bar bind:baz/>
<p ref:p>{bar + baz}</p>

@ -1,11 +1,9 @@
<div class:active="isActive(user)"></div>
<script> <script>
export default { export let user;
helpers: {
isActive(user) { function isActive(user) {
return user.active; return user.active;
}
}
} }
</script> </script>
<div class:active="isActive(user)"></div>

@ -1,8 +1,8 @@
<li>
<slot></slot>
</li>
<script> <script>
import { onmount } from 'svelte';
let id;
const initialValues = { const initialValues = {
'id-0': 'zero', 'id-0': 'zero',
'id-1': 'one', 'id-1': 'one',
@ -10,9 +10,11 @@
'id-3': 'three' 'id-3': 'three'
}; };
export default { onmount(() => {
oncreate() { value = initialValues[id];
this.set({ value: initialValues[this.get().id] }); });
}
};
</script> </script>
<li>
<slot></slot>
</li>

@ -1,3 +1,16 @@
<script>
import Nested from './Nested.html';
export let count;
export let idToValue = Object.create(null);
function ids() {
return new Array(count)
.fill(null)
.map((_, i) => 'id-' + i);
}
</script>
<input type='number' bind:value='count'> <input type='number' bind:value='count'>
<ol> <ol>
@ -7,27 +20,3 @@
</Nested> </Nested>
{/each} {/each}
</ol> </ol>
<script>
import Nested from './Nested.html';
export default {
data() {
return {
idToValue: Object.create(null)
};
},
computed: {
ids({ count }) {
return new Array(count)
.fill(null)
.map((_, i) => 'id-' + i);
}
},
components: {
Nested
}
};
</script>

@ -1,8 +1,8 @@
<li>
<slot></slot>
</li>
<script> <script>
import { onmount } from 'svelte';
export let id;
const initialValues = { const initialValues = {
'id-0': 'zero', 'id-0': 'zero',
'id-1': 'one', 'id-1': 'one',
@ -10,9 +10,11 @@
'id-3': 'three' 'id-3': 'three'
}; };
export default { onmount(() => {
oncreate() { value = initialValues[id];
this.set({ value: initialValues[this.get().id] }); });
}
};
</script> </script>
<li>
<slot></slot>
</li>

@ -1,3 +1,17 @@
<script>
import Nested from './Nested.html';
export let count;
export let idToValue = Object.create(null);
function ids() {
return new Array(count)
.fill(null)
.map((_, i) => ({ id: 'id-' + i}))
.reverse();
}
</script>
<input type='number' bind:value='count'> <input type='number' bind:value='count'>
<ol> <ol>
@ -7,28 +21,3 @@
</Nested> </Nested>
{/each} {/each}
</ol> </ol>
<script>
import Nested from './Nested.html';
export default {
data() {
return {
idToValue: Object.create(null)
};
},
computed: {
ids({ count }) {
return new Array(count)
.fill(null)
.map((_, i) => ({ id: 'id-' + i}))
.reverse();
}
},
components: {
Nested
}
};
</script>

@ -1,22 +1,12 @@
{#if x}
<Widget bind:foo='bar.baz'/>
{/if}
<script> <script>
import Widget from './Widget.html'; import Widget from './Widget.html';
export default { export let x = false;
data: function () { export let bar = {
return { baz: 42
x: false,
bar: {
baz: 42
}
};
},
components: {
Widget
}
}; };
</script> </script>
{#if x}
<Widget bind:foo='bar.baz'/>
{/if}

@ -1,22 +1,13 @@
{#each fields as field}
<Nested {field} bind:value='values[field]'/>
{/each}
<script> <script>
import Nested from './Nested.html'; import Nested from './Nested.html';
export default { export let fields = ['firstname', 'lastname'];
data: function () { export let values = {
return { firstname: '',
fields: ['firstname', 'lastname'], lastname: ''
values: {
firstname: '',
lastname: ''
}
};
},
components: {
Nested
}
}; };
</script> </script>
{#each fields as field}
<Nested {field} bind:value='values[field]'/>
{/each}

@ -1,9 +1,5 @@
<p>y: {y}</p>
<script> <script>
export default { export let y = 'bar';
data: () => ({
y: 'bar'
})
};
</script> </script>
<p>y: {y}</p>

@ -1,7 +1,3 @@
<script> <script>
export default { export let x = true;
data: () => ({
x: true
})
};
</script> </script>

@ -1,9 +1,5 @@
<p>y: {y}</p>
<script> <script>
export default { export let y = 'foo';
data: () => ({
y: 'foo'
})
};
</script> </script>
<p>y: {y}</p>

@ -1,3 +1,12 @@
<script>
import Foo from './Foo.html';
import Bar from './Bar.html';
import Baz from './Baz.html';
export let y;
export let x;
</script>
<p>y: {y}</p> <p>y: {y}</p>
<Baz bind:x/> <Baz bind:x/>
@ -7,17 +16,3 @@
{:else} {:else}
<Bar bind:y/> <Bar bind:y/>
{/if} {/if}
<script>
import Foo from './Foo.html';
import Bar from './Bar.html';
import Baz from './Baz.html';
export default {
components: {
Foo,
Bar,
Baz
}
};
</script>

@ -1,9 +1,5 @@
<p>y: {y}</p>
<script> <script>
export default { export let y = 'bar';
data: () => ({
y: 'bar'
})
};
</script> </script>
<p>y: {y}</p>

@ -1,7 +1,3 @@
<script> <script>
export default { export let x = true;
data: () => ({
x: true
})
};
</script> </script>

@ -1,9 +1,5 @@
<p>y: {y}</p>
<script> <script>
export default { export let y = 'foo';
data: () => ({
y: 'foo'
})
};
</script> </script>
<p>y: {y}</p>

@ -1,3 +1,12 @@
<script>
import Foo from './Foo.html';
import Bar from './Bar.html';
import Baz from './Baz.html';
export let y;
export let x;
</script>
<p>y: {y}</p> <p>y: {y}</p>
{#if x} {#if x}
@ -7,17 +16,3 @@
{/if} {/if}
<Baz bind:x/> <Baz bind:x/>
<script>
import Foo from './Foo.html';
import Bar from './Bar.html';
import Baz from './Baz.html';
export default {
components: {
Foo,
Bar,
Baz
}
};
</script>

@ -1,44 +1,37 @@
<ComponentSelector {components} bind:selectedComponent/>
<Editor bind:code='selectedComponent.source' />
<pre>
{compiled}
</pre>
<script> <script>
import { onprops } from 'svelte';
import Editor from './Editor.html'; import Editor from './Editor.html';
import ComponentSelector from './ComponentSelector.html'; import ComponentSelector from './ComponentSelector.html';
export default { export let components;
components: { export let selectedComponent;
ComponentSelector, export let compiled;
Editor
},
onstate({ changed, current }) {
const { selectedComponent } = this.get();
if (changed.components) { let previouslySelectedComponent;
components.forEach(component => {
if (component === selectedComponent) return;
component.compiled = component.source.toUpperCase();
});
}
if (changed.selectedComponent) { onprops(() => {
selectedComponent.compiled = selectedComponent.source.toUpperCase(); components.forEach(component => {
this.updateBundle(); if (component === selectedComponent) return;
} component.compiled = component.source.toUpperCase();
}, });
methods: { if (selectedComponent !== previouslySelectedComponent) {
updateBundle() { selectedComponent.compiled = selectedComponent.source.toUpperCase();
const components = this.get('components'); updateBundle();
const compiled = components.map(component => component.compiled).join('\n'); previouslySelectedComponent = selectedComponent;
this.set({ compiled });
}
} }
});
function updateBundle() {
compiled = components.map(component => component.compiled).join('\n');
} }
</script> </script>
<ComponentSelector {components} bind:selectedComponent/>
<Editor bind:code='selectedComponent.source' />
<pre>
{compiled}
</pre>

@ -1,21 +1,11 @@
<Widget bind:value='deep.name'/>
<p>{deep.name}</p>
<script> <script>
import Widget from './Widget.html'; import Widget from './Widget.html';
export default { export let deep = {
data () { name: 'foo'
return {
deep: {
name: 'foo'
}
};
},
components: {
Widget
}
}; };
</script> </script>
<Widget bind:value='deep.name'/>
<p>{deep.name}</p>

@ -1,22 +1,12 @@
<script>
import Widget from './Widget.html';
export let a = [{ name: 'foo' }, { name: 'bar' }, { name: 'baz' }];
export let getName = x => x.name;
</script>
{#each a as x} {#each a as x}
<Widget bind:value='x.name'/> <Widget bind:value='x.name'/>
{/each} {/each}
<p>{a.map(getName).join(', ')}</p> <p>{a.map(getName).join(', ')}</p>
<script>
import Widget from './Widget.html';
export default {
data () {
return {
a: [{ name: 'foo' }, { name: 'bar' }, { name: 'baz' }],
getName: x => x.name
};
},
components: {
Widget
}
};
</script>

@ -1,13 +1,9 @@
{#each a as x}
<Widget bind:value='x'/>
{/each}
<script> <script>
import Widget from './Widget.html'; import Widget from './Widget.html';
export default { export let a;
components: {
Widget
}
};
</script> </script>
{#each a as x}
<Widget bind:value='x'/>
{/each}

@ -1,21 +1,11 @@
<script>
import Widget from './Widget.html';
export let a = [ 'foo', 'bar', 'baz' ];
</script>
{#each a as x} {#each a as x}
<Widget bind:value='x'/> <Widget bind:value='x'/>
{/each} {/each}
<p>{a.join(', ')}</p> <p>{a.join(', ')}</p>
<script>
import Widget from './Widget.html';
export default {
data () {
return {
a: [ 'foo', 'bar', 'baz' ]
};
},
components: {
Widget
}
};
</script>

@ -1,12 +1,8 @@
<B bind:currentIdentifier />
<B bind:currentIdentifier />
<script> <script>
import B from './B.html'; import B from './B.html';
export default { export let currentIdentifier;
components: {
B
}
}
</script> </script>
<B bind:currentIdentifier />
<B bind:currentIdentifier />

@ -1,3 +1,10 @@
<script>
import C from './C.html';
export let list = [1, 2, 3, 2, 1];
export let currentIdentifier;
</script>
{#each list as item} {#each list as item}
<p> <p>
<C identifier="{item}" bind:currentIdentifier> <C identifier="{item}" bind:currentIdentifier>
@ -5,16 +12,3 @@
</C> </C>
</p> </p>
{/each} {/each}
<script>
import C from './C.html';
export default {
data: () => ({
list: [1, 2, 3, 2, 1]
}),
components: {
C
}
}
</script>

@ -1,23 +1,19 @@
<span
on:click="toggle()"
class="{isCurrentlySelected ? 'selected' : ''}"
>
<slot></slot>
</span>
<script> <script>
export default { export let currentIdentifier;
computed: { export let identifier;
isCurrentlySelected: ({ currentIdentifier, identifier }) => currentIdentifier === identifier
}, function isCurrentlySelected() {
methods: { return currentIdentifier === identifier;
toggle() { }
const isCurrentlySelected = this.get().isCurrentlySelected
this.set({ function toggle() {
currentIdentifier: isCurrentlySelected ? null : this.get().identifier currentIdentifier = isCurrentlySelected ? null : identifier
})
}
} }
}
</script> </script>
<span
on:click="{toggle}"
class="{isCurrentlySelected() ? 'selected' : ''}"
>
<slot></slot>
</span>

@ -1,17 +1,8 @@
<A bind:currentIdentifier />
<A bind:currentIdentifier />
<script> <script>
import A from './A.html'; import A from './A.html';
export default { export let currentIdentifier = 2;
data() {
return {
currentIdentifier: 2
}
},
components: {
A
}
}
</script> </script>
<A bind:currentIdentifier />
<A bind:currentIdentifier />

@ -1,14 +1,11 @@
<button on:click='set({ "x-count": state["x-count"] + 1 })'>+1</button>
<script> <script>
export default { export let undefined = 0;
data: () => ({
"x-count": 0 function state() {
}), // [svelte-upgrade warning]
computed: { // this function needs to be manually rewritten
state(arg) { return arg;
return arg; }
}
}
};
</script> </script>
<button on:click='{() => undefined += 1}'>+1</button>

@ -1,12 +1,8 @@
<Counter bind:x-count='x'/>
<p>count: {x}</p>
<script> <script>
import Counter from './Counter.html'; import Counter from './Counter.html';
export default { export let x;
components: {
Counter
}
};
</script> </script>
<Counter bind:x-count='x'/>
<p>count: {x}</p>

@ -1,12 +1,10 @@
<button class='bar' on:click='set({ x: "q" })'>bar</button>
<p>bar x: {x}</p>
<Baz bind:x/>
<script> <script>
import Baz from './Baz.html'; import Baz from './Baz.html';
export default { export let x;
components: { Baz }
};
</script> </script>
<button class='bar' on:click='{() => x = "q"}'>bar</button>
<p>bar x: {x}</p>
<Baz bind:x/>

@ -1,2 +1,2 @@
<button class='baz' on:click='set({ x: "r" })'>baz</button> <button class='baz' on:click='{() => x = "r"}'>baz</button>
<p>baz x: {x}</p> <p>baz x: {x}</p>

@ -1,12 +1,10 @@
<button class='foo' on:click='set({ x: "p" })'>foo</button>
<p>foo x: {x}</p>
<Bar bind:x/>
<script> <script>
import Bar from './Bar.html'; import Bar from './Bar.html';
export default { export let x;
components: { Bar }
};
</script> </script>
<button class='foo' on:click='{() => x = "p"}'>foo</button>
<p>foo x: {x}</p>
<Bar bind:x/>

@ -1,11 +1,9 @@
<p>x: {x}</p>
<Foo bind:x/>
<script> <script>
import Foo from './Foo.html'; import Foo from './Foo.html';
export default { export let x;
components: { Foo }
};
</script> </script>
<p>x: {x}</p>
<Foo bind:x/>

@ -1,9 +1,5 @@
<button on:click='set({ count: count + 1 })'>+1</button>
<script> <script>
export default { export let count = 0;
data: () => ({
count: 0
})
};
</script> </script>
<button on:click='{() => count += 1}'>+1</button>

@ -1,16 +1,8 @@
<Counter bind:count='x'/>
<p>count: {x}</p>
<script> <script>
import Counter from './Counter.html'; import Counter from './Counter.html';
export default { export let x = 10;
data: () => ({
x: 10
}),
components: {
Counter
}
};
</script> </script>
<Counter bind:count='x'/>
<p>count: {x}</p>

@ -1 +1 @@
<button on:click="set({show:false})">Hide</button> <button on:click="{() => show = false}">Hide</button>

@ -1,14 +1,10 @@
<script>
import Nested from './Nested.html';
export let show;
</script>
{#if show} {#if show}
<Nested bind:show/> <Nested bind:show/>
{:else} {:else}
<button on:click="set({show:true})">Show</button> <button on:click="{() => show = true}">Show</button>
{/if} {/if}
<script>
import Nested from './Nested.html';
export default {
components: {
Nested
}
};
</script>

@ -1,9 +1,5 @@
<button on:click='set({ count: count + 1 })'>+1</button>
<script> <script>
export default { export let count = 0;
data: () => ({
count: 0
})
};
</script> </script>
<button on:click='{() => count += 1}'>+1</button>

@ -1,12 +1,8 @@
<Counter bind:count='x'/>
<p>count: {x}</p>
<script> <script>
import Counter from './Counter.html'; import Counter from './Counter.html';
export default { export let x;
components: {
Counter
}
};
</script> </script>
<Counter bind:count='x'/>
<p>count: {x}</p>

@ -1,17 +1,10 @@
{#if foo}
<Widget p='{q}'/>
{/if}
<script> <script>
import Widget from './Widget.html'; import Widget from './Widget.html';
export default { export let foo = false;
data: () => ({ export let q;
foo: false
}),
components: {
Widget
}
};
</script> </script>
{#if foo}
<Widget p='{q}'/>
{/if}

@ -1,11 +1,9 @@
<div>
<Widget {foo}/>
</div>
<script> <script>
import Widget from './Widget.html'; import Widget from './Widget.html';
export default { export let foo;
components: { Widget }
};
</script> </script>
<div>
<Widget {foo}/>
</div>

@ -1,11 +1,12 @@
<div>
<Widget foo='{bar}' baz='{40 + x}' qux='this is a {compound} string' quux='{go.deeper}'/>
</div>
<script> <script>
import Widget from './Widget.html'; import Widget from './Widget.html';
export default { export let bar;
components: { Widget } export let x;
}; export let compound;
export let go;
</script> </script>
<div>
<Widget foo='{bar}' baz='{40 + x}' qux='this is a {compound} string' quux='{go.deeper}'/>
</div>

@ -1,11 +1,7 @@
<div>
<Widget foo=''/>
</div>
<script> <script>
import Widget from './Widget.html'; import Widget from './Widget.html';
export default {
components: { Widget }
};
</script> </script>
<div>
<Widget foo=''/>
</div>

@ -1,10 +1,5 @@
<Link x href="/cool"/>
<script> <script>
import Link from './Link.html'; import Link from './Link.html';
export default {
components: {
Link
}
};
</script> </script>
<Link x href="/cool"/>

@ -1,9 +1,5 @@
<Foo x/>
<script> <script>
import Foo from './Foo.html'; import Foo from './Foo.html';
export default {
components: { Foo }
};
</script> </script>
<Foo x/>

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save