Skip to content

Commit c4e0797

Browse files
committed
[compiler] Add definitions for Object entries/keys/values (#34047)
Fixes remaining issue in #32261, where passing a previously useMemo()-d value to `Object.entries()` makes the compiler think the value is mutated and fail validatePreserveExistingMemo. While I was there I added Object.keys() and Object.values() too. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34047). * #34049 * __->__ #34047 * #34044 DiffTrain build for [0860b9c](0860b9c)
1 parent 12966d2 commit c4e0797

35 files changed

+183
-86
lines changed

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

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21362,6 +21362,7 @@ function parseAliasingSignatureConfig(typeConfig, moduleName, loc) {
2136221362
const temporaries = typeConfig.temporaries.map(define);
2136321363
const effects = typeConfig.effects.map((effect) => {
2136421364
switch (effect.kind) {
21365+
case 'ImmutableCapture':
2136521366
case 'CreateFrom':
2136621367
case 'Capture':
2136721368
case 'Alias':
@@ -29804,6 +29805,96 @@ const TYPED_GLOBALS = [
2980429805
returnValueKind: ValueKind.Mutable,
2980529806
}),
2980629807
],
29808+
[
29809+
'entries',
29810+
addFunction(DEFAULT_SHAPES, [], {
29811+
positionalParams: [Effect.Capture],
29812+
restParam: null,
29813+
returnType: { kind: 'Object', shapeId: BuiltInArrayId },
29814+
calleeEffect: Effect.Read,
29815+
returnValueKind: ValueKind.Mutable,
29816+
aliasing: {
29817+
receiver: '@receiver',
29818+
params: ['@object'],
29819+
rest: null,
29820+
returns: '@returns',
29821+
temporaries: [],
29822+
effects: [
29823+
{
29824+
kind: 'Create',
29825+
into: '@returns',
29826+
reason: ValueReason.KnownReturnSignature,
29827+
value: ValueKind.Mutable,
29828+
},
29829+
{
29830+
kind: 'Capture',
29831+
from: '@object',
29832+
into: '@returns',
29833+
},
29834+
],
29835+
},
29836+
}),
29837+
],
29838+
[
29839+
'keys',
29840+
addFunction(DEFAULT_SHAPES, [], {
29841+
positionalParams: [Effect.Read],
29842+
restParam: null,
29843+
returnType: { kind: 'Object', shapeId: BuiltInArrayId },
29844+
calleeEffect: Effect.Read,
29845+
returnValueKind: ValueKind.Mutable,
29846+
aliasing: {
29847+
receiver: '@receiver',
29848+
params: ['@object'],
29849+
rest: null,
29850+
returns: '@returns',
29851+
temporaries: [],
29852+
effects: [
29853+
{
29854+
kind: 'Create',
29855+
into: '@returns',
29856+
reason: ValueReason.KnownReturnSignature,
29857+
value: ValueKind.Mutable,
29858+
},
29859+
{
29860+
kind: 'ImmutableCapture',
29861+
from: '@object',
29862+
into: '@returns',
29863+
},
29864+
],
29865+
},
29866+
}),
29867+
],
29868+
[
29869+
'values',
29870+
addFunction(DEFAULT_SHAPES, [], {
29871+
positionalParams: [Effect.Capture],
29872+
restParam: null,
29873+
returnType: { kind: 'Object', shapeId: BuiltInArrayId },
29874+
calleeEffect: Effect.Read,
29875+
returnValueKind: ValueKind.Mutable,
29876+
aliasing: {
29877+
receiver: '@receiver',
29878+
params: ['@object'],
29879+
rest: null,
29880+
returns: '@returns',
29881+
temporaries: [],
29882+
effects: [
29883+
{
29884+
kind: 'Create',
29885+
into: '@returns',
29886+
reason: ValueReason.KnownReturnSignature,
29887+
value: ValueKind.Mutable,
29888+
},
29889+
{
29890+
kind: 'Capture',
29891+
from: '@object',
29892+
into: '@returns',
29893+
},
29894+
],
29895+
},
29896+
}),
29897+
],
2980729898
]),
2980829899
],
2980929900
[
@@ -30623,6 +30714,11 @@ const AliasEffectSchema = zod.z.object({
3062330714
from: LifetimeIdSchema,
3062430715
into: LifetimeIdSchema,
3062530716
});
30717+
const ImmutableCaptureEffectSchema = zod.z.object({
30718+
kind: zod.z.literal('ImmutableCapture'),
30719+
from: LifetimeIdSchema,
30720+
into: LifetimeIdSchema,
30721+
});
3062630722
const CaptureEffectSchema = zod.z.object({
3062730723
kind: zod.z.literal('Capture'),
3062830724
from: LifetimeIdSchema,
@@ -30662,6 +30758,7 @@ const AliasingEffectSchema = zod.z.union([
3066230758
AssignEffectSchema,
3066330759
AliasEffectSchema,
3066430760
CaptureEffectSchema,
30761+
ImmutableCaptureEffectSchema,
3066530762
ImpureEffectSchema,
3066630763
MutateEffectSchema,
3066730764
MutateTransitiveConditionallySchema,

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
52612a7cbdd8e1fee9599478247f78725869ebad
1+
0860b9cc1f4a7188b41204bddc57a127a8bbf6e9
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
52612a7cbdd8e1fee9599478247f78725869ebad
1+
0860b9cc1f4a7188b41204bddc57a127a8bbf6e9

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ __DEV__ &&
14341434
exports.useTransition = function () {
14351435
return resolveDispatcher().useTransition();
14361436
};
1437-
exports.version = "19.2.0-www-classic-52612a7c-20250801";
1437+
exports.version = "19.2.0-www-classic-0860b9cc-20250801";
14381438
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
14391439
"function" ===
14401440
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
@@ -1434,7 +1434,7 @@ __DEV__ &&
14341434
exports.useTransition = function () {
14351435
return resolveDispatcher().useTransition();
14361436
};
1437-
exports.version = "19.2.0-www-modern-52612a7c-20250801";
1437+
exports.version = "19.2.0-www-modern-0860b9cc-20250801";
14381438
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
14391439
"function" ===
14401440
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
@@ -610,4 +610,4 @@ exports.useSyncExternalStore = function (
610610
exports.useTransition = function () {
611611
return ReactSharedInternals.H.useTransition();
612612
};
613-
exports.version = "19.2.0-www-classic-52612a7c-20250801";
613+
exports.version = "19.2.0-www-classic-0860b9cc-20250801";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,4 +610,4 @@ exports.useSyncExternalStore = function (
610610
exports.useTransition = function () {
611611
return ReactSharedInternals.H.useTransition();
612612
};
613-
exports.version = "19.2.0-www-modern-52612a7c-20250801";
613+
exports.version = "19.2.0-www-modern-0860b9cc-20250801";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ exports.useSyncExternalStore = function (
614614
exports.useTransition = function () {
615615
return ReactSharedInternals.H.useTransition();
616616
};
617-
exports.version = "19.2.0-www-classic-52612a7c-20250801";
617+
exports.version = "19.2.0-www-classic-0860b9cc-20250801";
618618
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
619619
"function" ===
620620
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
@@ -614,7 +614,7 @@ exports.useSyncExternalStore = function (
614614
exports.useTransition = function () {
615615
return ReactSharedInternals.H.useTransition();
616616
};
617-
exports.version = "19.2.0-www-modern-52612a7c-20250801";
617+
exports.version = "19.2.0-www-modern-0860b9cc-20250801";
618618
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
619619
"function" ===
620620
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
@@ -19318,10 +19318,10 @@ __DEV__ &&
1931819318
(function () {
1931919319
var internals = {
1932019320
bundleType: 1,
19321-
version: "19.2.0-www-classic-52612a7c-20250801",
19321+
version: "19.2.0-www-classic-0860b9cc-20250801",
1932219322
rendererPackageName: "react-art",
1932319323
currentDispatcherRef: ReactSharedInternals,
19324-
reconcilerVersion: "19.2.0-www-classic-52612a7c-20250801"
19324+
reconcilerVersion: "19.2.0-www-classic-0860b9cc-20250801"
1932519325
};
1932619326
internals.overrideHookState = overrideHookState;
1932719327
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -19355,7 +19355,7 @@ __DEV__ &&
1935519355
exports.Shape = Shape;
1935619356
exports.Surface = Surface;
1935719357
exports.Text = Text;
19358-
exports.version = "19.2.0-www-classic-52612a7c-20250801";
19358+
exports.version = "19.2.0-www-classic-0860b9cc-20250801";
1935919359
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
1936019360
"function" ===
1936119361
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)