Skip to content

Commit

Permalink
feat: add support for three-way-comparison (spaceship) operator
Browse files Browse the repository at this point in the history
Close GH-52
  • Loading branch information
zackad committed Aug 26, 2024
1 parent b754eb6 commit e5e9c54
Show file tree
Hide file tree
Showing 6 changed files with 17 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 three-way-comparion operator (spaceship operator)

### Bugfixes
- Fix handling mapping that omit key part
- Fix documentation about `twigAlwaysBreakObjects` option to reflect actual default value
Expand Down
6 changes: 6 additions & 0 deletions src/melody/melody-extension-core/operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ export const BinaryGreaterThanOrEqualExpression = createBinaryOperatorNode({
precedence: 20,
associativity: LEFT
});
export const BinaryThreeWayComparisonExpression = createBinaryOperatorNode({
text: "<=>",
type: "BinaryThreeWayComparisonExpression",
precedence: 20,
associativity: LEFT
});

export const BinaryNotInExpression = createBinaryOperatorNode({
text: "not in",
Expand Down
3 changes: 3 additions & 0 deletions tests/Expressions/__snapshots__/arrowFunctions.snap.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ Arrow function with multiple arguments:

Arrow function with multiple arguments and second filter argument:
{{ numbers|reduce((carry, v, k) => carry + v * k, 10) }}

Arrow function with three-way-comparison (spaceship) operator
{{ array|sort((a, b) => a.value <=> b.value) }}
1 change: 1 addition & 0 deletions tests/Expressions/__snapshots__/operators.snap.twig
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
{{ a ? b }}
{{ a ? : b }}
{{ a ?? b }}
{{ a <=> b }}

{{ a is divisible by(b) }}
{{ a is not divisible by(b) }}
Expand Down
3 changes: 3 additions & 0 deletions tests/Expressions/arrowFunctions.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ Arrow function with multiple arguments:

Arrow function with multiple arguments and second filter argument:
{{ numbers|reduce((carry, v, k) => carry + v * k, 10) }}

Arrow function with three-way-comparison (spaceship) operator
{{ array|sort((a, b) => a.value <=> b.value) }}
1 change: 1 addition & 0 deletions tests/Expressions/operators.twig
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
{{ a ? b }}
{{ a ?: b }}
{{ a ?? b }}
{{ a <=> b }}

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

0 comments on commit e5e9c54

Please sign in to comment.