Skip to content

Commit 179d8e8

Browse files
feat: add opt-out for prestet-flow to work with @babel/preset-typescript
1 parent 0e51eef commit 179d8e8

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Diff for: packages/babel-preset-react-app/index.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66
*/
77
'use strict';
88

9+
const validateBoolOption = (name, value, defaultValue) => {
10+
if (typeof value === 'undefined') {
11+
value = defaultValue;
12+
}
13+
14+
if (typeof value !== 'boolean') {
15+
throw new Error(`Preset react-app: '${name}' option must be a boolean.`);
16+
}
17+
18+
return value;
19+
};
20+
921
module.exports = function(api, opts) {
1022
if (!opts) {
1123
opts = {};
@@ -21,6 +33,8 @@ module.exports = function(api, opts) {
2133
var isEnvDevelopment = env === 'development';
2234
var isEnvProduction = env === 'production';
2335
var isEnvTest = env === 'test';
36+
var isFlowEnabled = validateBoolOption('flow', opts.flow, true);
37+
2438
if (!isEnvDevelopment && !isEnvProduction && !isEnvTest) {
2539
throw new Error(
2640
'Using `babel-preset-react-app` requires that you specify `NODE_ENV` or ' +
@@ -64,7 +78,7 @@ module.exports = function(api, opts) {
6478
development: isEnvDevelopment || isEnvTest,
6579
},
6680
],
67-
[require('@babel/preset-flow').default],
81+
isFlowEnabled && [require('@babel/preset-flow').default],
6882
].filter(Boolean),
6983
plugins: [
7084
// Experimental macros support. Will be documented after it's had some time

0 commit comments

Comments
 (0)