Skip to content

Commit 9b26db0

Browse files
committed
Avoid meta programming to initialize functions in module scope (#26388)
I'm trying to get rid of all meta programming in the module scope so that closure can do a better job figuring out cyclic dependencies and ability to reorder. This is converting a lot of the patterns that assign functions conditionally to using function declarations instead. ``` let fn; if (__DEV__) { fn = function() { ... }; } ``` -> ``` function fn() { if (__DEV__) { ... } } ``` DiffTrain build for [d310d65](d310d65)
1 parent 18d3ea0 commit 9b26db0

25 files changed

+2392
-2499
lines changed

compiled/facebook-www/JSXDEVRuntime-dev.classic.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ function defineRefPropWarningGetter(props, displayName) {
941941
* @internal
942942
*/
943943

944-
var ReactElement = function (type, key, ref, self, source, owner, props) {
944+
function ReactElement(type, key, ref, self, source, owner, props) {
945945
var element = {
946946
// This tag allows us to uniquely identify this as a React Element
947947
$$typeof: REACT_ELEMENT_TYPE,
@@ -993,7 +993,7 @@ var ReactElement = function (type, key, ref, self, source, owner, props) {
993993
}
994994

995995
return element;
996-
};
996+
}
997997
/**
998998
* https://github.com/reactjs/rfcs/pull/107
999999
* @param {*} type

compiled/facebook-www/JSXDEVRuntime-dev.modern.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ function defineRefPropWarningGetter(props, displayName) {
941941
* @internal
942942
*/
943943

944-
var ReactElement = function (type, key, ref, self, source, owner, props) {
944+
function ReactElement(type, key, ref, self, source, owner, props) {
945945
var element = {
946946
// This tag allows us to uniquely identify this as a React Element
947947
$$typeof: REACT_ELEMENT_TYPE,
@@ -993,7 +993,7 @@ var ReactElement = function (type, key, ref, self, source, owner, props) {
993993
}
994994

995995
return element;
996-
};
996+
}
997997
/**
998998
* https://github.com/reactjs/rfcs/pull/107
999999
* @param {*} type

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6bd53a5bdfe24d9a70819c4eba40b488e62900cd
1+
d310d654a7c7aab6c8213da84ef36dfba82711b0

compiled/facebook-www/React-dev.classic.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (
2727
}
2828
"use strict";
2929

30-
var ReactVersion = "18.3.0-www-classic-96f33629";
30+
var ReactVersion = "18.3.0-www-classic-e762d1a9";
3131

3232
// ATTENTION
3333
// When adding new symbols to this file,
@@ -756,7 +756,7 @@ function warnIfStringRefCannotBeAutoConverted$1(config) {
756756
* @internal
757757
*/
758758

759-
var ReactElement$1 = function (type, key, ref, self, source, owner, props) {
759+
function ReactElement$1(type, key, ref, self, source, owner, props) {
760760
var element = {
761761
// This tag allows us to uniquely identify this as a React Element
762762
$$typeof: REACT_ELEMENT_TYPE,
@@ -808,7 +808,7 @@ var ReactElement$1 = function (type, key, ref, self, source, owner, props) {
808808
}
809809

810810
return element;
811-
};
811+
}
812812
/**
813813
* Create and return a new ReactElement of the given type.
814814
* See https://reactjs.org/docs/react-api.html#createelement
@@ -3574,7 +3574,7 @@ function defineRefPropWarningGetter(props, displayName) {
35743574
* @internal
35753575
*/
35763576

3577-
var ReactElement = function (type, key, ref, self, source, owner, props) {
3577+
function ReactElement(type, key, ref, self, source, owner, props) {
35783578
var element = {
35793579
// This tag allows us to uniquely identify this as a React Element
35803580
$$typeof: REACT_ELEMENT_TYPE,
@@ -3626,7 +3626,7 @@ var ReactElement = function (type, key, ref, self, source, owner, props) {
36263626
}
36273627

36283628
return element;
3629-
};
3629+
}
36303630
/**
36313631
* https://github.com/reactjs/rfcs/pull/107
36323632
* @param {*} type

compiled/facebook-www/React-dev.modern.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (
2727
}
2828
"use strict";
2929

30-
var ReactVersion = "18.3.0-www-modern-724bb919";
30+
var ReactVersion = "18.3.0-www-modern-9bafe2f6";
3131

3232
// ATTENTION
3333
// When adding new symbols to this file,
@@ -756,7 +756,7 @@ function warnIfStringRefCannotBeAutoConverted$1(config) {
756756
* @internal
757757
*/
758758

759-
var ReactElement$1 = function (type, key, ref, self, source, owner, props) {
759+
function ReactElement$1(type, key, ref, self, source, owner, props) {
760760
var element = {
761761
// This tag allows us to uniquely identify this as a React Element
762762
$$typeof: REACT_ELEMENT_TYPE,
@@ -808,7 +808,7 @@ var ReactElement$1 = function (type, key, ref, self, source, owner, props) {
808808
}
809809

810810
return element;
811-
};
811+
}
812812
/**
813813
* Create and return a new ReactElement of the given type.
814814
* See https://reactjs.org/docs/react-api.html#createelement
@@ -3539,7 +3539,7 @@ function defineRefPropWarningGetter(props, displayName) {
35393539
* @internal
35403540
*/
35413541

3542-
var ReactElement = function (type, key, ref, self, source, owner, props) {
3542+
function ReactElement(type, key, ref, self, source, owner, props) {
35433543
var element = {
35443544
// This tag allows us to uniquely identify this as a React Element
35453545
$$typeof: REACT_ELEMENT_TYPE,
@@ -3591,7 +3591,7 @@ var ReactElement = function (type, key, ref, self, source, owner, props) {
35913591
}
35923592

35933593
return element;
3594-
};
3594+
}
35953595
/**
35963596
* https://github.com/reactjs/rfcs/pull/107
35973597
* @param {*} type

compiled/facebook-www/ReactART-dev.classic.js

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function _assertThisInitialized(self) {
6969
return self;
7070
}
7171

72-
var ReactVersion = "18.3.0-www-classic-5ea6b0b1";
72+
var ReactVersion = "18.3.0-www-classic-d10ee72f";
7373

7474
var LegacyRoot = 0;
7575
var ConcurrentRoot = 1;
@@ -10978,11 +10978,10 @@ var didWarnAboutUninitializedState;
1097810978
var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate;
1097910979
var didWarnAboutLegacyLifecyclesAndDerivedState;
1098010980
var didWarnAboutUndefinedDerivedState;
10981-
var warnOnUndefinedDerivedState;
10982-
var warnOnInvalidCallback;
1098310981
var didWarnAboutDirectlyAssigningPropsToState;
1098410982
var didWarnAboutContextTypeAndContextTypes;
1098510983
var didWarnAboutInvalidateContextType;
10984+
var didWarnOnInvalidCallback;
1098610985

1098710986
{
1098810987
didWarnAboutStateAssignmentForComponent = new Set();
@@ -10993,9 +10992,30 @@ var didWarnAboutInvalidateContextType;
1099310992
didWarnAboutUndefinedDerivedState = new Set();
1099410993
didWarnAboutContextTypeAndContextTypes = new Set();
1099510994
didWarnAboutInvalidateContextType = new Set();
10996-
var didWarnOnInvalidCallback = new Set();
10995+
didWarnOnInvalidCallback = new Set(); // This is so gross but it's at least non-critical and can be removed if
10996+
// it causes problems. This is meant to give a nicer error message for
10997+
// ReactDOM15.unstable_renderSubtreeIntoContainer(reactDOM16Component,
10998+
// ...)) which otherwise throws a "_processChildContext is not a function"
10999+
// exception.
11000+
11001+
Object.defineProperty(fakeInternalInstance, "_processChildContext", {
11002+
enumerable: false,
11003+
value: function () {
11004+
throw new Error(
11005+
"_processChildContext is not available in React 16+. This likely " +
11006+
"means you have multiple copies of React and are attempting to nest " +
11007+
"a React 15 tree inside a React 16 tree using " +
11008+
"unstable_renderSubtreeIntoContainer, which isn't supported. Try " +
11009+
"to make sure you have only one copy of React (and ideally, switch " +
11010+
"to ReactDOM.createPortal)."
11011+
);
11012+
}
11013+
});
11014+
Object.freeze(fakeInternalInstance);
11015+
}
1099711016

10998-
warnOnInvalidCallback = function (callback, callerName) {
11017+
function warnOnInvalidCallback(callback, callerName) {
11018+
{
1099911019
if (callback === null || typeof callback === "function") {
1100011020
return;
1100111021
}
@@ -11012,9 +11032,11 @@ var didWarnAboutInvalidateContextType;
1101211032
callback
1101311033
);
1101411034
}
11015-
};
11035+
}
11036+
}
1101611037

11017-
warnOnUndefinedDerivedState = function (type, partialState) {
11038+
function warnOnUndefinedDerivedState(type, partialState) {
11039+
{
1101811040
if (partialState === undefined) {
1101911041
var componentName = getComponentNameFromType(type) || "Component";
1102011042

@@ -11028,26 +11050,7 @@ var didWarnAboutInvalidateContextType;
1102811050
);
1102911051
}
1103011052
}
11031-
}; // This is so gross but it's at least non-critical and can be removed if
11032-
// it causes problems. This is meant to give a nicer error message for
11033-
// ReactDOM15.unstable_renderSubtreeIntoContainer(reactDOM16Component,
11034-
// ...)) which otherwise throws a "_processChildContext is not a function"
11035-
// exception.
11036-
11037-
Object.defineProperty(fakeInternalInstance, "_processChildContext", {
11038-
enumerable: false,
11039-
value: function () {
11040-
throw new Error(
11041-
"_processChildContext is not available in React 16+. This likely " +
11042-
"means you have multiple copies of React and are attempting to nest " +
11043-
"a React 15 tree inside a React 16 tree using " +
11044-
"unstable_renderSubtreeIntoContainer, which isn't supported. Try " +
11045-
"to make sure you have only one copy of React (and ideally, switch " +
11046-
"to ReactDOM.createPortal)."
11047-
);
11048-
}
11049-
});
11050-
Object.freeze(fakeInternalInstance);
11053+
}
1105111054
}
1105211055

1105311056
function applyDerivedStateFromProps(
@@ -18854,20 +18857,10 @@ if (typeof ReactFbErrorUtils.invokeGuardedCallback !== "function") {
1885418857
);
1885518858
}
1885618859

18857-
var invokeGuardedCallbackImpl = function (
18858-
name,
18859-
func,
18860-
context,
18861-
a,
18862-
b,
18863-
c,
18864-
d,
18865-
e,
18866-
f
18867-
) {
18860+
function invokeGuardedCallbackImpl(name, func, context, a, b, c, d, e, f) {
1886818861
// This will call `this.onError(err)` if an error was caught.
1886918862
ReactFbErrorUtils.invokeGuardedCallback.apply(this, arguments);
18870-
};
18863+
}
1887118864

1887218865
var hasError = false;
1887318866
var caughtError = null; // Used by event system to capture/rethrow the first error.
@@ -18949,7 +18942,7 @@ function reportUncaughtErrorInDEV(error) {
1894918942
}
1895018943
}
1895118944

18952-
var callComponentWillUnmountWithTimer = function (current, instance) {
18945+
function callComponentWillUnmountWithTimer(current, instance) {
1895318946
instance.props = current.memoizedProps;
1895418947
instance.state = current.memoizedState;
1895518948

@@ -18963,7 +18956,7 @@ var callComponentWillUnmountWithTimer = function (current, instance) {
1896318956
} else {
1896418957
instance.componentWillUnmount();
1896518958
}
18966-
}; // Capture errors so they don't interrupt unmounting.
18959+
} // Capture errors so they don't interrupt unmounting.
1896718960

1896818961
function safelyCallComponentWillUnmount(
1896918962
current,
@@ -26923,10 +26916,10 @@ function FiberNode(tag, pendingProps, key, mode) {
2692326916
// 5) It should be easy to port this to a C struct and keep a C implementation
2692426917
// compatible.
2692526918

26926-
var createFiber = function (tag, pendingProps, key, mode) {
26919+
function createFiber(tag, pendingProps, key, mode) {
2692726920
// $FlowFixMe: the shapes are exact here but Flow doesn't like constructors
2692826921
return new FiberNode(tag, pendingProps, key, mode);
26929-
};
26922+
}
2693026923

2693126924
function shouldConstruct(Component) {
2693226925
var prototype = Component.prototype;

0 commit comments

Comments
 (0)