Skip to content

Commit

Permalink
Add @babel/plugin-proposal-numeric-separator to the babel plugins w…
Browse files Browse the repository at this point in the history
…hen not in Hermes (#681)

Summary:
Changelog:
* **[Feature]**: Enable ES2021 numeric separator syntax in React Native

**Summary**

This PR solves issue #645. It adds `babel/plugin-proposal-numeric-separator` to the list of babel plugins when not using Hermes to more closely match ES2021. Now that ES2021 has been finalized, people will probably (?—I know I did) expect `1_000_000` to be treated as a valid number.

As I noted in a [comment](#645 (comment)) in #645, should `babel/preset-env` be included instead of including many different plugins manually? Even for engines like Hermes which don't need all the same transforms as JSC, I don't think the unneeded transforms would drastically increase the bundle size, right?

**Test plan**
Tested it using a sample app on `"react-native": "0.65.0-rc.2"`. Solves the `react-native bundle` issue on iOS (only tested on device as I encountered issues compiling for the simulator) and Android production / release builds when not using Hermes.

Pull Request resolved: #681

Reviewed By: rubennorte

Differential Revision: D29556107

Pulled By: motiz88

fbshipit-source-id: 2d66bf8993cb10dd1f020939f4ad1bbf49cccc19
  • Loading branch information
SConaway authored and facebook-github-bot committed Jan 11, 2023
1 parent 67d211d commit 22bc39f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/metro-react-native-babel-preset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-export-default-from": "^7.0.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0",
"@babel/plugin-proposal-numeric-separator": "^7.0.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/plugin-proposal-optional-catch-binding": "^7.0.0",
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const getPreset = (src, options) => {
]);
extraPlugins.push([require('@babel/plugin-transform-function-name')]);
extraPlugins.push([require('@babel/plugin-transform-literals')]);
extraPlugins.push([require('@babel/plugin-proposal-numeric-separator')]);
extraPlugins.push([require('@babel/plugin-transform-sticky-regex')]);
} else {
extraPlugins.push([
Expand Down
10 changes: 9 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,14 @@
"@babel/helper-plugin-utils" "^7.18.6"
"@babel/plugin-syntax-nullish-coalescing-operator" "^7.8.3"

"@babel/plugin-proposal-numeric-separator@^7.0.0":
version "7.18.6"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-numeric-separator/-/plugin-proposal-numeric-separator-7.18.6.tgz#899b14fbafe87f053d2c5ff05b36029c62e13c75"
integrity sha512-ozlZFogPqoLm8WBr5Z8UckIoE4YQ5KESVcNudyXOR8uqIkliTEgJ3RoketfG6pmzLdeZF0H/wjE9/cCEitBl7Q==
dependencies:
"@babel/helper-plugin-utils" "^7.18.6"
"@babel/plugin-syntax-numeric-separator" "^7.10.4"

"@babel/plugin-proposal-object-rest-spread@^7.0.0":
version "7.20.2"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.20.2.tgz#a556f59d555f06961df1e572bb5eca864c84022d"
Expand Down Expand Up @@ -391,7 +399,7 @@
dependencies:
"@babel/helper-plugin-utils" "^7.8.0"

"@babel/plugin-syntax-numeric-separator@^7.8.3":
"@babel/plugin-syntax-numeric-separator@^7.10.4", "@babel/plugin-syntax-numeric-separator@^7.8.3":
version "7.10.4"
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-numeric-separator/-/plugin-syntax-numeric-separator-7.10.4.tgz#b9b070b3e33570cd9fd07ba7fa91c0dd37b9af97"
integrity sha512-9H6YdfkcK/uOnY/K7/aA2xpzaAgkQn37yzWUMRK7OaPOqOpGS1+n0H5hxT9AUw9EsSjPW8SVyMJwYRtWs3X3ug==
Expand Down

0 comments on commit 22bc39f

Please sign in to comment.