Skip to content

Commit 2b6b1b4

Browse files
committed
[compiler] Name anonymous functions from inlined useCallbacks (#34586)
@eps1lon flagged this case. Inlined useCallback has an extra LoadLocal indirection which caused us not to add a name. While I was there I added some extra checks to make sure we don't generate names for a given node twice (just in case). DiffTrain build for [2c6d92f](2c6d92f)
1 parent fed5e27 commit 2b6b1b4

35 files changed

+94
-89
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51991,7 +51991,7 @@ function nameAnonymousFunctions(fn) {
5199151991
const functions = nameAnonymousFunctionsImpl(fn);
5199251992
function visit(node, prefix) {
5199351993
var _a, _b;
51994-
if (node.generatedName != null) {
51994+
if (node.generatedName != null && node.fn.nameHint == null) {
5199551995
const name = `${prefix}${node.generatedName}]`;
5199651996
node.fn.nameHint = name;
5199751997
node.fn.loweredFunc.func.nameHint = name;
@@ -52024,6 +52024,10 @@ function nameAnonymousFunctionsImpl(fn) {
5202452024
if (name != null && name.kind === 'named') {
5202552025
names.set(lvalue.identifier.id, name.value);
5202652026
}
52027+
const func = functions.get(value.place.identifier.id);
52028+
if (func != null) {
52029+
functions.set(lvalue.identifier.id, func);
52030+
}
5202752031
break;
5202852032
}
5202952033
case 'PropertyLoad': {
@@ -52051,6 +52055,7 @@ function nameAnonymousFunctionsImpl(fn) {
5205152055
const node = functions.get(value.value.identifier.id);
5205252056
const variableName = value.lvalue.place.identifier.name;
5205352057
if (node != null &&
52058+
node.generatedName == null &&
5205452059
variableName != null &&
5205552060
variableName.kind === 'named') {
5205652061
node.generatedName = variableName.value;
@@ -52081,7 +52086,7 @@ function nameAnonymousFunctionsImpl(fn) {
5208152086
continue;
5208252087
}
5208352088
const node = functions.get(arg.identifier.id);
52084-
if (node != null) {
52089+
if (node != null && node.generatedName == null) {
5208552090
const generatedName = fnArgCount > 1 ? `${calleeName}(arg${i})` : `${calleeName}()`;
5208652091
node.generatedName = generatedName;
5208752092
functions.delete(arg.identifier.id);
@@ -52095,7 +52100,7 @@ function nameAnonymousFunctionsImpl(fn) {
5209552100
continue;
5209652101
}
5209752102
const node = functions.get(attr.place.identifier.id);
52098-
if (node != null) {
52103+
if (node != null && node.generatedName == null) {
5209952104
const elementName = value.tag.kind === 'BuiltinTag'
5210052105
? value.tag.name
5210152106
: ((_b = names.get(value.tag.identifier.id)) !== null && _b !== void 0 ? _b : null);

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e2332183591ff3a5657c3322a21bcdcccae32088
1+
2c6d92fd80ec6917cb7387dbb771e35e82b0126d
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e2332183591ff3a5657c3322a21bcdcccae32088
1+
2c6d92fd80ec6917cb7387dbb771e35e82b0126d

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ __DEV__ &&
14191419
exports.useTransition = function () {
14201420
return resolveDispatcher().useTransition();
14211421
};
1422-
exports.version = "19.2.0-www-classic-e2332183-20250924";
1422+
exports.version = "19.2.0-www-classic-2c6d92fd-20250924";
14231423
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
14241424
"function" ===
14251425
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
@@ -1419,7 +1419,7 @@ __DEV__ &&
14191419
exports.useTransition = function () {
14201420
return resolveDispatcher().useTransition();
14211421
};
1422-
exports.version = "19.2.0-www-modern-e2332183-20250924";
1422+
exports.version = "19.2.0-www-modern-2c6d92fd-20250924";
14231423
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
14241424
"function" ===
14251425
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
@@ -602,4 +602,4 @@ exports.useSyncExternalStore = function (
602602
exports.useTransition = function () {
603603
return ReactSharedInternals.H.useTransition();
604604
};
605-
exports.version = "19.2.0-www-classic-e2332183-20250924";
605+
exports.version = "19.2.0-www-classic-2c6d92fd-20250924";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,4 +602,4 @@ exports.useSyncExternalStore = function (
602602
exports.useTransition = function () {
603603
return ReactSharedInternals.H.useTransition();
604604
};
605-
exports.version = "19.2.0-www-modern-e2332183-20250924";
605+
exports.version = "19.2.0-www-modern-2c6d92fd-20250924";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ exports.useSyncExternalStore = function (
606606
exports.useTransition = function () {
607607
return ReactSharedInternals.H.useTransition();
608608
};
609-
exports.version = "19.2.0-www-classic-e2332183-20250924";
609+
exports.version = "19.2.0-www-classic-2c6d92fd-20250924";
610610
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
611611
"function" ===
612612
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
@@ -606,7 +606,7 @@ exports.useSyncExternalStore = function (
606606
exports.useTransition = function () {
607607
return ReactSharedInternals.H.useTransition();
608608
};
609-
exports.version = "19.2.0-www-modern-e2332183-20250924";
609+
exports.version = "19.2.0-www-modern-2c6d92fd-20250924";
610610
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
611611
"function" ===
612612
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
@@ -20224,10 +20224,10 @@ __DEV__ &&
2022420224
(function () {
2022520225
var internals = {
2022620226
bundleType: 1,
20227-
version: "19.2.0-www-classic-e2332183-20250924",
20227+
version: "19.2.0-www-classic-2c6d92fd-20250924",
2022820228
rendererPackageName: "react-art",
2022920229
currentDispatcherRef: ReactSharedInternals,
20230-
reconcilerVersion: "19.2.0-www-classic-e2332183-20250924"
20230+
reconcilerVersion: "19.2.0-www-classic-2c6d92fd-20250924"
2023120231
};
2023220232
internals.overrideHookState = overrideHookState;
2023320233
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -20261,7 +20261,7 @@ __DEV__ &&
2026120261
exports.Shape = Shape;
2026220262
exports.Surface = Surface;
2026320263
exports.Text = Text;
20264-
exports.version = "19.2.0-www-classic-e2332183-20250924";
20264+
exports.version = "19.2.0-www-classic-2c6d92fd-20250924";
2026520265
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
2026620266
"function" ===
2026720267
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)