Shopify / javascript

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

split-if-assignments should handle `else if` assignments #241

Closed GoodForOneFare closed 7 years ago

GoodForOneFare commented 7 years ago

Previously, else if (foo = bar) would throw an exception because the transform tried to move the assignment to before the else. That would've created an invalid AST.

This updates the logic to rewrite else if (foo = bar) {} to

else { 
  foo = bar; 
  if (foo) {

  }
}

Please review @lemonmade, @TylerHorth

GoodForOneFare commented 7 years ago

@lemonmade please take another look. I've cleaned up indentation, and used path.replace instead of direct node assignment.