Shopify / javascript

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

Remove hanging `return void 0` from if alternates #82

Closed GoodForOneFare closed 8 years ago

GoodForOneFare commented 8 years ago

The decaf process generates 54 functions that end with a pointless else block:

foo = () => {
  if (bar != null) {
    return bar(true);
  } else { // REMOVE THIS ELSE.
    return void 0;
  }
}

These should be removed.

GoodForOneFare commented 8 years ago

Note that decaf also generates similar non-returning alternates that may be cleaned up as part of this transform (or raise a separate issue if another transform is a better idea):

  _doRequest() {
    let ref;

    if ((ref = this.operation) != null) {
      ref.abort();
    } else { // DELETE THIS ELSE.
      void 0;
    }

    this.operation = $.ajax({
      url: this.url,
    });
  }
lemonmade commented 8 years ago

I don't understand when CoffeeScript/ decaf decides to process things into conditional blocks versus ternaries :( I think these are probably separate transforms, but we can leave it as a single issue.

andyfangaf commented 8 years ago

Fixed in https://github.com/Shopify/javascript/pull/91