Skip to content

Commit

Permalink
feat: support for colon as separators between argument names and values
Browse files Browse the repository at this point in the history
  • Loading branch information
zackad committed Nov 11, 2024
1 parent 79e390f commit a2a1eb1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Features
- Add support for default value on macros
- Add support for test expression `instance of`, feature of [Craft CMS](https://craftcms.com/docs/5.x/reference/twig/tests.html#instance-of)
- Add support for colon as separators between argument names and values

### Internals
- Test with Node.js 22, current active lts version
Expand Down
3 changes: 2 additions & 1 deletion src/melody/melody-parser/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,8 @@ export default class Parser {
args.push(arrowFunction);
} else if (
tokens.test(Types.SYMBOL) &&
tokens.lat(1) === Types.ASSIGNMENT
(tokens.lat(1) === Types.ASSIGNMENT ||
tokens.lat(1) === Types.COLON)
) {
// OPTION 2: named filter argument(s)
const name = tokens.next();
Expand Down
4 changes: 4 additions & 0 deletions tests/Expressions/__snapshots__/callExpression.snap.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

{{ date('d/m/Y H:i', timezone = 'Europe/Paris') }}

{# Colon as separator for named argument, require twig 3.12 or later #}
{# Ref: https://github.com/zackad/prettier-plugin-twig/issues/74 #}
{{ date('d/m/Y H:i', timezone = 'Europe/Paris') }}

<span class="{{ css.partner }}">
<div>
<div>
Expand Down
4 changes: 4 additions & 0 deletions tests/Expressions/callExpression.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

{{ date('d/m/Y H:i', timezone="Europe/Paris") }}

{# Colon as separator for named argument, require twig 3.12 or later #}
{# Ref: https://github.com/zackad/prettier-plugin-twig/issues/74 #}
{{ date('d/m/Y H:i', timezone:"Europe/Paris") }}

<span class="{{ css.partner }}">
<div>
<div>
Expand Down

0 comments on commit a2a1eb1

Please sign in to comment.