@@ -20,6 +20,12 @@ const validateBoolOption = (name, value, defaultValue) => {
20
20
return value ;
21
21
} ;
22
22
23
+ // @babel /preset-env provides good validations and error messages for bogus
24
+ // options. Here we are simply falling back to default if the overrides are
25
+ // falsey.
26
+ const validatePresetEnvOptions = ( options , defaultOptions ) =>
27
+ options || defaultOptions ;
28
+
23
29
module . exports = function ( api , opts ) {
24
30
if ( ! opts ) {
25
31
opts = { } ;
@@ -37,6 +43,11 @@ module.exports = function(api, opts) {
37
43
var isEnvTest = env === 'test' ;
38
44
39
45
var areHelpersEnabled = validateBoolOption ( 'helpers' , opts . helpers , false ) ;
46
+ var isRegeneratorEnabled = validateBoolOption (
47
+ 'regenerator' ,
48
+ opts . regenerator ,
49
+ true
50
+ ) ;
40
51
var useAbsoluteRuntime = validateBoolOption (
41
52
'absoluteRuntime' ,
42
53
opts . absoluteRuntime ,
@@ -50,6 +61,13 @@ module.exports = function(api, opts) {
50
61
) ;
51
62
}
52
63
64
+ // We allow for separate preset overrides for production/development and test.
65
+ var presetEnvOverrides = validatePresetEnvOptions ( opts . presetEnv , undefined ) ;
66
+ var presetEnvTestOverrides = validatePresetEnvOptions (
67
+ opts . presetEnvTest ,
68
+ undefined
69
+ ) ;
70
+
53
71
if ( ! isEnvDevelopment && ! isEnvProduction && ! isEnvTest ) {
54
72
throw new Error (
55
73
'Using `babel-preset-react-app` requires that you specify `NODE_ENV` or ' +
@@ -70,36 +88,42 @@ module.exports = function(api, opts) {
70
88
isEnvTest && [
71
89
// ES features necessary for user's Node version
72
90
require ( '@babel/preset-env' ) . default ,
73
- {
74
- targets : {
75
- node : 'current' ,
91
+ Object . assign (
92
+ {
93
+ targets : {
94
+ node : 'current' ,
95
+ } ,
96
+ // Do not transform modules to CJS
97
+ modules : false ,
98
+ // Exclude transforms that make all code slower
99
+ exclude : [ 'transform-typeof-symbol' ] ,
76
100
} ,
77
- // Do not transform modules to CJS
78
- modules : false ,
79
- // Exclude transforms that make all code slower
80
- exclude : [ 'transform-typeof-symbol' ] ,
81
- } ,
101
+ presetEnvTestOverrides
102
+ ) ,
82
103
] ,
83
104
( isEnvProduction || isEnvDevelopment ) && [
84
105
// Latest stable ECMAScript features
85
106
require ( '@babel/preset-env' ) . default ,
86
- {
87
- // We want Create React App to be IE 9 compatible until React itself
88
- // no longer works with IE 9
89
- targets : {
90
- ie : 9 ,
107
+ Object . assign (
108
+ {
109
+ // We want Create React App to be IE 9 compatible until React itself
110
+ // no longer works with IE 9
111
+ targets : {
112
+ ie : 9 ,
113
+ } ,
114
+ // Users cannot override this behavior because this Babel
115
+ // configuration is highly tuned for ES5 support
116
+ ignoreBrowserslistConfig : true ,
117
+ // If users import all core-js they're probably not concerned with
118
+ // bundle size. We shouldn't rely on magic to try and shrink it.
119
+ useBuiltIns : false ,
120
+ // Do not transform modules to CJS
121
+ modules : false ,
122
+ // Exclude transforms that make all code slower
123
+ exclude : [ 'transform-typeof-symbol' ] ,
91
124
} ,
92
- // Users cannot override this behavior because this Babel
93
- // configuration is highly tuned for ES5 support
94
- ignoreBrowserslistConfig : true ,
95
- // If users import all core-js they're probably not concerned with
96
- // bundle size. We shouldn't rely on magic to try and shrink it.
97
- useBuiltIns : false ,
98
- // Do not transform modules to CJS
99
- modules : false ,
100
- // Exclude transforms that make all code slower
101
- exclude : [ 'transform-typeof-symbol' ] ,
102
- } ,
125
+ presetEnvOverrides
126
+ ) ,
103
127
] ,
104
128
] . filter ( Boolean ) ,
105
129
plugins : [
@@ -110,7 +134,7 @@ module.exports = function(api, opts) {
110
134
{
111
135
corejs : false ,
112
136
helpers : areHelpersEnabled ,
113
- regenerator : true ,
137
+ regenerator : isRegeneratorEnabled ,
114
138
// https://babeljs.io/docs/en/babel-plugin-transform-runtime#useesmodules
115
139
// We should turn this on once the lowest version of Node LTS
116
140
// supports ES Modules.
0 commit comments