metro-react-native-babel-preset
Advanced tools
Comparing version 0.58.0 to 0.59.0
{ | ||
"name": "metro-react-native-babel-preset", | ||
"version": "0.58.0", | ||
"version": "0.59.0", | ||
"description": "Babel preset for React Native applications", | ||
@@ -30,2 +30,4 @@ "main": "src/index.js", | ||
"@babel/plugin-syntax-flow": "^7.2.0", | ||
"@babel/plugin-syntax-nullish-coalescing-operator": "^7.0.0", | ||
"@babel/plugin-syntax-optional-chaining": "^7.0.0", | ||
"@babel/plugin-transform-arrow-functions": "^7.0.0", | ||
@@ -46,2 +48,3 @@ "@babel/plugin-transform-block-scoping": "^7.0.0", | ||
"@babel/plugin-transform-react-jsx": "^7.0.0", | ||
"@babel/plugin-transform-react-jsx-self": "^7.0.0", | ||
"@babel/plugin-transform-react-jsx-source": "^7.0.0", | ||
@@ -48,0 +51,0 @@ "@babel/plugin-transform-regenerator": "^7.0.0", |
# metro-react-native-babel-preset | ||
Babel presets for React Native applications. React Native itself uses this Babel preset by default when transforming your app's source code. | ||
Babel presets for [React Native](https://reactnative.dev) applications. React Native itself uses this Babel preset by default when transforming your app's source code. | ||
If you wish to use a custom Babel configuration by writing a `.babelrc` file in your project's root directory, you must specify all the plugins necessary to transform your code. React Native does not apply its default Babel configuration in this case. So, to make your life easier, you can use this preset to get the default configuration and then specify more plugins that run before it. | ||
If you wish to use a custom Babel configuration by writing a `babel.config.js` file in your project's root directory, you must specify all the plugins necessary to transform your code. React Native does not apply its default Babel configuration in this case. So, to make your life easier, you can use this preset to get the default configuration and then specify more plugins that run before it. | ||
## Usage | ||
As mentioned above, you only need to use this preset if you are writing a custom `.babelrc` file. | ||
As mentioned above, you only need to use this preset if you are writing a custom `babel.config.js` file. | ||
@@ -14,2 +14,5 @@ ### Installation | ||
Install `metro-react-native-babel-preset` in your app: | ||
with `npm`: | ||
```sh | ||
@@ -19,5 +22,11 @@ npm i metro-react-native-babel-preset --save-dev | ||
or with `yarn`: | ||
```sh | ||
yarn add -d metro-react-native-babel-preset | ||
``` | ||
### Configuring Babel | ||
Then, create a file called `.babelrc` in your project's root directory. The existence of this `.babelrc` file will tell React Native to use your custom Babel configuration instead of its own. Then load this preset: | ||
Then, create a file called `babel.config.js` in your project's root directory. The existence of this `babel.config.js` file will tell React Native to use your custom Babel configuration instead of its own. Then load this preset: | ||
@@ -30,3 +39,3 @@ ``` | ||
You can further customize your Babel configuration by specifying plugins and other options. See [Babel's `.babelrc` documentation](https://babeljs.io/docs/usage/babelrc/) to learn more. | ||
You can further customize your Babel configuration by specifying plugins and other options. See [Babel's `babel.config.js` documentation](https://babeljs.io/docs/en/config-files/) to learn more. | ||
@@ -33,0 +42,0 @@ ## Help and Support |
@@ -69,2 +69,3 @@ /** | ||
"Linking", | ||
"LogBox", | ||
"NativeEventEmitter", | ||
@@ -71,0 +72,0 @@ "PanResponder", |
@@ -43,4 +43,32 @@ /** | ||
function _toConsumableArray(arr) { | ||
return ( | ||
_arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread() | ||
); | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
} | ||
function _iterableToArray(iter) { | ||
if ( | ||
Symbol.iterator in Object(iter) || | ||
Object.prototype.toString.call(iter) === "[object Arguments]" | ||
) | ||
return Array.from(iter); | ||
} | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) | ||
arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
} | ||
const lazyImports = require("./lazy-imports"); | ||
const passthroughSyntaxPlugins = require("../passthrough-syntax-plugins"); | ||
function isTypeScriptSource(fileName) { | ||
@@ -65,3 +93,4 @@ return !!fileName && fileName.endsWith(".ts"); | ||
[require("@babel/plugin-syntax-dynamic-import")], | ||
[require("@babel/plugin-syntax-export-default-from")], | ||
[require("@babel/plugin-syntax-export-default-from")] | ||
].concat(_toConsumableArray(passthroughSyntaxPlugins), [ | ||
[require("@babel/plugin-transform-computed-properties")], | ||
@@ -73,7 +102,6 @@ [require("@babel/plugin-transform-destructuring")], | ||
[require("@babel/plugin-transform-shorthand-properties")], | ||
[require("@babel/plugin-transform-react-jsx")], | ||
[require("@babel/plugin-transform-regenerator")], | ||
[require("@babel/plugin-transform-sticky-regex")], | ||
[require("@babel/plugin-transform-unicode-regex")] | ||
]; | ||
]); | ||
const es2015ArrowFunctions = [ | ||
@@ -117,3 +145,3 @@ require("@babel/plugin-transform-arrow-functions") | ||
const reactJsxSource = [require("@babel/plugin-transform-react-jsx-source")]; | ||
const symbolMember = [require("../transforms/transform-symbol-member")]; | ||
const reactJsxSelf = [require("@babel/plugin-transform-react-jsx-self")]; | ||
const babelRuntime = [ | ||
@@ -127,7 +155,5 @@ require("@babel/plugin-transform-runtime"), | ||
function unstable_disableES6Transforms(options) { | ||
return !!(options && options.unstable_disableES6Transforms); | ||
} | ||
const getPreset = (src, options) => { | ||
const transformProfile = | ||
(options && options.unstable_transformProfile) || "default"; | ||
const isNull = src == null; | ||
@@ -139,2 +165,6 @@ const hasClass = isNull || src.indexOf("class") !== -1; | ||
if (!options.useTransformReactJsxExperimental) { | ||
extraPlugins.push([require("@babel/plugin-transform-react-jsx")]); | ||
} | ||
if (!options || !options.disableImportExportTransform) { | ||
@@ -188,9 +218,2 @@ extraPlugins.push( | ||
if ( | ||
!unstable_disableES6Transforms(options) && | ||
(hasForOf || src.indexOf("Symbol") !== -1) | ||
) { | ||
extraPlugins.push(symbolMember); | ||
} | ||
if ( | ||
isNull || | ||
@@ -203,3 +226,6 @@ src.indexOf("React.createClass") !== -1 || | ||
if (isNull || src.indexOf("?.") !== -1) { | ||
if ( | ||
transformProfile !== "hermes-canary" && | ||
(isNull || src.indexOf("?.") !== -1) | ||
) { | ||
extraPlugins.push(optionalChaining); | ||
@@ -212,4 +238,5 @@ } | ||
if (options && options.dev) { | ||
if (options && options.dev && !options.useTransformReactJsxExperimental) { | ||
extraPlugins.push(reactJsxSource); | ||
extraPlugins.push(reactJsxSelf); | ||
} | ||
@@ -216,0 +243,0 @@ |
@@ -18,1 +18,2 @@ /** | ||
module.exports.getPreset = main.getPreset; | ||
module.exports.passthroughSyntaxPlugins = require("./passthrough-syntax-plugins"); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15917
42
39
415
+ Added@babel/plugin-syntax-nullish-coalescing-operator@^7.0.0
+ Added@babel/plugin-transform-react-jsx-self@7.24.7(transitive)
+ Addedelectron-to-chromium@1.5.30(transitive)
+ Addedupdate-browserslist-db@1.1.1(transitive)
- Removedelectron-to-chromium@1.5.29(transitive)
- Removedupdate-browserslist-db@1.1.0(transitive)