fix: default to precedence 1 for custom operators

This commit is contained in:
Jason Etcovitch
2021-02-05 23:57:36 +08:00
committed by Jun Yang
parent dce75a1a22
commit 20f559e545
2 changed files with 9 additions and 1 deletions
+2 -1
View File
@@ -25,6 +25,7 @@ export class OperatorToken extends Token {
this.operator = this.getText()
}
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 %}')
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')
})
})