conditional operator not supported
See original GitHub issueGreat plugin. Thanks for writing. Are conditionals supposed to be supported?
This sample input
const countJumps = (list, index, step) => {
const value = list.get(index);
if (value === undefined) return step;
return countJumps(list.set(index, value + 1), index + value, step + 1);
};
const countJumpsTernary = (list, index, step) => {
const value = list.get(index);
return value === undefined
? step
: countJumps(list.set(index, value + 1), index + value, step + 1);
};
Produces this output
const countJumps = (list, index, step) => {
var _repeat = true;
var _list, _index, _step;
while (_repeat) {
_repeat = false;
const value = list.get(index);
if (value === undefined) return step;
_list = list.set(index, value + 1);
_index = index + value;
_step = step + 1;
list = _list;
index = _index;
step = _step;
_repeat = true;
continue;
}
};
const countJumpsTernary = (list, index, step) => {
const value = list.get(index);
return value === undefined ? step : countJumps(list.set(index, value + 1), index + value, step + 1);
};
Is this the expected behavior?
I’m using a fresh install of babel with "tailcall-optimization"
as my only plugin.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
java - ternary operator not working - Stack Overflow
The statements in the ternary operator need to be non-void. They need to return something. System.out.println(direction == 0 ? 'L' : 'R');.
Read more >Conditional (ternary) operator - JavaScript - MDN Web Docs
The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark ( ? ) ......
Read more >Nullish coalescing operator '??' - The Modern JavaScript Tutorial
The nullish coalescing operator isn't anything completely new. It's just a nice syntax to get the first “defined” value of the two.
Read more >Null-conditional operator `??` not allowed in generics unless ...
I encountered a curiosity. Given the following code: public int TheFunction (T a, T b) { T c; c = (a != null)...
Read more >Member access operators and expressions - Microsoft Learn
Null-conditional operators ?. and ?[] · If a evaluates to null , the result of a?.x or a?[x] is null . · If...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is awesome! Thanks!
I just tested with this:
and with some nested ternary expressions, which have all worked perfectly.
I notice that if I write it as an arrow function, it doesn’t get converted:
output:
while if I write an arrow function with
if
/else
, it does get converted:output:
Maybe an ordering issue in the transform?
Okay
1.0.12
is out. Please reopen this issue if it didn’t solve your problems.