Skip to content

Commit

Permalink
fix: default to precedence 1 for custom operators
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonEtco authored and harttle committed Feb 5, 2021
1 parent dce75a1 commit 20f559e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/tokens/operator-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
7 changes: 7 additions & 0 deletions test/integration/liquid/operators-option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})

0 comments on commit 20f559e

Please sign in to comment.