@react-native/babel-preset 0.73.1 → 0.73.2

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.
@@ -46,7 +46,6 @@ module.exports = new Set([
46
46
  'View',
47
47
  'VirtualizedList',
48
48
  'VirtualizedSectionList',
49
-
50
49
  // APIs
51
50
  'ActionSheetIOS',
52
51
  'Alert',
@@ -82,7 +81,6 @@ module.exports = new Set([
82
81
  'ReactNative',
83
82
  'UTFSequence',
84
83
  'Vibration',
85
-
86
84
  // Plugins
87
85
  'RCTDeviceEventEmitter',
88
86
  'RCTNativeAppEventEmitter',
@@ -10,17 +10,76 @@
10
10
 
11
11
  'use strict';
12
12
 
13
+ function ownKeys(object, enumerableOnly) {
14
+ var keys = Object.keys(object);
15
+ if (Object.getOwnPropertySymbols) {
16
+ var symbols = Object.getOwnPropertySymbols(object);
17
+ enumerableOnly &&
18
+ (symbols = symbols.filter(function (sym) {
19
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
20
+ })),
21
+ keys.push.apply(keys, symbols);
22
+ }
23
+ return keys;
24
+ }
25
+ function _objectSpread(target) {
26
+ for (var i = 1; i < arguments.length; i++) {
27
+ var source = null != arguments[i] ? arguments[i] : {};
28
+ i % 2
29
+ ? ownKeys(Object(source), !0).forEach(function (key) {
30
+ _defineProperty(target, key, source[key]);
31
+ })
32
+ : Object.getOwnPropertyDescriptors
33
+ ? Object.defineProperties(
34
+ target,
35
+ Object.getOwnPropertyDescriptors(source),
36
+ )
37
+ : ownKeys(Object(source)).forEach(function (key) {
38
+ Object.defineProperty(
39
+ target,
40
+ key,
41
+ Object.getOwnPropertyDescriptor(source, key),
42
+ );
43
+ });
44
+ }
45
+ return target;
46
+ }
47
+ function _defineProperty(obj, key, value) {
48
+ key = _toPropertyKey(key);
49
+ if (key in obj) {
50
+ Object.defineProperty(obj, key, {
51
+ value: value,
52
+ enumerable: true,
53
+ configurable: true,
54
+ writable: true,
55
+ });
56
+ } else {
57
+ obj[key] = value;
58
+ }
59
+ return obj;
60
+ }
61
+ function _toPropertyKey(arg) {
62
+ var key = _toPrimitive(arg, 'string');
63
+ return typeof key === 'symbol' ? key : String(key);
64
+ }
65
+ function _toPrimitive(input, hint) {
66
+ if (typeof input !== 'object' || input === null) return input;
67
+ var prim = input[Symbol.toPrimitive];
68
+ if (prim !== undefined) {
69
+ var res = prim.call(input, hint || 'default');
70
+ if (typeof res !== 'object') return res;
71
+ throw new TypeError('@@toPrimitive must return a primitive value.');
72
+ }
73
+ return (hint === 'string' ? String : Number)(input);
74
+ }
13
75
  const passthroughSyntaxPlugins = require('../passthrough-syntax-plugins');
14
76
  const lazyImports = require('./lazy-imports');
15
-
16
77
  function isTypeScriptSource(fileName) {
17
78
  return !!fileName && fileName.endsWith('.ts');
18
79
  }
19
-
20
80
  function isTSXSource(fileName) {
21
81
  return !!fileName && fileName.endsWith('.tsx');
22
82
  }
23
-
24
83
  const defaultPlugins = [
25
84
  [require('@babel/plugin-syntax-flow')],
26
85
  [require('babel-plugin-transform-flow-enums')],
@@ -28,32 +87,32 @@ const defaultPlugins = [
28
87
  [
29
88
  require('@babel/plugin-proposal-class-properties'),
30
89
  // use `this.foo = bar` instead of `this.defineProperty('foo', ...)`
31
- {loose: true},
90
+ {
91
+ loose: true,
92
+ },
32
93
  ],
33
94
  [require('@babel/plugin-syntax-dynamic-import')],
34
95
  [require('@babel/plugin-syntax-export-default-from')],
35
96
  ...passthroughSyntaxPlugins,
36
97
  [require('@babel/plugin-transform-unicode-regex')],
37
98
  ];
38
-
39
99
  const getPreset = (src, options) => {
40
100
  const transformProfile =
41
101
  (options && options.unstable_transformProfile) || 'default';
42
102
  const isHermesStable = transformProfile === 'hermes-stable';
43
103
  const isHermesCanary = transformProfile === 'hermes-canary';
44
104
  const isHermes = isHermesStable || isHermesCanary;
45
-
46
105
  const isNull = src == null;
47
106
  const hasClass = isNull || src.indexOf('class') !== -1;
48
-
49
107
  const extraPlugins = [];
50
108
  if (!options.useTransformReactJSXExperimental) {
51
109
  extraPlugins.push([
52
110
  require('@babel/plugin-transform-react-jsx'),
53
- {runtime: 'automatic'},
111
+ {
112
+ runtime: 'automatic',
113
+ },
54
114
  ]);
55
115
  }
56
-
57
116
  if (!options || !options.disableImportExportTransform) {
58
117
  extraPlugins.push(
59
118
  [require('@babel/plugin-proposal-export-default-from')],
@@ -61,7 +120,8 @@ const getPreset = (src, options) => {
61
120
  require('@babel/plugin-transform-modules-commonjs'),
62
121
  {
63
122
  strict: false,
64
- strictMode: false, // prevent "use strict" injections
123
+ strictMode: false,
124
+ // prevent "use strict" injections
65
125
  lazy:
66
126
  options && options.lazyImportExportTransform != null
67
127
  ? options.lazyImportExportTransform
@@ -79,7 +139,6 @@ const getPreset = (src, options) => {
79
139
  // TODO(gaearon): put this back into '=>' indexOf bailout
80
140
  // and patch react-refresh to not depend on this transform.
81
141
  extraPlugins.push([require('@babel/plugin-transform-arrow-functions')]);
82
-
83
142
  if (!isHermes) {
84
143
  extraPlugins.push([require('@babel/plugin-transform-computed-properties')]);
85
144
  extraPlugins.push([require('@babel/plugin-transform-parameters')]);
@@ -101,7 +160,9 @@ const getPreset = (src, options) => {
101
160
  if (!isHermesCanary) {
102
161
  extraPlugins.push([
103
162
  require('@babel/plugin-transform-destructuring'),
104
- {useBuiltIns: true},
163
+ {
164
+ useBuiltIns: true,
165
+ },
105
166
  ]);
106
167
  }
107
168
  if (!isHermes && (isNull || hasClass || src.indexOf('...') !== -1)) {
@@ -110,7 +171,10 @@ const getPreset = (src, options) => {
110
171
  [
111
172
  require('@babel/plugin-proposal-object-rest-spread'),
112
173
  // Assume no dependence on getters or evaluation order. See https://github.com/babel/babel/pull/11520
113
- {loose: true, useBuiltIns: true},
174
+ {
175
+ loose: true,
176
+ useBuiltIns: true,
177
+ },
114
178
  ],
115
179
  );
116
180
  }
@@ -130,35 +194,42 @@ const getPreset = (src, options) => {
130
194
  if (!isHermes && (isNull || src.indexOf('?.') !== -1)) {
131
195
  extraPlugins.push([
132
196
  require('@babel/plugin-proposal-optional-chaining'),
133
- {loose: true},
197
+ {
198
+ loose: true,
199
+ },
134
200
  ]);
135
201
  }
136
202
  if (!isHermes && (isNull || src.indexOf('??') !== -1)) {
137
203
  extraPlugins.push([
138
204
  require('@babel/plugin-proposal-nullish-coalescing-operator'),
139
- {loose: true},
205
+ {
206
+ loose: true,
207
+ },
140
208
  ]);
141
209
  }
142
-
143
210
  if (options && options.dev && !options.useTransformReactJSXExperimental) {
144
211
  extraPlugins.push([require('@babel/plugin-transform-react-jsx-source')]);
145
212
  extraPlugins.push([require('@babel/plugin-transform-react-jsx-self')]);
146
213
  }
147
-
148
214
  if (!options || options.enableBabelRuntime !== false) {
149
215
  // Allows configuring a specific runtime version to optimize output
150
- const isVersion = typeof options?.enableBabelRuntime === 'string';
151
-
216
+ const isVersion =
217
+ typeof (options === null || options === void 0
218
+ ? void 0
219
+ : options.enableBabelRuntime) === 'string';
152
220
  extraPlugins.push([
153
221
  require('@babel/plugin-transform-runtime'),
154
- {
155
- helpers: true,
156
- regenerator: !isHermes,
157
- ...(isVersion && {version: options.enableBabelRuntime}),
158
- },
222
+ _objectSpread(
223
+ {
224
+ helpers: true,
225
+ regenerator: !isHermes,
226
+ },
227
+ isVersion && {
228
+ version: options.enableBabelRuntime,
229
+ },
230
+ ),
159
231
  ]);
160
232
  }
161
-
162
233
  return {
163
234
  comments: false,
164
235
  compact: true,
@@ -201,15 +272,22 @@ const getPreset = (src, options) => {
201
272
  ],
202
273
  };
203
274
  };
204
-
205
275
  module.exports = options => {
206
276
  if (options.withDevTools == null) {
207
277
  const env = process.env.BABEL_ENV || process.env.NODE_ENV;
208
278
  if (!env || env === 'development') {
209
- return getPreset(null, {...options, dev: true});
279
+ return getPreset(
280
+ null,
281
+ _objectSpread(
282
+ _objectSpread({}, options),
283
+ {},
284
+ {
285
+ dev: true,
286
+ },
287
+ ),
288
+ );
210
289
  }
211
290
  }
212
291
  return getPreset(null, options);
213
292
  };
214
-
215
293
  module.exports.getPreset = getPreset;
package/lib/index.js ADDED
@@ -0,0 +1,18 @@
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 main = require('./configs/main');
14
+ module.exports = function (babel, options) {
15
+ return main(options);
16
+ };
17
+ module.exports.getPreset = main.getPreset;
18
+ module.exports.passthroughSyntaxPlugins = require('./passthrough-syntax-plugins');
@@ -19,5 +19,4 @@ const passthroughSyntaxPlugins = [
19
19
  [require('@babel/plugin-syntax-nullish-coalescing-operator')],
20
20
  [require('@babel/plugin-syntax-optional-chaining')],
21
21
  ];
22
-
23
22
  module.exports = passthroughSyntaxPlugins;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native/babel-preset",
3
- "version": "0.73.1",
3
+ "version": "0.73.2",
4
4
  "description": "Babel preset for React Native applications",
5
5
  "main": "src/index.js",
6
6
  "repository": {
@@ -8,9 +8,13 @@
8
8
  "url": "git@github.com:facebook/react-native.git"
9
9
  },
10
10
  "scripts": {
11
- "prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src",
12
- "cleanup-release": "test ! -e build && mv src build && mv src.real src"
11
+ "build": "yarn clean && node scripts/build.js --verbose",
12
+ "clean": "rimraf lib",
13
+ "prepare": "yarn run build"
13
14
  },
15
+ "files": [
16
+ "lib"
17
+ ],
14
18
  "keywords": [
15
19
  "babel",
16
20
  "preset",
@@ -58,10 +62,28 @@
58
62
  "babel-plugin-transform-flow-enums": "^0.0.2",
59
63
  "react-refresh": "^0.4.0"
60
64
  },
65
+ "devDependencies": {
66
+ "@babel/plugin-proposal-class-properties": "^7.18.0",
67
+ "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.0",
68
+ "@babel/plugin-proposal-object-rest-spread": "^7.20.0",
69
+ "@babel/plugin-proposal-optional-chaining": "^7.20.0",
70
+ "@babel/plugin-syntax-dynamic-import": "^7.8.0",
71
+ "@babel/plugin-transform-async-to-generator": "^7.20.0",
72
+ "@babel/plugin-transform-destructuring": "^7.20.0",
73
+ "@babel/plugin-transform-flow-strip-types": "^7.20.0",
74
+ "@babel/preset-env": "^7.20.0",
75
+ "chalk": "^4.0.0",
76
+ "glob": "^7.1.1",
77
+ "invariant": "^2.2.4",
78
+ "micromatch": "^4.0.4",
79
+ "mkdirp": "^0.5.1",
80
+ "prettier": "2.8.8",
81
+ "rimraf": "^3.0.2"
82
+ },
61
83
  "peerDependencies": {
62
84
  "@babel/core": "*"
63
85
  },
64
86
  "engines": {
65
- "node": ">=16"
87
+ "node": ">=18"
66
88
  }
67
89
  }
package/BUCK DELETED
@@ -1,23 +0,0 @@
1
- load("@fbsource//tools/build_defs/third_party:yarn_defs.bzl", "yarn_workspace")
2
-
3
- oncall("react_native")
4
-
5
- yarn_workspace(
6
- name = "yarn-workspace",
7
- srcs = glob(
8
- ["src/**/*.js"],
9
- exclude = [
10
- "**/__fixtures__/**",
11
- "**/__flowtests__/**",
12
- "**/__mocks__/**",
13
- "**/__server_snapshot_tests__/**",
14
- "**/__tests__/**",
15
- "**/.*",
16
- "**/.*/**",
17
- "**/.*/.*",
18
- "**/*.xcodeproj/**",
19
- "**/*.xcworkspace/**",
20
- ],
21
- ),
22
- visibility = ["PUBLIC"],
23
- )
File without changes