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

Remove IIFE wrappers from dev invariant checks #16963

Merged
merged 1 commit into from
Sep 30, 2019

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Sep 30, 2019

The error transform works by replacing calls to invariant with an if statement.

Since we're replacing a call expression with a statement, Babel wraps the new statement in an immediately-invoked function expression (IIFE). This wrapper is unnecessary in practice because our invariant calls are always part of their own expression statement.

In the production bundle, the function wrappers are removed by Closure. But they remain in the development bundles.

This commit updates the transform to confirm that an invariant call expression's parent node is an expression statement. (If not, it throws a transform error.)

Then, it replaces the expression statement instead of the expression itself, effectively removing the extraneous IIFE wrapper.

The error transform works by replacing calls to `invariant` with
an `if` statement.

Since we're replacing a call expression with a statement, Babel wraps
the new statement in an immediately-invoked function expression (IIFE).
This wrapper is unnecessary in practice because our `invariant` calls
are always part of their own expression statement.

In the production bundle, the function wrappers are removed by Closure.
But they remain in the development bundles.

This commit updates the transform to confirm that an `invariant` call
expression's parent node is an expression statement. (If not, it throws
a transform error.)

Then, it replaces the expression statement instead of the expression
itself, effectively removing the extraneous IIFE wrapper.
@sizebot
Copy link

sizebot commented Sep 30, 2019

Details of bundled changes.

Comparing: d3622d0...8307966

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.profiling.min.js -0.0% -0.0% 121.05 KB 121.04 KB 38.16 KB 38.16 KB NODE_PROFILING
react-dom-server.browser.development.js -0.8% -0.4% 142.07 KB 140.87 KB 37.05 KB 36.91 KB UMD_DEV
ReactDOM-dev.js -0.6% -0.3% 981.76 KB 976.05 KB 217.07 KB 216.5 KB FB_WWW_DEV
react-dom-test-utils.development.js -0.7% -0.3% 57.37 KB 56.94 KB 15.76 KB 15.7 KB UMD_DEV
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.78 KB 3.78 KB 1.53 KB 1.53 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% -0.0% 11.19 KB 11.19 KB 4.16 KB 4.16 KB UMD_PROD
ReactDOMUnstableNativeDependencies-dev.js -0.5% -0.2% 58.97 KB 58.7 KB 14.89 KB 14.86 KB FB_WWW_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.1% 1.2 KB 1.2 KB 701 B 702 B UMD_PROD
react-dom-test-utils.development.js -0.8% -0.3% 55.64 KB 55.21 KB 15.43 KB 15.37 KB NODE_DEV
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.61 KB 3.61 KB 1.48 KB 1.48 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% -0.0% 10.96 KB 10.96 KB 4.09 KB 4.09 KB NODE_PROD
react-dom.development.js -0.5% -0.2% 956.36 KB 951.58 KB 215.89 KB 215.41 KB UMD_DEV
react-dom.production.min.js 0.0% 0.0% 117.27 KB 117.29 KB 37.82 KB 37.82 KB UMD_PROD
ReactTestUtils-dev.js -1.0% -0.4% 52.55 KB 52.03 KB 14.08 KB 14.02 KB FB_WWW_DEV
react-dom.profiling.min.js 0.0% 0.0% 120.81 KB 120.81 KB 38.84 KB 38.85 KB UMD_PROFILING
react-dom.development.js -0.5% -0.2% 950.41 KB 945.63 KB 214.35 KB 213.86 KB NODE_DEV
react-dom-server.node.development.js -0.8% -0.4% 139.02 KB 137.88 KB 36.29 KB 36.15 KB NODE_DEV
react-dom.production.min.js 0.0% 🔺+0.1% 117.36 KB 117.4 KB 37.09 KB 37.13 KB NODE_PROD
ReactDOM-prod.js 🔺+1.0% 🔺+0.8% 396.21 KB 400.27 KB 72.45 KB 73.02 KB FB_WWW_PROD
ReactDOM-profiling.js -0.0% -0.0% 401.1 KB 401.08 KB 73.55 KB 73.53 KB FB_WWW_PROFILING
react-dom-server.browser.development.js -0.9% -0.4% 138 KB 136.8 KB 36.06 KB 35.92 KB NODE_DEV
react-dom-server.browser.production.min.js 0.0% 0.0% 19.79 KB 19.79 KB 7.36 KB 7.36 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js -0.3% -0.1% 60.73 KB 60.53 KB 15.85 KB 15.84 KB UMD_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 🔺+0.1% 10.74 KB 10.74 KB 3.67 KB 3.67 KB UMD_PROD
ReactDOMServer-dev.js -1.0% -0.4% 142.15 KB 140.69 KB 35.62 KB 35.48 KB FB_WWW_DEV
react-dom-unstable-native-dependencies.development.js -0.3% -0.1% 60.4 KB 60.2 KB 15.73 KB 15.71 KB NODE_DEV
react-dom-unstable-fizz.node.development.js 0.0% +0.1% 3.87 KB 3.87 KB 1.51 KB 1.51 KB NODE_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 🔺+0.1% 10.49 KB 10.49 KB 3.57 KB 3.57 KB NODE_PROD
react-dom-unstable-fizz.node.production.min.js 0.0% 🔺+0.1% 1.1 KB 1.1 KB 667 B 668 B NODE_PROD

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js -0.5% -0.2% 672.49 KB 669.15 KB 145.82 KB 145.49 KB UMD_DEV
react-art.production.min.js 0.0% -0.0% 103.87 KB 103.87 KB 31.62 KB 31.61 KB UMD_PROD
react-art.development.js -0.6% -0.2% 603.12 KB 599.78 KB 128.4 KB 128.08 KB NODE_DEV
react-art.production.min.js 0.0% 🔺+0.1% 68.88 KB 68.89 KB 20.87 KB 20.89 KB NODE_PROD
ReactART-dev.js -0.6% -0.3% 618.49 KB 614.49 KB 128.29 KB 127.91 KB FB_WWW_DEV
ReactART-prod.js 🔺+0.4% 🔺+0.2% 230.34 KB 231.33 KB 38.98 KB 39.07 KB FB_WWW_PROD

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-prod.js 🔺+0.1% 0.0% 275.88 KB 276.18 KB 47.2 KB 47.21 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js 0.0% 0.0% 285.59 KB 285.72 KB 48.9 KB 48.92 KB RN_OSS_PROFILING
ReactFabric-prod.js -0.1% -0.1% 267.63 KB 267.26 KB 45.81 KB 45.78 KB RN_OSS_PROD
ReactFabric-profiling.js 0.0% 0.0% 277.77 KB 277.9 KB 47.61 KB 47.63 KB RN_OSS_PROFILING
ReactFabric-dev.js -0.6% -0.3% 757.88 KB 753.38 KB 159.87 KB 159.43 KB RN_FB_DEV
ReactFabric-prod.js -0.1% -0.1% 267.63 KB 267.26 KB 45.82 KB 45.79 KB RN_FB_PROD
ReactNativeRenderer-dev.js -0.6% -0.3% 751.79 KB 747.33 KB 158.83 KB 158.4 KB RN_OSS_DEV
ReactFabric-profiling.js 0.0% 0.0% 277.77 KB 277.9 KB 47.62 KB 47.64 KB RN_FB_PROFILING
ReactNativeRenderer-dev.js -0.6% -0.3% 751.95 KB 747.49 KB 158.9 KB 158.47 KB RN_FB_DEV
ReactNativeRenderer-prod.js 🔺+0.1% 0.0% 275.87 KB 276.18 KB 47.21 KB 47.21 KB RN_FB_PROD
ReactNativeRenderer-profiling.js 0.0% 0.0% 285.58 KB 285.71 KB 48.91 KB 48.92 KB RN_FB_PROFILING
ReactFabric-dev.js -0.6% -0.3% 757.71 KB 753.21 KB 159.79 KB 159.34 KB RN_OSS_DEV

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactTestRenderer-dev.js -0.6% -0.3% 629.84 KB 625.77 KB 130.73 KB 130.34 KB FB_WWW_DEV
react-test-renderer-shallow.development.js -0.8% -0.3% 39.28 KB 38.96 KB 9.97 KB 9.94 KB UMD_DEV
react-test-renderer-shallow.production.min.js 0.0% 0.0% 11.45 KB 11.45 KB 3.54 KB 3.54 KB UMD_PROD
react-test-renderer-shallow.development.js -1.0% -0.4% 33.24 KB 32.92 KB 8.51 KB 8.47 KB NODE_DEV
react-test-renderer-shallow.production.min.js 0.0% 🔺+0.1% 11.6 KB 11.6 KB 3.64 KB 3.64 KB NODE_PROD
react-test-renderer.development.js -0.5% -0.3% 616.69 KB 613.34 KB 131.26 KB 130.92 KB UMD_DEV
react-test-renderer.production.min.js 0.0% 🔺+0.1% 70.8 KB 70.82 KB 21.66 KB 21.68 KB UMD_PROD
ReactShallowRenderer-dev.js -1.3% -0.6% 34.5 KB 34.04 KB 8.43 KB 8.38 KB FB_WWW_DEV
react-test-renderer.development.js -0.5% -0.3% 611.96 KB 608.61 KB 130.08 KB 129.73 KB NODE_DEV
react-test-renderer.production.min.js 0.0% 0.0% 70.51 KB 70.52 KB 21.37 KB 21.37 KB NODE_PROD

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js -0.6% -0.3% 603.66 KB 600.32 KB 127.56 KB 127.22 KB NODE_DEV
react-reconciler.production.min.js 0.0% 🔺+0.1% 71.6 KB 71.63 KB 21.2 KB 21.21 KB NODE_PROD
react-reconciler-reflection.development.js -1.2% -0.6% 20 KB 19.76 KB 6.43 KB 6.39 KB NODE_DEV
react-reconciler-reflection.production.min.js 0.0% 🔺+0.1% 2.88 KB 2.88 KB 1.25 KB 1.25 KB NODE_PROD
react-reconciler-persistent.development.js -0.6% -0.3% 600.84 KB 597.49 KB 126.37 KB 126.03 KB NODE_DEV
react-reconciler-persistent.production.min.js 0.0% 🔺+0.1% 71.61 KB 71.64 KB 21.21 KB 21.22 KB NODE_PROD

Generated by 🚫 dangerJS against 8307966

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants