Shopify / javascript

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

Add codemod for "flattening" iife global assignments #229

Closed nathanmarks closed 7 years ago

nathanmarks commented 8 years ago

Let me know if you have a better idea for a name...

This was created for preparing files in marketing_assets for some of the other transforms we have such as global-assign-to-default-export, etc...

It takes in your appGlobalIdentifiers (such as ShopifyMarketing) and lifts the code from inside the IIFE to the module root. It looks at the return statement inside the IIFE and assigns that + members of the returned object to the global identifier.

If the naming of the return identifier is inconsistent, it uses the property identifier found on the global object rather than the return identifier used inside the IIFE.

Every module in marketing_assets and other marketing properties are written using this pattern: https://github.com/Shopify/marketing_assets/blob/master/app/assets/javascripts/marketing_assets/modules/accordion.js

GoodForOneFare commented 8 years ago

Good stuff. Also needs:

GoodForOneFare commented 7 years ago

Reopened this PR in the standalone shopify-codemod repo: https://github.com/Shopify/shopify-codemod/pull/1. Closing here.