Default arguments transform is not equivalent
osuushi opened this issue · 2 comments
Example:
function example (x) {
x = x || 1;
return x;
}
example(0); // --> 1
But the transformed version:
function example(x=1) {
return x;
}
example(0); // --> 0
This same issue also applies to the transform for a = a ? a : 1
That's true. That's one of the several corner cases where Lebab goes wrong. It's simply following heuristics, and these aren't 100% reliable.
We could exclude these two patterns from the transform, but that would make the transform pretty useless - while x = x || 1
is quite common pattern, x = x === undefined ? x : 1
is pretty rare one.
I guess the best I can do is to link this issue from the main page, similarly to #107, to make people more aware of the potential pitfalls.
Thanks for bringing this up.
I've restructured README to emphasize which transforms are "safe" and which are "unsafe", like this default-param
transform.