From d2c8d133ff11b2a7bdcf4aef39d4d7c8f41949b8 Mon Sep 17 00:00:00 2001 From: harttle Date: Wed, 2 Oct 2019 22:30:35 +0800 Subject: [PATCH] fix: `unless` content is not waited, fixes #160 --- src/builtin/tags/unless.ts | 4 ++-- test/integration/builtin/tags/unless.ts | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/builtin/tags/unless.ts b/src/builtin/tags/unless.ts index 670ec4cdd..8219d61d4 100644 --- a/src/builtin/tags/unless.ts +++ b/src/builtin/tags/unless.ts @@ -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 diff --git a/test/integration/builtin/tags/unless.ts b/test/integration/builtin/tags/unless.ts index ca0b1a5d1..823411ef3 100644 --- a/test/integration/builtin/tags/unless.ts +++ b/test/integration/builtin/tags/unless.ts @@ -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%}'