Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function walk (opts, nodes) {
}

// if the node has content, recurse (unless it's a loop, handled later)
if (node.content && node.tag !== loops[0] && node.tag !== scopes[0]) {
if (node.content && loops.includes(node.tag) === false && node.tag !== scopes[0]) {
node.content = walk(opts, node.content)
}

Expand Down Expand Up @@ -318,10 +318,10 @@ function walk (opts, nodes) {
}

// parse loops
if (node.tag === loops[0]) {
if (loops.includes(node.tag)) {
// handle syntax error
if (!(node.attrs && node.attrs.loop)) {
throw new Error(`the "${loops[0]}" tag must have a "loop" attribute`)
throw new Error(`the "${node.tag}" tag must have a "loop" attribute`)
}

// parse the "loop" param
Expand Down
7 changes: 7 additions & 0 deletions test/expect/loop_customtag.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@

<p>2: 3</p>


<p>0: 1</p>

<p>1: 2</p>

<p>2: 3</p>

<p>x</p>
7 changes: 5 additions & 2 deletions test/fixtures/loop_customtag.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<p>x</p>
<zeach loop='item, index in items'>
<for loop='item, index in items'>
<p>{{index}}: {{item}}</p>
</zeach>
</for>
<each loop='item, index in items'>
<p>{{index}}: {{item}}</p>
</each>
<p>x</p>
2 changes: 1 addition & 1 deletion test/test-loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ test('Loops - conflicting locals', (t) => {

test('Loops - custom tag', (t) => {
return process(t, 'loop_customtag', {
loopTags: ['zeach'],
loopTags: ['for', 'each'],
locals: { items: [1, 2, 3] }
})
})
Expand Down