@react-native/babel-preset 0.73.5 → 0.73.7

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 CHANGED
@@ -1,20 +1,12 @@
1
1
  {
2
2
  "name": "@react-native/babel-preset",
3
- "version": "0.73.5",
3
+ "version": "0.73.7",
4
4
  "description": "Babel preset for React Native applications",
5
- "main": "src/index.js",
5
+ "main": "dist/index.js",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git@github.com:facebook/react-native.git"
9
9
  },
10
- "scripts": {
11
- "prepare-release": "test -d lib && mv src src.real && mv lib src",
12
- "cleanup-release": "test ! -e lib && mv src lib && mv src.real src && rimraf lib",
13
- "build-clean": "rimraf build && rimraf src.real",
14
- "build": " node scripts/build.js --verbose",
15
- "prepare": "yarn run build-clean && yarn run build && yarn run prepare-release",
16
- "postpublish": "yarn run cleanup-release"
17
- },
18
10
  "keywords": [
19
11
  "babel",
20
12
  "preset",
@@ -59,28 +51,9 @@
59
51
  "@babel/plugin-transform-typescript": "^7.5.0",
60
52
  "@babel/plugin-transform-unicode-regex": "^7.0.0",
61
53
  "@babel/template": "^7.0.0",
62
- "@react-native/babel-plugin-codegen": "*",
63
54
  "babel-plugin-transform-flow-enums": "^0.0.2",
64
55
  "react-refresh": "^0.4.0"
65
56
  },
66
- "devDependencies": {
67
- "@babel/plugin-proposal-class-properties": "^7.18.0",
68
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.0",
69
- "@babel/plugin-proposal-object-rest-spread": "^7.20.0",
70
- "@babel/plugin-proposal-optional-chaining": "^7.20.0",
71
- "@babel/plugin-syntax-dynamic-import": "^7.8.0",
72
- "@babel/plugin-transform-async-to-generator": "^7.20.0",
73
- "@babel/plugin-transform-destructuring": "^7.20.0",
74
- "@babel/plugin-transform-flow-strip-types": "^7.20.0",
75
- "@babel/preset-env": "^7.20.0",
76
- "chalk": "^4.0.0",
77
- "glob": "^7.1.1",
78
- "invariant": "^2.2.4",
79
- "micromatch": "^4.0.4",
80
- "mkdirp": "^0.5.1",
81
- "prettier": "2.8.8",
82
- "rimraf": "^3.0.2"
83
- },
84
57
  "peerDependencies": {
85
58
  "@babel/core": "*"
86
59
  },
@@ -46,6 +46,7 @@ module.exports = new Set([
46
46
  'View',
47
47
  'VirtualizedList',
48
48
  'VirtualizedSectionList',
49
+
49
50
  // APIs
50
51
  'ActionSheetIOS',
51
52
  'Alert',
@@ -81,6 +82,7 @@ module.exports = new Set([
81
82
  'ReactNative',
82
83
  'UTFSequence',
83
84
  'Vibration',
85
+
84
86
  // Plugins
85
87
  'RCTDeviceEventEmitter',
86
88
  'RCTNativeAppEventEmitter',
@@ -10,76 +10,17 @@
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
- }
75
13
  const passthroughSyntaxPlugins = require('../passthrough-syntax-plugins');
76
14
  const lazyImports = require('./lazy-imports');
15
+
77
16
  function isTypeScriptSource(fileName) {
78
17
  return !!fileName && fileName.endsWith('.ts');
79
18
  }
19
+
80
20
  function isTSXSource(fileName) {
81
21
  return !!fileName && fileName.endsWith('.tsx');
82
22
  }
23
+
83
24
  const defaultPlugins = [
84
25
  [require('@babel/plugin-syntax-flow')],
85
26
  [require('babel-plugin-transform-flow-enums')],
@@ -87,38 +28,32 @@ const defaultPlugins = [
87
28
  [
88
29
  require('@babel/plugin-proposal-class-properties'),
89
30
  // use `this.foo = bar` instead of `this.defineProperty('foo', ...)`
90
- {
91
- loose: true,
92
- },
31
+ {loose: true},
93
32
  ],
94
33
  [require('@babel/plugin-syntax-dynamic-import')],
95
34
  [require('@babel/plugin-syntax-export-default-from')],
96
35
  ...passthroughSyntaxPlugins,
97
36
  [require('@babel/plugin-transform-unicode-regex')],
98
37
  ];
38
+
99
39
  const getPreset = (src, options) => {
100
40
  const transformProfile =
101
41
  (options && options.unstable_transformProfile) || 'default';
102
42
  const isHermesStable = transformProfile === 'hermes-stable';
103
43
  const isHermesCanary = transformProfile === 'hermes-canary';
104
44
  const isHermes = isHermesStable || isHermesCanary;
45
+
105
46
  const isNull = src == null;
106
47
  const hasClass = isNull || src.indexOf('class') !== -1;
48
+
107
49
  const extraPlugins = [];
108
50
  if (!options.useTransformReactJSXExperimental) {
109
51
  extraPlugins.push([
110
52
  require('@babel/plugin-transform-react-jsx'),
111
- {
112
- runtime: 'automatic',
113
- },
53
+ {runtime: 'automatic'},
114
54
  ]);
115
55
  }
116
- if (
117
- !options.disableStaticViewConfigsCodegen &&
118
- /\bcodegenNativeComponent</.test(src)
119
- ) {
120
- extraPlugins.push([require('@react-native/babel-plugin-codegen')]);
121
- }
56
+
122
57
  if (!options || !options.disableImportExportTransform) {
123
58
  extraPlugins.push(
124
59
  [require('@babel/plugin-proposal-export-default-from')],
@@ -126,8 +61,7 @@ const getPreset = (src, options) => {
126
61
  require('@babel/plugin-transform-modules-commonjs'),
127
62
  {
128
63
  strict: false,
129
- strictMode: false,
130
- // prevent "use strict" injections
64
+ strictMode: false, // prevent "use strict" injections
131
65
  lazy:
132
66
  options && options.lazyImportExportTransform != null
133
67
  ? options.lazyImportExportTransform
@@ -145,6 +79,7 @@ const getPreset = (src, options) => {
145
79
  // TODO(gaearon): put this back into '=>' indexOf bailout
146
80
  // and patch react-refresh to not depend on this transform.
147
81
  extraPlugins.push([require('@babel/plugin-transform-arrow-functions')]);
82
+
148
83
  if (!isHermes) {
149
84
  extraPlugins.push([require('@babel/plugin-transform-computed-properties')]);
150
85
  extraPlugins.push([require('@babel/plugin-transform-parameters')]);
@@ -166,9 +101,7 @@ const getPreset = (src, options) => {
166
101
  if (!isHermesCanary) {
167
102
  extraPlugins.push([
168
103
  require('@babel/plugin-transform-destructuring'),
169
- {
170
- useBuiltIns: true,
171
- },
104
+ {useBuiltIns: true},
172
105
  ]);
173
106
  }
174
107
  if (!isHermes && (isNull || hasClass || src.indexOf('...') !== -1)) {
@@ -177,10 +110,7 @@ const getPreset = (src, options) => {
177
110
  [
178
111
  require('@babel/plugin-proposal-object-rest-spread'),
179
112
  // Assume no dependence on getters or evaluation order. See https://github.com/babel/babel/pull/11520
180
- {
181
- loose: true,
182
- useBuiltIns: true,
183
- },
113
+ {loose: true, useBuiltIns: true},
184
114
  ],
185
115
  );
186
116
  }
@@ -200,42 +130,35 @@ const getPreset = (src, options) => {
200
130
  if (!isHermes && (isNull || src.indexOf('?.') !== -1)) {
201
131
  extraPlugins.push([
202
132
  require('@babel/plugin-proposal-optional-chaining'),
203
- {
204
- loose: true,
205
- },
133
+ {loose: true},
206
134
  ]);
207
135
  }
208
136
  if (!isHermes && (isNull || src.indexOf('??') !== -1)) {
209
137
  extraPlugins.push([
210
138
  require('@babel/plugin-proposal-nullish-coalescing-operator'),
211
- {
212
- loose: true,
213
- },
139
+ {loose: true},
214
140
  ]);
215
141
  }
142
+
216
143
  if (options && options.dev && !options.useTransformReactJSXExperimental) {
217
144
  extraPlugins.push([require('@babel/plugin-transform-react-jsx-source')]);
218
145
  extraPlugins.push([require('@babel/plugin-transform-react-jsx-self')]);
219
146
  }
147
+
220
148
  if (!options || options.enableBabelRuntime !== false) {
221
149
  // Allows configuring a specific runtime version to optimize output
222
- const isVersion =
223
- typeof (options === null || options === void 0
224
- ? void 0
225
- : options.enableBabelRuntime) === 'string';
150
+ const isVersion = typeof options?.enableBabelRuntime === 'string';
151
+
226
152
  extraPlugins.push([
227
153
  require('@babel/plugin-transform-runtime'),
228
- _objectSpread(
229
- {
230
- helpers: true,
231
- regenerator: !isHermes,
232
- },
233
- isVersion && {
234
- version: options.enableBabelRuntime,
235
- },
236
- ),
154
+ {
155
+ helpers: true,
156
+ regenerator: !isHermes,
157
+ ...(isVersion && {version: options.enableBabelRuntime}),
158
+ },
237
159
  ]);
238
160
  }
161
+
239
162
  return {
240
163
  comments: false,
241
164
  compact: true,
@@ -278,22 +201,15 @@ const getPreset = (src, options) => {
278
201
  ],
279
202
  };
280
203
  };
204
+
281
205
  module.exports = options => {
282
206
  if (options.withDevTools == null) {
283
207
  const env = process.env.BABEL_ENV || process.env.NODE_ENV;
284
208
  if (!env || env === 'development') {
285
- return getPreset(
286
- null,
287
- _objectSpread(
288
- _objectSpread({}, options),
289
- {},
290
- {
291
- dev: true,
292
- },
293
- ),
294
- );
209
+ return getPreset(null, {...options, dev: true});
295
210
  }
296
211
  }
297
212
  return getPreset(null, options);
298
213
  };
214
+
299
215
  module.exports.getPreset = getPreset;
package/src/index.js CHANGED
@@ -11,8 +11,10 @@
11
11
  'use strict';
12
12
 
13
13
  const main = require('./configs/main');
14
+
14
15
  module.exports = function (babel, options) {
15
16
  return main(options);
16
17
  };
18
+
17
19
  module.exports.getPreset = main.getPreset;
18
20
  module.exports.passthroughSyntaxPlugins = require('./passthrough-syntax-plugins');
@@ -19,4 +19,5 @@ const passthroughSyntaxPlugins = [
19
19
  [require('@babel/plugin-syntax-nullish-coalescing-operator')],
20
20
  [require('@babel/plugin-syntax-optional-chaining')],
21
21
  ];
22
+
22
23
  module.exports = passthroughSyntaxPlugins;
package/.babelrc DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "plugins": [
3
- "@babel/plugin-proposal-object-rest-spread",
4
- "@babel/plugin-transform-async-to-generator",
5
- "@babel/plugin-transform-destructuring",
6
- "@babel/plugin-transform-flow-strip-types",
7
- "@babel/plugin-syntax-dynamic-import",
8
- "@babel/plugin-proposal-class-properties",
9
- "@babel/plugin-proposal-nullish-coalescing-operator",
10
- "@babel/plugin-proposal-optional-chaining"
11
- ]
12
- }
package/.prettierrc DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "arrowParens": "avoid",
3
- "bracketSameLine": true,
4
- "bracketSpacing": false,
5
- "requirePragma": true,
6
- "singleQuote": true,
7
- "trailingComma": "all"
8
- }
package/scripts/build.js DELETED
@@ -1,114 +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
- */
9
-
10
- /**
11
- * script to build (transpile) files.
12
- *
13
- * Based off of the build script from Metro, and tweaked to run in just one
14
- * package instead of in a monorepo. Just run `build.js` and the JS files in
15
- * `src/` will be built in `lib/`, and the original source files will be copied
16
- * over as `Example.js.flow`, so consumers of this module can still make use of
17
- * type checking.
18
- *
19
- * Call this script with the `--verbose` flag to show the full output of this
20
- * script.
21
- */
22
-
23
- 'use strict';
24
-
25
- const babel = require('@babel/core');
26
- const chalk = require('chalk');
27
- const fs = require('fs');
28
- const glob = require('glob');
29
- const micromatch = require('micromatch');
30
- const mkdirp = require('mkdirp');
31
- const path = require('path');
32
- const prettier = require('prettier');
33
- const prettierConfig = JSON.parse(
34
- fs.readFileSync(path.resolve(__dirname, '..', '.prettierrc'), 'utf8'),
35
- );
36
-
37
- const SRC_DIR = 'src';
38
- const BUILD_DIR = 'lib';
39
- const JS_FILES_PATTERN = '**/*.js';
40
- const IGNORE_PATTERN = '**/__tests__/**';
41
- const PACKAGE_DIR = path.resolve(__dirname, '../');
42
-
43
- const fixedWidth = str => {
44
- const WIDTH = 80;
45
- const strs = str.match(new RegExp(`(.{1,${WIDTH}})`, 'g')) || [str];
46
- let lastString = strs[strs.length - 1];
47
- if (lastString.length < WIDTH) {
48
- lastString += Array(WIDTH - lastString.length).join(chalk.dim('.'));
49
- }
50
- return strs.slice(0, -1).concat(lastString).join('\n');
51
- };
52
-
53
- function getBuildPath(file, buildFolder) {
54
- const pkgSrcPath = path.resolve(PACKAGE_DIR, SRC_DIR);
55
- const pkgBuildPath = path.resolve(PACKAGE_DIR, BUILD_DIR);
56
- const relativeToSrcPath = path.relative(pkgSrcPath, file);
57
- return path.resolve(pkgBuildPath, relativeToSrcPath);
58
- }
59
-
60
- function buildFile(file, silent) {
61
- const destPath = getBuildPath(file, BUILD_DIR);
62
-
63
- mkdirp.sync(path.dirname(destPath));
64
- if (micromatch.isMatch(file, IGNORE_PATTERN)) {
65
- silent ||
66
- process.stdout.write(
67
- chalk.dim(' \u2022 ') +
68
- path.relative(PACKAGE_DIR, file) +
69
- ' (ignore)\n',
70
- );
71
- } else if (!micromatch.isMatch(file, JS_FILES_PATTERN)) {
72
- fs.createReadStream(file).pipe(fs.createWriteStream(destPath));
73
- silent ||
74
- process.stdout.write(
75
- chalk.red(' \u2022 ') +
76
- path.relative(PACKAGE_DIR, file) +
77
- chalk.red(' \u21D2 ') +
78
- path.relative(PACKAGE_DIR, destPath) +
79
- ' (copy)' +
80
- '\n',
81
- );
82
- } else {
83
- const transformed = prettier.format(
84
- babel.transformFileSync(file, {}).code,
85
- {
86
- ...prettierConfig,
87
- parser: 'babel',
88
- },
89
- );
90
- fs.writeFileSync(destPath, transformed);
91
- const source = fs.readFileSync(file).toString('utf-8');
92
- if (/@flow/.test(source)) {
93
- fs.createReadStream(file).pipe(fs.createWriteStream(destPath + '.flow'));
94
- }
95
- silent ||
96
- process.stdout.write(
97
- chalk.green(' \u2022 ') +
98
- path.relative(PACKAGE_DIR, file) +
99
- chalk.green(' \u21D2 ') +
100
- path.relative(PACKAGE_DIR, destPath) +
101
- '\n',
102
- );
103
- }
104
- }
105
-
106
- const srcDir = path.resolve(__dirname, '..', SRC_DIR);
107
- const pattern = path.resolve(srcDir, '**/*');
108
- const files = glob.sync(pattern, {nodir: true});
109
-
110
- process.stdout.write(fixedWidth(`${path.basename(PACKAGE_DIR)}\n`));
111
-
112
- files.forEach(file => buildFile(file, !process.argv.includes('--verbose')));
113
-
114
- process.stdout.write(`[ ${chalk.green('OK')} ]\n`);