Skip to content

Commit

Permalink
Extend filterCallbackFunction expression with extra (optional) argume…
Browse files Browse the repository at this point in the history
…nts.
  • Loading branch information
antoineveldhoven committed Sep 27, 2023
1 parent 5a7d299 commit 1f81225
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/twig.expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,17 +487,19 @@ module.exports = function (Twig) {
* ((params) => body)
*/
type: Twig.expression.type.filterCallbackFunction,
regex: /^\(\(*([\w\s]+(?:,\s?[\w\s]+)*)\)*\s*=>\s*[{}]*(.*)[}]*\)/,
regex: /^\(\(*\s*([a-zA-Z_]\w*\s*(?:\s?,\s?[a-zA-Z_]\w*\s*)*)\)*\s*=>\s*([^,]*),*\s*(\w*(?:,\s?\w*)*)\s*\)/,
next: Twig.expression.set.expressions.concat([Twig.expression.type.subexpression.end]),
compile(token, stack, output) {
const filter = output.pop();
if (filter.type !== Twig.expression.type.filter) {
throw new Twig.Error('Expected filter before filterCallbackFunction.');
}

filter.params = token;
token.params = token.match[1].trim();
token.body = '{{ ' + token.match[2] + ' }}';
token.args = token.match[3].trim();
filter.params = token;

output.push(filter);
},
parse(token, stack) {
Expand Down

0 comments on commit 1f81225

Please sign in to comment.