Skip to content

Commit

Permalink
feat: add support for empty coalesce operator
Browse files Browse the repository at this point in the history
  • Loading branch information
zackad committed Dec 3, 2024
1 parent ec51ac4 commit 39607a4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## unreleased

### Features
- Add support for [empty coalesce operator](https://plugins.craftcms.com/empty-coalesce), a CraftCMS extension

### Internals
- Remove unused dependencies `resolve`

Expand Down
8 changes: 8 additions & 0 deletions src/melody/melody-extension-core/operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,14 @@ export const BinaryNullCoalesceExpression = createBinaryOperatorNode({
precedence: 300,
associativity: LEFT
});

// Ref: https://plugins.craftcms.com/empty-coalesce
export const BinaryEmptyCoalesceExpression = createBinaryOperatorNode({
text: "???",
type: "BinaryEmptyCoalesceExpression",
precedence: 300,
associativity: LEFT
});
//endregion

//region Test Expressions
Expand Down
4 changes: 4 additions & 0 deletions tests/Expressions/__snapshots__/operators.snap.twig
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
{{ a ?? b }}
{{ a <=> b }}

{# Empty coalesce operator, extension for CraftCMS #}
{# Ref: https://plugins.craftcms.com/empty-coalesce #}
{{ a ??? b }}

{{ a is divisible by(b) }}
{{ a is not divisible by(b) }}
{{ a is defined }}
Expand Down
4 changes: 4 additions & 0 deletions tests/Expressions/operators.twig
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
{{ a ?? b }}
{{ a <=> b }}

{# Empty coalesce operator, extension for CraftCMS #}
{# Ref: https://plugins.craftcms.com/empty-coalesce #}
{{ a ??? b }}

{{ a is divisible by(b) }}
{{ a is not divisible by(b) }}
{{ a is defined }}
Expand Down

0 comments on commit 39607a4

Please sign in to comment.