mirror of https://github.com/sveltejs/svelte
parent
22751e9ba4
commit
cf1a80a28f
@ -1,10 +1,10 @@
|
||||
import parse from './parse/index.js';
|
||||
import generate from './generate/index.js';
|
||||
|
||||
export function compile ( template ) {
|
||||
const parsed = parse( template );
|
||||
export function compile ( template, options = {} ) {
|
||||
const parsed = parse( template, options );
|
||||
// TODO validate template
|
||||
const generated = generate( parsed, template );
|
||||
const generated = generate( parsed, template, options );
|
||||
|
||||
return generated;
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
<button on:click='set({ count: count + 1 })'>+1</button>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data: () => ({
|
||||
count: 0
|
||||
})
|
||||
};
|
||||
</script>
|
@ -0,0 +1,27 @@
|
||||
export default {
|
||||
html: `
|
||||
<button>+1</button>
|
||||
<p>count: 0</p>
|
||||
`,
|
||||
|
||||
test ( assert, component, target, window ) {
|
||||
const click = new window.MouseEvent( 'click' );
|
||||
const button = target.querySelector( 'button' );
|
||||
|
||||
button.dispatchEvent( click );
|
||||
|
||||
assert.equal( component.get( 'x' ), 1 );
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
<button>+1</button>
|
||||
<p>count: 1</p>
|
||||
` );
|
||||
|
||||
button.dispatchEvent( click );
|
||||
|
||||
assert.equal( component.get( 'x' ), 2 );
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
<button>+1</button>
|
||||
<p>count: 2</p>
|
||||
` );
|
||||
}
|
||||
};
|
@ -0,0 +1,12 @@
|
||||
<Counter bind:count='x'/>
|
||||
<p>count: {{x}}</p>
|
||||
|
||||
<script>
|
||||
import Counter from './Counter.html';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
Counter
|
||||
}
|
||||
};
|
||||
</script>
|
Loading…
Reference in new issue