mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
fix: default to precedence 1 for custom operators
This commit is contained in:
committed by
Jun Yang
parent
dce75a1a22
commit
20f559e545
@@ -25,6 +25,7 @@ export class OperatorToken extends Token {
|
|||||||
this.operator = this.getText()
|
this.operator = this.getText()
|
||||||
}
|
}
|
||||||
getPrecedence () {
|
getPrecedence () {
|
||||||
return precedence[this.getText()]
|
const key = this.getText()
|
||||||
|
return key in precedence ? precedence[key] : 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,4 +24,11 @@ describe('LiquidOptions#operators', function () {
|
|||||||
const second = await engine.parseAndRender('{% if "foo" isFooBar "foo" %}True{% else %}False{% endif %}')
|
const second = await engine.parseAndRender('{% if "foo" isFooBar "foo" %}True{% else %}False{% endif %}')
|
||||||
expect(second).to.equal('False')
|
expect(second).to.equal('False')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should evaluate a custom operator with the correct precedence', async function () {
|
||||||
|
const first = await engine.parseAndRender('{% if "foo" isFooBar "bar" or "foo" == "bar" %}True{% else %}False{% endif %}')
|
||||||
|
expect(first).to.equal('True')
|
||||||
|
const second = await engine.parseAndRender('{% if "foo" isFooBar "foo" or "foo" == "bar" %}True{% else %}False{% endif %}')
|
||||||
|
expect(second).to.equal('False')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user