diff --git a/src/tokens/operator-token.ts b/src/tokens/operator-token.ts index 31631f5620..fd1f93a1c9 100644 --- a/src/tokens/operator-token.ts +++ b/src/tokens/operator-token.ts @@ -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 } } diff --git a/test/integration/liquid/operators-option.ts b/test/integration/liquid/operators-option.ts index 90da4454e6..61093343a0 100644 --- a/test/integration/liquid/operators-option.ts +++ b/test/integration/liquid/operators-option.ts @@ -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') + }) })