Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add support for three-way-comparison (spaceship) operator #53

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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