Skip to content

Commit

Permalink
Always wrap UMD bundles in IIFEs
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Sep 28, 2017
1 parent 0cf8ca1 commit 6b47743
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions scripts/rollup/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,13 @@ function getHeaderSanityCheck(bundleType, hasteName) {

function getBanner(bundleType, hasteName, filename) {
switch (bundleType) {
// UMDs are not wrapped in conditions.
// UMDs are wrapped in IIFEs to avoid leaking globals.
case UMD_DEV:
case UMD_PROD:
return Header.getHeader(filename, reactVersion);
return (
Header.getHeader(filename, reactVersion) +
`'use strict';\n\n\n(function() {`
);
// CommonJS DEV bundle is guarded to help weak dead code elimination.
case NODE_DEV:
// Wrap the contents of the if-DEV check with an IIFE.
Expand Down Expand Up @@ -115,6 +118,10 @@ function getBanner(bundleType, hasteName, filename) {
function getFooter(bundleType) {
// Only need a footer if getBanner() has an opening brace.
switch (bundleType) {
// UMDs are wrapped in IIFEs to avoid leaking globals.
case UMD_DEV:
case UMD_PROD:
return '\n})();\n';
// Non-UMD DEV bundles need conditions to help weak dead code elimination.
case NODE_DEV:
case FB_DEV:
Expand Down

0 comments on commit 6b47743

Please sign in to comment.