Skip to content

Commit ab9cbb6

Browse files
committed
[compiler] Avoid empty switch cases (#33625)
Small cosmetic win, found this when i was looking at some code internally with lots of cases that all share the same logic. Previously, all the but last one would have an empty block. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/33625). * #33643 * #33642 * #33640 * __->__ #33625 * #33624 DiffTrain build for [e130c08](e130c08)
1 parent 608544b commit ab9cbb6

35 files changed

+94
-93
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43992,12 +43992,9 @@ function codegenFunction(fn, { uniqueIdentifiers, fbtOperands, }) {
4399243992
}
4399343993
function codegenReactiveFunction(cx, fn) {
4399443994
for (const param of fn.params) {
43995-
if (param.kind === 'Identifier') {
43996-
cx.temp.set(param.identifier.declarationId, null);
43997-
}
43998-
else {
43999-
cx.temp.set(param.place.identifier.declarationId, null);
44000-
}
43995+
const place = param.kind === 'Identifier' ? param : param.place;
43996+
cx.temp.set(place.identifier.declarationId, null);
43997+
cx.declare(place.identifier);
4400143998
}
4400243999
const params = fn.params.map(param => convertParameter(param));
4400344000
const body = codegenBlock(cx, fn.body);
@@ -44549,7 +44546,7 @@ function codegenTerminal(cx, terminal) {
4454944546
? codegenPlaceToExpression(cx, case_.test)
4455044547
: null;
4455144548
const block = codegenBlock(cx, case_.block);
44552-
return libExports$1.switchCase(test, [block]);
44549+
return libExports$1.switchCase(test, block.body.length === 0 ? [] : [block]);
4455344550
}));
4455444551
}
4455544552
case 'throw': {
@@ -45628,6 +45625,10 @@ function compareScopeDeclaration(a, b) {
4562845625

4562945626
function extractScopeDeclarationsFromDestructuring(fn) {
4563045627
const state = new State$1(fn.env);
45628+
for (const param of fn.params) {
45629+
const place = param.kind === 'Identifier' ? param : param.place;
45630+
state.declared.add(place.identifier.declarationId);
45631+
}
4563145632
visitReactiveFunction(fn, new Visitor$9(), state);
4563245633
}
4563345634
let State$1 = class State {

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
cee7939b0017ff58230e19663c22393bfd9025ef
1+
e130c08b06470b5fc4ec8095310d19e782924427
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
cee7939b0017ff58230e19663c22393bfd9025ef
1+
e130c08b06470b5fc4ec8095310d19e782924427

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,7 @@ __DEV__ &&
14791479
exports.useTransition = function () {
14801480
return resolveDispatcher().useTransition();
14811481
};
1482-
exports.version = "19.2.0-www-classic-cee7939b-20250625";
1482+
exports.version = "19.2.0-www-classic-e130c08b-20250625";
14831483
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
14841484
"function" ===
14851485
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,7 @@ __DEV__ &&
14791479
exports.useTransition = function () {
14801480
return resolveDispatcher().useTransition();
14811481
};
1482-
exports.version = "19.2.0-www-modern-cee7939b-20250625";
1482+
exports.version = "19.2.0-www-modern-e130c08b-20250625";
14831483
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
14841484
"function" ===
14851485
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,4 +630,4 @@ exports.useSyncExternalStore = function (
630630
exports.useTransition = function () {
631631
return ReactSharedInternals.H.useTransition();
632632
};
633-
exports.version = "19.2.0-www-classic-cee7939b-20250625";
633+
exports.version = "19.2.0-www-classic-e130c08b-20250625";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,4 +630,4 @@ exports.useSyncExternalStore = function (
630630
exports.useTransition = function () {
631631
return ReactSharedInternals.H.useTransition();
632632
};
633-
exports.version = "19.2.0-www-modern-cee7939b-20250625";
633+
exports.version = "19.2.0-www-modern-e130c08b-20250625";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ exports.useSyncExternalStore = function (
634634
exports.useTransition = function () {
635635
return ReactSharedInternals.H.useTransition();
636636
};
637-
exports.version = "19.2.0-www-classic-cee7939b-20250625";
637+
exports.version = "19.2.0-www-classic-e130c08b-20250625";
638638
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
639639
"function" ===
640640
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ exports.useSyncExternalStore = function (
634634
exports.useTransition = function () {
635635
return ReactSharedInternals.H.useTransition();
636636
};
637-
exports.version = "19.2.0-www-modern-cee7939b-20250625";
637+
exports.version = "19.2.0-www-modern-e130c08b-20250625";
638638
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
639639
"function" ===
640640
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19073,10 +19073,10 @@ __DEV__ &&
1907319073
(function () {
1907419074
var internals = {
1907519075
bundleType: 1,
19076-
version: "19.2.0-www-classic-cee7939b-20250625",
19076+
version: "19.2.0-www-classic-e130c08b-20250625",
1907719077
rendererPackageName: "react-art",
1907819078
currentDispatcherRef: ReactSharedInternals,
19079-
reconcilerVersion: "19.2.0-www-classic-cee7939b-20250625"
19079+
reconcilerVersion: "19.2.0-www-classic-e130c08b-20250625"
1908019080
};
1908119081
internals.overrideHookState = overrideHookState;
1908219082
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -19110,7 +19110,7 @@ __DEV__ &&
1911019110
exports.Shape = Shape;
1911119111
exports.Surface = Surface;
1911219112
exports.Text = Text;
19113-
exports.version = "19.2.0-www-classic-cee7939b-20250625";
19113+
exports.version = "19.2.0-www-classic-e130c08b-20250625";
1911419114
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
1911519115
"function" ===
1911619116
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)