mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
Wrap contents of if-DEV condition in an IIFE (#10361)
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.
This commit is contained in:
@@ -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 '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user