diff --git a/CHANGELOG.md b/CHANGELOG.md index d4d0a40..ed9312c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 2.4.1 (WIP) * Fix variables not being available for custom elements that require synchronous rendering +* Add support for `gte` and `lte` operator, which are aliases for `ge` and `le` ## 2.4.0 (2024-08-12) diff --git a/lib/expression/expression.js b/lib/expression/expression.js index 3ca0f55..e04c409 100644 --- a/lib/expression/expression.js +++ b/lib/expression/expression.js @@ -578,7 +578,7 @@ Expression.setMethod(function branch(name, pieces, fnc) { * * @author Jelle De Loecker * @since 1.2.9 - * @version 2.4.0 + * @version 2.4.1 * * @param {Array} tokens An array of tokens * @param {Object} vars An object of variables @@ -743,11 +743,11 @@ Expression.setMethod(function parseExpression(tokens, vars, call_chain) { } } else if (op == 'gt') { result = a > b; - } else if (op == 'ge') { + } else if (op == 'ge' || op == 'gte') { result = a >= b; } else if (op == 'lt') { result = a < b; - } else if (op == 'le') { + } else if (op == 'le' || op == 'lte') { result = a <= b; } else if (op == 'plus') { result = a + b; diff --git a/lib/parser/expressions_parser.js b/lib/parser/expressions_parser.js index c9533f9..90a0831 100644 --- a/lib/parser/expressions_parser.js +++ b/lib/parser/expressions_parser.js @@ -701,7 +701,7 @@ Eparser.setMethod(function getConditionalExpression(condition, level) { * * @author Jelle De Loecker * @since 1.2.9 - * @version 2.4.0 + * @version 2.4.1 * * @param {Number} level * @param {Symbol} state Are we in some kind of literal ({}, []) @@ -710,7 +710,7 @@ Eparser.setMethod(function getConditionalExpression(condition, level) { */ Eparser.setMethod(function getExpression(level, state) { - var pre_variable_index, + let pre_variable_index, variable_count = 0, variable, has_array, @@ -885,6 +885,8 @@ Eparser.setMethod(function getExpression(level, state) { case 'gt': case 'le': case 'ge': + case 'gte': + case 'lte': // Set the "keyword" property to true, // in case `previous_token` is used token.keyword = true; diff --git a/test/10-expressions.js b/test/10-expressions.js index 68a5b92..c33e3d4 100644 --- a/test/10-expressions.js +++ b/test/10-expressions.js @@ -69,6 +69,11 @@ describe('Expressions', function() { ['{% if my_obj.c eq "a" or my_obj.b eq "a" %}ERR{% elseif my_obj.a eq "a" and my_obj.b eq "b" %}AB{% else %}ERRTOO{% /if %}', 'AB'], ['{% if opt_str %}{{ opt_str }}{% /if %}', 'truthy'], ['{% if opt_empty %}OOPS{% /if %}', ''], + ['{% if Math.max(1, 2) gte 2 %}ALWAYSTRUE{% else %}WRONG{% / if %}', 'ALWAYSTRUE'], + ['{% if Math.max(0, 0) gte 2 %}WRONG{% else %}ALWAYSELSE{% / if %}', 'ALWAYSELSE'], + ['{% if (Math.max(0, 0) gte 2) %}WRONG{% else %}ALWAYSELSE{% / if %}', 'ALWAYSELSE'], + ['{% if (Math.max(0, 0)) gte 2 %}WRONG{% else %}ALWAYSELSE{% / if %}', 'ALWAYSELSE'], + ['{% if ((Math.max(0, 0) gte 2) %}WRONG{% else %}ALWAYSELSE{% / if %}', 'ALWAYSELSE'], // @TODO: ['{% if 1 emptyhtml %}WRONG{% /if %}', ''], ];