mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 12:20:40 -07:00
* allow `lenientIf` for multiple operands * update tests
This commit is contained in:
@@ -24,7 +24,7 @@ export class Expression {
|
|||||||
}
|
}
|
||||||
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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return operands[0]
|
return operands[0]
|
||||||
|
|||||||
@@ -55,10 +55,15 @@ describe('LiquidOptions#strict*', function () {
|
|||||||
const html = await engine.render(tpl, ctx)
|
const html = await engine.render(tpl, ctx)
|
||||||
return expect(html).toBe('beforeXafter')
|
return expect(html).toBe('beforeXafter')
|
||||||
})
|
})
|
||||||
it('should still throw with an undefined variable in a compound `if` expression', function () {
|
it('should not throw with an undefined variable in a compound `if` expression', async function () {
|
||||||
const tpl = engine.parse('{% if notdefined == 15 %}a{% endif %}')
|
const tpl = engine.parse('before{% if notdefined == 15 %}X{% else %}Y{% endif %}after')
|
||||||
const fhtml = engine.render(tpl, ctx)
|
const html = await engine.render(tpl, ctx)
|
||||||
return expect(fhtml).rejects.toThrow(/undefined variable: notdefined/)
|
return expect(html).toBe('beforeYafter')
|
||||||
|
})
|
||||||
|
it('should correctly evaluate undefined variable in a compound `if` expression', async function () {
|
||||||
|
const tpl = engine.parse('before{% if notdefined != "value" %}X{% else %}Y{% endif %}after')
|
||||||
|
const html = await engine.render(tpl, ctx)
|
||||||
|
return expect(html).toBe('beforeXafter')
|
||||||
})
|
})
|
||||||
it('should allow an undefined variable when before the `default` filter', async function () {
|
it('should allow an undefined variable when before the `default` filter', async function () {
|
||||||
const tpl = engine.parse('{{notdefined | default: "a" | tolower}}')
|
const tpl = engine.parse('{{notdefined | default: "a" | tolower}}')
|
||||||
|
|||||||
Reference in New Issue
Block a user