@react-native/babel-preset 0.73.9 → 0.73.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -4
- package/{dist → src}/configs/hmr.js +2 -2
- package/src/configs/lazy-imports.js +93 -0
- package/src/configs/main.js +215 -0
- package/{dist → src}/index.js +5 -3
- package/{dist → src}/passthrough-syntax-plugins.js +4 -3
- package/dist/configs/lazy-imports.js +0 -91
- package/dist/configs/main.js +0 -226
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native/babel-preset",
|
|
3
|
-
"version": "0.73.
|
|
3
|
+
"version": "0.73.11",
|
|
4
4
|
"description": "Babel preset for React Native applications",
|
|
5
5
|
"exports": {
|
|
6
|
-
".": "./
|
|
6
|
+
".": "./src/index.js",
|
|
7
7
|
"./package.json": "./package.json"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
|
-
"
|
|
10
|
+
"src"
|
|
11
11
|
],
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
@@ -57,7 +57,6 @@
|
|
|
57
57
|
"@babel/plugin-transform-typescript": "^7.5.0",
|
|
58
58
|
"@babel/plugin-transform-unicode-regex": "^7.0.0",
|
|
59
59
|
"@babel/template": "^7.0.0",
|
|
60
|
-
"@react-native/babel-plugin-codegen": "*",
|
|
61
60
|
"babel-plugin-transform-flow-enums": "^0.0.2",
|
|
62
61
|
"react-refresh": "^0.4.0"
|
|
63
62
|
},
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// This is the set of modules that React Native publicly exports and that we
|
|
12
|
+
// want to require lazily. Keep this list in sync with
|
|
13
|
+
// react-native/index.js (though having extra entries here is fairly harmless).
|
|
14
|
+
|
|
15
|
+
'use strict';
|
|
16
|
+
|
|
17
|
+
module.exports = new Set([
|
|
18
|
+
'AccessibilityInfo',
|
|
19
|
+
'ActivityIndicator',
|
|
20
|
+
'Button',
|
|
21
|
+
'DatePickerIOS',
|
|
22
|
+
'DrawerLayoutAndroid',
|
|
23
|
+
'FlatList',
|
|
24
|
+
'Image',
|
|
25
|
+
'ImageBackground',
|
|
26
|
+
'InputAccessoryView',
|
|
27
|
+
'KeyboardAvoidingView',
|
|
28
|
+
'Modal',
|
|
29
|
+
'Pressable',
|
|
30
|
+
'ProgressBarAndroid',
|
|
31
|
+
'ProgressViewIOS',
|
|
32
|
+
'SafeAreaView',
|
|
33
|
+
'ScrollView',
|
|
34
|
+
'SectionList',
|
|
35
|
+
'Slider',
|
|
36
|
+
'Switch',
|
|
37
|
+
'RefreshControl',
|
|
38
|
+
'StatusBar',
|
|
39
|
+
'Text',
|
|
40
|
+
'TextInput',
|
|
41
|
+
'Touchable',
|
|
42
|
+
'TouchableHighlight',
|
|
43
|
+
'TouchableNativeFeedback',
|
|
44
|
+
'TouchableOpacity',
|
|
45
|
+
'TouchableWithoutFeedback',
|
|
46
|
+
'View',
|
|
47
|
+
'VirtualizedList',
|
|
48
|
+
'VirtualizedSectionList',
|
|
49
|
+
|
|
50
|
+
// APIs
|
|
51
|
+
'ActionSheetIOS',
|
|
52
|
+
'Alert',
|
|
53
|
+
'Animated',
|
|
54
|
+
'Appearance',
|
|
55
|
+
'AppRegistry',
|
|
56
|
+
'AppState',
|
|
57
|
+
'AsyncStorage',
|
|
58
|
+
'BackHandler',
|
|
59
|
+
'Clipboard',
|
|
60
|
+
'DeviceInfo',
|
|
61
|
+
'Dimensions',
|
|
62
|
+
'Easing',
|
|
63
|
+
'ReactNative',
|
|
64
|
+
'I18nManager',
|
|
65
|
+
'InteractionManager',
|
|
66
|
+
'Keyboard',
|
|
67
|
+
'LayoutAnimation',
|
|
68
|
+
'Linking',
|
|
69
|
+
'LogBox',
|
|
70
|
+
'NativeEventEmitter',
|
|
71
|
+
'PanResponder',
|
|
72
|
+
'PermissionsAndroid',
|
|
73
|
+
'PixelRatio',
|
|
74
|
+
'PushNotificationIOS',
|
|
75
|
+
'Settings',
|
|
76
|
+
'Share',
|
|
77
|
+
'StyleSheet',
|
|
78
|
+
'Systrace',
|
|
79
|
+
'ToastAndroid',
|
|
80
|
+
'TVEventHandler',
|
|
81
|
+
'UIManager',
|
|
82
|
+
'ReactNative',
|
|
83
|
+
'UTFSequence',
|
|
84
|
+
'Vibration',
|
|
85
|
+
|
|
86
|
+
// Plugins
|
|
87
|
+
'RCTDeviceEventEmitter',
|
|
88
|
+
'RCTNativeAppEventEmitter',
|
|
89
|
+
'NativeModules',
|
|
90
|
+
'Platform',
|
|
91
|
+
'processColor',
|
|
92
|
+
'requireNativeComponent',
|
|
93
|
+
]);
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const passthroughSyntaxPlugins = require('../passthrough-syntax-plugins');
|
|
14
|
+
const lazyImports = require('./lazy-imports');
|
|
15
|
+
|
|
16
|
+
function isTypeScriptSource(fileName) {
|
|
17
|
+
return !!fileName && fileName.endsWith('.ts');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function isTSXSource(fileName) {
|
|
21
|
+
return !!fileName && fileName.endsWith('.tsx');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const defaultPlugins = [
|
|
25
|
+
[require('@babel/plugin-syntax-flow')],
|
|
26
|
+
[require('babel-plugin-transform-flow-enums')],
|
|
27
|
+
[require('@babel/plugin-transform-block-scoping')],
|
|
28
|
+
[
|
|
29
|
+
require('@babel/plugin-proposal-class-properties'),
|
|
30
|
+
// use `this.foo = bar` instead of `this.defineProperty('foo', ...)`
|
|
31
|
+
{loose: true},
|
|
32
|
+
],
|
|
33
|
+
[require('@babel/plugin-syntax-dynamic-import')],
|
|
34
|
+
[require('@babel/plugin-syntax-export-default-from')],
|
|
35
|
+
...passthroughSyntaxPlugins,
|
|
36
|
+
[require('@babel/plugin-transform-unicode-regex')],
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
const getPreset = (src, options) => {
|
|
40
|
+
const transformProfile =
|
|
41
|
+
(options && options.unstable_transformProfile) || 'default';
|
|
42
|
+
const isHermesStable = transformProfile === 'hermes-stable';
|
|
43
|
+
const isHermesCanary = transformProfile === 'hermes-canary';
|
|
44
|
+
const isHermes = isHermesStable || isHermesCanary;
|
|
45
|
+
|
|
46
|
+
const isNull = src == null;
|
|
47
|
+
const hasClass = isNull || src.indexOf('class') !== -1;
|
|
48
|
+
|
|
49
|
+
const extraPlugins = [];
|
|
50
|
+
if (!options.useTransformReactJSXExperimental) {
|
|
51
|
+
extraPlugins.push([
|
|
52
|
+
require('@babel/plugin-transform-react-jsx'),
|
|
53
|
+
{runtime: 'automatic'},
|
|
54
|
+
]);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!options || !options.disableImportExportTransform) {
|
|
58
|
+
extraPlugins.push(
|
|
59
|
+
[require('@babel/plugin-proposal-export-default-from')],
|
|
60
|
+
[
|
|
61
|
+
require('@babel/plugin-transform-modules-commonjs'),
|
|
62
|
+
{
|
|
63
|
+
strict: false,
|
|
64
|
+
strictMode: false, // prevent "use strict" injections
|
|
65
|
+
lazy:
|
|
66
|
+
options && options.lazyImportExportTransform != null
|
|
67
|
+
? options.lazyImportExportTransform
|
|
68
|
+
: importSpecifier => lazyImports.has(importSpecifier),
|
|
69
|
+
allowTopLevelThis: true, // dont rewrite global `this` -> `undefined`
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (hasClass) {
|
|
76
|
+
extraPlugins.push([require('@babel/plugin-transform-classes')]);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// TODO(gaearon): put this back into '=>' indexOf bailout
|
|
80
|
+
// and patch react-refresh to not depend on this transform.
|
|
81
|
+
extraPlugins.push([require('@babel/plugin-transform-arrow-functions')]);
|
|
82
|
+
|
|
83
|
+
if (!isHermes) {
|
|
84
|
+
extraPlugins.push([require('@babel/plugin-transform-computed-properties')]);
|
|
85
|
+
extraPlugins.push([require('@babel/plugin-transform-parameters')]);
|
|
86
|
+
extraPlugins.push([
|
|
87
|
+
require('@babel/plugin-transform-shorthand-properties'),
|
|
88
|
+
]);
|
|
89
|
+
extraPlugins.push([
|
|
90
|
+
require('@babel/plugin-proposal-optional-catch-binding'),
|
|
91
|
+
]);
|
|
92
|
+
extraPlugins.push([require('@babel/plugin-transform-function-name')]);
|
|
93
|
+
extraPlugins.push([require('@babel/plugin-transform-literals')]);
|
|
94
|
+
extraPlugins.push([require('@babel/plugin-proposal-numeric-separator')]);
|
|
95
|
+
extraPlugins.push([require('@babel/plugin-transform-sticky-regex')]);
|
|
96
|
+
} else {
|
|
97
|
+
extraPlugins.push([
|
|
98
|
+
require('@babel/plugin-transform-named-capturing-groups-regex'),
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
if (!isHermesCanary) {
|
|
102
|
+
extraPlugins.push([
|
|
103
|
+
require('@babel/plugin-transform-destructuring'),
|
|
104
|
+
{useBuiltIns: true},
|
|
105
|
+
]);
|
|
106
|
+
}
|
|
107
|
+
if (!isHermes && (isNull || hasClass || src.indexOf('...') !== -1)) {
|
|
108
|
+
extraPlugins.push(
|
|
109
|
+
[require('@babel/plugin-transform-spread')],
|
|
110
|
+
[
|
|
111
|
+
require('@babel/plugin-proposal-object-rest-spread'),
|
|
112
|
+
// Assume no dependence on getters or evaluation order. See https://github.com/babel/babel/pull/11520
|
|
113
|
+
{loose: true, useBuiltIns: true},
|
|
114
|
+
],
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
if (isNull || src.indexOf('async') !== -1) {
|
|
118
|
+
extraPlugins.push([
|
|
119
|
+
require('@babel/plugin-proposal-async-generator-functions'),
|
|
120
|
+
]);
|
|
121
|
+
extraPlugins.push([require('@babel/plugin-transform-async-to-generator')]);
|
|
122
|
+
}
|
|
123
|
+
if (
|
|
124
|
+
isNull ||
|
|
125
|
+
src.indexOf('React.createClass') !== -1 ||
|
|
126
|
+
src.indexOf('createReactClass') !== -1
|
|
127
|
+
) {
|
|
128
|
+
extraPlugins.push([require('@babel/plugin-transform-react-display-name')]);
|
|
129
|
+
}
|
|
130
|
+
if (!isHermes && (isNull || src.indexOf('?.') !== -1)) {
|
|
131
|
+
extraPlugins.push([
|
|
132
|
+
require('@babel/plugin-proposal-optional-chaining'),
|
|
133
|
+
{loose: true},
|
|
134
|
+
]);
|
|
135
|
+
}
|
|
136
|
+
if (!isHermes && (isNull || src.indexOf('??') !== -1)) {
|
|
137
|
+
extraPlugins.push([
|
|
138
|
+
require('@babel/plugin-proposal-nullish-coalescing-operator'),
|
|
139
|
+
{loose: true},
|
|
140
|
+
]);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (options && options.dev && !options.useTransformReactJSXExperimental) {
|
|
144
|
+
extraPlugins.push([require('@babel/plugin-transform-react-jsx-source')]);
|
|
145
|
+
extraPlugins.push([require('@babel/plugin-transform-react-jsx-self')]);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (!options || options.enableBabelRuntime !== false) {
|
|
149
|
+
// Allows configuring a specific runtime version to optimize output
|
|
150
|
+
const isVersion = typeof options?.enableBabelRuntime === 'string';
|
|
151
|
+
|
|
152
|
+
extraPlugins.push([
|
|
153
|
+
require('@babel/plugin-transform-runtime'),
|
|
154
|
+
{
|
|
155
|
+
helpers: true,
|
|
156
|
+
regenerator: !isHermes,
|
|
157
|
+
...(isVersion && {version: options.enableBabelRuntime}),
|
|
158
|
+
},
|
|
159
|
+
]);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
comments: false,
|
|
164
|
+
compact: true,
|
|
165
|
+
overrides: [
|
|
166
|
+
// the flow strip types plugin must go BEFORE class properties!
|
|
167
|
+
// there'll be a test case that fails if you don't.
|
|
168
|
+
{
|
|
169
|
+
plugins: [require('@babel/plugin-transform-flow-strip-types')],
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
plugins: defaultPlugins,
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
test: isTypeScriptSource,
|
|
176
|
+
plugins: [
|
|
177
|
+
[
|
|
178
|
+
require('@babel/plugin-transform-typescript'),
|
|
179
|
+
{
|
|
180
|
+
isTSX: false,
|
|
181
|
+
allowNamespaces: true,
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
],
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
test: isTSXSource,
|
|
188
|
+
plugins: [
|
|
189
|
+
[
|
|
190
|
+
require('@babel/plugin-transform-typescript'),
|
|
191
|
+
{
|
|
192
|
+
isTSX: true,
|
|
193
|
+
allowNamespaces: true,
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
],
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
plugins: extraPlugins,
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
module.exports = options => {
|
|
206
|
+
if (options.withDevTools == null) {
|
|
207
|
+
const env = process.env.BABEL_ENV || process.env.NODE_ENV;
|
|
208
|
+
if (!env || env === 'development') {
|
|
209
|
+
return getPreset(null, {...options, dev: true});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return getPreset(null, options);
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
module.exports.getPreset = getPreset;
|
package/{dist → src}/index.js
RENAMED
|
@@ -8,11 +8,13 @@
|
|
|
8
8
|
* @oncall react_native
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const main = require('./configs/main');
|
|
12
14
|
|
|
13
|
-
const main = require("./configs/main");
|
|
14
15
|
module.exports = function (babel, options) {
|
|
15
16
|
return main(options);
|
|
16
17
|
};
|
|
18
|
+
|
|
17
19
|
module.exports.getPreset = main.getPreset;
|
|
18
|
-
module.exports.passthroughSyntaxPlugins = require(
|
|
20
|
+
module.exports.passthroughSyntaxPlugins = require('./passthrough-syntax-plugins');
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @oncall react_native
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
'use strict';
|
|
12
12
|
|
|
13
13
|
// This list of syntax plugins is used for two purposes:
|
|
14
14
|
// 1. Enabling experimental syntax features in the INPUT to the Metro Babel
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
// 2. Enabling these same features in parser passes that consume the OUTPUT of
|
|
17
17
|
// the Metro Babel transformer.
|
|
18
18
|
const passthroughSyntaxPlugins = [
|
|
19
|
-
[require(
|
|
20
|
-
[require(
|
|
19
|
+
[require('@babel/plugin-syntax-nullish-coalescing-operator')],
|
|
20
|
+
[require('@babel/plugin-syntax-optional-chaining')],
|
|
21
21
|
];
|
|
22
|
+
|
|
22
23
|
module.exports = passthroughSyntaxPlugins;
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
* @format
|
|
8
|
-
* @oncall react_native
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
// This is the set of modules that React Native publicly exports and that we
|
|
12
|
-
// want to require lazily. Keep this list in sync with
|
|
13
|
-
// react-native/index.js (though having extra entries here is fairly harmless).
|
|
14
|
-
|
|
15
|
-
"use strict";
|
|
16
|
-
|
|
17
|
-
module.exports = new Set([
|
|
18
|
-
"AccessibilityInfo",
|
|
19
|
-
"ActivityIndicator",
|
|
20
|
-
"Button",
|
|
21
|
-
"DatePickerIOS",
|
|
22
|
-
"DrawerLayoutAndroid",
|
|
23
|
-
"FlatList",
|
|
24
|
-
"Image",
|
|
25
|
-
"ImageBackground",
|
|
26
|
-
"InputAccessoryView",
|
|
27
|
-
"KeyboardAvoidingView",
|
|
28
|
-
"Modal",
|
|
29
|
-
"Pressable",
|
|
30
|
-
"ProgressBarAndroid",
|
|
31
|
-
"ProgressViewIOS",
|
|
32
|
-
"SafeAreaView",
|
|
33
|
-
"ScrollView",
|
|
34
|
-
"SectionList",
|
|
35
|
-
"Slider",
|
|
36
|
-
"Switch",
|
|
37
|
-
"RefreshControl",
|
|
38
|
-
"StatusBar",
|
|
39
|
-
"Text",
|
|
40
|
-
"TextInput",
|
|
41
|
-
"Touchable",
|
|
42
|
-
"TouchableHighlight",
|
|
43
|
-
"TouchableNativeFeedback",
|
|
44
|
-
"TouchableOpacity",
|
|
45
|
-
"TouchableWithoutFeedback",
|
|
46
|
-
"View",
|
|
47
|
-
"VirtualizedList",
|
|
48
|
-
"VirtualizedSectionList",
|
|
49
|
-
// APIs
|
|
50
|
-
"ActionSheetIOS",
|
|
51
|
-
"Alert",
|
|
52
|
-
"Animated",
|
|
53
|
-
"Appearance",
|
|
54
|
-
"AppRegistry",
|
|
55
|
-
"AppState",
|
|
56
|
-
"AsyncStorage",
|
|
57
|
-
"BackHandler",
|
|
58
|
-
"Clipboard",
|
|
59
|
-
"DeviceInfo",
|
|
60
|
-
"Dimensions",
|
|
61
|
-
"Easing",
|
|
62
|
-
"ReactNative",
|
|
63
|
-
"I18nManager",
|
|
64
|
-
"InteractionManager",
|
|
65
|
-
"Keyboard",
|
|
66
|
-
"LayoutAnimation",
|
|
67
|
-
"Linking",
|
|
68
|
-
"LogBox",
|
|
69
|
-
"NativeEventEmitter",
|
|
70
|
-
"PanResponder",
|
|
71
|
-
"PermissionsAndroid",
|
|
72
|
-
"PixelRatio",
|
|
73
|
-
"PushNotificationIOS",
|
|
74
|
-
"Settings",
|
|
75
|
-
"Share",
|
|
76
|
-
"StyleSheet",
|
|
77
|
-
"Systrace",
|
|
78
|
-
"ToastAndroid",
|
|
79
|
-
"TVEventHandler",
|
|
80
|
-
"UIManager",
|
|
81
|
-
"ReactNative",
|
|
82
|
-
"UTFSequence",
|
|
83
|
-
"Vibration",
|
|
84
|
-
// Plugins
|
|
85
|
-
"RCTDeviceEventEmitter",
|
|
86
|
-
"RCTNativeAppEventEmitter",
|
|
87
|
-
"NativeModules",
|
|
88
|
-
"Platform",
|
|
89
|
-
"processColor",
|
|
90
|
-
"requireNativeComponent",
|
|
91
|
-
]);
|
package/dist/configs/main.js
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
* @format
|
|
8
|
-
* @oncall react_native
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
"use strict";
|
|
12
|
-
|
|
13
|
-
const passthroughSyntaxPlugins = require("../passthrough-syntax-plugins");
|
|
14
|
-
const lazyImports = require("./lazy-imports");
|
|
15
|
-
function isTypeScriptSource(fileName) {
|
|
16
|
-
return !!fileName && fileName.endsWith(".ts");
|
|
17
|
-
}
|
|
18
|
-
function isTSXSource(fileName) {
|
|
19
|
-
return !!fileName && fileName.endsWith(".tsx");
|
|
20
|
-
}
|
|
21
|
-
const defaultPlugins = [
|
|
22
|
-
[require("@babel/plugin-syntax-flow")],
|
|
23
|
-
[require("babel-plugin-transform-flow-enums")],
|
|
24
|
-
[require("@babel/plugin-transform-block-scoping")],
|
|
25
|
-
[
|
|
26
|
-
require("@babel/plugin-proposal-class-properties"),
|
|
27
|
-
// use `this.foo = bar` instead of `this.defineProperty('foo', ...)`
|
|
28
|
-
{
|
|
29
|
-
loose: true,
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
[require("@babel/plugin-syntax-dynamic-import")],
|
|
33
|
-
[require("@babel/plugin-syntax-export-default-from")],
|
|
34
|
-
...passthroughSyntaxPlugins,
|
|
35
|
-
[require("@babel/plugin-transform-unicode-regex")],
|
|
36
|
-
];
|
|
37
|
-
const getPreset = (src, options) => {
|
|
38
|
-
const transformProfile =
|
|
39
|
-
(options && options.unstable_transformProfile) || "default";
|
|
40
|
-
const isHermesStable = transformProfile === "hermes-stable";
|
|
41
|
-
const isHermesCanary = transformProfile === "hermes-canary";
|
|
42
|
-
const isHermes = isHermesStable || isHermesCanary;
|
|
43
|
-
const isNull = src == null;
|
|
44
|
-
const hasClass = isNull || src.indexOf("class") !== -1;
|
|
45
|
-
const extraPlugins = [];
|
|
46
|
-
if (!options.useTransformReactJSXExperimental) {
|
|
47
|
-
extraPlugins.push([
|
|
48
|
-
require("@babel/plugin-transform-react-jsx"),
|
|
49
|
-
{
|
|
50
|
-
runtime: "automatic",
|
|
51
|
-
},
|
|
52
|
-
]);
|
|
53
|
-
}
|
|
54
|
-
if (
|
|
55
|
-
!options.disableStaticViewConfigsCodegen &&
|
|
56
|
-
/\bcodegenNativeComponent</.test(src)
|
|
57
|
-
) {
|
|
58
|
-
extraPlugins.push([require("@react-native/babel-plugin-codegen")]);
|
|
59
|
-
}
|
|
60
|
-
if (!options || !options.disableImportExportTransform) {
|
|
61
|
-
extraPlugins.push(
|
|
62
|
-
[require("@babel/plugin-proposal-export-default-from")],
|
|
63
|
-
[
|
|
64
|
-
require("@babel/plugin-transform-modules-commonjs"),
|
|
65
|
-
{
|
|
66
|
-
strict: false,
|
|
67
|
-
strictMode: false,
|
|
68
|
-
// prevent "use strict" injections
|
|
69
|
-
lazy:
|
|
70
|
-
options && options.lazyImportExportTransform != null
|
|
71
|
-
? options.lazyImportExportTransform
|
|
72
|
-
: (importSpecifier) => lazyImports.has(importSpecifier),
|
|
73
|
-
allowTopLevelThis: true, // dont rewrite global `this` -> `undefined`
|
|
74
|
-
},
|
|
75
|
-
]
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (hasClass) {
|
|
80
|
-
extraPlugins.push([require("@babel/plugin-transform-classes")]);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// TODO(gaearon): put this back into '=>' indexOf bailout
|
|
84
|
-
// and patch react-refresh to not depend on this transform.
|
|
85
|
-
extraPlugins.push([require("@babel/plugin-transform-arrow-functions")]);
|
|
86
|
-
if (!isHermes) {
|
|
87
|
-
extraPlugins.push([require("@babel/plugin-transform-computed-properties")]);
|
|
88
|
-
extraPlugins.push([require("@babel/plugin-transform-parameters")]);
|
|
89
|
-
extraPlugins.push([
|
|
90
|
-
require("@babel/plugin-transform-shorthand-properties"),
|
|
91
|
-
]);
|
|
92
|
-
extraPlugins.push([
|
|
93
|
-
require("@babel/plugin-proposal-optional-catch-binding"),
|
|
94
|
-
]);
|
|
95
|
-
extraPlugins.push([require("@babel/plugin-transform-function-name")]);
|
|
96
|
-
extraPlugins.push([require("@babel/plugin-transform-literals")]);
|
|
97
|
-
extraPlugins.push([require("@babel/plugin-proposal-numeric-separator")]);
|
|
98
|
-
extraPlugins.push([require("@babel/plugin-transform-sticky-regex")]);
|
|
99
|
-
} else {
|
|
100
|
-
extraPlugins.push([
|
|
101
|
-
require("@babel/plugin-transform-named-capturing-groups-regex"),
|
|
102
|
-
]);
|
|
103
|
-
}
|
|
104
|
-
if (!isHermesCanary) {
|
|
105
|
-
extraPlugins.push([
|
|
106
|
-
require("@babel/plugin-transform-destructuring"),
|
|
107
|
-
{
|
|
108
|
-
useBuiltIns: true,
|
|
109
|
-
},
|
|
110
|
-
]);
|
|
111
|
-
}
|
|
112
|
-
if (!isHermes && (isNull || hasClass || src.indexOf("...") !== -1)) {
|
|
113
|
-
extraPlugins.push(
|
|
114
|
-
[require("@babel/plugin-transform-spread")],
|
|
115
|
-
[
|
|
116
|
-
require("@babel/plugin-proposal-object-rest-spread"),
|
|
117
|
-
// Assume no dependence on getters or evaluation order. See https://github.com/babel/babel/pull/11520
|
|
118
|
-
{
|
|
119
|
-
loose: true,
|
|
120
|
-
useBuiltIns: true,
|
|
121
|
-
},
|
|
122
|
-
]
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
if (isNull || src.indexOf("async") !== -1) {
|
|
126
|
-
extraPlugins.push([
|
|
127
|
-
require("@babel/plugin-proposal-async-generator-functions"),
|
|
128
|
-
]);
|
|
129
|
-
extraPlugins.push([require("@babel/plugin-transform-async-to-generator")]);
|
|
130
|
-
}
|
|
131
|
-
if (
|
|
132
|
-
isNull ||
|
|
133
|
-
src.indexOf("React.createClass") !== -1 ||
|
|
134
|
-
src.indexOf("createReactClass") !== -1
|
|
135
|
-
) {
|
|
136
|
-
extraPlugins.push([require("@babel/plugin-transform-react-display-name")]);
|
|
137
|
-
}
|
|
138
|
-
if (!isHermes && (isNull || src.indexOf("?.") !== -1)) {
|
|
139
|
-
extraPlugins.push([
|
|
140
|
-
require("@babel/plugin-proposal-optional-chaining"),
|
|
141
|
-
{
|
|
142
|
-
loose: true,
|
|
143
|
-
},
|
|
144
|
-
]);
|
|
145
|
-
}
|
|
146
|
-
if (!isHermes && (isNull || src.indexOf("??") !== -1)) {
|
|
147
|
-
extraPlugins.push([
|
|
148
|
-
require("@babel/plugin-proposal-nullish-coalescing-operator"),
|
|
149
|
-
{
|
|
150
|
-
loose: true,
|
|
151
|
-
},
|
|
152
|
-
]);
|
|
153
|
-
}
|
|
154
|
-
if (options && options.dev && !options.useTransformReactJSXExperimental) {
|
|
155
|
-
extraPlugins.push([require("@babel/plugin-transform-react-jsx-source")]);
|
|
156
|
-
extraPlugins.push([require("@babel/plugin-transform-react-jsx-self")]);
|
|
157
|
-
}
|
|
158
|
-
if (!options || options.enableBabelRuntime !== false) {
|
|
159
|
-
// Allows configuring a specific runtime version to optimize output
|
|
160
|
-
const isVersion = typeof options?.enableBabelRuntime === "string";
|
|
161
|
-
extraPlugins.push([
|
|
162
|
-
require("@babel/plugin-transform-runtime"),
|
|
163
|
-
{
|
|
164
|
-
helpers: true,
|
|
165
|
-
regenerator: !isHermes,
|
|
166
|
-
...(isVersion && {
|
|
167
|
-
version: options.enableBabelRuntime,
|
|
168
|
-
}),
|
|
169
|
-
},
|
|
170
|
-
]);
|
|
171
|
-
}
|
|
172
|
-
return {
|
|
173
|
-
comments: false,
|
|
174
|
-
compact: true,
|
|
175
|
-
overrides: [
|
|
176
|
-
// the flow strip types plugin must go BEFORE class properties!
|
|
177
|
-
// there'll be a test case that fails if you don't.
|
|
178
|
-
{
|
|
179
|
-
plugins: [require("@babel/plugin-transform-flow-strip-types")],
|
|
180
|
-
},
|
|
181
|
-
{
|
|
182
|
-
plugins: defaultPlugins,
|
|
183
|
-
},
|
|
184
|
-
{
|
|
185
|
-
test: isTypeScriptSource,
|
|
186
|
-
plugins: [
|
|
187
|
-
[
|
|
188
|
-
require("@babel/plugin-transform-typescript"),
|
|
189
|
-
{
|
|
190
|
-
isTSX: false,
|
|
191
|
-
allowNamespaces: true,
|
|
192
|
-
},
|
|
193
|
-
],
|
|
194
|
-
],
|
|
195
|
-
},
|
|
196
|
-
{
|
|
197
|
-
test: isTSXSource,
|
|
198
|
-
plugins: [
|
|
199
|
-
[
|
|
200
|
-
require("@babel/plugin-transform-typescript"),
|
|
201
|
-
{
|
|
202
|
-
isTSX: true,
|
|
203
|
-
allowNamespaces: true,
|
|
204
|
-
},
|
|
205
|
-
],
|
|
206
|
-
],
|
|
207
|
-
},
|
|
208
|
-
{
|
|
209
|
-
plugins: extraPlugins,
|
|
210
|
-
},
|
|
211
|
-
],
|
|
212
|
-
};
|
|
213
|
-
};
|
|
214
|
-
module.exports = (options) => {
|
|
215
|
-
if (options.withDevTools == null) {
|
|
216
|
-
const env = process.env.BABEL_ENV || process.env.NODE_ENV;
|
|
217
|
-
if (!env || env === "development") {
|
|
218
|
-
return getPreset(null, {
|
|
219
|
-
...options,
|
|
220
|
-
dev: true,
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return getPreset(null, options);
|
|
225
|
-
};
|
|
226
|
-
module.exports.getPreset = getPreset;
|