Skip to content

Commit

Permalink
fix: unless content is not waited, fixes #160
Browse files Browse the repository at this point in the history
  • Loading branch information
harttle committed Oct 2, 2019
1 parent 96d98e4 commit d2c8d13
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/builtin/tags/unless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export default {
render: async function (ctx: Context, hash: Hash, emitter: Emitter) {
const r = this.liquid.renderer
const cond = await new Expression(this.cond).value(ctx)
await isFalsy(cond)
await (isFalsy(cond)
? r.renderTemplates(this.templates, ctx, emitter)
: r.renderTemplates(this.elseTemplates, ctx, emitter)
: r.renderTemplates(this.elseTemplates, ctx, emitter))
}
} as ITagImplOptions
13 changes: 13 additions & 0 deletions test/integration/builtin/tags/unless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ describe('tags/unless', function () {
const html = await liquid.parseAndRender(src)
return expect(html).to.equal('')
})

it('should output unless contents in order', async function () {
const src = `
Before {{ location }}
{% unless false %}Inside {{ location }}{% endunless %}
After {{ location }}`
const html = await liquid.parseAndRender(src, { location: 'wonderland' })
expect(html).to.equal(`
Before wonderland
Inside wonderland
After wonderland`)
})

describe('sync support', function () {
it('should render else when predicate yields true', function () {
const src = '{% unless 0 %}yes{%else%}no{%endunless%}'
Expand Down

0 comments on commit d2c8d13

Please sign in to comment.