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

A lethal combo. #420

Closed
WebReflection opened this issue Feb 11, 2017 · 2 comments
Closed

A lethal combo. #420

WebReflection opened this issue Feb 11, 2017 · 2 comments
Labels
bug Confirmed bug has PR Has an open PR that fixes this issue

Comments

@WebReflection
Copy link

WebReflection commented Feb 11, 2017

Apologies for the fancy bug title but I couldn't think of any more descriptive one.

I've managed to isolate a series of issues in a single snippet that fails with babili 0.0.11

const that = (...args) => {
  let i = args.length;
  if (!i) return;
  else {
    const info = {args};
    while (false);
    return info;
  }
};

Despite being useless, it's valid JS syntax that's part of the real-world logic I am using.

How to make above snippet not to fail?

Please note the following is a list of OR conditions.
Each point itself will change the result, making babili happy.

  • use do ; while(false); instead
  • avoid the creation of the info constant and return directly return {args};
  • keep the info but return {args}; instead
  • drop the else and use if (i) { instead
  • don't access args.length and let i = 1;
  • drop the while(false) line
  • use if (false); instead of while (false);

Thanks in advance for figuring out how come such little snippets can produce so many failures/not-failures scenarios.

@boopathi
Copy link
Member

Nice example.

With #408, the output is

const that = (...a) => {
  let b = a.length;
  if (!b) return;

  return { args: a };
};

but still, it should be

const that = (...a) => {
  let b = a.length;
  if (b) return { args: a };
};

Ultimately, it could be

const that = (...a) => a.length ? {args: a} : void 0;

But, because we treat a.length to possibly be a side-effecty getter and not computing side-effects between defn of b and usage of b (yet) (#221) , we are not able to safely replace it.

@WebReflection
Copy link
Author

Please also keep in mind in my case I had to create a new variable in order to circumvent the failure.

@boopathi boopathi added the has PR Has an open PR that fixes this issue label Feb 20, 2017
@boopathi boopathi added this to Requests in Few more optimizations Apr 12, 2017
@boopathi boopathi moved this from Requests to Closed in Few more optimizations May 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug has PR Has an open PR that fixes this issue
Projects
Development

No branches or pull requests

2 participants