Skip to content

Commit 1f81225

Browse files
Extend filterCallbackFunction expression with extra (optional) arguments.
1 parent 5a7d299 commit 1f81225

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/twig.expression.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,17 +487,19 @@ module.exports = function (Twig) {
487487
* ((params) => body)
488488
*/
489489
type: Twig.expression.type.filterCallbackFunction,
490-
regex: /^\(\(*([\w\s]+(?:,\s?[\w\s]+)*)\)*\s*=>\s*[{}]*(.*)[}]*\)/,
490+
regex: /^\(\(*\s*([a-zA-Z_]\w*\s*(?:\s?,\s?[a-zA-Z_]\w*\s*)*)\)*\s*=>\s*([^,]*),*\s*(\w*(?:,\s?\w*)*)\s*\)/,
491491
next: Twig.expression.set.expressions.concat([Twig.expression.type.subexpression.end]),
492492
compile(token, stack, output) {
493493
const filter = output.pop();
494494
if (filter.type !== Twig.expression.type.filter) {
495495
throw new Twig.Error('Expected filter before filterCallbackFunction.');
496496
}
497497

498-
filter.params = token;
499498
token.params = token.match[1].trim();
500499
token.body = '{{ ' + token.match[2] + ' }}';
500+
token.args = token.match[3].trim();
501+
filter.params = token;
502+
501503
output.push(filter);
502504
},
503505
parse(token, stack) {

0 commit comments

Comments
 (0)