Shopify / javascript

The home for all things JavaScript at Shopify.
MIT License
251 stars 38 forks source link

Improve ternaries that decaf to IIFEs #158

Closed lemonmade closed 8 years ago

lemonmade commented 8 years ago

From CoffeeScript, we get many of these gross IIFEs that are basically just ternary expressions:

(() => {
  if (foo) {
    return bar;
  } else {
    return baz;
  }
 })()

This pattern (IIFE, containing only a conditional, optionally with an else clause, where each branch of the conditional returns some value) should be transformed into something like foo ? bar : baz, assuming that the containing expression can take a ternary (return, assignment, etc should all be fine to accept a ternary in place of this expression).

andyfangaf commented 8 years ago

@justinthec do you want to try this out together?

justinthec commented 8 years ago

Do these not autoclose on PR merge?

GoodForOneFare commented 8 years ago

You need "Fixes #158" in the commit message: https://help.github.com/articles/closing-issues-via-commit-messages/