From 2f6d84befc11cd2cee3f0502175f01a547fd6805 Mon Sep 17 00:00:00 2001 From: Harttle Date: Tue, 3 May 2022 13:22:18 +0800 Subject: [PATCH] test: cases for async variables --- package-lock.json | 6 +++--- src/render/expression.ts | 6 +++--- test/integration/builtin/tags/if.ts | 6 ++++++ test/integration/liquid/liquid.ts | 5 +++++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 38eee5639..b236e995d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2662,9 +2662,9 @@ } }, "caniuse-lite": { - "version": "1.0.30001312", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001312.tgz", - "integrity": "sha512-Wiz1Psk2MEK0pX3rUzWaunLTZzqS2JYZFzNKqAiJGiuxIjRPLgV6+VDPOg6lQOUxmDwhTlh198JsTTi8Hzw6aQ==", + "version": "1.0.30001335", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001335.tgz", + "integrity": "sha512-ddP1Tgm7z2iIxu6QTtbZUv6HJxSaV/PZeSrWFZtbY4JZ69tOeNhBCl3HyRQgeNZKE5AOn1kpV7fhljigy0Ty3w==", "dev": true }, "cardinal": { diff --git a/src/render/expression.ts b/src/render/expression.ts index 3b4239cf7..a206c9c38 100644 --- a/src/render/expression.ts +++ b/src/render/expression.ts @@ -25,9 +25,9 @@ export class Expression { const operands: any[] = [] for (const token of this.postfix) { if (TypeGuards.isOperatorToken(token)) { - const r = yield operands.pop() - const l = yield operands.pop() - const result = evalOperatorToken(ctx.opts.operators, token, l, r, ctx) + const r = operands.pop() + const l = operands.pop() + const result = yield evalOperatorToken(ctx.opts.operators, token, l, r, ctx) operands.push(result) } else { operands.push(yield evalToken(token, ctx, lenient && this.postfix.length === 1)) diff --git a/test/integration/builtin/tags/if.ts b/test/integration/builtin/tags/if.ts index 634db5762..396aec3cf 100644 --- a/test/integration/builtin/tags/if.ts +++ b/test/integration/builtin/tags/if.ts @@ -142,4 +142,10 @@ describe('tags/if', function () { const html = liquid.parseAndRenderSync(src, scope) return expect(html).to.equal('true') }) + it('should support async variables', async () => { + const src = `{%if var == 'var' %}success{%endif%}` + const scope = { 'var': Promise.resolve('var') } + const html = await liquid.parseAndRender(src, scope) + return expect(html).to.equal('success') + }) }) diff --git a/test/integration/liquid/liquid.ts b/test/integration/liquid/liquid.ts index 05c95b883..129339764 100644 --- a/test/integration/liquid/liquid.ts +++ b/test/integration/liquid/liquid.ts @@ -52,6 +52,11 @@ describe('Liquid', function () { const src = '{{ foo }}' return expect(engine.parseAndRender(src, {}, { strictVariables: true })).rejectedWith(/undefined variable/) }) + it('should support async variables in output', async () => { + const src = '{{ foo }}' + const html = await engine.parseAndRender(src, { foo: Promise.resolve('FOO') }) + expect(html).to.equal('FOO') + }) }) describe('#express()', function () { const liquid = new Liquid({ root: '/root' })