From b6d707a2cd959e1668494bf67d05f30e9eb5b469 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Wed, 2 Aug 2017 13:37:16 -0700 Subject: [PATCH] Wrap contents of if-DEV condition in an IIFE This avoids strict mode conflicts for certain browsers wrt functions being defined within an if-block. Also re-added the if-DEV condition for the ReactNative renderer since it was removed for this reason. --- scripts/rollup/build.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/rollup/build.js b/scripts/rollup/build.js index 33662d9caaf9..70891ebc18f2 100644 --- a/scripts/rollup/build.js +++ b/scripts/rollup/build.js @@ -82,22 +82,24 @@ function getBanner(bundleType, hasteName, filename) { return Header.getUMDHeader(filename, reactVersion); // CommonJS DEV bundle is guarded to help weak dead code elimination. case NODE_DEV: - return `'use strict';\n\n\nif (process.env.NODE_ENV !== "production") {\n`; + // Wrap the contents of the if-DEV check with an IIFE. + // Block-level function definitions can cause problems for strict mode. + return `'use strict';\n\n\nif (process.env.NODE_ENV !== "production") {\n(function() {\n`; case NODE_PROD: return ''; // All FB and RN bundles need Haste headers. - // FB DEV bundles are also guarded; - // RN bundles are not b'c of an older JSC packaged for Android. - // See github.com/facebook/react-native/issues/14995 + // DEV bundle is guarded to help weak dead code elimination. case FB_DEV: case FB_PROD: case RN_DEV: case RN_PROD: const isDev = bundleType === FB_DEV || bundleType === RN_DEV; const hasteFinalName = hasteName + (isDev ? '-dev' : '-prod'); + // Wrap the contents of the if-DEV check with an IIFE. + // Block-level function definitions can cause problems for strict mode. return ( Header.getProvidesHeader(hasteFinalName) + - (bundleType === FB_DEV ? `\n\n'use strict';\n\n\nif (__DEV__) {\n` : '') + (isDev ? `\n\n'use strict';\n\n\nif (__DEV__) {\n(function() {\n` : '') ); default: throw new Error('Unknown type.'); @@ -110,7 +112,8 @@ function getFooter(bundleType) { // Non-UMD DEV bundles need conditions to help weak dead code elimination. case NODE_DEV: case FB_DEV: - return '\n}\n'; + case RN_DEV: + return '\n})();\n}\n'; default: return ''; }