Skip to content

Conversation

@antoineveldhoven
Copy link
Contributor

Aiming to fix #853

Copilot assisted commit.

Copilot AI review requested due to automatic review settings November 17, 2025 14:34
Copilot finished reviewing on behalf of antoineveldhoven November 17, 2025 14:37
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes issue #853 by implementing proper handling of shorthand ternary operators (a ? b) within arrays and objects. The key improvement is using an explicit hasColon flag to differentiate between full ternary operators (a ? b : c) and shorthand ternary operators (a ? b), replacing the previous fragile approach that relied on checking for undefined values.

Key Changes:

  • Added hasColon flag tracking during expression compilation to distinguish full vs shorthand ternary operators
  • Refactored ternary operator parsing to explicitly handle shorthand and full ternary cases separately
  • Added test coverage for shorthand ternary operators in both objects and arrays

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
test/test.expressions.js Adds two new test cases for shorthand ternary operators inside objects and arrays
src/twig.expression.operator.js Updates operator.parse to accept token parameter and handle shorthand ternary logic explicitly based on hasColon flag
src/twig.expression.js Sets hasColon flag when : follows ? operator, and updates all operator.parse calls to pass token parameter

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Still problems with ternary operators in arrays.

1 participant