eslint-plugin-react-hooks 7.0.0-canary-93f85932-20251016 → 7.0.0-canary-58bdc0bb-20251019

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,8 +16,8 @@ if (process.env.NODE_ENV !== "production") {
16
16
 
17
17
  var core$1 = require('@babel/core');
18
18
  var BabelParser = require('@babel/parser');
19
- var zod = require('zod');
20
- var zodValidationError = require('zod-validation-error');
19
+ var v4 = require('zod/v4');
20
+ var v4$1 = require('zod-validation-error/v4');
21
21
  var crypto = require('crypto');
22
22
  var HermesParser = require('hermes-parser');
23
23
  var util = require('util');
@@ -18303,7 +18303,7 @@ function getRuleForCategoryImpl(category) {
18303
18303
  category,
18304
18304
  severity: ErrorSeverity.Error,
18305
18305
  name: 'void-use-memo',
18306
- description: 'Validates that useMemos always return a value. See [`useMemo()` docs](https://react.dev/reference/react/useMemo) for more information.',
18306
+ description: 'Validates that useMemos always return a value and that the result of the useMemo is used by the component/hook. See [`useMemo()` docs](https://react.dev/reference/react/useMemo) for more information.',
18307
18307
  preset: LintRulePreset.RecommendedLatest,
18308
18308
  };
18309
18309
  }
@@ -18735,7 +18735,7 @@ var ValueKind;
18735
18735
  ValueKind["Mutable"] = "mutable";
18736
18736
  ValueKind["Context"] = "context";
18737
18737
  })(ValueKind || (ValueKind = {}));
18738
- const ValueKindSchema = zod.z.enum([
18738
+ const ValueKindSchema = v4.z.enum([
18739
18739
  ValueKind.MaybeFrozen,
18740
18740
  ValueKind.Frozen,
18741
18741
  ValueKind.Primitive,
@@ -18743,7 +18743,7 @@ const ValueKindSchema = zod.z.enum([
18743
18743
  ValueKind.Mutable,
18744
18744
  ValueKind.Context,
18745
18745
  ]);
18746
- const ValueReasonSchema = zod.z.enum([
18746
+ const ValueReasonSchema = v4.z.enum([
18747
18747
  ValueReason.Context,
18748
18748
  ValueReason.Effect,
18749
18749
  ValueReason.Global,
@@ -18767,7 +18767,7 @@ var Effect;
18767
18767
  Effect["Mutate"] = "mutate";
18768
18768
  Effect["Store"] = "store";
18769
18769
  })(Effect || (Effect = {}));
18770
- const EffectSchema = zod.z.enum([
18770
+ const EffectSchema = v4.z.enum([
18771
18771
  Effect.Read,
18772
18772
  Effect.Mutate,
18773
18773
  Effect.ConditionallyMutate,
@@ -21185,25 +21185,25 @@ function assertValidBlockNesting(fn) {
21185
21185
  function assertValidMutableRanges(fn) {
21186
21186
  for (const [, block] of fn.body.blocks) {
21187
21187
  for (const phi of block.phis) {
21188
- visit$2(phi.place, `phi for block bb${block.id}`);
21188
+ visit$1(phi.place, `phi for block bb${block.id}`);
21189
21189
  for (const [pred, operand] of phi.operands) {
21190
- visit$2(operand, `phi predecessor bb${pred} for block bb${block.id}`);
21190
+ visit$1(operand, `phi predecessor bb${pred} for block bb${block.id}`);
21191
21191
  }
21192
21192
  }
21193
21193
  for (const instr of block.instructions) {
21194
21194
  for (const operand of eachInstructionLValue(instr)) {
21195
- visit$2(operand, `instruction [${instr.id}]`);
21195
+ visit$1(operand, `instruction [${instr.id}]`);
21196
21196
  }
21197
21197
  for (const operand of eachInstructionOperand(instr)) {
21198
- visit$2(operand, `instruction [${instr.id}]`);
21198
+ visit$1(operand, `instruction [${instr.id}]`);
21199
21199
  }
21200
21200
  }
21201
21201
  for (const operand of eachTerminalOperand(block.terminal)) {
21202
- visit$2(operand, `terminal [${block.terminal.id}]`);
21202
+ visit$1(operand, `terminal [${block.terminal.id}]`);
21203
21203
  }
21204
21204
  }
21205
21205
  }
21206
- function visit$2(place, description) {
21206
+ function visit$1(place, description) {
21207
21207
  validateMutableRange(place, place.identifier.mutableRange, description);
21208
21208
  if (place.identifier.scope !== null) {
21209
21209
  validateMutableRange(place, place.identifier.scope.range, description);
@@ -31322,85 +31322,85 @@ function getReanimatedModuleType(registry) {
31322
31322
  return addObject(registry, null, reanimatedType);
31323
31323
  }
31324
31324
 
31325
- const ObjectPropertiesSchema = zod.z
31326
- .record(zod.z.string(), zod.z.lazy(() => TypeSchema))
31325
+ const ObjectPropertiesSchema = v4.z
31326
+ .record(v4.z.string(), v4.z.lazy(() => TypeSchema))
31327
31327
  .refine(record => {
31328
31328
  return Object.keys(record).every(key => key === '*' || key === 'default' || libExports$1.isValidIdentifier(key));
31329
31329
  }, 'Expected all "object" property names to be valid identifier, `*` to match any property, of `default` to define a module default export');
31330
- const ObjectTypeSchema = zod.z.object({
31331
- kind: zod.z.literal('object'),
31330
+ const ObjectTypeSchema = v4.z.object({
31331
+ kind: v4.z.literal('object'),
31332
31332
  properties: ObjectPropertiesSchema.nullable(),
31333
31333
  });
31334
- const LifetimeIdSchema = zod.z.string().refine(id => id.startsWith('@'), {
31334
+ const LifetimeIdSchema = v4.z.string().refine(id => id.startsWith('@'), {
31335
31335
  message: "Placeholder names must start with '@'",
31336
31336
  });
31337
- const FreezeEffectSchema = zod.z.object({
31338
- kind: zod.z.literal('Freeze'),
31337
+ const FreezeEffectSchema = v4.z.object({
31338
+ kind: v4.z.literal('Freeze'),
31339
31339
  value: LifetimeIdSchema,
31340
31340
  reason: ValueReasonSchema,
31341
31341
  });
31342
- const MutateEffectSchema = zod.z.object({
31343
- kind: zod.z.literal('Mutate'),
31342
+ const MutateEffectSchema = v4.z.object({
31343
+ kind: v4.z.literal('Mutate'),
31344
31344
  value: LifetimeIdSchema,
31345
31345
  });
31346
- const MutateTransitiveConditionallySchema = zod.z.object({
31347
- kind: zod.z.literal('MutateTransitiveConditionally'),
31346
+ const MutateTransitiveConditionallySchema = v4.z.object({
31347
+ kind: v4.z.literal('MutateTransitiveConditionally'),
31348
31348
  value: LifetimeIdSchema,
31349
31349
  });
31350
- const CreateEffectSchema = zod.z.object({
31351
- kind: zod.z.literal('Create'),
31350
+ const CreateEffectSchema = v4.z.object({
31351
+ kind: v4.z.literal('Create'),
31352
31352
  into: LifetimeIdSchema,
31353
31353
  value: ValueKindSchema,
31354
31354
  reason: ValueReasonSchema,
31355
31355
  });
31356
- const AssignEffectSchema = zod.z.object({
31357
- kind: zod.z.literal('Assign'),
31356
+ const AssignEffectSchema = v4.z.object({
31357
+ kind: v4.z.literal('Assign'),
31358
31358
  from: LifetimeIdSchema,
31359
31359
  into: LifetimeIdSchema,
31360
31360
  });
31361
- const AliasEffectSchema = zod.z.object({
31362
- kind: zod.z.literal('Alias'),
31361
+ const AliasEffectSchema = v4.z.object({
31362
+ kind: v4.z.literal('Alias'),
31363
31363
  from: LifetimeIdSchema,
31364
31364
  into: LifetimeIdSchema,
31365
31365
  });
31366
- const ImmutableCaptureEffectSchema = zod.z.object({
31367
- kind: zod.z.literal('ImmutableCapture'),
31366
+ const ImmutableCaptureEffectSchema = v4.z.object({
31367
+ kind: v4.z.literal('ImmutableCapture'),
31368
31368
  from: LifetimeIdSchema,
31369
31369
  into: LifetimeIdSchema,
31370
31370
  });
31371
- const CaptureEffectSchema = zod.z.object({
31372
- kind: zod.z.literal('Capture'),
31371
+ const CaptureEffectSchema = v4.z.object({
31372
+ kind: v4.z.literal('Capture'),
31373
31373
  from: LifetimeIdSchema,
31374
31374
  into: LifetimeIdSchema,
31375
31375
  });
31376
- const CreateFromEffectSchema = zod.z.object({
31377
- kind: zod.z.literal('CreateFrom'),
31376
+ const CreateFromEffectSchema = v4.z.object({
31377
+ kind: v4.z.literal('CreateFrom'),
31378
31378
  from: LifetimeIdSchema,
31379
31379
  into: LifetimeIdSchema,
31380
31380
  });
31381
- const ApplyArgSchema = zod.z.union([
31381
+ const ApplyArgSchema = v4.z.union([
31382
31382
  LifetimeIdSchema,
31383
- zod.z.object({
31384
- kind: zod.z.literal('Spread'),
31383
+ v4.z.object({
31384
+ kind: v4.z.literal('Spread'),
31385
31385
  place: LifetimeIdSchema,
31386
31386
  }),
31387
- zod.z.object({
31388
- kind: zod.z.literal('Hole'),
31387
+ v4.z.object({
31388
+ kind: v4.z.literal('Hole'),
31389
31389
  }),
31390
31390
  ]);
31391
- const ApplyEffectSchema = zod.z.object({
31392
- kind: zod.z.literal('Apply'),
31391
+ const ApplyEffectSchema = v4.z.object({
31392
+ kind: v4.z.literal('Apply'),
31393
31393
  receiver: LifetimeIdSchema,
31394
31394
  function: LifetimeIdSchema,
31395
- mutatesFunction: zod.z.boolean(),
31396
- args: zod.z.array(ApplyArgSchema),
31395
+ mutatesFunction: v4.z.boolean(),
31396
+ args: v4.z.array(ApplyArgSchema),
31397
31397
  into: LifetimeIdSchema,
31398
31398
  });
31399
- const ImpureEffectSchema = zod.z.object({
31400
- kind: zod.z.literal('Impure'),
31399
+ const ImpureEffectSchema = v4.z.object({
31400
+ kind: v4.z.literal('Impure'),
31401
31401
  place: LifetimeIdSchema,
31402
31402
  });
31403
- const AliasingEffectSchema = zod.z.union([
31403
+ const AliasingEffectSchema = v4.z.union([
31404
31404
  FreezeEffectSchema,
31405
31405
  CreateEffectSchema,
31406
31406
  CreateFromEffectSchema,
@@ -31413,50 +31413,50 @@ const AliasingEffectSchema = zod.z.union([
31413
31413
  MutateTransitiveConditionallySchema,
31414
31414
  ApplyEffectSchema,
31415
31415
  ]);
31416
- const AliasingSignatureSchema = zod.z.object({
31416
+ const AliasingSignatureSchema = v4.z.object({
31417
31417
  receiver: LifetimeIdSchema,
31418
- params: zod.z.array(LifetimeIdSchema),
31418
+ params: v4.z.array(LifetimeIdSchema),
31419
31419
  rest: LifetimeIdSchema.nullable(),
31420
31420
  returns: LifetimeIdSchema,
31421
- effects: zod.z.array(AliasingEffectSchema),
31422
- temporaries: zod.z.array(LifetimeIdSchema),
31421
+ effects: v4.z.array(AliasingEffectSchema),
31422
+ temporaries: v4.z.array(LifetimeIdSchema),
31423
31423
  });
31424
- const FunctionTypeSchema = zod.z.object({
31425
- kind: zod.z.literal('function'),
31426
- positionalParams: zod.z.array(EffectSchema),
31424
+ const FunctionTypeSchema = v4.z.object({
31425
+ kind: v4.z.literal('function'),
31426
+ positionalParams: v4.z.array(EffectSchema),
31427
31427
  restParam: EffectSchema.nullable(),
31428
31428
  calleeEffect: EffectSchema,
31429
- returnType: zod.z.lazy(() => TypeSchema),
31429
+ returnType: v4.z.lazy(() => TypeSchema),
31430
31430
  returnValueKind: ValueKindSchema,
31431
- noAlias: zod.z.boolean().nullable().optional(),
31432
- mutableOnlyIfOperandsAreMutable: zod.z.boolean().nullable().optional(),
31433
- impure: zod.z.boolean().nullable().optional(),
31434
- canonicalName: zod.z.string().nullable().optional(),
31431
+ noAlias: v4.z.boolean().nullable().optional(),
31432
+ mutableOnlyIfOperandsAreMutable: v4.z.boolean().nullable().optional(),
31433
+ impure: v4.z.boolean().nullable().optional(),
31434
+ canonicalName: v4.z.string().nullable().optional(),
31435
31435
  aliasing: AliasingSignatureSchema.nullable().optional(),
31436
- knownIncompatible: zod.z.string().nullable().optional(),
31436
+ knownIncompatible: v4.z.string().nullable().optional(),
31437
31437
  });
31438
- const HookTypeSchema = zod.z.object({
31439
- kind: zod.z.literal('hook'),
31440
- positionalParams: zod.z.array(EffectSchema).nullable().optional(),
31438
+ const HookTypeSchema = v4.z.object({
31439
+ kind: v4.z.literal('hook'),
31440
+ positionalParams: v4.z.array(EffectSchema).nullable().optional(),
31441
31441
  restParam: EffectSchema.nullable().optional(),
31442
- returnType: zod.z.lazy(() => TypeSchema),
31442
+ returnType: v4.z.lazy(() => TypeSchema),
31443
31443
  returnValueKind: ValueKindSchema.nullable().optional(),
31444
- noAlias: zod.z.boolean().nullable().optional(),
31444
+ noAlias: v4.z.boolean().nullable().optional(),
31445
31445
  aliasing: AliasingSignatureSchema.nullable().optional(),
31446
- knownIncompatible: zod.z.string().nullable().optional(),
31446
+ knownIncompatible: v4.z.string().nullable().optional(),
31447
31447
  });
31448
- const BuiltInTypeSchema = zod.z.union([
31449
- zod.z.literal('Any'),
31450
- zod.z.literal('Ref'),
31451
- zod.z.literal('Array'),
31452
- zod.z.literal('Primitive'),
31453
- zod.z.literal('MixedReadonly'),
31448
+ const BuiltInTypeSchema = v4.z.union([
31449
+ v4.z.literal('Any'),
31450
+ v4.z.literal('Ref'),
31451
+ v4.z.literal('Array'),
31452
+ v4.z.literal('Primitive'),
31453
+ v4.z.literal('MixedReadonly'),
31454
31454
  ]);
31455
- const TypeReferenceSchema = zod.z.object({
31456
- kind: zod.z.literal('type'),
31455
+ const TypeReferenceSchema = v4.z.object({
31456
+ kind: v4.z.literal('type'),
31457
31457
  name: BuiltInTypeSchema,
31458
31458
  });
31459
- const TypeSchema = zod.z.union([
31459
+ const TypeSchema = v4.z.union([
31460
31460
  ObjectTypeSchema,
31461
31461
  FunctionTypeSchema,
31462
31462
  HookTypeSchema,
@@ -32052,96 +32052,89 @@ function defaultModuleTypeProvider(moduleName) {
32052
32052
  }
32053
32053
 
32054
32054
  var _Environment_instances, _Environment_globals, _Environment_shapes, _Environment_moduleTypes, _Environment_nextIdentifer, _Environment_nextBlock, _Environment_nextScope, _Environment_scope, _Environment_outlinedFunctions, _Environment_contextIdentifiers, _Environment_hoistedIdentifiers, _Environment_flowTypeEnvironment, _Environment_resolveModuleType, _Environment_isKnownReactModule, _Environment_getCustomHookType;
32055
- const ReactElementSymbolSchema = zod.z.object({
32056
- elementSymbol: zod.z.union([
32057
- zod.z.literal('react.element'),
32058
- zod.z.literal('react.transitional.element'),
32055
+ const ReactElementSymbolSchema = v4.z.object({
32056
+ elementSymbol: v4.z.union([
32057
+ v4.z.literal('react.element'),
32058
+ v4.z.literal('react.transitional.element'),
32059
32059
  ]),
32060
- globalDevVar: zod.z.string(),
32060
+ globalDevVar: v4.z.string(),
32061
32061
  });
32062
- const ExternalFunctionSchema = zod.z.object({
32063
- source: zod.z.string(),
32064
- importSpecifierName: zod.z.string(),
32062
+ const ExternalFunctionSchema = v4.z.object({
32063
+ source: v4.z.string(),
32064
+ importSpecifierName: v4.z.string(),
32065
32065
  });
32066
- const InstrumentationSchema = zod.z
32066
+ const InstrumentationSchema = v4.z
32067
32067
  .object({
32068
32068
  fn: ExternalFunctionSchema,
32069
32069
  gating: ExternalFunctionSchema.nullable(),
32070
- globalGating: zod.z.string().nullable(),
32070
+ globalGating: v4.z.string().nullable(),
32071
32071
  })
32072
32072
  .refine(opts => opts.gating != null || opts.globalGating != null, 'Expected at least one of gating or globalGating');
32073
32073
  const USE_FIRE_FUNCTION_NAME = 'useFire';
32074
32074
  const EMIT_FREEZE_GLOBAL_GATING = 'true';
32075
- const MacroMethodSchema = zod.z.union([
32076
- zod.z.object({ type: zod.z.literal('wildcard') }),
32077
- zod.z.object({ type: zod.z.literal('name'), name: zod.z.string() }),
32078
- ]);
32079
- const MacroSchema = zod.z.union([
32080
- zod.z.string(),
32081
- zod.z.tuple([zod.z.string(), zod.z.array(MacroMethodSchema)]),
32082
- ]);
32083
- const HookSchema = zod.z.object({
32084
- effectKind: zod.z.nativeEnum(Effect),
32085
- valueKind: zod.z.nativeEnum(ValueKind),
32086
- noAlias: zod.z.boolean().default(false),
32087
- transitiveMixedData: zod.z.boolean().default(false),
32075
+ const MacroSchema = v4.z.string();
32076
+ const HookSchema = v4.z.object({
32077
+ effectKind: v4.z.nativeEnum(Effect),
32078
+ valueKind: v4.z.nativeEnum(ValueKind),
32079
+ noAlias: v4.z.boolean().default(false),
32080
+ transitiveMixedData: v4.z.boolean().default(false),
32088
32081
  });
32089
- const EnvironmentConfigSchema = zod.z.object({
32090
- customHooks: zod.z.map(zod.z.string(), HookSchema).default(new Map()),
32091
- moduleTypeProvider: zod.z.nullable(zod.z.any()).default(null),
32092
- customMacros: zod.z.nullable(zod.z.array(MacroSchema)).default(null),
32093
- enableResetCacheOnSourceFileChanges: zod.z.nullable(zod.z.boolean()).default(null),
32094
- enablePreserveExistingMemoizationGuarantees: zod.z.boolean().default(true),
32095
- validatePreserveExistingMemoizationGuarantees: zod.z.boolean().default(true),
32096
- enablePreserveExistingManualUseMemo: zod.z.boolean().default(false),
32097
- enableForest: zod.z.boolean().default(false),
32098
- enableUseTypeAnnotations: zod.z.boolean().default(false),
32099
- flowTypeProvider: zod.z.nullable(zod.z.any()).default(null),
32100
- enableOptionalDependencies: zod.z.boolean().default(true),
32101
- enableFire: zod.z.boolean().default(false),
32102
- enableNameAnonymousFunctions: zod.z.boolean().default(false),
32103
- inferEffectDependencies: zod.z
32104
- .nullable(zod.z.array(zod.z.object({
32082
+ const EnvironmentConfigSchema = v4.z.object({
32083
+ customHooks: v4.z.map(v4.z.string(), HookSchema).default(new Map()),
32084
+ moduleTypeProvider: v4.z.nullable(v4.z.any()).default(null),
32085
+ customMacros: v4.z.nullable(v4.z.array(MacroSchema)).default(null),
32086
+ enableResetCacheOnSourceFileChanges: v4.z.nullable(v4.z.boolean()).default(null),
32087
+ enablePreserveExistingMemoizationGuarantees: v4.z.boolean().default(true),
32088
+ validatePreserveExistingMemoizationGuarantees: v4.z.boolean().default(true),
32089
+ enablePreserveExistingManualUseMemo: v4.z.boolean().default(false),
32090
+ enableForest: v4.z.boolean().default(false),
32091
+ enableUseTypeAnnotations: v4.z.boolean().default(false),
32092
+ flowTypeProvider: v4.z.nullable(v4.z.any()).default(null),
32093
+ enableOptionalDependencies: v4.z.boolean().default(true),
32094
+ enableFire: v4.z.boolean().default(false),
32095
+ enableNameAnonymousFunctions: v4.z.boolean().default(false),
32096
+ inferEffectDependencies: v4.z
32097
+ .nullable(v4.z.array(v4.z.object({
32105
32098
  function: ExternalFunctionSchema,
32106
- autodepsIndex: zod.z.number().min(1, 'autodepsIndex must be > 0'),
32099
+ autodepsIndex: v4.z.number().min(1, 'autodepsIndex must be > 0'),
32107
32100
  })))
32108
32101
  .default(null),
32109
32102
  inlineJsxTransform: ReactElementSymbolSchema.nullable().default(null),
32110
- validateHooksUsage: zod.z.boolean().default(true),
32111
- validateRefAccessDuringRender: zod.z.boolean().default(true),
32112
- validateNoSetStateInRender: zod.z.boolean().default(true),
32113
- validateNoSetStateInEffects: zod.z.boolean().default(false),
32114
- validateNoDerivedComputationsInEffects: zod.z.boolean().default(false),
32115
- validateNoJSXInTryStatements: zod.z.boolean().default(false),
32116
- validateStaticComponents: zod.z.boolean().default(false),
32117
- validateMemoizedEffectDependencies: zod.z.boolean().default(false),
32118
- validateNoCapitalizedCalls: zod.z.nullable(zod.z.array(zod.z.string())).default(null),
32119
- validateBlocklistedImports: zod.z.nullable(zod.z.array(zod.z.string())).default(null),
32120
- validateNoImpureFunctionsInRender: zod.z.boolean().default(false),
32121
- validateNoFreezingKnownMutableFunctions: zod.z.boolean().default(false),
32122
- enableAssumeHooksFollowRulesOfReact: zod.z.boolean().default(true),
32123
- enableTransitivelyFreezeFunctionExpressions: zod.z.boolean().default(true),
32103
+ validateHooksUsage: v4.z.boolean().default(true),
32104
+ validateRefAccessDuringRender: v4.z.boolean().default(true),
32105
+ validateNoSetStateInRender: v4.z.boolean().default(true),
32106
+ validateNoSetStateInEffects: v4.z.boolean().default(false),
32107
+ validateNoDerivedComputationsInEffects: v4.z.boolean().default(false),
32108
+ validateNoJSXInTryStatements: v4.z.boolean().default(false),
32109
+ validateStaticComponents: v4.z.boolean().default(false),
32110
+ validateMemoizedEffectDependencies: v4.z.boolean().default(false),
32111
+ validateNoCapitalizedCalls: v4.z.nullable(v4.z.array(v4.z.string())).default(null),
32112
+ validateBlocklistedImports: v4.z.nullable(v4.z.array(v4.z.string())).default(null),
32113
+ validateNoImpureFunctionsInRender: v4.z.boolean().default(false),
32114
+ validateNoFreezingKnownMutableFunctions: v4.z.boolean().default(false),
32115
+ enableAssumeHooksFollowRulesOfReact: v4.z.boolean().default(true),
32116
+ enableTransitivelyFreezeFunctionExpressions: v4.z.boolean().default(true),
32124
32117
  enableEmitFreeze: ExternalFunctionSchema.nullable().default(null),
32125
32118
  enableEmitHookGuards: ExternalFunctionSchema.nullable().default(null),
32126
- enableInstructionReordering: zod.z.boolean().default(false),
32127
- enableFunctionOutlining: zod.z.boolean().default(true),
32128
- enableJsxOutlining: zod.z.boolean().default(false),
32119
+ enableInstructionReordering: v4.z.boolean().default(false),
32120
+ enableFunctionOutlining: v4.z.boolean().default(true),
32121
+ enableJsxOutlining: v4.z.boolean().default(false),
32129
32122
  enableEmitInstrumentForget: InstrumentationSchema.nullable().default(null),
32130
- assertValidMutableRanges: zod.z.boolean().default(false),
32131
- enableChangeVariableCodegen: zod.z.boolean().default(false),
32132
- enableMemoizationComments: zod.z.boolean().default(false),
32133
- throwUnknownException__testonly: zod.z.boolean().default(false),
32134
- enableTreatFunctionDepsAsConditional: zod.z.boolean().default(false),
32135
- disableMemoizationForDebugging: zod.z.boolean().default(false),
32123
+ assertValidMutableRanges: v4.z.boolean().default(false),
32124
+ enableChangeVariableCodegen: v4.z.boolean().default(false),
32125
+ enableMemoizationComments: v4.z.boolean().default(false),
32126
+ throwUnknownException__testonly: v4.z.boolean().default(false),
32127
+ enableTreatFunctionDepsAsConditional: v4.z.boolean().default(false),
32128
+ disableMemoizationForDebugging: v4.z.boolean().default(false),
32136
32129
  enableChangeDetectionForDebugging: ExternalFunctionSchema.nullable().default(null),
32137
- enableCustomTypeDefinitionForReanimated: zod.z.boolean().default(false),
32138
- hookPattern: zod.z.string().nullable().default(null),
32139
- enableTreatRefLikeIdentifiersAsRefs: zod.z.boolean().default(true),
32140
- enableTreatSetIdentifiersAsStateSetters: zod.z.boolean().default(false),
32130
+ enableCustomTypeDefinitionForReanimated: v4.z.boolean().default(false),
32131
+ hookPattern: v4.z.string().nullable().default(null),
32132
+ enableTreatRefLikeIdentifiersAsRefs: v4.z.boolean().default(true),
32133
+ enableTreatSetIdentifiersAsStateSetters: v4.z.boolean().default(false),
32141
32134
  lowerContextAccess: ExternalFunctionSchema.nullable().default(null),
32142
- validateNoVoidUseMemo: zod.z.boolean().default(false),
32143
- validateNoDynamicallyCreatedComponentsOrHooks: zod.z.boolean().default(false),
32144
- enableAllowSetStateFromRefsInEffects: zod.z.boolean().default(true),
32135
+ validateNoVoidUseMemo: v4.z.boolean().default(true),
32136
+ validateNoDynamicallyCreatedComponentsOrHooks: v4.z.boolean().default(false),
32137
+ enableAllowSetStateFromRefsInEffects: v4.z.boolean().default(true),
32145
32138
  });
32146
32139
  class Environment {
32147
32140
  constructor(scope, fnType, compilerMode, config, contextIdentifiers, parentFunction, logger, filename, code, programContext) {
@@ -32518,7 +32511,7 @@ function validateEnvironmentConfig(partialConfig) {
32518
32511
  }
32519
32512
  CompilerError.throwInvalidConfig({
32520
32513
  reason: 'Could not validate environment config. Update React Compiler config to fix the error',
32521
- description: `${zodValidationError.fromZodError(config.error)}`,
32514
+ description: `${v4$1.fromZodError(config.error)}`,
32522
32515
  loc: null,
32523
32516
  suggestions: null,
32524
32517
  });
@@ -32530,7 +32523,7 @@ function tryParseExternalFunction(maybeExternalFunction) {
32530
32523
  }
32531
32524
  CompilerError.throwInvalidConfig({
32532
32525
  reason: 'Could not parse external function. Update React Compiler config to fix the error',
32533
- description: `${zodValidationError.fromZodError(externalFunction.error)}`,
32526
+ description: `${v4$1.fromZodError(externalFunction.error)}`,
32534
32527
  loc: null,
32535
32528
  suggestions: null,
32536
32529
  });
@@ -37124,174 +37117,189 @@ var GuardKind;
37124
37117
  GuardKind[GuardKind["DisallowHook"] = 3] = "DisallowHook";
37125
37118
  })(GuardKind || (GuardKind = {}));
37126
37119
 
37120
+ var InlineLevel;
37121
+ (function (InlineLevel) {
37122
+ InlineLevel["Transitive"] = "Transitive";
37123
+ InlineLevel["Shallow"] = "Shallow";
37124
+ })(InlineLevel || (InlineLevel = {}));
37125
+ const SHALLOW_MACRO = {
37126
+ level: InlineLevel.Shallow,
37127
+ properties: null,
37128
+ };
37129
+ const TRANSITIVE_MACRO = {
37130
+ level: InlineLevel.Transitive,
37131
+ properties: null,
37132
+ };
37133
+ const FBT_MACRO = {
37134
+ level: InlineLevel.Transitive,
37135
+ properties: new Map([['*', SHALLOW_MACRO]]),
37136
+ };
37137
+ FBT_MACRO.properties.set('enum', FBT_MACRO);
37127
37138
  function memoizeFbtAndMacroOperandsInSameScope(fn) {
37128
37139
  var _a;
37129
- const fbtMacroTags = new Set([
37130
- ...Array.from(FBT_TAGS).map((tag) => [tag, []]),
37131
- ...((_a = fn.env.config.customMacros) !== null && _a !== void 0 ? _a : []),
37140
+ const macroKinds = new Map([
37141
+ ...Array.from(FBT_TAGS.entries()),
37142
+ ...((_a = fn.env.config.customMacros) !== null && _a !== void 0 ? _a : []).map(name => [name, TRANSITIVE_MACRO]),
37132
37143
  ]);
37133
- const macroTagsCalls = new Set();
37134
- const macroValues = new Map();
37135
- const macroMethods = new Map();
37136
- visit$1(fn, fbtMacroTags, macroTagsCalls, macroMethods, macroValues);
37137
- for (const root of macroValues.keys()) {
37138
- const scope = root.scope;
37139
- if (scope == null) {
37140
- continue;
37141
- }
37142
- if (!macroTagsCalls.has(root.id)) {
37143
- continue;
37144
- }
37145
- mergeScopes(root, scope, macroValues, macroTagsCalls);
37146
- }
37147
- return macroTagsCalls;
37148
- }
37149
- const FBT_TAGS = new Set([
37150
- 'fbt',
37151
- 'fbt:param',
37152
- 'fbt:enum',
37153
- 'fbt:plural',
37154
- 'fbs',
37155
- 'fbs:param',
37156
- 'fbs:enum',
37157
- 'fbs:plural',
37144
+ const macroTags = populateMacroTags(fn, macroKinds);
37145
+ const macroValues = mergeMacroArguments(fn, macroTags, macroKinds);
37146
+ return macroValues;
37147
+ }
37148
+ const FBT_TAGS = new Map([
37149
+ ['fbt', FBT_MACRO],
37150
+ ['fbt:param', SHALLOW_MACRO],
37151
+ ['fbt:enum', FBT_MACRO],
37152
+ ['fbt:plural', SHALLOW_MACRO],
37153
+ ['fbs', FBT_MACRO],
37154
+ ['fbs:param', SHALLOW_MACRO],
37155
+ ['fbs:enum', FBT_MACRO],
37156
+ ['fbs:plural', SHALLOW_MACRO],
37158
37157
  ]);
37159
37158
  const SINGLE_CHILD_FBT_TAGS = new Set([
37160
37159
  'fbt:param',
37161
37160
  'fbs:param',
37162
37161
  ]);
37163
- function visit$1(fn, fbtMacroTags, macroTagsCalls, macroMethods, macroValues) {
37164
- for (const [, block] of fn.body.blocks) {
37165
- for (const phi of block.phis) {
37166
- const macroOperands = [];
37167
- for (const operand of phi.operands.values()) {
37168
- if (macroValues.has(operand.identifier)) {
37169
- macroOperands.push(operand.identifier);
37170
- }
37171
- }
37172
- if (macroOperands.length !== 0) {
37173
- macroValues.set(phi.place.identifier, macroOperands);
37174
- }
37175
- }
37176
- for (const instruction of block.instructions) {
37177
- const { lvalue, value } = instruction;
37178
- if (lvalue === null) {
37179
- continue;
37180
- }
37181
- if (value.kind === 'Primitive' &&
37182
- typeof value.value === 'string' &&
37183
- matchesExactTag(value.value, fbtMacroTags)) {
37184
- macroTagsCalls.add(lvalue.identifier.id);
37185
- }
37186
- else if (value.kind === 'LoadGlobal' &&
37187
- matchesExactTag(value.binding.name, fbtMacroTags)) {
37188
- macroTagsCalls.add(lvalue.identifier.id);
37189
- }
37190
- else if (value.kind === 'LoadGlobal' &&
37191
- matchTagRoot(value.binding.name, fbtMacroTags) !== null) {
37192
- const methods = matchTagRoot(value.binding.name, fbtMacroTags);
37193
- macroMethods.set(lvalue.identifier.id, methods);
37194
- }
37195
- else if (value.kind === 'PropertyLoad' &&
37196
- macroMethods.has(value.object.identifier.id)) {
37197
- const methods = macroMethods.get(value.object.identifier.id);
37198
- const newMethods = [];
37199
- for (const method of methods) {
37200
- if (method.length > 0 &&
37201
- (method[0].type === 'wildcard' ||
37202
- (method[0].type === 'name' && method[0].name === value.property))) {
37203
- if (method.length > 1) {
37204
- newMethods.push(method.slice(1));
37205
- }
37206
- else {
37207
- macroTagsCalls.add(lvalue.identifier.id);
37162
+ function populateMacroTags(fn, macroKinds) {
37163
+ var _a;
37164
+ const macroTags = new Map();
37165
+ for (const block of fn.body.blocks.values()) {
37166
+ for (const instr of block.instructions) {
37167
+ const { lvalue, value } = instr;
37168
+ switch (value.kind) {
37169
+ case 'Primitive': {
37170
+ if (typeof value.value === 'string') {
37171
+ const macroDefinition = macroKinds.get(value.value);
37172
+ if (macroDefinition != null) {
37173
+ macroTags.set(lvalue.identifier.id, macroDefinition);
37208
37174
  }
37209
37175
  }
37176
+ break;
37210
37177
  }
37211
- if (newMethods.length > 0) {
37212
- macroMethods.set(lvalue.identifier.id, newMethods);
37178
+ case 'LoadGlobal': {
37179
+ let macroDefinition = macroKinds.get(value.binding.name);
37180
+ if (macroDefinition != null) {
37181
+ macroTags.set(lvalue.identifier.id, macroDefinition);
37182
+ }
37183
+ break;
37213
37184
  }
37214
- }
37215
- else if (value.kind === 'PropertyLoad' &&
37216
- macroTagsCalls.has(value.object.identifier.id)) {
37217
- macroTagsCalls.add(lvalue.identifier.id);
37218
- }
37219
- else if (isFbtJsxExpression(fbtMacroTags, macroTagsCalls, value) ||
37220
- isFbtJsxChild(macroTagsCalls, lvalue, value) ||
37221
- isFbtCallExpression(macroTagsCalls, value)) {
37222
- macroTagsCalls.add(lvalue.identifier.id);
37223
- macroValues.set(lvalue.identifier, Array.from(eachInstructionValueOperand(value), operand => operand.identifier));
37224
- }
37225
- else if (Iterable_some(eachInstructionValueOperand(value), operand => macroValues.has(operand.identifier))) {
37226
- const macroOperands = [];
37227
- for (const operand of eachInstructionValueOperand(value)) {
37228
- if (macroValues.has(operand.identifier)) {
37229
- macroOperands.push(operand.identifier);
37185
+ case 'PropertyLoad': {
37186
+ if (typeof value.property === 'string') {
37187
+ const macroDefinition = macroTags.get(value.object.identifier.id);
37188
+ if (macroDefinition != null) {
37189
+ const propertyDefinition = macroDefinition.properties != null
37190
+ ? ((_a = macroDefinition.properties.get(value.property)) !== null && _a !== void 0 ? _a : macroDefinition.properties.get('*'))
37191
+ : null;
37192
+ const propertyMacro = propertyDefinition !== null && propertyDefinition !== void 0 ? propertyDefinition : macroDefinition;
37193
+ macroTags.set(lvalue.identifier.id, propertyMacro);
37194
+ }
37230
37195
  }
37196
+ break;
37231
37197
  }
37232
- macroValues.set(lvalue.identifier, macroOperands);
37233
37198
  }
37234
37199
  }
37235
37200
  }
37201
+ return macroTags;
37236
37202
  }
37237
- function mergeScopes(root, scope, macroValues, macroTagsCalls) {
37238
- const operands = macroValues.get(root);
37239
- if (operands == null) {
37240
- return;
37241
- }
37242
- for (const operand of operands) {
37243
- operand.scope = scope;
37244
- expandFbtScopeRange(scope.range, operand.mutableRange);
37245
- macroTagsCalls.add(operand.id);
37246
- mergeScopes(operand, scope, macroValues, macroTagsCalls);
37247
- }
37248
- }
37249
- function matchesExactTag(s, tags) {
37250
- return Array.from(tags).some(macro => typeof macro === 'string'
37251
- ? s === macro
37252
- : macro[1].length === 0 && macro[0] === s);
37253
- }
37254
- function matchTagRoot(s, tags) {
37255
- const methods = [];
37256
- for (const macro of tags) {
37257
- if (typeof macro === 'string') {
37258
- continue;
37203
+ function mergeMacroArguments(fn, macroTags, macroKinds) {
37204
+ var _a;
37205
+ const macroValues = new Set(macroTags.keys());
37206
+ for (const block of Array.from(fn.body.blocks.values()).reverse()) {
37207
+ for (let i = block.instructions.length - 1; i >= 0; i--) {
37208
+ const instr = block.instructions[i];
37209
+ const { lvalue, value } = instr;
37210
+ switch (value.kind) {
37211
+ case 'DeclareContext':
37212
+ case 'DeclareLocal':
37213
+ case 'Destructure':
37214
+ case 'LoadContext':
37215
+ case 'LoadLocal':
37216
+ case 'PostfixUpdate':
37217
+ case 'PrefixUpdate':
37218
+ case 'StoreContext':
37219
+ case 'StoreLocal': {
37220
+ break;
37221
+ }
37222
+ case 'CallExpression':
37223
+ case 'MethodCall': {
37224
+ const scope = lvalue.identifier.scope;
37225
+ if (scope == null) {
37226
+ continue;
37227
+ }
37228
+ const callee = value.kind === 'CallExpression' ? value.callee : value.property;
37229
+ const macroDefinition = (_a = macroTags.get(callee.identifier.id)) !== null && _a !== void 0 ? _a : macroTags.get(lvalue.identifier.id);
37230
+ if (macroDefinition != null) {
37231
+ visitOperands(macroDefinition, scope, lvalue, value, macroValues, macroTags);
37232
+ }
37233
+ break;
37234
+ }
37235
+ case 'JsxExpression': {
37236
+ const scope = lvalue.identifier.scope;
37237
+ if (scope == null) {
37238
+ continue;
37239
+ }
37240
+ let macroDefinition;
37241
+ if (value.tag.kind === 'Identifier') {
37242
+ macroDefinition = macroTags.get(value.tag.identifier.id);
37243
+ }
37244
+ else {
37245
+ macroDefinition = macroKinds.get(value.tag.name);
37246
+ }
37247
+ macroDefinition !== null && macroDefinition !== void 0 ? macroDefinition : (macroDefinition = macroTags.get(lvalue.identifier.id));
37248
+ if (macroDefinition != null) {
37249
+ visitOperands(macroDefinition, scope, lvalue, value, macroValues, macroTags);
37250
+ }
37251
+ break;
37252
+ }
37253
+ default: {
37254
+ const scope = lvalue.identifier.scope;
37255
+ if (scope == null) {
37256
+ continue;
37257
+ }
37258
+ const macroDefinition = macroTags.get(lvalue.identifier.id);
37259
+ if (macroDefinition != null) {
37260
+ visitOperands(macroDefinition, scope, lvalue, value, macroValues, macroTags);
37261
+ }
37262
+ break;
37263
+ }
37264
+ }
37259
37265
  }
37260
- const [tag, rest] = macro;
37261
- if (tag === s && rest.length > 0) {
37262
- methods.push(rest);
37266
+ for (const phi of block.phis) {
37267
+ const scope = phi.place.identifier.scope;
37268
+ if (scope == null) {
37269
+ continue;
37270
+ }
37271
+ const macroDefinition = macroTags.get(phi.place.identifier.id);
37272
+ if (macroDefinition == null ||
37273
+ macroDefinition.level === InlineLevel.Shallow) {
37274
+ continue;
37275
+ }
37276
+ macroValues.add(phi.place.identifier.id);
37277
+ for (const operand of phi.operands.values()) {
37278
+ operand.identifier.scope = scope;
37279
+ expandFbtScopeRange(scope.range, operand.identifier.mutableRange);
37280
+ macroTags.set(operand.identifier.id, macroDefinition);
37281
+ macroValues.add(operand.identifier.id);
37282
+ }
37263
37283
  }
37264
37284
  }
37265
- if (methods.length > 0) {
37266
- return methods;
37267
- }
37268
- else {
37269
- return null;
37270
- }
37271
- }
37272
- function isFbtCallExpression(macroTagsCalls, value) {
37273
- return ((value.kind === 'CallExpression' &&
37274
- macroTagsCalls.has(value.callee.identifier.id)) ||
37275
- (value.kind === 'MethodCall' &&
37276
- macroTagsCalls.has(value.property.identifier.id)));
37277
- }
37278
- function isFbtJsxExpression(fbtMacroTags, macroTagsCalls, value) {
37279
- return (value.kind === 'JsxExpression' &&
37280
- ((value.tag.kind === 'Identifier' &&
37281
- macroTagsCalls.has(value.tag.identifier.id)) ||
37282
- (value.tag.kind === 'BuiltinTag' &&
37283
- matchesExactTag(value.tag.name, fbtMacroTags))));
37284
- }
37285
- function isFbtJsxChild(macroTagsCalls, lvalue, value) {
37286
- return ((value.kind === 'JsxExpression' || value.kind === 'JsxFragment') &&
37287
- lvalue !== null &&
37288
- macroTagsCalls.has(lvalue.identifier.id));
37285
+ return macroValues;
37289
37286
  }
37290
37287
  function expandFbtScopeRange(fbtRange, extendWith) {
37291
37288
  if (extendWith.start !== 0) {
37292
37289
  fbtRange.start = makeInstructionId(Math.min(fbtRange.start, extendWith.start));
37293
37290
  }
37294
37291
  }
37292
+ function visitOperands(macroDefinition, scope, lvalue, value, macroValues, macroTags) {
37293
+ macroValues.add(lvalue.identifier.id);
37294
+ for (const operand of eachInstructionValueOperand(value)) {
37295
+ if (macroDefinition.level === InlineLevel.Transitive) {
37296
+ operand.identifier.scope = scope;
37297
+ expandFbtScopeRange(scope.range, operand.identifier.mutableRange);
37298
+ macroTags.set(operand.identifier.id, macroDefinition);
37299
+ }
37300
+ macroValues.add(operand.identifier.id);
37301
+ }
37302
+ }
37295
37303
 
37296
37304
  var _Context_nextCacheIndex, _Context_declarations;
37297
37305
  const MEMO_CACHE_SENTINEL = 'react.memo_cache_sentinel';
@@ -40489,7 +40497,7 @@ function inferMutationAliasingEffects(fn, { isFunctionExpression } = {
40489
40497
  }
40490
40498
  queue(fn.body.entry, initialState);
40491
40499
  const hoistedContextDeclarations = findHoistedContextDeclarations(fn);
40492
- const context = new Context$1(isFunctionExpression, fn, hoistedContextDeclarations);
40500
+ const context = new Context$1(isFunctionExpression, fn, hoistedContextDeclarations, findNonMutatedDestructureSpreads(fn));
40493
40501
  let iterationCount = 0;
40494
40502
  while (queuedStates.size !== 0) {
40495
40503
  iterationCount++;
@@ -40553,7 +40561,7 @@ function findHoistedContextDeclarations(fn) {
40553
40561
  return hoisted;
40554
40562
  }
40555
40563
  let Context$1 = class Context {
40556
- constructor(isFunctionExpression, fn, hoistedContextDeclarations) {
40564
+ constructor(isFunctionExpression, fn, hoistedContextDeclarations, nonMutatingSpreads) {
40557
40565
  this.internedEffects = new Map();
40558
40566
  this.instructionSignatureCache = new Map();
40559
40567
  this.effectInstructionValueCache = new Map();
@@ -40563,6 +40571,7 @@ let Context$1 = class Context {
40563
40571
  this.isFuctionExpression = isFunctionExpression;
40564
40572
  this.fn = fn;
40565
40573
  this.hoistedContextDeclarations = hoistedContextDeclarations;
40574
+ this.nonMutatingSpreads = nonMutatingSpreads;
40566
40575
  }
40567
40576
  cacheApplySignature(signature, effect, f) {
40568
40577
  const inner = getOrInsertDefault(this.applySignatureCache, signature, new Map());
@@ -40578,6 +40587,114 @@ let Context$1 = class Context {
40578
40587
  return interned;
40579
40588
  }
40580
40589
  };
40590
+ function findNonMutatedDestructureSpreads(fn) {
40591
+ const knownFrozen = new Set();
40592
+ if (fn.fnType === 'Component') {
40593
+ const [props] = fn.params;
40594
+ if (props != null && props.kind === 'Identifier') {
40595
+ knownFrozen.add(props.identifier.id);
40596
+ }
40597
+ }
40598
+ else {
40599
+ for (const param of fn.params) {
40600
+ if (param.kind === 'Identifier') {
40601
+ knownFrozen.add(param.identifier.id);
40602
+ }
40603
+ }
40604
+ }
40605
+ const candidateNonMutatingSpreads = new Map();
40606
+ for (const block of fn.body.blocks.values()) {
40607
+ if (candidateNonMutatingSpreads.size !== 0) {
40608
+ for (const phi of block.phis) {
40609
+ for (const operand of phi.operands.values()) {
40610
+ const spread = candidateNonMutatingSpreads.get(operand.identifier.id);
40611
+ if (spread != null) {
40612
+ candidateNonMutatingSpreads.delete(spread);
40613
+ }
40614
+ }
40615
+ }
40616
+ }
40617
+ for (const instr of block.instructions) {
40618
+ const { lvalue, value } = instr;
40619
+ switch (value.kind) {
40620
+ case 'Destructure': {
40621
+ if (!knownFrozen.has(value.value.identifier.id) ||
40622
+ !(value.lvalue.kind === InstructionKind.Let ||
40623
+ value.lvalue.kind === InstructionKind.Const) ||
40624
+ value.lvalue.pattern.kind !== 'ObjectPattern') {
40625
+ continue;
40626
+ }
40627
+ for (const item of value.lvalue.pattern.properties) {
40628
+ if (item.kind !== 'Spread') {
40629
+ continue;
40630
+ }
40631
+ candidateNonMutatingSpreads.set(item.place.identifier.id, item.place.identifier.id);
40632
+ }
40633
+ break;
40634
+ }
40635
+ case 'LoadLocal': {
40636
+ const spread = candidateNonMutatingSpreads.get(value.place.identifier.id);
40637
+ if (spread != null) {
40638
+ candidateNonMutatingSpreads.set(lvalue.identifier.id, spread);
40639
+ }
40640
+ break;
40641
+ }
40642
+ case 'StoreLocal': {
40643
+ const spread = candidateNonMutatingSpreads.get(value.value.identifier.id);
40644
+ if (spread != null) {
40645
+ candidateNonMutatingSpreads.set(lvalue.identifier.id, spread);
40646
+ candidateNonMutatingSpreads.set(value.lvalue.place.identifier.id, spread);
40647
+ }
40648
+ break;
40649
+ }
40650
+ case 'JsxFragment':
40651
+ case 'JsxExpression': {
40652
+ break;
40653
+ }
40654
+ case 'PropertyLoad': {
40655
+ break;
40656
+ }
40657
+ case 'CallExpression':
40658
+ case 'MethodCall': {
40659
+ const callee = value.kind === 'CallExpression' ? value.callee : value.property;
40660
+ if (getHookKind(fn.env, callee.identifier) != null) {
40661
+ if (!isRefOrRefValue(lvalue.identifier)) {
40662
+ knownFrozen.add(lvalue.identifier.id);
40663
+ }
40664
+ }
40665
+ else {
40666
+ if (candidateNonMutatingSpreads.size !== 0) {
40667
+ for (const operand of eachInstructionValueOperand(value)) {
40668
+ const spread = candidateNonMutatingSpreads.get(operand.identifier.id);
40669
+ if (spread != null) {
40670
+ candidateNonMutatingSpreads.delete(spread);
40671
+ }
40672
+ }
40673
+ }
40674
+ }
40675
+ break;
40676
+ }
40677
+ default: {
40678
+ if (candidateNonMutatingSpreads.size !== 0) {
40679
+ for (const operand of eachInstructionValueOperand(value)) {
40680
+ const spread = candidateNonMutatingSpreads.get(operand.identifier.id);
40681
+ if (spread != null) {
40682
+ candidateNonMutatingSpreads.delete(spread);
40683
+ }
40684
+ }
40685
+ }
40686
+ }
40687
+ }
40688
+ }
40689
+ }
40690
+ const nonMutatingSpreads = new Set();
40691
+ for (const [key, value] of candidateNonMutatingSpreads) {
40692
+ if (key === value) {
40693
+ nonMutatingSpreads.add(key);
40694
+ }
40695
+ }
40696
+ return nonMutatingSpreads;
40697
+ }
40581
40698
  function inferParam(param, initialState, paramKind) {
40582
40699
  const place = param.kind === 'Identifier' ? param : param.place;
40583
40700
  const value = {
@@ -41832,7 +41949,9 @@ function computeSignatureForInstruction(context, env, instr) {
41832
41949
  kind: 'Create',
41833
41950
  into: place,
41834
41951
  reason: ValueReason.Other,
41835
- value: ValueKind.Mutable,
41952
+ value: context.nonMutatingSpreads.has(place.identifier.id)
41953
+ ? ValueKind.Frozen
41954
+ : ValueKind.Mutable,
41836
41955
  });
41837
41956
  effects.push({
41838
41957
  kind: 'Capture',
@@ -44523,7 +44642,6 @@ function extractManualMemoizationArgs(instr, kind, sidemap, errors) {
44523
44642
  };
44524
44643
  }
44525
44644
  function dropManualMemoization(func) {
44526
- var _a;
44527
44645
  const errors = new CompilerError();
44528
44646
  const isValidationEnabled = func.env.config.validatePreserveExistingMemoizationGuarantees ||
44529
44647
  func.env.config.validateNoSetStateInRender ||
@@ -44553,26 +44671,6 @@ function dropManualMemoization(func) {
44553
44671
  if (fnPlace == null) {
44554
44672
  continue;
44555
44673
  }
44556
- if (func.env.config.validateNoVoidUseMemo &&
44557
- manualMemo.kind === 'useMemo') {
44558
- const funcToCheck = (_a = sidemap.functions.get(fnPlace.identifier.id)) === null || _a === void 0 ? void 0 : _a.value;
44559
- if (funcToCheck !== undefined && funcToCheck.loweredFunc.func) {
44560
- if (!hasNonVoidReturn(funcToCheck.loweredFunc.func)) {
44561
- errors.pushDiagnostic(CompilerDiagnostic.create({
44562
- category: ErrorCategory.VoidUseMemo,
44563
- reason: 'useMemo() callbacks must return a value',
44564
- description: `This ${manualMemo.loadInstr.value.kind === 'PropertyLoad'
44565
- ? 'React.useMemo'
44566
- : 'useMemo'} callback doesn't return a value. useMemo is for computing and caching values, not for arbitrary side effects`,
44567
- suggestions: null,
44568
- }).withDetails({
44569
- kind: 'error',
44570
- loc: instr.value.loc,
44571
- message: 'useMemo() callbacks must return a value',
44572
- }));
44573
- }
44574
- }
44575
- }
44576
44674
  instr.value = getManualMemoizationReplacement(fnPlace, instr.value.loc, manualMemo.kind);
44577
44675
  if (isValidationEnabled) {
44578
44676
  if (!sidemap.functions.has(fnPlace.identifier.id)) {
@@ -44684,17 +44782,6 @@ function findOptionalPlaces(fn) {
44684
44782
  }
44685
44783
  return optionals;
44686
44784
  }
44687
- function hasNonVoidReturn(func) {
44688
- for (const [, block] of func.body.blocks) {
44689
- if (block.terminal.kind === 'return') {
44690
- if (block.terminal.returnVariant === 'Explicit' ||
44691
- block.terminal.returnVariant === 'Implicit') {
44692
- return true;
44693
- }
44694
- }
44695
- }
44696
- return false;
44697
- }
44698
44785
 
44699
44786
  class StableSidemap {
44700
44787
  constructor(env) {
@@ -50177,11 +50264,18 @@ function isUnmemoized(operand, scopes) {
50177
50264
 
50178
50265
  function validateUseMemo(fn) {
50179
50266
  const errors = new CompilerError();
50267
+ const voidMemoErrors = new CompilerError();
50180
50268
  const useMemos = new Set();
50181
50269
  const react = new Set();
50182
50270
  const functions = new Map();
50271
+ const unusedUseMemos = new Map();
50183
50272
  for (const [, block] of fn.body.blocks) {
50184
50273
  for (const { lvalue, value } of block.instructions) {
50274
+ if (unusedUseMemos.size !== 0) {
50275
+ for (const operand of eachInstructionValueOperand(value)) {
50276
+ unusedUseMemos.delete(operand.identifier.id);
50277
+ }
50278
+ }
50185
50279
  switch (value.kind) {
50186
50280
  case 'LoadGlobal': {
50187
50281
  if (value.binding.name === 'useMemo') {
@@ -50206,10 +50300,8 @@ function validateUseMemo(fn) {
50206
50300
  }
50207
50301
  case 'MethodCall':
50208
50302
  case 'CallExpression': {
50209
- const callee = value.kind === 'CallExpression'
50210
- ? value.callee.identifier.id
50211
- : value.property.identifier.id;
50212
- const isUseMemo = useMemos.has(callee);
50303
+ const callee = value.kind === 'CallExpression' ? value.callee : value.property;
50304
+ const isUseMemo = useMemos.has(callee.identifier.id);
50213
50305
  if (!isUseMemo || value.args.length === 0) {
50214
50306
  continue;
50215
50307
  }
@@ -50249,13 +50341,84 @@ function validateUseMemo(fn) {
50249
50341
  message: 'Async and generator functions are not supported',
50250
50342
  }));
50251
50343
  }
50344
+ validateNoContextVariableAssignment(body.loweredFunc.func, errors);
50345
+ if (fn.env.config.validateNoVoidUseMemo) {
50346
+ if (!hasNonVoidReturn(body.loweredFunc.func)) {
50347
+ voidMemoErrors.pushDiagnostic(CompilerDiagnostic.create({
50348
+ category: ErrorCategory.VoidUseMemo,
50349
+ reason: 'useMemo() callbacks must return a value',
50350
+ description: `This useMemo() callback doesn't return a value. useMemo() is for computing and caching values, not for arbitrary side effects`,
50351
+ suggestions: null,
50352
+ }).withDetails({
50353
+ kind: 'error',
50354
+ loc: body.loc,
50355
+ message: 'useMemo() callbacks must return a value',
50356
+ }));
50357
+ }
50358
+ else {
50359
+ unusedUseMemos.set(lvalue.identifier.id, callee.loc);
50360
+ }
50361
+ }
50252
50362
  break;
50253
50363
  }
50254
50364
  }
50255
50365
  }
50366
+ if (unusedUseMemos.size !== 0) {
50367
+ for (const operand of eachTerminalOperand(block.terminal)) {
50368
+ unusedUseMemos.delete(operand.identifier.id);
50369
+ }
50370
+ }
50371
+ }
50372
+ if (unusedUseMemos.size !== 0) {
50373
+ for (const loc of unusedUseMemos.values()) {
50374
+ voidMemoErrors.pushDiagnostic(CompilerDiagnostic.create({
50375
+ category: ErrorCategory.VoidUseMemo,
50376
+ reason: 'useMemo() result is unused',
50377
+ description: `This useMemo() value is unused. useMemo() is for computing and caching values, not for arbitrary side effects`,
50378
+ suggestions: null,
50379
+ }).withDetails({
50380
+ kind: 'error',
50381
+ loc,
50382
+ message: 'useMemo() result is unused',
50383
+ }));
50384
+ }
50256
50385
  }
50386
+ fn.env.logErrors(voidMemoErrors.asResult());
50257
50387
  return errors.asResult();
50258
50388
  }
50389
+ function validateNoContextVariableAssignment(fn, errors) {
50390
+ for (const block of fn.body.blocks.values()) {
50391
+ for (const instr of block.instructions) {
50392
+ const value = instr.value;
50393
+ switch (value.kind) {
50394
+ case 'StoreContext': {
50395
+ errors.pushDiagnostic(CompilerDiagnostic.create({
50396
+ category: ErrorCategory.UseMemo,
50397
+ reason: 'useMemo() callbacks may not reassign variables declared outside of the callback',
50398
+ description: 'useMemo() callbacks must be pure functions and cannot reassign variables defined outside of the callback function',
50399
+ suggestions: null,
50400
+ }).withDetails({
50401
+ kind: 'error',
50402
+ loc: value.lvalue.place.loc,
50403
+ message: 'Cannot reassign variable',
50404
+ }));
50405
+ break;
50406
+ }
50407
+ }
50408
+ }
50409
+ }
50410
+ }
50411
+ function hasNonVoidReturn(func) {
50412
+ for (const [, block] of func.body.blocks) {
50413
+ if (block.terminal.kind === 'return') {
50414
+ if (block.terminal.returnVariant === 'Explicit' ||
50415
+ block.terminal.returnVariant === 'Implicit') {
50416
+ return true;
50417
+ }
50418
+ }
50419
+ }
50420
+ return false;
50421
+ }
50259
50422
 
50260
50423
  function validateLocalsNotReassignedAfterRender(fn) {
50261
50424
  const contextVariables = new Set();
@@ -53700,27 +53863,27 @@ function isNonNamespacedImport(importDeclPath) {
53700
53863
  importDeclPath.node.importKind !== 'typeof');
53701
53864
  }
53702
53865
 
53703
- zod.z.enum([
53866
+ v4.z.enum([
53704
53867
  'all_errors',
53705
53868
  'critical_errors',
53706
53869
  'none',
53707
53870
  ]);
53708
- const DynamicGatingOptionsSchema = zod.z.object({
53709
- source: zod.z.string(),
53871
+ const DynamicGatingOptionsSchema = v4.z.object({
53872
+ source: v4.z.string(),
53710
53873
  });
53711
- const CustomOptOutDirectiveSchema = zod.z
53712
- .nullable(zod.z.array(zod.z.string()))
53874
+ const CustomOptOutDirectiveSchema = v4.z
53875
+ .nullable(v4.z.array(v4.z.string()))
53713
53876
  .default(null);
53714
- const CompilerReactTargetSchema = zod.z.union([
53715
- zod.z.literal('17'),
53716
- zod.z.literal('18'),
53717
- zod.z.literal('19'),
53718
- zod.z.object({
53719
- kind: zod.z.literal('donotuse_meta_internal'),
53720
- runtimeModule: zod.z.string().default('react'),
53877
+ const CompilerReactTargetSchema = v4.z.union([
53878
+ v4.z.literal('17'),
53879
+ v4.z.literal('18'),
53880
+ v4.z.literal('19'),
53881
+ v4.z.object({
53882
+ kind: v4.z.literal('donotuse_meta_internal'),
53883
+ runtimeModule: v4.z.string().default('react'),
53721
53884
  }),
53722
53885
  ]);
53723
- zod.z.enum([
53886
+ v4.z.enum([
53724
53887
  'infer',
53725
53888
  'syntax',
53726
53889
  'annotation',
@@ -53793,7 +53956,7 @@ function parsePluginOptions(obj) {
53793
53956
  else {
53794
53957
  CompilerError.throwInvalidConfig({
53795
53958
  reason: 'Could not parse dynamic gating. Update React Compiler config to fix the error',
53796
- description: `${zodValidationError.fromZodError(result.error)}`,
53959
+ description: `${v4$1.fromZodError(result.error)}`,
53797
53960
  loc: null,
53798
53961
  suggestions: null,
53799
53962
  });
@@ -53809,7 +53972,7 @@ function parsePluginOptions(obj) {
53809
53972
  else {
53810
53973
  CompilerError.throwInvalidConfig({
53811
53974
  reason: 'Could not parse custom opt out directives. Update React Compiler config to fix the error',
53812
- description: `${zodValidationError.fromZodError(result.error)}`,
53975
+ description: `${v4$1.fromZodError(result.error)}`,
53813
53976
  loc: null,
53814
53977
  suggestions: null,
53815
53978
  });
@@ -53832,7 +53995,7 @@ function parseTargetConfig(value) {
53832
53995
  else {
53833
53996
  CompilerError.throwInvalidConfig({
53834
53997
  reason: 'Not a valid target',
53835
- description: `${zodValidationError.fromZodError(parsed.error)}`,
53998
+ description: `${v4$1.fromZodError(parsed.error)}`,
53836
53999
  suggestions: null,
53837
54000
  loc: null,
53838
54001
  });
@@ -57346,6 +57509,10 @@ function isUseEffectEventIdentifier(node) {
57346
57509
  return node.type === 'Identifier' && node.name === 'useEffectEvent';
57347
57510
  }
57348
57511
  function useEffectEventError(fn, called) {
57512
+ if (fn === null) {
57513
+ return (`React Hook "useEffectEvent" can only be called at the top level of your component.` +
57514
+ ` It cannot be passed down.`);
57515
+ }
57349
57516
  return (`\`${fn}\` is a function created with React Hook "useEffectEvent", and can only be called from ` +
57350
57517
  'Effects and Effect Events in the same component.' +
57351
57518
  (called ? '' : ' It cannot be assigned to a variable or passed down.'));
@@ -57645,6 +57812,7 @@ const rule = {
57645
57812
  analyzer.leaveNode(node);
57646
57813
  },
57647
57814
  CallExpression(node) {
57815
+ var _a, _b;
57648
57816
  if (isHook(node.callee)) {
57649
57817
  const reactHooksMap = last(codePathReactHooksMapStack);
57650
57818
  const codePathSegment = last(codePathSegmentStack);
@@ -57661,6 +57829,15 @@ const rule = {
57661
57829
  node.arguments.length > 0) {
57662
57830
  lastEffect = node;
57663
57831
  }
57832
+ if (isUseEffectEventIdentifier(nodeWithoutNamespace) &&
57833
+ ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) !== 'VariableDeclarator' &&
57834
+ ((_b = node.parent) === null || _b === void 0 ? void 0 : _b.type) !== 'ExpressionStatement') {
57835
+ const message = useEffectEventError(null, false);
57836
+ context.report({
57837
+ node,
57838
+ message,
57839
+ });
57840
+ }
57664
57841
  },
57665
57842
  Identifier(node) {
57666
57843
  if (lastEffect == null && useEffectEventFunctions.has(node)) {