Skip to content

Commit a797db3

Browse files
huntiesatya164
andauthored
fix: migrate to babel-plugin-syntax-hermes-parser (#822)
### Summary Fixes compatibility of `react-native-builder-bob/babel-preset` with React Native versions `>= 0.76.0` — likely broken today, without user config modifications. - `@babel/preset-flow` is [discontinued](babel/babel#16264). The Flow language has since evolved (e.g. `as` syntax) and newer `react-native` versions can no longer be parsed. - This is succeeded by [babel-plugin-syntax-hermes-parser](https://github.com/facebook/hermes/tree/main/tools/hermes-parser/js/babel-plugin-syntax-hermes-parser). Context: - facebook/react-native#50683 (comment) Co-authored-by: Satyajit Sahoo <[email protected]>
1 parent a260218 commit a797db3

File tree

4 files changed

+56
-28
lines changed

4 files changed

+56
-28
lines changed

Diff for: packages/create-react-native-library/templates/common/babel.config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
module.exports = {
2-
presets: ['module:react-native-builder-bob/babel-preset'],
32
overrides: [
3+
{
4+
exclude: /\/node_modules\//,
5+
presets: ['module:react-native-builder-bob/babel-preset'],
6+
},
47
{
58
include: /\/node_modules\//,
69
presets: ['module:@react-native/babel-preset'],

Diff for: packages/react-native-builder-bob/babel-preset.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,14 @@ module.exports = function (api, options, cwd) {
5050
},
5151
],
5252
require.resolve('@babel/preset-typescript'),
53-
require.resolve('@babel/preset-flow'),
5453
],
5554
plugins: [
5655
require.resolve('@babel/plugin-transform-strict-mode'),
56+
[
57+
require.resolve('babel-plugin-syntax-hermes-parser'),
58+
{ parseLangTypes: 'flow' },
59+
],
60+
require.resolve('@babel/plugin-transform-flow-strip-types'),
5761
[
5862
require.resolve('./lib/babel'),
5963
{

Diff for: packages/react-native-builder-bob/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,14 @@
4646
},
4747
"dependencies": {
4848
"@babel/core": "^7.25.2",
49+
"@babel/plugin-transform-flow-strip-types": "^7.26.5",
4950
"@babel/plugin-transform-strict-mode": "^7.24.7",
5051
"@babel/preset-env": "^7.25.2",
51-
"@babel/preset-flow": "^7.24.7",
5252
"@babel/preset-react": "^7.24.7",
5353
"@babel/preset-typescript": "^7.24.7",
5454
"arktype": "^2.1.15",
5555
"babel-plugin-module-resolver": "^5.0.2",
56+
"babel-plugin-syntax-hermes-parser": "^0.28.0",
5657
"browserslist": "^4.20.4",
5758
"cross-spawn": "^7.0.3",
5859
"dedent": "^0.7.0",

Diff for: yarn.lock

+45-25
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,13 @@ __metadata:
244244
languageName: node
245245
linkType: hard
246246

247+
"@babel/helper-plugin-utils@npm:^7.25.9, @babel/helper-plugin-utils@npm:^7.26.5":
248+
version: 7.26.5
249+
resolution: "@babel/helper-plugin-utils@npm:7.26.5"
250+
checksum: 4771fbb1711c624c62d12deabc2ed7435a6e6994b6ce09d5ede1bc1bf19be59c3775461a1e693bdd596af865685e87bb2abc778f62ceadc1b2095a8e2aa74180
251+
languageName: node
252+
linkType: hard
253+
247254
"@babel/helper-remap-async-to-generator@npm:^7.24.7, @babel/helper-remap-async-to-generator@npm:^7.25.0":
248255
version: 7.25.0
249256
resolution: "@babel/helper-remap-async-to-generator@npm:7.25.0"
@@ -487,14 +494,14 @@ __metadata:
487494
languageName: node
488495
linkType: hard
489496

490-
"@babel/plugin-syntax-flow@npm:^7.24.7":
491-
version: 7.24.7
492-
resolution: "@babel/plugin-syntax-flow@npm:7.24.7"
497+
"@babel/plugin-syntax-flow@npm:^7.26.0":
498+
version: 7.26.0
499+
resolution: "@babel/plugin-syntax-flow@npm:7.26.0"
493500
dependencies:
494-
"@babel/helper-plugin-utils": ^7.24.7
501+
"@babel/helper-plugin-utils": ^7.25.9
495502
peerDependencies:
496503
"@babel/core": ^7.0.0-0
497-
checksum: 43b78b5fcdedb2a6d80c3d02a1a564fbfde86b73b442d616a8f318f673caa6ce0151513af5a00fcae42a512f144e70ef259d368b9537ee35d40336a6c895a7d4
504+
checksum: fdc0d0a7b512e00d933e12cf93c785ea4645a193f4b539230b7601cfaa8c704410199318ce9ea14e5fca7d13e9027822f7d81a7871d3e854df26b6af04cc3c6c
498505
languageName: node
499506
linkType: hard
500507

@@ -859,15 +866,15 @@ __metadata:
859866
languageName: node
860867
linkType: hard
861868

862-
"@babel/plugin-transform-flow-strip-types@npm:^7.24.7":
863-
version: 7.25.2
864-
resolution: "@babel/plugin-transform-flow-strip-types@npm:7.25.2"
869+
"@babel/plugin-transform-flow-strip-types@npm:^7.26.5":
870+
version: 7.26.5
871+
resolution: "@babel/plugin-transform-flow-strip-types@npm:7.26.5"
865872
dependencies:
866-
"@babel/helper-plugin-utils": ^7.24.8
867-
"@babel/plugin-syntax-flow": ^7.24.7
873+
"@babel/helper-plugin-utils": ^7.26.5
874+
"@babel/plugin-syntax-flow": ^7.26.0
868875
peerDependencies:
869876
"@babel/core": ^7.0.0-0
870-
checksum: 9f7b96cbd374077eaf04b59e468976d2e89ec353807d7ac28f129f686945447df92aeb5b60acf906f3ec0f9ebef5d9f88735c7aa39af97033a6ab96c79c9a909
877+
checksum: a15ae76aea55f1801a5c8ebdfdd0e4616f256ca1eeb504b0781120242aae5a2174439a084bacd2b9e3e83d2a8463cf10c2a8c9f0f0504ded21144297c2b4a380
871878
languageName: node
872879
linkType: hard
873880

@@ -1433,19 +1440,6 @@ __metadata:
14331440
languageName: node
14341441
linkType: hard
14351442

1436-
"@babel/preset-flow@npm:^7.24.7":
1437-
version: 7.24.7
1438-
resolution: "@babel/preset-flow@npm:7.24.7"
1439-
dependencies:
1440-
"@babel/helper-plugin-utils": ^7.24.7
1441-
"@babel/helper-validator-option": ^7.24.7
1442-
"@babel/plugin-transform-flow-strip-types": ^7.24.7
1443-
peerDependencies:
1444-
"@babel/core": ^7.0.0-0
1445-
checksum: 4caca02a6e0a477eb22994d686a1fbf65b5ab0240ae77530696434dba7efff4c5dcbf9186a774168dd4c492423141a22af3f2874c356aa22429f3c83eaf34419
1446-
languageName: node
1447-
linkType: hard
1448-
14491443
"@babel/preset-modules@npm:0.1.6-no-external-plugins":
14501444
version: 0.1.6-no-external-plugins
14511445
resolution: "@babel/preset-modules@npm:0.1.6-no-external-plugins"
@@ -4616,6 +4610,15 @@ __metadata:
46164610
languageName: node
46174611
linkType: hard
46184612

4613+
"babel-plugin-syntax-hermes-parser@npm:^0.28.0":
4614+
version: 0.28.0
4615+
resolution: "babel-plugin-syntax-hermes-parser@npm:0.28.0"
4616+
dependencies:
4617+
hermes-parser: 0.28.0
4618+
checksum: 62d16a422f935d2a313fc64a9258cea07974cf97d66fce888bc58c044bbfa84ef891ae7dff7cddd3b891f81936534d29df087040f1e8447d6d60668c5e449f50
4619+
languageName: node
4620+
linkType: hard
4621+
46194622
"babel-preset-current-node-syntax@npm:^1.0.0":
46204623
version: 1.0.1
46214624
resolution: "babel-preset-current-node-syntax@npm:1.0.1"
@@ -8121,6 +8124,13 @@ __metadata:
81218124
languageName: node
81228125
linkType: hard
81238126

8127+
"hermes-estree@npm:0.28.0":
8128+
version: 0.28.0
8129+
resolution: "hermes-estree@npm:0.28.0"
8130+
checksum: d4cf9dd2b718bb0ac0681b015befb96c9a3d3709735ebb5e191bbca559cae06215fac37949cb67e3e8d2dd1af829779d2bfe389763759416dac28129b2462ffe
8131+
languageName: node
8132+
linkType: hard
8133+
81248134
"hermes-parser@npm:0.20.1":
81258135
version: 0.20.1
81268136
resolution: "hermes-parser@npm:0.20.1"
@@ -8130,6 +8140,15 @@ __metadata:
81308140
languageName: node
81318141
linkType: hard
81328142

8143+
"hermes-parser@npm:0.28.0":
8144+
version: 0.28.0
8145+
resolution: "hermes-parser@npm:0.28.0"
8146+
dependencies:
8147+
hermes-estree: 0.28.0
8148+
checksum: 42aa969f4afb29bb76f0df44f7a672c0ce67814e639882091e1c94f579f2e158dcb761885080c66af89287845073f8a115e72a143bc28e5f6ab9814397524930
8149+
languageName: node
8150+
linkType: hard
8151+
81338152
"hosted-git-info@npm:^2.1.4":
81348153
version: 2.8.9
81358154
resolution: "hosted-git-info@npm:2.8.9"
@@ -12731,9 +12750,9 @@ __metadata:
1273112750
dependencies:
1273212751
"@babel/cli": ^7.24.8
1273312752
"@babel/core": ^7.25.2
12753+
"@babel/plugin-transform-flow-strip-types": ^7.26.5
1273412754
"@babel/plugin-transform-strict-mode": ^7.24.7
1273512755
"@babel/preset-env": ^7.25.2
12736-
"@babel/preset-flow": ^7.24.7
1273712756
"@babel/preset-react": ^7.24.7
1273812757
"@babel/preset-typescript": ^7.24.7
1273912758
"@jest/globals": ^29.7.0
@@ -12751,6 +12770,7 @@ __metadata:
1275112770
"@types/yargs": ^17.0.10
1275212771
arktype: ^2.1.15
1275312772
babel-plugin-module-resolver: ^5.0.2
12773+
babel-plugin-syntax-hermes-parser: ^0.28.0
1275412774
browserslist: ^4.20.4
1275512775
concurrently: ^7.2.2
1275612776
cross-spawn: ^7.0.3

0 commit comments

Comments
 (0)