Skip to content

Commit 6af4e04

Browse files
tido64zamotany
authored andcommitted
fix: add babel plugins to support Hermes (#617)
1 parent 2c68e97 commit 6af4e04

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

packages/haul-babel-preset-react-native/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@
2626
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
2727
"@babel/plugin-syntax-export-default-from": "^7.2.0",
2828
"@babel/plugin-transform-async-to-generator": "^7.4.4",
29+
"@babel/plugin-transform-classes": "^7.0.0",
2930
"@babel/plugin-transform-exponentiation-operator": "^7.2.0",
3031
"@babel/plugin-transform-flow-strip-types": "^7.4.4",
3132
"@babel/plugin-transform-literals": "^7.2.0",
3233
"@babel/plugin-transform-modules-commonjs": "^7.4.4",
3334
"@babel/plugin-transform-react-display-name": "^7.2.0",
3435
"@babel/plugin-transform-react-jsx": "^7.3.0",
3536
"@babel/plugin-transform-react-jsx-source": "^7.2.0",
37+
"@babel/plugin-transform-shorthand-properties": "^7.0.0",
3638
"@babel/plugin-transform-sticky-regex": "^7.2.0",
39+
"@babel/plugin-transform-template-literals": "^7.0.0",
3740
"@babel/plugin-transform-typescript": "^7.4.4",
3841
"@babel/plugin-transform-unicode-regex": "^7.4.4",
3942
"@babel/template": "^7.4.4",

packages/haul-babel-preset-react-native/src/index.ts

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const defaultPlugins = [
2-
[require('@babel/plugin-proposal-class-properties')],
2+
[require('@babel/plugin-proposal-class-properties'), { loose: true }],
33
[require('@babel/plugin-proposal-optional-catch-binding')],
44
[require('@babel/plugin-syntax-dynamic-import')],
55
[require('@babel/plugin-syntax-export-default-from')],
@@ -13,6 +13,13 @@ const defaultPlugins = [
1313
[require('@babel/plugin-transform-async-to-generator')],
1414
];
1515

16+
// Additional plugins for Hermes because it doesn't support ES6 yet
17+
const hermesPlugins = [
18+
[require('@babel/plugin-transform-classes')],
19+
[require('@babel/plugin-transform-shorthand-properties')],
20+
[require('@babel/plugin-transform-template-literals'), { loose: true }],
21+
];
22+
1623
function isTypeScriptSource(fileName: string) {
1724
return !!fileName && fileName.endsWith('.ts');
1825
}
@@ -21,7 +28,7 @@ function isTSXSource(fileName: string) {
2128
return !!fileName && fileName.endsWith('.tsx');
2229
}
2330

24-
export default function getHaulBabelPreset() {
31+
export default function getHaulBabelPreset(options: { hermes: boolean }) {
2532
return {
2633
compact: false,
2734
overrides: [
@@ -30,16 +37,18 @@ export default function getHaulBabelPreset() {
3037
plugins: [require('@babel/plugin-transform-flow-strip-types')],
3138
},
3239
{
33-
plugins: defaultPlugins.concat(
34-
process.env.HAUL_PLATFORM
40+
plugins: [
41+
...defaultPlugins,
42+
...(options.hermes ? hermesPlugins : []),
43+
...(process.env.HAUL_PLATFORM
3544
? [
3645
[
3746
require('./transforms/stripDeadPlatformSelect'),
3847
{ platform: process.env.HAUL_PLATFORM },
3948
],
4049
]
41-
: []
42-
),
50+
: []),
51+
],
4352
},
4453
{
4554
test: /node_modules\/react-native/,

0 commit comments

Comments
 (0)