Skip to content

Commit

Permalink
use mustache section as guard for non list value
Browse files Browse the repository at this point in the history
  • Loading branch information
shaman-apprentice authored and shaman-apprentice committed May 14, 2019
1 parent a9a80cd commit 5c7eed9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/transformers/section.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export default () => ({
if (isMustacheFalsy(sectionData))
return '';

return sectionData.map(innerCtx => transformedInnerTmpl(innerCtx))
return sectionData.map
? sectionData.map(innerCtx => transformedInnerTmpl(innerCtx))
: transformedInnerTmpl(ctx)
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/transformers/test/section.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ test('section without end tag', () => {
expect(() => Mustache.render(template, data)).toThrow()
expect(() => renderLitInnerHtml(template, data)).toThrow('missing end delimiter at: \'{{#list}}{{x}}{{/lst}}\'')
})

test('section with non-falsy data, which provides no map as guard', () => {
const template = '{{#a.b}}{{a.b}}{{/a.b}}'
const data = { a: { b: 1 } }
expectTemplatesInnerHTML(template, data)
})

0 comments on commit 5c7eed9

Please sign in to comment.