Skip to content

Commit 66ad834

Browse files
committed
[compiler][be] Make program traversal more readable (#33147)
React Compiler's program traversal logic is pretty lengthy and complex as we've added a lot of features piecemeal. `compileProgram` is 300+ lines long and has confusing control flow (defining helpers inline, invoking visitors, mutating-asts-while-iterating, mutating global `ALREADY_COMPILED` state). - Moved more stuff to `ProgramContext` - Separated `compileProgram` into a bunch of helpers Tested by syncing this stack to a Meta codebase and observing no compilation output changes (D74487851, P1806855669, P1806855379) --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/33147). * #33149 * #33148 * __->__ #33147 DiffTrain build for [5069e18](5069e18)
1 parent 20ce6e4 commit 66ad834

37 files changed

+2554
-2695
lines changed

compiled/eslint-plugin-react-hooks/index.js

Lines changed: 228 additions & 144 deletions
Large diffs are not rendered by default.

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9518f1185621aecb99fd72385cdb137c6e8bd8fe
1+
5069e18060e00d7c07b2b04ebc8a3fa21e2d810a
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9518f1185621aecb99fd72385cdb137c6e8bd8fe
1+
5069e18060e00d7c07b2b04ebc8a3fa21e2d810a

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ __DEV__ &&
5959
this.refs = emptyObject;
6060
this.updater = updater || ReactNoopUpdateQueue;
6161
}
62+
function noop() {}
6263
function testStringCoercion(value) {
6364
return "" + value;
6465
}
@@ -383,7 +384,6 @@ __DEV__ &&
383384
? (checkKeyStringCoercion(element.key), escape("" + element.key))
384385
: index.toString(36);
385386
}
386-
function noop$1() {}
387387
function resolveThenable(thenable) {
388388
switch (thenable.status) {
389389
case "fulfilled":
@@ -393,7 +393,7 @@ __DEV__ &&
393393
default:
394394
switch (
395395
("string" === typeof thenable.status
396-
? thenable.then(noop$1, noop$1)
396+
? thenable.then(noop, noop)
397397
: ((thenable.status = "pending"),
398398
thenable.then(
399399
function (fulfilledValue) {
@@ -646,7 +646,6 @@ __DEV__ &&
646646
(ReactSharedInternals.T = prevTransition);
647647
}
648648
}
649-
function noop() {}
650649
function addTransitionType(type) {
651650
if (enableViewTransition) {
652651
var transition = ReactSharedInternals.T;
@@ -1538,7 +1537,7 @@ __DEV__ &&
15381537
exports.useTransition = function () {
15391538
return resolveDispatcher().useTransition();
15401539
};
1541-
exports.version = "19.2.0-www-classic-9518f118-20250508";
1540+
exports.version = "19.2.0-www-classic-5069e180-20250509";
15421541
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
15431542
"function" ===
15441543
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ __DEV__ &&
5959
this.refs = emptyObject;
6060
this.updater = updater || ReactNoopUpdateQueue;
6161
}
62+
function noop() {}
6263
function testStringCoercion(value) {
6364
return "" + value;
6465
}
@@ -383,7 +384,6 @@ __DEV__ &&
383384
? (checkKeyStringCoercion(element.key), escape("" + element.key))
384385
: index.toString(36);
385386
}
386-
function noop$1() {}
387387
function resolveThenable(thenable) {
388388
switch (thenable.status) {
389389
case "fulfilled":
@@ -393,7 +393,7 @@ __DEV__ &&
393393
default:
394394
switch (
395395
("string" === typeof thenable.status
396-
? thenable.then(noop$1, noop$1)
396+
? thenable.then(noop, noop)
397397
: ((thenable.status = "pending"),
398398
thenable.then(
399399
function (fulfilledValue) {
@@ -646,7 +646,6 @@ __DEV__ &&
646646
(ReactSharedInternals.T = prevTransition);
647647
}
648648
}
649-
function noop() {}
650649
function addTransitionType(type) {
651650
if (enableViewTransition) {
652651
var transition = ReactSharedInternals.T;
@@ -1538,7 +1537,7 @@ __DEV__ &&
15381537
exports.useTransition = function () {
15391538
return resolveDispatcher().useTransition();
15401539
};
1541-
exports.version = "19.2.0-www-modern-9518f118-20250508";
1540+
exports.version = "19.2.0-www-modern-5069e180-20250509";
15421541
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
15431542
"function" ===
15441543
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ var pureComponentPrototype = (PureComponent.prototype = new ComponentDummy());
9090
pureComponentPrototype.constructor = PureComponent;
9191
assign(pureComponentPrototype, Component.prototype);
9292
pureComponentPrototype.isPureReactComponent = !0;
93-
var isArrayImpl = Array.isArray,
94-
ReactSharedInternals = { H: null, A: null, T: null, S: null },
93+
var isArrayImpl = Array.isArray;
94+
function noop() {}
95+
var ReactSharedInternals = { H: null, A: null, T: null, S: null },
9596
hasOwnProperty = Object.prototype.hasOwnProperty;
9697
function ReactElement(type, key, self, source, owner, props) {
9798
self = props.ref;
@@ -152,7 +153,6 @@ function getElementKey(element, index) {
152153
? escape("" + element.key)
153154
: index.toString(36);
154155
}
155-
function noop$1() {}
156156
function resolveThenable(thenable) {
157157
switch (thenable.status) {
158158
case "fulfilled":
@@ -162,7 +162,7 @@ function resolveThenable(thenable) {
162162
default:
163163
switch (
164164
("string" === typeof thenable.status
165-
? thenable.then(noop$1, noop$1)
165+
? thenable.then(noop, noop)
166166
: ((thenable.status = "pending"),
167167
thenable.then(
168168
function (fulfilledValue) {
@@ -383,7 +383,6 @@ function startTransition(scope, options) {
383383
(ReactSharedInternals.T = prevTransition);
384384
}
385385
}
386-
function noop() {}
387386
function addTransitionType(type) {
388387
if (enableViewTransition) {
389388
var transition = ReactSharedInternals.T;
@@ -636,4 +635,4 @@ exports.useSyncExternalStore = function (
636635
exports.useTransition = function () {
637636
return ReactSharedInternals.H.useTransition();
638637
};
639-
exports.version = "19.2.0-www-classic-9518f118-20250508";
638+
exports.version = "19.2.0-www-classic-5069e180-20250509";

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ var pureComponentPrototype = (PureComponent.prototype = new ComponentDummy());
9090
pureComponentPrototype.constructor = PureComponent;
9191
assign(pureComponentPrototype, Component.prototype);
9292
pureComponentPrototype.isPureReactComponent = !0;
93-
var isArrayImpl = Array.isArray,
94-
ReactSharedInternals = { H: null, A: null, T: null, S: null },
93+
var isArrayImpl = Array.isArray;
94+
function noop() {}
95+
var ReactSharedInternals = { H: null, A: null, T: null, S: null },
9596
hasOwnProperty = Object.prototype.hasOwnProperty;
9697
function ReactElement(type, key, self, source, owner, props) {
9798
self = props.ref;
@@ -152,7 +153,6 @@ function getElementKey(element, index) {
152153
? escape("" + element.key)
153154
: index.toString(36);
154155
}
155-
function noop$1() {}
156156
function resolveThenable(thenable) {
157157
switch (thenable.status) {
158158
case "fulfilled":
@@ -162,7 +162,7 @@ function resolveThenable(thenable) {
162162
default:
163163
switch (
164164
("string" === typeof thenable.status
165-
? thenable.then(noop$1, noop$1)
165+
? thenable.then(noop, noop)
166166
: ((thenable.status = "pending"),
167167
thenable.then(
168168
function (fulfilledValue) {
@@ -383,7 +383,6 @@ function startTransition(scope, options) {
383383
(ReactSharedInternals.T = prevTransition);
384384
}
385385
}
386-
function noop() {}
387386
function addTransitionType(type) {
388387
if (enableViewTransition) {
389388
var transition = ReactSharedInternals.T;
@@ -636,4 +635,4 @@ exports.useSyncExternalStore = function (
636635
exports.useTransition = function () {
637636
return ReactSharedInternals.H.useTransition();
638637
};
639-
exports.version = "19.2.0-www-modern-9518f118-20250508";
638+
exports.version = "19.2.0-www-modern-5069e180-20250509";

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ var pureComponentPrototype = (PureComponent.prototype = new ComponentDummy());
9494
pureComponentPrototype.constructor = PureComponent;
9595
assign(pureComponentPrototype, Component.prototype);
9696
pureComponentPrototype.isPureReactComponent = !0;
97-
var isArrayImpl = Array.isArray,
98-
ReactSharedInternals = { H: null, A: null, T: null, S: null },
97+
var isArrayImpl = Array.isArray;
98+
function noop() {}
99+
var ReactSharedInternals = { H: null, A: null, T: null, S: null },
99100
hasOwnProperty = Object.prototype.hasOwnProperty;
100101
function ReactElement(type, key, self, source, owner, props) {
101102
self = props.ref;
@@ -156,7 +157,6 @@ function getElementKey(element, index) {
156157
? escape("" + element.key)
157158
: index.toString(36);
158159
}
159-
function noop$1() {}
160160
function resolveThenable(thenable) {
161161
switch (thenable.status) {
162162
case "fulfilled":
@@ -166,7 +166,7 @@ function resolveThenable(thenable) {
166166
default:
167167
switch (
168168
("string" === typeof thenable.status
169-
? thenable.then(noop$1, noop$1)
169+
? thenable.then(noop, noop)
170170
: ((thenable.status = "pending"),
171171
thenable.then(
172172
function (fulfilledValue) {
@@ -387,7 +387,6 @@ function startTransition(scope, options) {
387387
(ReactSharedInternals.T = prevTransition);
388388
}
389389
}
390-
function noop() {}
391390
function addTransitionType(type) {
392391
if (enableViewTransition) {
393392
var transition = ReactSharedInternals.T;
@@ -640,7 +639,7 @@ exports.useSyncExternalStore = function (
640639
exports.useTransition = function () {
641640
return ReactSharedInternals.H.useTransition();
642641
};
643-
exports.version = "19.2.0-www-classic-9518f118-20250508";
642+
exports.version = "19.2.0-www-classic-5069e180-20250509";
644643
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
645644
"function" ===
646645
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ var pureComponentPrototype = (PureComponent.prototype = new ComponentDummy());
9494
pureComponentPrototype.constructor = PureComponent;
9595
assign(pureComponentPrototype, Component.prototype);
9696
pureComponentPrototype.isPureReactComponent = !0;
97-
var isArrayImpl = Array.isArray,
98-
ReactSharedInternals = { H: null, A: null, T: null, S: null },
97+
var isArrayImpl = Array.isArray;
98+
function noop() {}
99+
var ReactSharedInternals = { H: null, A: null, T: null, S: null },
99100
hasOwnProperty = Object.prototype.hasOwnProperty;
100101
function ReactElement(type, key, self, source, owner, props) {
101102
self = props.ref;
@@ -156,7 +157,6 @@ function getElementKey(element, index) {
156157
? escape("" + element.key)
157158
: index.toString(36);
158159
}
159-
function noop$1() {}
160160
function resolveThenable(thenable) {
161161
switch (thenable.status) {
162162
case "fulfilled":
@@ -166,7 +166,7 @@ function resolveThenable(thenable) {
166166
default:
167167
switch (
168168
("string" === typeof thenable.status
169-
? thenable.then(noop$1, noop$1)
169+
? thenable.then(noop, noop)
170170
: ((thenable.status = "pending"),
171171
thenable.then(
172172
function (fulfilledValue) {
@@ -387,7 +387,6 @@ function startTransition(scope, options) {
387387
(ReactSharedInternals.T = prevTransition);
388388
}
389389
}
390-
function noop() {}
391390
function addTransitionType(type) {
392391
if (enableViewTransition) {
393392
var transition = ReactSharedInternals.T;
@@ -640,7 +639,7 @@ exports.useSyncExternalStore = function (
640639
exports.useTransition = function () {
641640
return ReactSharedInternals.H.useTransition();
642641
};
643-
exports.version = "19.2.0-www-modern-9518f118-20250508";
642+
exports.version = "19.2.0-www-modern-5069e180-20250509";
644643
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
645644
"function" ===
646645
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)