diff --git a/lib/index.js b/lib/index.js index 2e751ee..6074742 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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) } @@ -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 diff --git a/test/expect/loop_customtag.html b/test/expect/loop_customtag.html index bbdaa77..6a9143a 100644 --- a/test/expect/loop_customtag.html +++ b/test/expect/loop_customtag.html @@ -6,4 +6,11 @@

2: 3

+ +

0: 1

+ +

1: 2

+ +

2: 3

+

x

diff --git a/test/fixtures/loop_customtag.html b/test/fixtures/loop_customtag.html index 8683019..2f3641e 100644 --- a/test/fixtures/loop_customtag.html +++ b/test/fixtures/loop_customtag.html @@ -1,5 +1,8 @@

x

- +

{{index}}: {{item}}

-
+ + +

{{index}}: {{item}}

+

x

diff --git a/test/test-loops.js b/test/test-loops.js index 8adf727..3521808 100644 --- a/test/test-loops.js +++ b/test/test-loops.js @@ -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] } }) })