Skip to content

Commit 670a4d9

Browse files
robhoganmeta-codesync[bot]
authored andcommitted
Babel preset: Add unstable_preserveClasses to experiment with disabling class transforms for SH (#54153)
Summary: Pull Request resolved: #54153 Disable `babel/plugin-transform-classes` and `babel/plugin-transform-class-properties` when `customTransformOptions.unstable_preserveClasses` is truthy. Changelog: [Internal] Reviewed By: huntie Differential Revision: D84506895 fbshipit-source-id: 6c66cf6cea037ec183235a058a86b558a7876582
1 parent 93278d5 commit 670a4d9

File tree

1 file changed

+11
-2
lines changed
  • packages/react-native-babel-preset/src/configs

1 file changed

+11
-2
lines changed

packages/react-native-babel-preset/src/configs/main.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const EXCLUDED_FIRST_PARTY_PATHS = [
2020
/[/\\]private[/\\]react-native-fantom[/\\]/,
2121
];
2222

23+
// customTransformOptions may be strings from URL params, or booleans passed
24+
// programatically. For strings, handle them as Metro does when parsing URLs.
25+
const TRUE_VALS = new Set([true, 'true', '1']);
26+
2327
function isTypeScriptSource(fileName) {
2428
return !!fileName && fileName.endsWith('.ts');
2529
}
@@ -55,6 +59,9 @@ const getPreset = (src, options) => {
5559

5660
const isNull = src == null;
5761
const hasClass = isNull || src.indexOf('class') !== -1;
62+
const preserveClasses = TRUE_VALS.has(
63+
options?.customTransformOptions?.unstable_preserveClasses,
64+
);
5865

5966
const extraPlugins = [];
6067
const firstPartyPlugins = [];
@@ -91,7 +98,7 @@ const getPreset = (src, options) => {
9198
);
9299
}
93100

94-
if (hasClass) {
101+
if (hasClass && !preserveClasses) {
95102
extraPlugins.push([require('@babel/plugin-transform-classes')]);
96103
}
97104

@@ -235,7 +242,9 @@ const getPreset = (src, options) => {
235242
],
236243
[require('babel-plugin-transform-flow-enums')],
237244
[require('@babel/plugin-transform-block-scoping')],
238-
[require('@babel/plugin-transform-class-properties'), {loose}],
245+
...(preserveClasses
246+
? []
247+
: [[require('@babel/plugin-transform-class-properties'), {loose}]]),
239248
[require('@babel/plugin-transform-private-methods'), {loose}],
240249
[
241250
require('@babel/plugin-transform-private-property-in-object'),

0 commit comments

Comments
 (0)