mirror of https://github.com/sveltejs/svelte
parent
83f0f7d202
commit
2f62a5aaca
@ -0,0 +1 @@
|
|||||||
|
export const whitespace = /\s/;
|
@ -0,0 +1,15 @@
|
|||||||
|
import { whitespace } from '../patterns.js';
|
||||||
|
|
||||||
|
export function trimStart ( str ) {
|
||||||
|
let i = 0;
|
||||||
|
while ( whitespace.test( str[i] ) ) i += 1;
|
||||||
|
|
||||||
|
return str.slice( i );
|
||||||
|
}
|
||||||
|
|
||||||
|
export function trimEnd ( str ) {
|
||||||
|
let i = str.length;
|
||||||
|
while ( whitespace.test( str[ i - 1 ] ) ) i -= 1;
|
||||||
|
|
||||||
|
return str.slice( 0, i );
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
import * as assert from 'assert';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
html: '<p>1 + 2 = 3</p><p>3 * 3 = 9</p>',
|
||||||
|
test ( component, target ) {
|
||||||
|
component.set({ a: 3 });
|
||||||
|
assert.equal( component.get( 'c' ), 5 );
|
||||||
|
assert.equal( component.get( 'cSquared' ), 25 );
|
||||||
|
assert.equal( target.innerHTML, '<p>3 + 2 = 5</p><p>5 * 5 = 25</p>' );
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,16 @@
|
|||||||
|
<p>{{a}} + {{b}} = {{c}}</p>
|
||||||
|
<p>{{c}} * {{c}} = {{cSquared}}</p>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
data: () => ({
|
||||||
|
a: 1,
|
||||||
|
b: 2
|
||||||
|
}),
|
||||||
|
|
||||||
|
computed: {
|
||||||
|
c: ( a, b ) => a + b,
|
||||||
|
cSquared: c => c * c
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
@ -1,15 +1,15 @@
|
|||||||
import * as assert from 'assert';
|
import * as assert from 'assert';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
html: '<button>toggle</button><!--#if visible-->',
|
html: '<button>toggle</button>\n\n<!--#if visible-->',
|
||||||
test ( component, target, window ) {
|
test ( component, target, window ) {
|
||||||
const button = target.querySelector( 'button' );
|
const button = target.querySelector( 'button' );
|
||||||
const event = new window.MouseEvent( 'click' );
|
const event = new window.MouseEvent( 'click' );
|
||||||
|
|
||||||
button.dispatchEvent( event );
|
button.dispatchEvent( event );
|
||||||
assert.equal( target.innerHTML, '<button>toggle</button><p>hello!</p><!--#if visible-->' );
|
assert.equal( target.innerHTML, '<button>toggle</button>\n\n<p>hello!</p><!--#if visible-->' );
|
||||||
|
|
||||||
button.dispatchEvent( event );
|
button.dispatchEvent( event );
|
||||||
assert.equal( target.innerHTML, '<button>toggle</button><!--#if visible-->' );
|
assert.equal( target.innerHTML, '<button>toggle</button>\n\n<!--#if visible-->' );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
<p> {{a}} {{b}} : {{c}} : </p>
|
@ -0,0 +1,71 @@
|
|||||||
|
{
|
||||||
|
"html": {
|
||||||
|
"start": 0,
|
||||||
|
"end": 30,
|
||||||
|
"type": "Fragment",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"start": 0,
|
||||||
|
"end": 30,
|
||||||
|
"type": "Element",
|
||||||
|
"name": "p",
|
||||||
|
"attributes": [],
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"start": 4,
|
||||||
|
"end": 9,
|
||||||
|
"type": "MustacheTag",
|
||||||
|
"expression": {
|
||||||
|
"start": 6,
|
||||||
|
"end": 7,
|
||||||
|
"type": "Identifier",
|
||||||
|
"name": "a"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"start": 9,
|
||||||
|
"end": 10,
|
||||||
|
"type": "Text",
|
||||||
|
"data": " "
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"start": 10,
|
||||||
|
"end": 15,
|
||||||
|
"type": "MustacheTag",
|
||||||
|
"expression": {
|
||||||
|
"start": 12,
|
||||||
|
"end": 13,
|
||||||
|
"type": "Identifier",
|
||||||
|
"name": "b"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"start": 15,
|
||||||
|
"end": 18,
|
||||||
|
"type": "Text",
|
||||||
|
"data": " : "
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"start": 18,
|
||||||
|
"end": 23,
|
||||||
|
"type": "MustacheTag",
|
||||||
|
"expression": {
|
||||||
|
"start": 20,
|
||||||
|
"end": 21,
|
||||||
|
"type": "Identifier",
|
||||||
|
"name": "c"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"start": 23,
|
||||||
|
"end": 26,
|
||||||
|
"type": "Text",
|
||||||
|
"data": " :"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"css": null,
|
||||||
|
"js": null
|
||||||
|
}
|
Loading…
Reference in new issue