Repository navigation
Add support for ternary operator block - #11687
Open
Dmitriy Antipov (THEb0nny) wants to merge 4 commits into
Open
Dmitriy Antipov (THEb0nny) wants to merge 4 commits into
Dmitriy Antipov (THEb0nny) wants to merge 4 commits into
Conversation
Remove extra blank lines before the JavaScript and Python syntax examples.
Contributor
Author
BrickCode.for.EV3.-.Google.Chrome.2026-10-24.20-49-57-compressed.mp4 |
- Guard Blockly.Blocks lookup in initLogic to avoid potential TypeError if not registered - Unify and return the type of THEN and ELSE branches in returnType for logic_ternary - Make stripAsAny in compileTernary resilient to whitespace variations
Contributor
Author
|
Pushed an update with additional polish and robustness improvements:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds support for the ternary operator block (
logic_ternary) in MakeCode:if %1 then %2 else %3) with round reporter output shape.cond ? then : else) with operator-precedence-aware parenthesization for nested ternaries and higher-precedence parent expressions. Also cleans up unnecessaryas anycasts on relational operators (<,<=,>,>=) in the condition, while preserving necessary ones for literal equality checks (TS2367).a ? b : c) intologic_ternaryblocks.Booleanfor the condition input and unifies return types of bothTHENandELSEbranches in bothinfer()andreturnType()."ternaryBlock": trueinpxtarget.jsonunderruntime(placed in the Logic category with weight 30, matching the pattern ofbreakBlockin Loops). Even when the flag is disabled or absent, existing or decompiled ternary blocks still render and compile cleanly./blocks/logic/ternarywith interactive block examples and linked it from the Logic overview.Blockly.Blocksdefinitions ininitLogic().tests/decompile-test.Tests
testdecompiler: 166/166 passing.testlang: 59/59 passing.testtutorials: 25/25 passing."ternaryBlock": trueand"ternaryBlock": false.Screenshot