Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default arguments transform is not equivalent #125

Closed
osuushi opened this issue May 19, 2016 · 2 comments
Closed

Default arguments transform is not equivalent #125

osuushi opened this issue May 19, 2016 · 2 comments

Comments

@osuushi
Copy link

osuushi commented May 19, 2016

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

@nene
Copy link
Collaborator

nene commented May 19, 2016

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.

nene added a commit that referenced this issue May 19, 2016
nene added a commit that referenced this issue May 19, 2016
@nene nene closed this as completed May 20, 2016
nene added a commit that referenced this issue May 20, 2016
Thinking a bit more over #125 I realized that Lebab really has
two kinds of transforms - safe ones that could be applied almost blindly,
and unsafe ones that should be carefully inspected.

I further wanted to emphasize the recommended way of using lebab
is to apply one transform at a time, so I completely removed the
first code example that applies all the transforms.
@nene
Copy link
Collaborator

nene commented May 20, 2016

Thanks for bringing this up.

I've restructured README to emphasize which transforms are "safe" and which are "unsafe", like this default-param transform.

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

No branches or pull requests

2 participants