-
Notifications
You must be signed in to change notification settings - Fork 1
/
iteration.js
53 lines (50 loc) · 1.07 KB
/
iteration.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const assert = require('assert')
const hv = require('..')
assert.strictEqual(hv(`
<ul>
<li each="item in state.items">
<span>{item}</span>
<span>OK</span>
</li>
</ul>
`),
`h('ul', null, (state.items || []).map(function ($value, $index, $target) {
var item = $value
return h('li', null, [
h('span', null, (item)),
h('span', null, 'OK')
])
}, this))
`)
assert.strictEqual(hv(`
<ul>
<li each="item in state.items" key={item}>
<span>{item}</span>
<span>OK</span>
</li>
</ul>
`),
`h('ul', null, (state.items || []).map(function ($value, $index, $target) {
var item = $value
return h('li', { 'key': (item) }, [
h('span', null, (item)),
h('span', null, 'OK')
])
}, this))
`)
assert.strictEqual(hv(`
<ul>
<li each="item in state.items.filter(i => i.isPublished)">
<span>{item}</span>
<span>OK</span>
</li>
</ul>
`),
`h('ul', null, (state.items.filter(i => i.isPublished) || []).map(function ($value, $index, $target) {
var item = $value
return h('li', null, [
h('span', null, (item)),
h('span', null, 'OK')
])
}, this))
`)