Skip to content

Commit da15af7

Browse files
author
Jeff Escalante
committed
more conditional tests
1 parent a465801 commit da15af7

File tree

8 files changed

+49
-4
lines changed

8 files changed

+49
-4
lines changed

lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ function walk (opts, nodes) {
110110
}, '')
111111

112112
// evaluate the expression, get the winning node
113-
const expResult = ast[vm.runInContext(expression, ctx)].content
113+
const expResult = ast[vm.runInContext(expression, ctx)]
114114

115115
// remove all of the conditional tags from the tree
116116
// we subtract 1 from i as it's incremented from the initial if statement
117117
// in order to get the next node
118118
skip = current - i
119-
m.push(...expResult)
119+
if (expResult) m.push(...expResult.content)
120120
return m
121121
// nodes.splice(i - 1, current - i, ...expResult)
122122
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<p>x</p>
2+
3+
<p>y</p>
4+
5+
<p>z</p>
6+
<p>y</p>
7+
<p>x</p>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<p>x</p>
2+
<if condition='true'>
3+
<p>y</p>
4+
<if condition='true'>
5+
<p>z</p>
6+
</if>
7+
<p>y</p>
8+
</if>
9+
<p>x</p>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<p>x</p>
2+
<p>x</p>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<p>x</p>
2+
<if condition='false'>
3+
<p>hi</p>
4+
</if>
5+
<p>x</p>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<p>if</p>
2+
<p>x</p>
3+
<else>
4+
<p>else</p>
5+
</else>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<if condition='true'>
2+
<p>if</p>
3+
</if>
4+
<p>x</p>
5+
<else>
6+
<p>else</p>
7+
</else>

test/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ test('conditional - only "if" condition', (t) => {
3333
return matchExpected(t, 'conditional_if', { locals: { foo: 'bar' } })
3434
})
3535

36+
test('conditional - no render', (t) => {
37+
return matchExpected(t, 'conditional_norender', {})
38+
})
39+
3640
test('conditional - "if" tag missing condition', (t) => {
3741
return expectError('conditional_if_error', (err) => {
3842
t.truthy(err.toString() === 'Error: the "if" tag must have a "condition" attribute')
@@ -45,8 +49,14 @@ test('conditional - "elseif" tag missing condition', (t) => {
4549
})
4650
})
4751

48-
test.todo('conditional - other tag in middle of statement')
49-
test.todo('conditional - nested conditionals')
52+
test('conditional - other tag in middle of statement', (t) => {
53+
return matchExpected(t, 'conditional_tag_break', {})
54+
})
55+
56+
test('conditional - nested conditionals', (t) => {
57+
return matchExpected(t, 'conditional_nested', {})
58+
})
59+
5060
test.todo('conditional - expression error')
5161

5262
//

0 commit comments

Comments
 (0)