Remove toString-based minification check (#10673)
Dan Abramov committed
Sep 11, 2017 at 19:22 UTC
61282d38d5172e5b2c4f1a29bb20d55ba4d727dc
1 file changed
-44
packages/react/index.js
-44
@@ -1,50 +1,6 @@
1
'use strict';
2
3
-function testMinificationUsedDCE() {
4
- if (process.env.NODE_ENV === 'development') {
5
- // We expect this method only to be called in production.
6
- throw new Error('This is unreachable');
7
- }
8
- try {
9
- // use scoped variable for our initial test, in case
10
- // 'top-level' mangling is not enabled.
11
- var source = testMinificationUsedDCE.toString();
12
- var longVariableName = true;
13
- if (longVariableName && source.match(/longVariableName/g).length === 3) {
14
- // We are not minified.
15
- // This might be a Node environment where DCE is not expected anyway.
16
- return;
17
- }
18
- if (source.match(/toString/g).length !== 2) {
19
- // We always look for two matches:
20
- // The actual occurence and then the call to 'match'
21
- //
22
- // We know for a fact the above line exists so there should be 2
23
- // matches.
24
- // Therefore the browser gave us invalid source.
25
- return;
26
- }
27
- if (source.match(/unreachable/g).length === 2) {
28
- // We always look for two matches:
29
- // The actual occurence and then the call to 'match'
30
-
31
- // Dead code elimination would have stripped that branch
32
- // because it is impossible to reach in production.
33
- setTimeout(function() {
34
- // Ensure it gets reported to production logging
35
- throw new Error(
36
- 'React is running in production mode, but dead code ' +
37
- 'elimination has not been applied. Read how to correctly ' +
38
- 'configure React for production: ' +
39
- 'https://fburl.com/react-perf-use-the-production-build'
40
- );
41
- });
42
- }
43
- } catch (e) {}
44
-}
45
-
3
if (process.env.NODE_ENV === 'production') {
47
- testMinificationUsedDCE();
4
module.exports = require('./cjs/react.production.min.js');
5
} else {
6
module.exports = require('./cjs/react.development.js');