Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap contents of if-DEV condition in an IIFE #10361

Merged
merged 1 commit into from
Aug 2, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions scripts/rollup/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand All @@ -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 '';
}
Expand Down