mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
fix: case/when array equality, #673
This commit is contained in:
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
import { ValueToken, Liquid, toValue, evalToken, Value, Emitter, TagToken, TopLevelToken, Context, Template, Tag, ParseStream } from '..'
|
import { ValueToken, Liquid, toValue, evalToken, Value, Emitter, TagToken, TopLevelToken, Context, Template, Tag, ParseStream } from '..'
|
||||||
|
import { equals } from '../render'
|
||||||
|
|
||||||
export default class extends Tag {
|
export default class extends Tag {
|
||||||
value: Value
|
value: Value
|
||||||
@@ -58,7 +59,7 @@ export default class extends Tag {
|
|||||||
for (const branch of this.branches) {
|
for (const branch of this.branches) {
|
||||||
for (const valueToken of branch.values) {
|
for (const valueToken of branch.values) {
|
||||||
const value = yield evalToken(valueToken, ctx, ctx.opts.lenientIf)
|
const value = yield evalToken(valueToken, ctx, ctx.opts.lenientIf)
|
||||||
if (target === value) {
|
if (equals(target, value)) {
|
||||||
yield r.renderTemplates(branch.templates, ctx, emitter)
|
yield r.renderTemplates(branch.templates, ctx, emitter)
|
||||||
branchHit = true
|
branchHit = true
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -119,4 +119,17 @@ describe('tags/case', function () {
|
|||||||
'{%- endcase %}', {})
|
'{%- endcase %}', {})
|
||||||
expect(result).toEqual('show this')
|
expect(result).toEqual('show this')
|
||||||
})
|
})
|
||||||
|
it('should apply value equal for arrays', () => {
|
||||||
|
const engine = new Liquid()
|
||||||
|
const result = engine.parseAndRenderSync(`
|
||||||
|
{%- assign x = "a,b,c" | split: "," %}
|
||||||
|
{%- assign y = "a,b,c" | split: "," %}
|
||||||
|
{% case x %}{% when y %}TRUE{% else %}FALSE{% endcase %}
|
||||||
|
{% if x == y %}TRUE{% else %}FALSE{% endif %}
|
||||||
|
`)
|
||||||
|
expect(result).toEqual(`
|
||||||
|
TRUE
|
||||||
|
TRUE
|
||||||
|
`)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user