warp
warp copied to clipboard
Add conditionals to literalExpressionEvaluator pass
Currently conditional expressions (ternary operation) are not being evaluated in literalExpressionEvaluator pass.
Conditionals have the form: condition ? thenBranch : elseBranch.
If the value of condition can be known during this pass, then the whole conditional expression can be replaced with the corresponding branch expression. In other words, if condition is evaluated to be true then :
condition ? thenBranch : elseBranch can be replaced by thenBranch
Similar thing happens in case it is evaluated to be false
In which file can I find this?
Passes are stored in src/passes so you can find that in src/passes/literalExpressionEvaluator/literalExpressionEvaluator.ts
Does the issue want us to replace if-else statements of expressions with conditional/ternary operators?
actually the changes have been made by someone else already. can close this issue.
Actually no, the issue hasn't been addressed yet.
This task requires the pass to visit Conditional nodes (which are the ones that represent ternary operations) and evaluate the condition expression. Since the condition expression should be a boolean value, its evaluation should return true, false or null (in case it wasn't possible to determine the value of the expression at this point). So, when the evaluation is different from null it is possible to replace the conditional node by the corresponding branch expression node.
I just updated the description to make it clearer