Skip to content

Commit 47157c6

Browse files
committed
[compiler] Add support for commonjs (#34589)
We previously always generated import statements for any modules that had to be required, notably the `import {c} from 'react/compiler-runtime'` for the memo cache function. However, this obviously doesn't work when the source is using commonjs. Now we check the sourceType of the module and generate require() statements if the source type is 'script'. I initially explored using https://babeljs.io/docs/babel-helper-module-imports, but the API design was unfortunately not flexible enough for our use-case. Specifically, our pipeline is as follows: * Compile individual functions. Generate candidate imports, pre-allocating the local names for those imports. * If the file is compiled successfully, actually add the imports to the program. Ie we need to pre-allocate identifier names for the imports before we add them to the program — but that isn't supported by babel-helper-module-imports. So instead we generate our own require() calls if the sourceType is script. DiffTrain build for [8ad773b](8ad773b)
1 parent c6a7213 commit 47157c6

26 files changed

+113
-91
lines changed

compiled-rn/VERSION_NATIVE_FB

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
19.2.0-native-fb-2c6d92fd-20250924
1+
19.2.0-native-fb-8ad773b1-20250924

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOM-dev.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<ca6667bb08f6378c9fb14b43a6f7f001>>
10+
* @generated SignedSource<<9c16e0645fb189599108ec815a3cca64>>
1111
*/
1212

1313
"use strict";
@@ -404,5 +404,5 @@ __DEV__ &&
404404
exports.useFormStatus = function () {
405405
return resolveDispatcher().useHostTransitionStatus();
406406
};
407-
exports.version = "19.2.0-native-fb-2c6d92fd-20250924";
407+
exports.version = "19.2.0-native-fb-8ad773b1-20250924";
408408
})();

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOM-prod.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<0d6471c59efceed969fff0b755e0a2c2>>
10+
* @generated SignedSource<<2ba7a24595485f5678f07169a726feb9>>
1111
*/
1212

1313
"use strict";
@@ -203,4 +203,4 @@ exports.useFormState = function (action, initialState, permalink) {
203203
exports.useFormStatus = function () {
204204
return ReactSharedInternals.H.useHostTransitionStatus();
205205
};
206-
exports.version = "19.2.0-native-fb-2c6d92fd-20250924";
206+
exports.version = "19.2.0-native-fb-8ad773b1-20250924";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOM-profiling.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<0d6471c59efceed969fff0b755e0a2c2>>
10+
* @generated SignedSource<<2ba7a24595485f5678f07169a726feb9>>
1111
*/
1212

1313
"use strict";
@@ -203,4 +203,4 @@ exports.useFormState = function (action, initialState, permalink) {
203203
exports.useFormStatus = function () {
204204
return ReactSharedInternals.H.useHostTransitionStatus();
205205
};
206-
exports.version = "19.2.0-native-fb-2c6d92fd-20250924";
206+
exports.version = "19.2.0-native-fb-8ad773b1-20250924";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMClient-dev.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<3887e680aceb90f25b83129e27c979c2>>
10+
* @generated SignedSource<<604a5257cf88538694d63c972b802867>>
1111
*/
1212

1313
/*
@@ -29920,11 +29920,11 @@ __DEV__ &&
2992029920
};
2992129921
(function () {
2992229922
var isomorphicReactPackageVersion = React.version;
29923-
if ("19.2.0-native-fb-2c6d92fd-20250924" !== isomorphicReactPackageVersion)
29923+
if ("19.2.0-native-fb-8ad773b1-20250924" !== isomorphicReactPackageVersion)
2992429924
throw Error(
2992529925
'Incompatible React versions: The "react" and "react-dom" packages must have the exact same version. Instead got:\n - react: ' +
2992629926
(isomorphicReactPackageVersion +
29927-
"\n - react-dom: 19.2.0-native-fb-2c6d92fd-20250924\nLearn more: https://react.dev/warnings/version-mismatch")
29927+
"\n - react-dom: 19.2.0-native-fb-8ad773b1-20250924\nLearn more: https://react.dev/warnings/version-mismatch")
2992829928
);
2992929929
})();
2993029930
("function" === typeof Map &&
@@ -29961,10 +29961,10 @@ __DEV__ &&
2996129961
!(function () {
2996229962
var internals = {
2996329963
bundleType: 1,
29964-
version: "19.2.0-native-fb-2c6d92fd-20250924",
29964+
version: "19.2.0-native-fb-8ad773b1-20250924",
2996529965
rendererPackageName: "react-dom",
2996629966
currentDispatcherRef: ReactSharedInternals,
29967-
reconcilerVersion: "19.2.0-native-fb-2c6d92fd-20250924"
29967+
reconcilerVersion: "19.2.0-native-fb-8ad773b1-20250924"
2996829968
};
2996929969
internals.overrideHookState = overrideHookState;
2997029970
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -30113,5 +30113,5 @@ __DEV__ &&
3011330113
listenToAllSupportedEvents(container);
3011430114
return new ReactDOMHydrationRoot(initialChildren);
3011530115
};
30116-
exports.version = "19.2.0-native-fb-2c6d92fd-20250924";
30116+
exports.version = "19.2.0-native-fb-8ad773b1-20250924";
3011730117
})();

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMClient-prod.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<e016d2e6bbb8091dbeca722936ce0ac5>>
10+
* @generated SignedSource<<c9dcdb6726a2d2bf9ddedee14086e2d6>>
1111
*/
1212

1313
/*
@@ -17529,14 +17529,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) {
1752917529
};
1753017530
var isomorphicReactPackageVersion$jscomp$inline_2052 = React.version;
1753117531
if (
17532-
"19.2.0-native-fb-2c6d92fd-20250924" !==
17532+
"19.2.0-native-fb-8ad773b1-20250924" !==
1753317533
isomorphicReactPackageVersion$jscomp$inline_2052
1753417534
)
1753517535
throw Error(
1753617536
formatProdErrorMessage(
1753717537
527,
1753817538
isomorphicReactPackageVersion$jscomp$inline_2052,
17539-
"19.2.0-native-fb-2c6d92fd-20250924"
17539+
"19.2.0-native-fb-8ad773b1-20250924"
1754017540
)
1754117541
);
1754217542
ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
@@ -17558,10 +17558,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
1755817558
};
1755917559
var internals$jscomp$inline_2625 = {
1756017560
bundleType: 0,
17561-
version: "19.2.0-native-fb-2c6d92fd-20250924",
17561+
version: "19.2.0-native-fb-8ad773b1-20250924",
1756217562
rendererPackageName: "react-dom",
1756317563
currentDispatcherRef: ReactSharedInternals,
17564-
reconcilerVersion: "19.2.0-native-fb-2c6d92fd-20250924"
17564+
reconcilerVersion: "19.2.0-native-fb-8ad773b1-20250924"
1756517565
};
1756617566
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1756717567
var hook$jscomp$inline_2626 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -17668,4 +17668,4 @@ exports.hydrateRoot = function (container, initialChildren, options) {
1766817668
listenToAllSupportedEvents(container);
1766917669
return new ReactDOMHydrationRoot(initialChildren);
1767017670
};
17671-
exports.version = "19.2.0-native-fb-2c6d92fd-20250924";
17671+
exports.version = "19.2.0-native-fb-8ad773b1-20250924";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMClient-profiling.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<a54f37bf65e7a41a95e980456387bd86>>
10+
* @generated SignedSource<<10f54ed7e3fee9259c4ec839b15103e2>>
1111
*/
1212

1313
/*
@@ -19622,14 +19622,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) {
1962219622
};
1962319623
var isomorphicReactPackageVersion$jscomp$inline_2343 = React.version;
1962419624
if (
19625-
"19.2.0-native-fb-2c6d92fd-20250924" !==
19625+
"19.2.0-native-fb-8ad773b1-20250924" !==
1962619626
isomorphicReactPackageVersion$jscomp$inline_2343
1962719627
)
1962819628
throw Error(
1962919629
formatProdErrorMessage(
1963019630
527,
1963119631
isomorphicReactPackageVersion$jscomp$inline_2343,
19632-
"19.2.0-native-fb-2c6d92fd-20250924"
19632+
"19.2.0-native-fb-8ad773b1-20250924"
1963319633
)
1963419634
);
1963519635
ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
@@ -19651,10 +19651,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
1965119651
};
1965219652
var internals$jscomp$inline_2350 = {
1965319653
bundleType: 0,
19654-
version: "19.2.0-native-fb-2c6d92fd-20250924",
19654+
version: "19.2.0-native-fb-8ad773b1-20250924",
1965519655
rendererPackageName: "react-dom",
1965619656
currentDispatcherRef: ReactSharedInternals,
19657-
reconcilerVersion: "19.2.0-native-fb-2c6d92fd-20250924",
19657+
reconcilerVersion: "19.2.0-native-fb-8ad773b1-20250924",
1965819658
getLaneLabelMap: function () {
1965919659
for (
1966019660
var map = new Map(), lane = 1, index$330 = 0;
@@ -19777,4 +19777,4 @@ exports.hydrateRoot = function (container, initialChildren, options) {
1977719777
listenToAllSupportedEvents(container);
1977819778
return new ReactDOMHydrationRoot(initialChildren);
1977919779
};
19780-
exports.version = "19.2.0-native-fb-2c6d92fd-20250924";
19780+
exports.version = "19.2.0-native-fb-8ad773b1-20250924";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMProfiling-dev.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<9953d4671e81f19e8b264e3cb7cc7017>>
10+
* @generated SignedSource<<ba7b31e51ed2417d831d1890ff563387>>
1111
*/
1212

1313
/*
@@ -29976,11 +29976,11 @@ __DEV__ &&
2997629976
};
2997729977
(function () {
2997829978
var isomorphicReactPackageVersion = React.version;
29979-
if ("19.2.0-native-fb-2c6d92fd-20250924" !== isomorphicReactPackageVersion)
29979+
if ("19.2.0-native-fb-8ad773b1-20250924" !== isomorphicReactPackageVersion)
2998029980
throw Error(
2998129981
'Incompatible React versions: The "react" and "react-dom" packages must have the exact same version. Instead got:\n - react: ' +
2998229982
(isomorphicReactPackageVersion +
29983-
"\n - react-dom: 19.2.0-native-fb-2c6d92fd-20250924\nLearn more: https://react.dev/warnings/version-mismatch")
29983+
"\n - react-dom: 19.2.0-native-fb-8ad773b1-20250924\nLearn more: https://react.dev/warnings/version-mismatch")
2998429984
);
2998529985
})();
2998629986
("function" === typeof Map &&
@@ -30017,10 +30017,10 @@ __DEV__ &&
3001730017
!(function () {
3001830018
var internals = {
3001930019
bundleType: 1,
30020-
version: "19.2.0-native-fb-2c6d92fd-20250924",
30020+
version: "19.2.0-native-fb-8ad773b1-20250924",
3002130021
rendererPackageName: "react-dom",
3002230022
currentDispatcherRef: ReactSharedInternals,
30023-
reconcilerVersion: "19.2.0-native-fb-2c6d92fd-20250924"
30023+
reconcilerVersion: "19.2.0-native-fb-8ad773b1-20250924"
3002430024
};
3002530025
internals.overrideHookState = overrideHookState;
3002630026
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -30485,7 +30485,7 @@ __DEV__ &&
3048530485
exports.useFormStatus = function () {
3048630486
return resolveDispatcher().useHostTransitionStatus();
3048730487
};
30488-
exports.version = "19.2.0-native-fb-2c6d92fd-20250924";
30488+
exports.version = "19.2.0-native-fb-8ad773b1-20250924";
3048930489
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
3049030490
"function" ===
3049130491
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMProfiling-prod.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<b60b3e9131bc5b4970a68dcad44f10cb>>
10+
* @generated SignedSource<<a44db50534889d61d0f6b679cf7f9c40>>
1111
*/
1212

1313
/*
@@ -17540,14 +17540,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) {
1754017540
};
1754117541
var isomorphicReactPackageVersion$jscomp$inline_2053 = React.version;
1754217542
if (
17543-
"19.2.0-native-fb-2c6d92fd-20250924" !==
17543+
"19.2.0-native-fb-8ad773b1-20250924" !==
1754417544
isomorphicReactPackageVersion$jscomp$inline_2053
1754517545
)
1754617546
throw Error(
1754717547
formatProdErrorMessage(
1754817548
527,
1754917549
isomorphicReactPackageVersion$jscomp$inline_2053,
17550-
"19.2.0-native-fb-2c6d92fd-20250924"
17550+
"19.2.0-native-fb-8ad773b1-20250924"
1755117551
)
1755217552
);
1755317553
ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
@@ -17569,10 +17569,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
1756917569
};
1757017570
var internals$jscomp$inline_2628 = {
1757117571
bundleType: 0,
17572-
version: "19.2.0-native-fb-2c6d92fd-20250924",
17572+
version: "19.2.0-native-fb-8ad773b1-20250924",
1757317573
rendererPackageName: "react-dom",
1757417574
currentDispatcherRef: ReactSharedInternals,
17575-
reconcilerVersion: "19.2.0-native-fb-2c6d92fd-20250924"
17575+
reconcilerVersion: "19.2.0-native-fb-8ad773b1-20250924"
1757617576
};
1757717577
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1757817578
var hook$jscomp$inline_2629 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -17832,4 +17832,4 @@ exports.useFormState = function (action, initialState, permalink) {
1783217832
exports.useFormStatus = function () {
1783317833
return ReactSharedInternals.H.useHostTransitionStatus();
1783417834
};
17835-
exports.version = "19.2.0-native-fb-2c6d92fd-20250924";
17835+
exports.version = "19.2.0-native-fb-8ad773b1-20250924";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMProfiling-profiling.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<02f068793aa7e30ccc369cb5da4f40c7>>
10+
* @generated SignedSource<<94b5d1952f04ab15fac9ccac2c2cc698>>
1111
*/
1212

1313
/*
@@ -19637,14 +19637,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) {
1963719637
};
1963819638
var isomorphicReactPackageVersion$jscomp$inline_2344 = React.version;
1963919639
if (
19640-
"19.2.0-native-fb-2c6d92fd-20250924" !==
19640+
"19.2.0-native-fb-8ad773b1-20250924" !==
1964119641
isomorphicReactPackageVersion$jscomp$inline_2344
1964219642
)
1964319643
throw Error(
1964419644
formatProdErrorMessage(
1964519645
527,
1964619646
isomorphicReactPackageVersion$jscomp$inline_2344,
19647-
"19.2.0-native-fb-2c6d92fd-20250924"
19647+
"19.2.0-native-fb-8ad773b1-20250924"
1964819648
)
1964919649
);
1965019650
ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
@@ -19666,10 +19666,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
1966619666
};
1966719667
var internals$jscomp$inline_2351 = {
1966819668
bundleType: 0,
19669-
version: "19.2.0-native-fb-2c6d92fd-20250924",
19669+
version: "19.2.0-native-fb-8ad773b1-20250924",
1967019670
rendererPackageName: "react-dom",
1967119671
currentDispatcherRef: ReactSharedInternals,
19672-
reconcilerVersion: "19.2.0-native-fb-2c6d92fd-20250924",
19672+
reconcilerVersion: "19.2.0-native-fb-8ad773b1-20250924",
1967319673
getLaneLabelMap: function () {
1967419674
for (
1967519675
var map = new Map(), lane = 1, index$330 = 0;
@@ -19945,7 +19945,7 @@ exports.useFormState = function (action, initialState, permalink) {
1994519945
exports.useFormStatus = function () {
1994619946
return ReactSharedInternals.H.useHostTransitionStatus();
1994719947
};
19948-
exports.version = "19.2.0-native-fb-2c6d92fd-20250924";
19948+
exports.version = "19.2.0-native-fb-8ad773b1-20250924";
1994919949
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
1995019950
"function" ===
1995119951
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)