mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-19 06:20:38 -07:00
test: cases for async variables
This commit is contained in:
Generated
+3
-3
@@ -2662,9 +2662,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"caniuse-lite": {
|
"caniuse-lite": {
|
||||||
"version": "1.0.30001312",
|
"version": "1.0.30001335",
|
||||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001312.tgz",
|
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001335.tgz",
|
||||||
"integrity": "sha512-Wiz1Psk2MEK0pX3rUzWaunLTZzqS2JYZFzNKqAiJGiuxIjRPLgV6+VDPOg6lQOUxmDwhTlh198JsTTi8Hzw6aQ==",
|
"integrity": "sha512-ddP1Tgm7z2iIxu6QTtbZUv6HJxSaV/PZeSrWFZtbY4JZ69tOeNhBCl3HyRQgeNZKE5AOn1kpV7fhljigy0Ty3w==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"cardinal": {
|
"cardinal": {
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ export class Expression {
|
|||||||
const operands: any[] = []
|
const operands: any[] = []
|
||||||
for (const token of this.postfix) {
|
for (const token of this.postfix) {
|
||||||
if (TypeGuards.isOperatorToken(token)) {
|
if (TypeGuards.isOperatorToken(token)) {
|
||||||
const r = yield operands.pop()
|
const r = operands.pop()
|
||||||
const l = yield operands.pop()
|
const l = operands.pop()
|
||||||
const result = evalOperatorToken(ctx.opts.operators, token, l, r, ctx)
|
const result = yield evalOperatorToken(ctx.opts.operators, token, l, r, ctx)
|
||||||
operands.push(result)
|
operands.push(result)
|
||||||
} else {
|
} else {
|
||||||
operands.push(yield evalToken(token, ctx, lenient && this.postfix.length === 1))
|
operands.push(yield evalToken(token, ctx, lenient && this.postfix.length === 1))
|
||||||
|
|||||||
@@ -142,4 +142,10 @@ describe('tags/if', function () {
|
|||||||
const html = liquid.parseAndRenderSync(src, scope)
|
const html = liquid.parseAndRenderSync(src, scope)
|
||||||
return expect(html).to.equal('true')
|
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')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -52,6 +52,11 @@ describe('Liquid', function () {
|
|||||||
const src = '{{ foo }}'
|
const src = '{{ foo }}'
|
||||||
return expect(engine.parseAndRender(src, {}, { strictVariables: true })).rejectedWith(/undefined variable/)
|
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 () {
|
describe('#express()', function () {
|
||||||
const liquid = new Liquid({ root: '/root' })
|
const liquid = new Liquid({ root: '/root' })
|
||||||
|
|||||||
Reference in New Issue
Block a user