eslint-plugin-react-hooks 7.0.0 → 7.0.1

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');
@@ -17648,6 +17648,10 @@ function hasOwnProperty$1(obj, key) {
17648
17648
  return Object.prototype.hasOwnProperty.call(obj, key);
17649
17649
  }
17650
17650
 
17651
+ const CODEFRAME_LINES_ABOVE = 2;
17652
+ const CODEFRAME_LINES_BELOW = 3;
17653
+ const CODEFRAME_MAX_LINES = 10;
17654
+ const CODEFRAME_ABBREVIATED_SOURCE_LINES = 5;
17651
17655
  var ErrorSeverity;
17652
17656
  (function (ErrorSeverity) {
17653
17657
  ErrorSeverity["Error"] = "Error";
@@ -17964,7 +17968,7 @@ class CompilerError extends Error {
17964
17968
  }
17965
17969
  }
17966
17970
  function printCodeFrame(source, loc, message) {
17967
- return libExports.codeFrameColumns(source, {
17971
+ const printed = libExports.codeFrameColumns(source, {
17968
17972
  start: {
17969
17973
  line: loc.start.line,
17970
17974
  column: loc.start.column + 1,
@@ -17975,7 +17979,19 @@ function printCodeFrame(source, loc, message) {
17975
17979
  },
17976
17980
  }, {
17977
17981
  message,
17982
+ linesAbove: CODEFRAME_LINES_ABOVE,
17983
+ linesBelow: CODEFRAME_LINES_BELOW,
17978
17984
  });
17985
+ const lines = printed.split(/\r?\n/);
17986
+ if (loc.end.line - loc.start.line < CODEFRAME_MAX_LINES) {
17987
+ return printed;
17988
+ }
17989
+ const pipeIndex = lines[0].indexOf('|');
17990
+ return [
17991
+ ...lines.slice(0, CODEFRAME_LINES_ABOVE + CODEFRAME_ABBREVIATED_SOURCE_LINES),
17992
+ ' '.repeat(pipeIndex) + '…',
17993
+ ...lines.slice(-(CODEFRAME_LINES_BELOW + CODEFRAME_ABBREVIATED_SOURCE_LINES)),
17994
+ ].join('\n');
17979
17995
  }
17980
17996
  function printErrorSummary(category, message) {
17981
17997
  let heading;
@@ -18303,7 +18319,7 @@ function getRuleForCategoryImpl(category) {
18303
18319
  category,
18304
18320
  severity: ErrorSeverity.Error,
18305
18321
  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.',
18322
+ 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
18323
  preset: LintRulePreset.RecommendedLatest,
18308
18324
  };
18309
18325
  }
@@ -18735,7 +18751,7 @@ var ValueKind;
18735
18751
  ValueKind["Mutable"] = "mutable";
18736
18752
  ValueKind["Context"] = "context";
18737
18753
  })(ValueKind || (ValueKind = {}));
18738
- const ValueKindSchema = zod.z.enum([
18754
+ const ValueKindSchema = v4.z.enum([
18739
18755
  ValueKind.MaybeFrozen,
18740
18756
  ValueKind.Frozen,
18741
18757
  ValueKind.Primitive,
@@ -18743,7 +18759,7 @@ const ValueKindSchema = zod.z.enum([
18743
18759
  ValueKind.Mutable,
18744
18760
  ValueKind.Context,
18745
18761
  ]);
18746
- const ValueReasonSchema = zod.z.enum([
18762
+ const ValueReasonSchema = v4.z.enum([
18747
18763
  ValueReason.Context,
18748
18764
  ValueReason.Effect,
18749
18765
  ValueReason.Global,
@@ -18767,7 +18783,7 @@ var Effect;
18767
18783
  Effect["Mutate"] = "mutate";
18768
18784
  Effect["Store"] = "store";
18769
18785
  })(Effect || (Effect = {}));
18770
- const EffectSchema = zod.z.enum([
18786
+ const EffectSchema = v4.z.enum([
18771
18787
  Effect.Read,
18772
18788
  Effect.Mutate,
18773
18789
  Effect.ConditionallyMutate,
@@ -21185,25 +21201,25 @@ function assertValidBlockNesting(fn) {
21185
21201
  function assertValidMutableRanges(fn) {
21186
21202
  for (const [, block] of fn.body.blocks) {
21187
21203
  for (const phi of block.phis) {
21188
- visit$2(phi.place, `phi for block bb${block.id}`);
21204
+ visit$1(phi.place, `phi for block bb${block.id}`);
21189
21205
  for (const [pred, operand] of phi.operands) {
21190
- visit$2(operand, `phi predecessor bb${pred} for block bb${block.id}`);
21206
+ visit$1(operand, `phi predecessor bb${pred} for block bb${block.id}`);
21191
21207
  }
21192
21208
  }
21193
21209
  for (const instr of block.instructions) {
21194
21210
  for (const operand of eachInstructionLValue(instr)) {
21195
- visit$2(operand, `instruction [${instr.id}]`);
21211
+ visit$1(operand, `instruction [${instr.id}]`);
21196
21212
  }
21197
21213
  for (const operand of eachInstructionOperand(instr)) {
21198
- visit$2(operand, `instruction [${instr.id}]`);
21214
+ visit$1(operand, `instruction [${instr.id}]`);
21199
21215
  }
21200
21216
  }
21201
21217
  for (const operand of eachTerminalOperand(block.terminal)) {
21202
- visit$2(operand, `terminal [${block.terminal.id}]`);
21218
+ visit$1(operand, `terminal [${block.terminal.id}]`);
21203
21219
  }
21204
21220
  }
21205
21221
  }
21206
- function visit$2(place, description) {
21222
+ function visit$1(place, description) {
21207
21223
  validateMutableRange(place, place.identifier.mutableRange, description);
21208
21224
  if (place.identifier.scope !== null) {
21209
21225
  validateMutableRange(place, place.identifier.scope.range, description);
@@ -24145,7 +24161,7 @@ function lowerObjectMethod(builder, property) {
24145
24161
  };
24146
24162
  }
24147
24163
  function lowerObjectPropertyKey(builder, property) {
24148
- var _a, _b;
24164
+ var _a;
24149
24165
  const key = property.get('key');
24150
24166
  if (key.isStringLiteral()) {
24151
24167
  return {
@@ -24154,15 +24170,6 @@ function lowerObjectPropertyKey(builder, property) {
24154
24170
  };
24155
24171
  }
24156
24172
  else if (property.node.computed && key.isExpression()) {
24157
- if (!key.isIdentifier() && !key.isMemberExpression()) {
24158
- builder.errors.push({
24159
- reason: `(BuildHIR::lowerExpression) Expected Identifier, got ${key.type} key in ObjectExpression`,
24160
- category: ErrorCategory.Todo,
24161
- loc: (_a = key.node.loc) !== null && _a !== void 0 ? _a : null,
24162
- suggestions: null,
24163
- });
24164
- return null;
24165
- }
24166
24173
  const place = lowerExpressionToTemporary(builder, key);
24167
24174
  return {
24168
24175
  kind: 'computed',
@@ -24184,7 +24191,7 @@ function lowerObjectPropertyKey(builder, property) {
24184
24191
  builder.errors.push({
24185
24192
  reason: `(BuildHIR::lowerExpression) Expected Identifier, got ${key.type} key in ObjectExpression`,
24186
24193
  category: ErrorCategory.Todo,
24187
- loc: (_b = key.node.loc) !== null && _b !== void 0 ? _b : null,
24194
+ loc: (_a = key.node.loc) !== null && _a !== void 0 ? _a : null,
24188
24195
  suggestions: null,
24189
24196
  });
24190
24197
  return null;
@@ -31322,85 +31329,85 @@ function getReanimatedModuleType(registry) {
31322
31329
  return addObject(registry, null, reanimatedType);
31323
31330
  }
31324
31331
 
31325
- const ObjectPropertiesSchema = zod.z
31326
- .record(zod.z.string(), zod.z.lazy(() => TypeSchema))
31332
+ const ObjectPropertiesSchema = v4.z
31333
+ .record(v4.z.string(), v4.z.lazy(() => TypeSchema))
31327
31334
  .refine(record => {
31328
31335
  return Object.keys(record).every(key => key === '*' || key === 'default' || libExports$1.isValidIdentifier(key));
31329
31336
  }, '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'),
31337
+ const ObjectTypeSchema = v4.z.object({
31338
+ kind: v4.z.literal('object'),
31332
31339
  properties: ObjectPropertiesSchema.nullable(),
31333
31340
  });
31334
- const LifetimeIdSchema = zod.z.string().refine(id => id.startsWith('@'), {
31341
+ const LifetimeIdSchema = v4.z.string().refine(id => id.startsWith('@'), {
31335
31342
  message: "Placeholder names must start with '@'",
31336
31343
  });
31337
- const FreezeEffectSchema = zod.z.object({
31338
- kind: zod.z.literal('Freeze'),
31344
+ const FreezeEffectSchema = v4.z.object({
31345
+ kind: v4.z.literal('Freeze'),
31339
31346
  value: LifetimeIdSchema,
31340
31347
  reason: ValueReasonSchema,
31341
31348
  });
31342
- const MutateEffectSchema = zod.z.object({
31343
- kind: zod.z.literal('Mutate'),
31349
+ const MutateEffectSchema = v4.z.object({
31350
+ kind: v4.z.literal('Mutate'),
31344
31351
  value: LifetimeIdSchema,
31345
31352
  });
31346
- const MutateTransitiveConditionallySchema = zod.z.object({
31347
- kind: zod.z.literal('MutateTransitiveConditionally'),
31353
+ const MutateTransitiveConditionallySchema = v4.z.object({
31354
+ kind: v4.z.literal('MutateTransitiveConditionally'),
31348
31355
  value: LifetimeIdSchema,
31349
31356
  });
31350
- const CreateEffectSchema = zod.z.object({
31351
- kind: zod.z.literal('Create'),
31357
+ const CreateEffectSchema = v4.z.object({
31358
+ kind: v4.z.literal('Create'),
31352
31359
  into: LifetimeIdSchema,
31353
31360
  value: ValueKindSchema,
31354
31361
  reason: ValueReasonSchema,
31355
31362
  });
31356
- const AssignEffectSchema = zod.z.object({
31357
- kind: zod.z.literal('Assign'),
31363
+ const AssignEffectSchema = v4.z.object({
31364
+ kind: v4.z.literal('Assign'),
31358
31365
  from: LifetimeIdSchema,
31359
31366
  into: LifetimeIdSchema,
31360
31367
  });
31361
- const AliasEffectSchema = zod.z.object({
31362
- kind: zod.z.literal('Alias'),
31368
+ const AliasEffectSchema = v4.z.object({
31369
+ kind: v4.z.literal('Alias'),
31363
31370
  from: LifetimeIdSchema,
31364
31371
  into: LifetimeIdSchema,
31365
31372
  });
31366
- const ImmutableCaptureEffectSchema = zod.z.object({
31367
- kind: zod.z.literal('ImmutableCapture'),
31373
+ const ImmutableCaptureEffectSchema = v4.z.object({
31374
+ kind: v4.z.literal('ImmutableCapture'),
31368
31375
  from: LifetimeIdSchema,
31369
31376
  into: LifetimeIdSchema,
31370
31377
  });
31371
- const CaptureEffectSchema = zod.z.object({
31372
- kind: zod.z.literal('Capture'),
31378
+ const CaptureEffectSchema = v4.z.object({
31379
+ kind: v4.z.literal('Capture'),
31373
31380
  from: LifetimeIdSchema,
31374
31381
  into: LifetimeIdSchema,
31375
31382
  });
31376
- const CreateFromEffectSchema = zod.z.object({
31377
- kind: zod.z.literal('CreateFrom'),
31383
+ const CreateFromEffectSchema = v4.z.object({
31384
+ kind: v4.z.literal('CreateFrom'),
31378
31385
  from: LifetimeIdSchema,
31379
31386
  into: LifetimeIdSchema,
31380
31387
  });
31381
- const ApplyArgSchema = zod.z.union([
31388
+ const ApplyArgSchema = v4.z.union([
31382
31389
  LifetimeIdSchema,
31383
- zod.z.object({
31384
- kind: zod.z.literal('Spread'),
31390
+ v4.z.object({
31391
+ kind: v4.z.literal('Spread'),
31385
31392
  place: LifetimeIdSchema,
31386
31393
  }),
31387
- zod.z.object({
31388
- kind: zod.z.literal('Hole'),
31394
+ v4.z.object({
31395
+ kind: v4.z.literal('Hole'),
31389
31396
  }),
31390
31397
  ]);
31391
- const ApplyEffectSchema = zod.z.object({
31392
- kind: zod.z.literal('Apply'),
31398
+ const ApplyEffectSchema = v4.z.object({
31399
+ kind: v4.z.literal('Apply'),
31393
31400
  receiver: LifetimeIdSchema,
31394
31401
  function: LifetimeIdSchema,
31395
- mutatesFunction: zod.z.boolean(),
31396
- args: zod.z.array(ApplyArgSchema),
31402
+ mutatesFunction: v4.z.boolean(),
31403
+ args: v4.z.array(ApplyArgSchema),
31397
31404
  into: LifetimeIdSchema,
31398
31405
  });
31399
- const ImpureEffectSchema = zod.z.object({
31400
- kind: zod.z.literal('Impure'),
31406
+ const ImpureEffectSchema = v4.z.object({
31407
+ kind: v4.z.literal('Impure'),
31401
31408
  place: LifetimeIdSchema,
31402
31409
  });
31403
- const AliasingEffectSchema = zod.z.union([
31410
+ const AliasingEffectSchema = v4.z.union([
31404
31411
  FreezeEffectSchema,
31405
31412
  CreateEffectSchema,
31406
31413
  CreateFromEffectSchema,
@@ -31413,50 +31420,50 @@ const AliasingEffectSchema = zod.z.union([
31413
31420
  MutateTransitiveConditionallySchema,
31414
31421
  ApplyEffectSchema,
31415
31422
  ]);
31416
- const AliasingSignatureSchema = zod.z.object({
31423
+ const AliasingSignatureSchema = v4.z.object({
31417
31424
  receiver: LifetimeIdSchema,
31418
- params: zod.z.array(LifetimeIdSchema),
31425
+ params: v4.z.array(LifetimeIdSchema),
31419
31426
  rest: LifetimeIdSchema.nullable(),
31420
31427
  returns: LifetimeIdSchema,
31421
- effects: zod.z.array(AliasingEffectSchema),
31422
- temporaries: zod.z.array(LifetimeIdSchema),
31428
+ effects: v4.z.array(AliasingEffectSchema),
31429
+ temporaries: v4.z.array(LifetimeIdSchema),
31423
31430
  });
31424
- const FunctionTypeSchema = zod.z.object({
31425
- kind: zod.z.literal('function'),
31426
- positionalParams: zod.z.array(EffectSchema),
31431
+ const FunctionTypeSchema = v4.z.object({
31432
+ kind: v4.z.literal('function'),
31433
+ positionalParams: v4.z.array(EffectSchema),
31427
31434
  restParam: EffectSchema.nullable(),
31428
31435
  calleeEffect: EffectSchema,
31429
- returnType: zod.z.lazy(() => TypeSchema),
31436
+ returnType: v4.z.lazy(() => TypeSchema),
31430
31437
  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(),
31438
+ noAlias: v4.z.boolean().nullable().optional(),
31439
+ mutableOnlyIfOperandsAreMutable: v4.z.boolean().nullable().optional(),
31440
+ impure: v4.z.boolean().nullable().optional(),
31441
+ canonicalName: v4.z.string().nullable().optional(),
31435
31442
  aliasing: AliasingSignatureSchema.nullable().optional(),
31436
- knownIncompatible: zod.z.string().nullable().optional(),
31443
+ knownIncompatible: v4.z.string().nullable().optional(),
31437
31444
  });
31438
- const HookTypeSchema = zod.z.object({
31439
- kind: zod.z.literal('hook'),
31440
- positionalParams: zod.z.array(EffectSchema).nullable().optional(),
31445
+ const HookTypeSchema = v4.z.object({
31446
+ kind: v4.z.literal('hook'),
31447
+ positionalParams: v4.z.array(EffectSchema).nullable().optional(),
31441
31448
  restParam: EffectSchema.nullable().optional(),
31442
- returnType: zod.z.lazy(() => TypeSchema),
31449
+ returnType: v4.z.lazy(() => TypeSchema),
31443
31450
  returnValueKind: ValueKindSchema.nullable().optional(),
31444
- noAlias: zod.z.boolean().nullable().optional(),
31451
+ noAlias: v4.z.boolean().nullable().optional(),
31445
31452
  aliasing: AliasingSignatureSchema.nullable().optional(),
31446
- knownIncompatible: zod.z.string().nullable().optional(),
31453
+ knownIncompatible: v4.z.string().nullable().optional(),
31447
31454
  });
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'),
31455
+ const BuiltInTypeSchema = v4.z.union([
31456
+ v4.z.literal('Any'),
31457
+ v4.z.literal('Ref'),
31458
+ v4.z.literal('Array'),
31459
+ v4.z.literal('Primitive'),
31460
+ v4.z.literal('MixedReadonly'),
31454
31461
  ]);
31455
- const TypeReferenceSchema = zod.z.object({
31456
- kind: zod.z.literal('type'),
31462
+ const TypeReferenceSchema = v4.z.object({
31463
+ kind: v4.z.literal('type'),
31457
31464
  name: BuiltInTypeSchema,
31458
31465
  });
31459
- const TypeSchema = zod.z.union([
31466
+ const TypeSchema = v4.z.union([
31460
31467
  ObjectTypeSchema,
31461
31468
  FunctionTypeSchema,
31462
31469
  HookTypeSchema,
@@ -32052,96 +32059,90 @@ function defaultModuleTypeProvider(moduleName) {
32052
32059
  }
32053
32060
 
32054
32061
  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'),
32062
+ const ReactElementSymbolSchema = v4.z.object({
32063
+ elementSymbol: v4.z.union([
32064
+ v4.z.literal('react.element'),
32065
+ v4.z.literal('react.transitional.element'),
32059
32066
  ]),
32060
- globalDevVar: zod.z.string(),
32067
+ globalDevVar: v4.z.string(),
32061
32068
  });
32062
- const ExternalFunctionSchema = zod.z.object({
32063
- source: zod.z.string(),
32064
- importSpecifierName: zod.z.string(),
32069
+ const ExternalFunctionSchema = v4.z.object({
32070
+ source: v4.z.string(),
32071
+ importSpecifierName: v4.z.string(),
32065
32072
  });
32066
- const InstrumentationSchema = zod.z
32073
+ const InstrumentationSchema = v4.z
32067
32074
  .object({
32068
32075
  fn: ExternalFunctionSchema,
32069
32076
  gating: ExternalFunctionSchema.nullable(),
32070
- globalGating: zod.z.string().nullable(),
32077
+ globalGating: v4.z.string().nullable(),
32071
32078
  })
32072
32079
  .refine(opts => opts.gating != null || opts.globalGating != null, 'Expected at least one of gating or globalGating');
32073
32080
  const USE_FIRE_FUNCTION_NAME = 'useFire';
32074
32081
  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),
32082
+ const MacroSchema = v4.z.string();
32083
+ const HookSchema = v4.z.object({
32084
+ effectKind: v4.z.nativeEnum(Effect),
32085
+ valueKind: v4.z.nativeEnum(ValueKind),
32086
+ noAlias: v4.z.boolean().default(false),
32087
+ transitiveMixedData: v4.z.boolean().default(false),
32088
32088
  });
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({
32089
+ const EnvironmentConfigSchema = v4.z.object({
32090
+ customHooks: v4.z.map(v4.z.string(), HookSchema).default(new Map()),
32091
+ moduleTypeProvider: v4.z.nullable(v4.z.any()).default(null),
32092
+ customMacros: v4.z.nullable(v4.z.array(MacroSchema)).default(null),
32093
+ enableResetCacheOnSourceFileChanges: v4.z.nullable(v4.z.boolean()).default(null),
32094
+ enablePreserveExistingMemoizationGuarantees: v4.z.boolean().default(true),
32095
+ validatePreserveExistingMemoizationGuarantees: v4.z.boolean().default(true),
32096
+ enablePreserveExistingManualUseMemo: v4.z.boolean().default(false),
32097
+ enableForest: v4.z.boolean().default(false),
32098
+ enableUseTypeAnnotations: v4.z.boolean().default(false),
32099
+ flowTypeProvider: v4.z.nullable(v4.z.any()).default(null),
32100
+ enableOptionalDependencies: v4.z.boolean().default(true),
32101
+ enableFire: v4.z.boolean().default(false),
32102
+ enableNameAnonymousFunctions: v4.z.boolean().default(false),
32103
+ inferEffectDependencies: v4.z
32104
+ .nullable(v4.z.array(v4.z.object({
32105
32105
  function: ExternalFunctionSchema,
32106
- autodepsIndex: zod.z.number().min(1, 'autodepsIndex must be > 0'),
32106
+ autodepsIndex: v4.z.number().min(1, 'autodepsIndex must be > 0'),
32107
32107
  })))
32108
32108
  .default(null),
32109
32109
  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),
32110
+ validateHooksUsage: v4.z.boolean().default(true),
32111
+ validateRefAccessDuringRender: v4.z.boolean().default(true),
32112
+ validateNoSetStateInRender: v4.z.boolean().default(true),
32113
+ validateNoSetStateInEffects: v4.z.boolean().default(false),
32114
+ validateNoDerivedComputationsInEffects: v4.z.boolean().default(false),
32115
+ validateNoDerivedComputationsInEffects_exp: v4.z.boolean().default(false),
32116
+ validateNoJSXInTryStatements: v4.z.boolean().default(false),
32117
+ validateStaticComponents: v4.z.boolean().default(false),
32118
+ validateMemoizedEffectDependencies: v4.z.boolean().default(false),
32119
+ validateNoCapitalizedCalls: v4.z.nullable(v4.z.array(v4.z.string())).default(null),
32120
+ validateBlocklistedImports: v4.z.nullable(v4.z.array(v4.z.string())).default(null),
32121
+ validateNoImpureFunctionsInRender: v4.z.boolean().default(false),
32122
+ validateNoFreezingKnownMutableFunctions: v4.z.boolean().default(false),
32123
+ enableAssumeHooksFollowRulesOfReact: v4.z.boolean().default(true),
32124
+ enableTransitivelyFreezeFunctionExpressions: v4.z.boolean().default(true),
32124
32125
  enableEmitFreeze: ExternalFunctionSchema.nullable().default(null),
32125
32126
  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),
32127
+ enableInstructionReordering: v4.z.boolean().default(false),
32128
+ enableFunctionOutlining: v4.z.boolean().default(true),
32129
+ enableJsxOutlining: v4.z.boolean().default(false),
32129
32130
  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),
32131
+ assertValidMutableRanges: v4.z.boolean().default(false),
32132
+ enableChangeVariableCodegen: v4.z.boolean().default(false),
32133
+ enableMemoizationComments: v4.z.boolean().default(false),
32134
+ throwUnknownException__testonly: v4.z.boolean().default(false),
32135
+ enableTreatFunctionDepsAsConditional: v4.z.boolean().default(false),
32136
+ disableMemoizationForDebugging: v4.z.boolean().default(false),
32136
32137
  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),
32138
+ enableCustomTypeDefinitionForReanimated: v4.z.boolean().default(false),
32139
+ hookPattern: v4.z.string().nullable().default(null),
32140
+ enableTreatRefLikeIdentifiersAsRefs: v4.z.boolean().default(true),
32141
+ enableTreatSetIdentifiersAsStateSetters: v4.z.boolean().default(false),
32141
32142
  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),
32143
+ validateNoVoidUseMemo: v4.z.boolean().default(true),
32144
+ validateNoDynamicallyCreatedComponentsOrHooks: v4.z.boolean().default(false),
32145
+ enableAllowSetStateFromRefsInEffects: v4.z.boolean().default(true),
32145
32146
  });
32146
32147
  class Environment {
32147
32148
  constructor(scope, fnType, compilerMode, config, contextIdentifiers, parentFunction, logger, filename, code, programContext) {
@@ -32518,7 +32519,7 @@ function validateEnvironmentConfig(partialConfig) {
32518
32519
  }
32519
32520
  CompilerError.throwInvalidConfig({
32520
32521
  reason: 'Could not validate environment config. Update React Compiler config to fix the error',
32521
- description: `${zodValidationError.fromZodError(config.error)}`,
32522
+ description: `${v4$1.fromZodError(config.error)}`,
32522
32523
  loc: null,
32523
32524
  suggestions: null,
32524
32525
  });
@@ -32530,7 +32531,7 @@ function tryParseExternalFunction(maybeExternalFunction) {
32530
32531
  }
32531
32532
  CompilerError.throwInvalidConfig({
32532
32533
  reason: 'Could not parse external function. Update React Compiler config to fix the error',
32533
- description: `${zodValidationError.fromZodError(externalFunction.error)}`,
32534
+ description: `${v4$1.fromZodError(externalFunction.error)}`,
32534
32535
  loc: null,
32535
32536
  suggestions: null,
32536
32537
  });
@@ -37124,160 +37125,189 @@ var GuardKind;
37124
37125
  GuardKind[GuardKind["DisallowHook"] = 3] = "DisallowHook";
37125
37126
  })(GuardKind || (GuardKind = {}));
37126
37127
 
37128
+ var InlineLevel;
37129
+ (function (InlineLevel) {
37130
+ InlineLevel["Transitive"] = "Transitive";
37131
+ InlineLevel["Shallow"] = "Shallow";
37132
+ })(InlineLevel || (InlineLevel = {}));
37133
+ const SHALLOW_MACRO = {
37134
+ level: InlineLevel.Shallow,
37135
+ properties: null,
37136
+ };
37137
+ const TRANSITIVE_MACRO = {
37138
+ level: InlineLevel.Transitive,
37139
+ properties: null,
37140
+ };
37141
+ const FBT_MACRO = {
37142
+ level: InlineLevel.Transitive,
37143
+ properties: new Map([['*', SHALLOW_MACRO]]),
37144
+ };
37145
+ FBT_MACRO.properties.set('enum', FBT_MACRO);
37127
37146
  function memoizeFbtAndMacroOperandsInSameScope(fn) {
37128
37147
  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 : []),
37148
+ const macroKinds = new Map([
37149
+ ...Array.from(FBT_TAGS.entries()),
37150
+ ...((_a = fn.env.config.customMacros) !== null && _a !== void 0 ? _a : []).map(name => [name, TRANSITIVE_MACRO]),
37132
37151
  ]);
37133
- const fbtValues = new Set();
37134
- const macroMethods = new Map();
37135
- while (true) {
37136
- let vsize = fbtValues.size;
37137
- let msize = macroMethods.size;
37138
- visit$1(fn, fbtMacroTags, fbtValues, macroMethods);
37139
- if (vsize === fbtValues.size && msize === macroMethods.size) {
37140
- break;
37141
- }
37142
- }
37143
- return fbtValues;
37144
- }
37145
- const FBT_TAGS = new Set([
37146
- 'fbt',
37147
- 'fbt:param',
37148
- 'fbs',
37149
- 'fbs:param',
37152
+ const macroTags = populateMacroTags(fn, macroKinds);
37153
+ const macroValues = mergeMacroArguments(fn, macroTags, macroKinds);
37154
+ return macroValues;
37155
+ }
37156
+ const FBT_TAGS = new Map([
37157
+ ['fbt', FBT_MACRO],
37158
+ ['fbt:param', SHALLOW_MACRO],
37159
+ ['fbt:enum', FBT_MACRO],
37160
+ ['fbt:plural', SHALLOW_MACRO],
37161
+ ['fbs', FBT_MACRO],
37162
+ ['fbs:param', SHALLOW_MACRO],
37163
+ ['fbs:enum', FBT_MACRO],
37164
+ ['fbs:plural', SHALLOW_MACRO],
37150
37165
  ]);
37151
37166
  const SINGLE_CHILD_FBT_TAGS = new Set([
37152
37167
  'fbt:param',
37153
37168
  'fbs:param',
37154
37169
  ]);
37155
- function visit$1(fn, fbtMacroTags, fbtValues, macroMethods) {
37156
- for (const [, block] of fn.body.blocks) {
37157
- for (const instruction of block.instructions) {
37158
- const { lvalue, value } = instruction;
37159
- if (lvalue === null) {
37160
- continue;
37161
- }
37162
- if (value.kind === 'Primitive' &&
37163
- typeof value.value === 'string' &&
37164
- matchesExactTag(value.value, fbtMacroTags)) {
37165
- fbtValues.add(lvalue.identifier.id);
37166
- }
37167
- else if (value.kind === 'LoadGlobal' &&
37168
- matchesExactTag(value.binding.name, fbtMacroTags)) {
37169
- fbtValues.add(lvalue.identifier.id);
37170
- }
37171
- else if (value.kind === 'LoadGlobal' &&
37172
- matchTagRoot(value.binding.name, fbtMacroTags) !== null) {
37173
- const methods = matchTagRoot(value.binding.name, fbtMacroTags);
37174
- macroMethods.set(lvalue.identifier.id, methods);
37175
- }
37176
- else if (value.kind === 'PropertyLoad' &&
37177
- macroMethods.has(value.object.identifier.id)) {
37178
- const methods = macroMethods.get(value.object.identifier.id);
37179
- const newMethods = [];
37180
- for (const method of methods) {
37181
- if (method.length > 0 &&
37182
- (method[0].type === 'wildcard' ||
37183
- (method[0].type === 'name' && method[0].name === value.property))) {
37184
- if (method.length > 1) {
37185
- newMethods.push(method.slice(1));
37186
- }
37187
- else {
37188
- fbtValues.add(lvalue.identifier.id);
37170
+ function populateMacroTags(fn, macroKinds) {
37171
+ var _a;
37172
+ const macroTags = new Map();
37173
+ for (const block of fn.body.blocks.values()) {
37174
+ for (const instr of block.instructions) {
37175
+ const { lvalue, value } = instr;
37176
+ switch (value.kind) {
37177
+ case 'Primitive': {
37178
+ if (typeof value.value === 'string') {
37179
+ const macroDefinition = macroKinds.get(value.value);
37180
+ if (macroDefinition != null) {
37181
+ macroTags.set(lvalue.identifier.id, macroDefinition);
37189
37182
  }
37190
37183
  }
37184
+ break;
37191
37185
  }
37192
- if (newMethods.length > 0) {
37193
- macroMethods.set(lvalue.identifier.id, newMethods);
37194
- }
37195
- }
37196
- else if (isFbtCallExpression(fbtValues, value)) {
37197
- const fbtScope = lvalue.identifier.scope;
37198
- if (fbtScope === null) {
37199
- continue;
37186
+ case 'LoadGlobal': {
37187
+ let macroDefinition = macroKinds.get(value.binding.name);
37188
+ if (macroDefinition != null) {
37189
+ macroTags.set(lvalue.identifier.id, macroDefinition);
37190
+ }
37191
+ break;
37200
37192
  }
37201
- for (const operand of eachReactiveValueOperand(value)) {
37202
- operand.identifier.scope = fbtScope;
37203
- expandFbtScopeRange(fbtScope.range, operand.identifier.mutableRange);
37204
- fbtValues.add(operand.identifier.id);
37193
+ case 'PropertyLoad': {
37194
+ if (typeof value.property === 'string') {
37195
+ const macroDefinition = macroTags.get(value.object.identifier.id);
37196
+ if (macroDefinition != null) {
37197
+ const propertyDefinition = macroDefinition.properties != null
37198
+ ? ((_a = macroDefinition.properties.get(value.property)) !== null && _a !== void 0 ? _a : macroDefinition.properties.get('*'))
37199
+ : null;
37200
+ const propertyMacro = propertyDefinition !== null && propertyDefinition !== void 0 ? propertyDefinition : macroDefinition;
37201
+ macroTags.set(lvalue.identifier.id, propertyMacro);
37202
+ }
37203
+ }
37204
+ break;
37205
37205
  }
37206
37206
  }
37207
- else if (isFbtJsxExpression(fbtMacroTags, fbtValues, value) ||
37208
- isFbtJsxChild(fbtValues, lvalue, value)) {
37209
- const fbtScope = lvalue.identifier.scope;
37210
- if (fbtScope === null) {
37211
- continue;
37207
+ }
37208
+ }
37209
+ return macroTags;
37210
+ }
37211
+ function mergeMacroArguments(fn, macroTags, macroKinds) {
37212
+ var _a;
37213
+ const macroValues = new Set(macroTags.keys());
37214
+ for (const block of Array.from(fn.body.blocks.values()).reverse()) {
37215
+ for (let i = block.instructions.length - 1; i >= 0; i--) {
37216
+ const instr = block.instructions[i];
37217
+ const { lvalue, value } = instr;
37218
+ switch (value.kind) {
37219
+ case 'DeclareContext':
37220
+ case 'DeclareLocal':
37221
+ case 'Destructure':
37222
+ case 'LoadContext':
37223
+ case 'LoadLocal':
37224
+ case 'PostfixUpdate':
37225
+ case 'PrefixUpdate':
37226
+ case 'StoreContext':
37227
+ case 'StoreLocal': {
37228
+ break;
37212
37229
  }
37213
- for (const operand of eachReactiveValueOperand(value)) {
37214
- operand.identifier.scope = fbtScope;
37215
- expandFbtScopeRange(fbtScope.range, operand.identifier.mutableRange);
37216
- fbtValues.add(operand.identifier.id);
37230
+ case 'CallExpression':
37231
+ case 'MethodCall': {
37232
+ const scope = lvalue.identifier.scope;
37233
+ if (scope == null) {
37234
+ continue;
37235
+ }
37236
+ const callee = value.kind === 'CallExpression' ? value.callee : value.property;
37237
+ const macroDefinition = (_a = macroTags.get(callee.identifier.id)) !== null && _a !== void 0 ? _a : macroTags.get(lvalue.identifier.id);
37238
+ if (macroDefinition != null) {
37239
+ visitOperands(macroDefinition, scope, lvalue, value, macroValues, macroTags);
37240
+ }
37241
+ break;
37217
37242
  }
37218
- }
37219
- else if (fbtValues.has(lvalue.identifier.id)) {
37220
- const fbtScope = lvalue.identifier.scope;
37221
- if (fbtScope === null) {
37222
- return;
37243
+ case 'JsxExpression': {
37244
+ const scope = lvalue.identifier.scope;
37245
+ if (scope == null) {
37246
+ continue;
37247
+ }
37248
+ let macroDefinition;
37249
+ if (value.tag.kind === 'Identifier') {
37250
+ macroDefinition = macroTags.get(value.tag.identifier.id);
37251
+ }
37252
+ else {
37253
+ macroDefinition = macroKinds.get(value.tag.name);
37254
+ }
37255
+ macroDefinition !== null && macroDefinition !== void 0 ? macroDefinition : (macroDefinition = macroTags.get(lvalue.identifier.id));
37256
+ if (macroDefinition != null) {
37257
+ visitOperands(macroDefinition, scope, lvalue, value, macroValues, macroTags);
37258
+ }
37259
+ break;
37223
37260
  }
37224
- for (const operand of eachReactiveValueOperand(value)) {
37225
- if (operand.identifier.name !== null &&
37226
- operand.identifier.name.kind === 'named') {
37261
+ default: {
37262
+ const scope = lvalue.identifier.scope;
37263
+ if (scope == null) {
37227
37264
  continue;
37228
37265
  }
37229
- operand.identifier.scope = fbtScope;
37230
- expandFbtScopeRange(fbtScope.range, operand.identifier.mutableRange);
37266
+ const macroDefinition = macroTags.get(lvalue.identifier.id);
37267
+ if (macroDefinition != null) {
37268
+ visitOperands(macroDefinition, scope, lvalue, value, macroValues, macroTags);
37269
+ }
37270
+ break;
37231
37271
  }
37232
37272
  }
37233
37273
  }
37234
- }
37235
- }
37236
- function matchesExactTag(s, tags) {
37237
- return Array.from(tags).some(macro => typeof macro === 'string'
37238
- ? s === macro
37239
- : macro[1].length === 0 && macro[0] === s);
37240
- }
37241
- function matchTagRoot(s, tags) {
37242
- const methods = [];
37243
- for (const macro of tags) {
37244
- if (typeof macro === 'string') {
37245
- continue;
37246
- }
37247
- const [tag, rest] = macro;
37248
- if (tag === s && rest.length > 0) {
37249
- methods.push(rest);
37274
+ for (const phi of block.phis) {
37275
+ const scope = phi.place.identifier.scope;
37276
+ if (scope == null) {
37277
+ continue;
37278
+ }
37279
+ const macroDefinition = macroTags.get(phi.place.identifier.id);
37280
+ if (macroDefinition == null ||
37281
+ macroDefinition.level === InlineLevel.Shallow) {
37282
+ continue;
37283
+ }
37284
+ macroValues.add(phi.place.identifier.id);
37285
+ for (const operand of phi.operands.values()) {
37286
+ operand.identifier.scope = scope;
37287
+ expandFbtScopeRange(scope.range, operand.identifier.mutableRange);
37288
+ macroTags.set(operand.identifier.id, macroDefinition);
37289
+ macroValues.add(operand.identifier.id);
37290
+ }
37250
37291
  }
37251
37292
  }
37252
- if (methods.length > 0) {
37253
- return methods;
37254
- }
37255
- else {
37256
- return null;
37257
- }
37258
- }
37259
- function isFbtCallExpression(fbtValues, value) {
37260
- return ((value.kind === 'CallExpression' &&
37261
- fbtValues.has(value.callee.identifier.id)) ||
37262
- (value.kind === 'MethodCall' && fbtValues.has(value.property.identifier.id)));
37263
- }
37264
- function isFbtJsxExpression(fbtMacroTags, fbtValues, value) {
37265
- return (value.kind === 'JsxExpression' &&
37266
- ((value.tag.kind === 'Identifier' &&
37267
- fbtValues.has(value.tag.identifier.id)) ||
37268
- (value.tag.kind === 'BuiltinTag' &&
37269
- matchesExactTag(value.tag.name, fbtMacroTags))));
37270
- }
37271
- function isFbtJsxChild(fbtValues, lvalue, value) {
37272
- return ((value.kind === 'JsxExpression' || value.kind === 'JsxFragment') &&
37273
- lvalue !== null &&
37274
- fbtValues.has(lvalue.identifier.id));
37293
+ return macroValues;
37275
37294
  }
37276
37295
  function expandFbtScopeRange(fbtRange, extendWith) {
37277
37296
  if (extendWith.start !== 0) {
37278
37297
  fbtRange.start = makeInstructionId(Math.min(fbtRange.start, extendWith.start));
37279
37298
  }
37280
37299
  }
37300
+ function visitOperands(macroDefinition, scope, lvalue, value, macroValues, macroTags) {
37301
+ macroValues.add(lvalue.identifier.id);
37302
+ for (const operand of eachInstructionValueOperand(value)) {
37303
+ if (macroDefinition.level === InlineLevel.Transitive) {
37304
+ operand.identifier.scope = scope;
37305
+ expandFbtScopeRange(scope.range, operand.identifier.mutableRange);
37306
+ macroTags.set(operand.identifier.id, macroDefinition);
37307
+ }
37308
+ macroValues.add(operand.identifier.id);
37309
+ }
37310
+ }
37281
37311
 
37282
37312
  var _Context_nextCacheIndex, _Context_declarations;
37283
37313
  const MEMO_CACHE_SENTINEL = 'react.memo_cache_sentinel';
@@ -40475,7 +40505,7 @@ function inferMutationAliasingEffects(fn, { isFunctionExpression } = {
40475
40505
  }
40476
40506
  queue(fn.body.entry, initialState);
40477
40507
  const hoistedContextDeclarations = findHoistedContextDeclarations(fn);
40478
- const context = new Context$1(isFunctionExpression, fn, hoistedContextDeclarations);
40508
+ const context = new Context$1(isFunctionExpression, fn, hoistedContextDeclarations, findNonMutatedDestructureSpreads(fn));
40479
40509
  let iterationCount = 0;
40480
40510
  while (queuedStates.size !== 0) {
40481
40511
  iterationCount++;
@@ -40539,7 +40569,7 @@ function findHoistedContextDeclarations(fn) {
40539
40569
  return hoisted;
40540
40570
  }
40541
40571
  let Context$1 = class Context {
40542
- constructor(isFunctionExpression, fn, hoistedContextDeclarations) {
40572
+ constructor(isFunctionExpression, fn, hoistedContextDeclarations, nonMutatingSpreads) {
40543
40573
  this.internedEffects = new Map();
40544
40574
  this.instructionSignatureCache = new Map();
40545
40575
  this.effectInstructionValueCache = new Map();
@@ -40549,6 +40579,7 @@ let Context$1 = class Context {
40549
40579
  this.isFuctionExpression = isFunctionExpression;
40550
40580
  this.fn = fn;
40551
40581
  this.hoistedContextDeclarations = hoistedContextDeclarations;
40582
+ this.nonMutatingSpreads = nonMutatingSpreads;
40552
40583
  }
40553
40584
  cacheApplySignature(signature, effect, f) {
40554
40585
  const inner = getOrInsertDefault(this.applySignatureCache, signature, new Map());
@@ -40564,6 +40595,114 @@ let Context$1 = class Context {
40564
40595
  return interned;
40565
40596
  }
40566
40597
  };
40598
+ function findNonMutatedDestructureSpreads(fn) {
40599
+ const knownFrozen = new Set();
40600
+ if (fn.fnType === 'Component') {
40601
+ const [props] = fn.params;
40602
+ if (props != null && props.kind === 'Identifier') {
40603
+ knownFrozen.add(props.identifier.id);
40604
+ }
40605
+ }
40606
+ else {
40607
+ for (const param of fn.params) {
40608
+ if (param.kind === 'Identifier') {
40609
+ knownFrozen.add(param.identifier.id);
40610
+ }
40611
+ }
40612
+ }
40613
+ const candidateNonMutatingSpreads = new Map();
40614
+ for (const block of fn.body.blocks.values()) {
40615
+ if (candidateNonMutatingSpreads.size !== 0) {
40616
+ for (const phi of block.phis) {
40617
+ for (const operand of phi.operands.values()) {
40618
+ const spread = candidateNonMutatingSpreads.get(operand.identifier.id);
40619
+ if (spread != null) {
40620
+ candidateNonMutatingSpreads.delete(spread);
40621
+ }
40622
+ }
40623
+ }
40624
+ }
40625
+ for (const instr of block.instructions) {
40626
+ const { lvalue, value } = instr;
40627
+ switch (value.kind) {
40628
+ case 'Destructure': {
40629
+ if (!knownFrozen.has(value.value.identifier.id) ||
40630
+ !(value.lvalue.kind === InstructionKind.Let ||
40631
+ value.lvalue.kind === InstructionKind.Const) ||
40632
+ value.lvalue.pattern.kind !== 'ObjectPattern') {
40633
+ continue;
40634
+ }
40635
+ for (const item of value.lvalue.pattern.properties) {
40636
+ if (item.kind !== 'Spread') {
40637
+ continue;
40638
+ }
40639
+ candidateNonMutatingSpreads.set(item.place.identifier.id, item.place.identifier.id);
40640
+ }
40641
+ break;
40642
+ }
40643
+ case 'LoadLocal': {
40644
+ const spread = candidateNonMutatingSpreads.get(value.place.identifier.id);
40645
+ if (spread != null) {
40646
+ candidateNonMutatingSpreads.set(lvalue.identifier.id, spread);
40647
+ }
40648
+ break;
40649
+ }
40650
+ case 'StoreLocal': {
40651
+ const spread = candidateNonMutatingSpreads.get(value.value.identifier.id);
40652
+ if (spread != null) {
40653
+ candidateNonMutatingSpreads.set(lvalue.identifier.id, spread);
40654
+ candidateNonMutatingSpreads.set(value.lvalue.place.identifier.id, spread);
40655
+ }
40656
+ break;
40657
+ }
40658
+ case 'JsxFragment':
40659
+ case 'JsxExpression': {
40660
+ break;
40661
+ }
40662
+ case 'PropertyLoad': {
40663
+ break;
40664
+ }
40665
+ case 'CallExpression':
40666
+ case 'MethodCall': {
40667
+ const callee = value.kind === 'CallExpression' ? value.callee : value.property;
40668
+ if (getHookKind(fn.env, callee.identifier) != null) {
40669
+ if (!isRefOrRefValue(lvalue.identifier)) {
40670
+ knownFrozen.add(lvalue.identifier.id);
40671
+ }
40672
+ }
40673
+ else {
40674
+ if (candidateNonMutatingSpreads.size !== 0) {
40675
+ for (const operand of eachInstructionValueOperand(value)) {
40676
+ const spread = candidateNonMutatingSpreads.get(operand.identifier.id);
40677
+ if (spread != null) {
40678
+ candidateNonMutatingSpreads.delete(spread);
40679
+ }
40680
+ }
40681
+ }
40682
+ }
40683
+ break;
40684
+ }
40685
+ default: {
40686
+ if (candidateNonMutatingSpreads.size !== 0) {
40687
+ for (const operand of eachInstructionValueOperand(value)) {
40688
+ const spread = candidateNonMutatingSpreads.get(operand.identifier.id);
40689
+ if (spread != null) {
40690
+ candidateNonMutatingSpreads.delete(spread);
40691
+ }
40692
+ }
40693
+ }
40694
+ }
40695
+ }
40696
+ }
40697
+ }
40698
+ const nonMutatingSpreads = new Set();
40699
+ for (const [key, value] of candidateNonMutatingSpreads) {
40700
+ if (key === value) {
40701
+ nonMutatingSpreads.add(key);
40702
+ }
40703
+ }
40704
+ return nonMutatingSpreads;
40705
+ }
40567
40706
  function inferParam(param, initialState, paramKind) {
40568
40707
  const place = param.kind === 'Identifier' ? param : param.place;
40569
40708
  const value = {
@@ -41818,7 +41957,9 @@ function computeSignatureForInstruction(context, env, instr) {
41818
41957
  kind: 'Create',
41819
41958
  into: place,
41820
41959
  reason: ValueReason.Other,
41821
- value: ValueKind.Mutable,
41960
+ value: context.nonMutatingSpreads.has(place.identifier.id)
41961
+ ? ValueKind.Frozen
41962
+ : ValueKind.Mutable,
41822
41963
  });
41823
41964
  effects.push({
41824
41965
  kind: 'Capture',
@@ -44509,7 +44650,6 @@ function extractManualMemoizationArgs(instr, kind, sidemap, errors) {
44509
44650
  };
44510
44651
  }
44511
44652
  function dropManualMemoization(func) {
44512
- var _a;
44513
44653
  const errors = new CompilerError();
44514
44654
  const isValidationEnabled = func.env.config.validatePreserveExistingMemoizationGuarantees ||
44515
44655
  func.env.config.validateNoSetStateInRender ||
@@ -44539,26 +44679,6 @@ function dropManualMemoization(func) {
44539
44679
  if (fnPlace == null) {
44540
44680
  continue;
44541
44681
  }
44542
- if (func.env.config.validateNoVoidUseMemo &&
44543
- manualMemo.kind === 'useMemo') {
44544
- const funcToCheck = (_a = sidemap.functions.get(fnPlace.identifier.id)) === null || _a === void 0 ? void 0 : _a.value;
44545
- if (funcToCheck !== undefined && funcToCheck.loweredFunc.func) {
44546
- if (!hasNonVoidReturn(funcToCheck.loweredFunc.func)) {
44547
- errors.pushDiagnostic(CompilerDiagnostic.create({
44548
- category: ErrorCategory.VoidUseMemo,
44549
- reason: 'useMemo() callbacks must return a value',
44550
- description: `This ${manualMemo.loadInstr.value.kind === 'PropertyLoad'
44551
- ? 'React.useMemo'
44552
- : 'useMemo'} callback doesn't return a value. useMemo is for computing and caching values, not for arbitrary side effects`,
44553
- suggestions: null,
44554
- }).withDetails({
44555
- kind: 'error',
44556
- loc: instr.value.loc,
44557
- message: 'useMemo() callbacks must return a value',
44558
- }));
44559
- }
44560
- }
44561
- }
44562
44682
  instr.value = getManualMemoizationReplacement(fnPlace, instr.value.loc, manualMemo.kind);
44563
44683
  if (isValidationEnabled) {
44564
44684
  if (!sidemap.functions.has(fnPlace.identifier.id)) {
@@ -44670,17 +44790,6 @@ function findOptionalPlaces(fn) {
44670
44790
  }
44671
44791
  return optionals;
44672
44792
  }
44673
- function hasNonVoidReturn(func) {
44674
- for (const [, block] of func.body.blocks) {
44675
- if (block.terminal.kind === 'return') {
44676
- if (block.terminal.returnVariant === 'Explicit' ||
44677
- block.terminal.returnVariant === 'Implicit') {
44678
- return true;
44679
- }
44680
- }
44681
- }
44682
- return false;
44683
- }
44684
44793
 
44685
44794
  class StableSidemap {
44686
44795
  constructor(env) {
@@ -48124,7 +48233,7 @@ function* generateInstructionTypes(env, names, instr) {
48124
48233
  });
48125
48234
  }
48126
48235
  else {
48127
- break;
48236
+ continue;
48128
48237
  }
48129
48238
  }
48130
48239
  }
@@ -50163,11 +50272,18 @@ function isUnmemoized(operand, scopes) {
50163
50272
 
50164
50273
  function validateUseMemo(fn) {
50165
50274
  const errors = new CompilerError();
50275
+ const voidMemoErrors = new CompilerError();
50166
50276
  const useMemos = new Set();
50167
50277
  const react = new Set();
50168
50278
  const functions = new Map();
50279
+ const unusedUseMemos = new Map();
50169
50280
  for (const [, block] of fn.body.blocks) {
50170
50281
  for (const { lvalue, value } of block.instructions) {
50282
+ if (unusedUseMemos.size !== 0) {
50283
+ for (const operand of eachInstructionValueOperand(value)) {
50284
+ unusedUseMemos.delete(operand.identifier.id);
50285
+ }
50286
+ }
50171
50287
  switch (value.kind) {
50172
50288
  case 'LoadGlobal': {
50173
50289
  if (value.binding.name === 'useMemo') {
@@ -50192,10 +50308,8 @@ function validateUseMemo(fn) {
50192
50308
  }
50193
50309
  case 'MethodCall':
50194
50310
  case 'CallExpression': {
50195
- const callee = value.kind === 'CallExpression'
50196
- ? value.callee.identifier.id
50197
- : value.property.identifier.id;
50198
- const isUseMemo = useMemos.has(callee);
50311
+ const callee = value.kind === 'CallExpression' ? value.callee : value.property;
50312
+ const isUseMemo = useMemos.has(callee.identifier.id);
50199
50313
  if (!isUseMemo || value.args.length === 0) {
50200
50314
  continue;
50201
50315
  }
@@ -50235,13 +50349,87 @@ function validateUseMemo(fn) {
50235
50349
  message: 'Async and generator functions are not supported',
50236
50350
  }));
50237
50351
  }
50352
+ validateNoContextVariableAssignment(body.loweredFunc.func, errors);
50353
+ if (fn.env.config.validateNoVoidUseMemo) {
50354
+ if (!hasNonVoidReturn(body.loweredFunc.func)) {
50355
+ voidMemoErrors.pushDiagnostic(CompilerDiagnostic.create({
50356
+ category: ErrorCategory.VoidUseMemo,
50357
+ reason: 'useMemo() callbacks must return a value',
50358
+ description: `This useMemo() callback doesn't return a value. useMemo() is for computing and caching values, not for arbitrary side effects`,
50359
+ suggestions: null,
50360
+ }).withDetails({
50361
+ kind: 'error',
50362
+ loc: body.loc,
50363
+ message: 'useMemo() callbacks must return a value',
50364
+ }));
50365
+ }
50366
+ else {
50367
+ unusedUseMemos.set(lvalue.identifier.id, callee.loc);
50368
+ }
50369
+ }
50238
50370
  break;
50239
50371
  }
50240
50372
  }
50241
50373
  }
50374
+ if (unusedUseMemos.size !== 0) {
50375
+ for (const operand of eachTerminalOperand(block.terminal)) {
50376
+ unusedUseMemos.delete(operand.identifier.id);
50377
+ }
50378
+ }
50379
+ }
50380
+ if (unusedUseMemos.size !== 0) {
50381
+ for (const loc of unusedUseMemos.values()) {
50382
+ voidMemoErrors.pushDiagnostic(CompilerDiagnostic.create({
50383
+ category: ErrorCategory.VoidUseMemo,
50384
+ reason: 'useMemo() result is unused',
50385
+ description: `This useMemo() value is unused. useMemo() is for computing and caching values, not for arbitrary side effects`,
50386
+ suggestions: null,
50387
+ }).withDetails({
50388
+ kind: 'error',
50389
+ loc,
50390
+ message: 'useMemo() result is unused',
50391
+ }));
50392
+ }
50242
50393
  }
50394
+ fn.env.logErrors(voidMemoErrors.asResult());
50243
50395
  return errors.asResult();
50244
50396
  }
50397
+ function validateNoContextVariableAssignment(fn, errors) {
50398
+ const context = new Set(fn.context.map(place => place.identifier.id));
50399
+ for (const block of fn.body.blocks.values()) {
50400
+ for (const instr of block.instructions) {
50401
+ const value = instr.value;
50402
+ switch (value.kind) {
50403
+ case 'StoreContext': {
50404
+ if (context.has(value.lvalue.place.identifier.id)) {
50405
+ errors.pushDiagnostic(CompilerDiagnostic.create({
50406
+ category: ErrorCategory.UseMemo,
50407
+ reason: 'useMemo() callbacks may not reassign variables declared outside of the callback',
50408
+ description: 'useMemo() callbacks must be pure functions and cannot reassign variables defined outside of the callback function',
50409
+ suggestions: null,
50410
+ }).withDetails({
50411
+ kind: 'error',
50412
+ loc: value.lvalue.place.loc,
50413
+ message: 'Cannot reassign variable',
50414
+ }));
50415
+ }
50416
+ break;
50417
+ }
50418
+ }
50419
+ }
50420
+ }
50421
+ }
50422
+ function hasNonVoidReturn(func) {
50423
+ for (const [, block] of func.body.blocks) {
50424
+ if (block.terminal.kind === 'return') {
50425
+ if (block.terminal.returnVariant === 'Explicit' ||
50426
+ block.terminal.returnVariant === 'Implicit') {
50427
+ return true;
50428
+ }
50429
+ }
50430
+ }
50431
+ return false;
50432
+ }
50245
50433
 
50246
50434
  function validateLocalsNotReassignedAfterRender(fn) {
50247
50435
  const contextVariables = new Set();
@@ -51867,7 +52055,7 @@ function validateNoDerivedComputationsInEffects(fn) {
51867
52055
  });
51868
52056
  return (_a = locals.get(dep.identifier.id)) !== null && _a !== void 0 ? _a : dep.identifier.id;
51869
52057
  });
51870
- validateEffect(effectFunction.loweredFunc.func, dependencies, errors);
52058
+ validateEffect$1(effectFunction.loweredFunc.func, dependencies, errors);
51871
52059
  }
51872
52060
  }
51873
52061
  }
@@ -51877,7 +52065,7 @@ function validateNoDerivedComputationsInEffects(fn) {
51877
52065
  throw errors;
51878
52066
  }
51879
52067
  }
51880
- function validateEffect(effectFunction, effectDeps, errors) {
52068
+ function validateEffect$1(effectFunction, effectDeps, errors) {
51881
52069
  for (const operand of effectFunction.context) {
51882
52070
  if (isSetStateType(operand.identifier)) {
51883
52071
  continue;
@@ -51990,6 +52178,339 @@ function validateEffect(effectFunction, effectDeps, errors) {
51990
52178
  }
51991
52179
  }
51992
52180
 
52181
+ class DerivationCache {
52182
+ constructor() {
52183
+ this.hasChanges = false;
52184
+ this.cache = new Map();
52185
+ }
52186
+ snapshot() {
52187
+ const hasChanges = this.hasChanges;
52188
+ this.hasChanges = false;
52189
+ return hasChanges;
52190
+ }
52191
+ addDerivationEntry(derivedVar, sourcesIds, typeOfValue) {
52192
+ var _a, _b;
52193
+ let newValue = {
52194
+ place: derivedVar,
52195
+ sourcesIds: new Set(),
52196
+ typeOfValue: typeOfValue !== null && typeOfValue !== void 0 ? typeOfValue : 'ignored',
52197
+ };
52198
+ if (sourcesIds !== undefined) {
52199
+ for (const id of sourcesIds) {
52200
+ const sourcePlace = (_a = this.cache.get(id)) === null || _a === void 0 ? void 0 : _a.place;
52201
+ if (sourcePlace === undefined) {
52202
+ continue;
52203
+ }
52204
+ if (sourcePlace.identifier.name === null ||
52205
+ ((_b = sourcePlace.identifier.name) === null || _b === void 0 ? void 0 : _b.kind) === 'promoted') {
52206
+ newValue.sourcesIds.add(derivedVar.identifier.id);
52207
+ }
52208
+ else {
52209
+ newValue.sourcesIds.add(sourcePlace.identifier.id);
52210
+ }
52211
+ }
52212
+ }
52213
+ if (newValue.sourcesIds.size === 0) {
52214
+ newValue.sourcesIds.add(derivedVar.identifier.id);
52215
+ }
52216
+ const existingValue = this.cache.get(derivedVar.identifier.id);
52217
+ if (existingValue === undefined ||
52218
+ !this.isDerivationEqual(existingValue, newValue)) {
52219
+ this.cache.set(derivedVar.identifier.id, newValue);
52220
+ this.hasChanges = true;
52221
+ }
52222
+ }
52223
+ isDerivationEqual(a, b) {
52224
+ if (a.typeOfValue !== b.typeOfValue) {
52225
+ return false;
52226
+ }
52227
+ if (a.sourcesIds.size !== b.sourcesIds.size) {
52228
+ return false;
52229
+ }
52230
+ for (const id of a.sourcesIds) {
52231
+ if (!b.sourcesIds.has(id)) {
52232
+ return false;
52233
+ }
52234
+ }
52235
+ return true;
52236
+ }
52237
+ }
52238
+ function validateNoDerivedComputationsInEffects_exp(fn) {
52239
+ const functions = new Map();
52240
+ const derivationCache = new DerivationCache();
52241
+ const errors = new CompilerError();
52242
+ const effects = new Set();
52243
+ const setStateCache = new Map();
52244
+ const effectSetStateCache = new Map();
52245
+ const context = {
52246
+ functions,
52247
+ errors,
52248
+ derivationCache,
52249
+ effects,
52250
+ setStateCache,
52251
+ effectSetStateCache,
52252
+ };
52253
+ if (fn.fnType === 'Hook') {
52254
+ for (const param of fn.params) {
52255
+ if (param.kind === 'Identifier') {
52256
+ context.derivationCache.cache.set(param.identifier.id, {
52257
+ place: param,
52258
+ sourcesIds: new Set([param.identifier.id]),
52259
+ typeOfValue: 'fromProps',
52260
+ });
52261
+ context.derivationCache.hasChanges = true;
52262
+ }
52263
+ }
52264
+ }
52265
+ else if (fn.fnType === 'Component') {
52266
+ const props = fn.params[0];
52267
+ if (props != null && props.kind === 'Identifier') {
52268
+ context.derivationCache.cache.set(props.identifier.id, {
52269
+ place: props,
52270
+ sourcesIds: new Set([props.identifier.id]),
52271
+ typeOfValue: 'fromProps',
52272
+ });
52273
+ context.derivationCache.hasChanges = true;
52274
+ }
52275
+ }
52276
+ let isFirstPass = true;
52277
+ do {
52278
+ for (const block of fn.body.blocks.values()) {
52279
+ recordPhiDerivations(block, context);
52280
+ for (const instr of block.instructions) {
52281
+ recordInstructionDerivations(instr, context, isFirstPass);
52282
+ }
52283
+ }
52284
+ isFirstPass = false;
52285
+ } while (context.derivationCache.snapshot());
52286
+ for (const effect of effects) {
52287
+ validateEffect(effect, context);
52288
+ }
52289
+ if (errors.hasAnyErrors()) {
52290
+ throw errors;
52291
+ }
52292
+ }
52293
+ function recordPhiDerivations(block, context) {
52294
+ for (const phi of block.phis) {
52295
+ let typeOfValue = 'ignored';
52296
+ let sourcesIds = new Set();
52297
+ for (const operand of phi.operands.values()) {
52298
+ const operandMetadata = context.derivationCache.cache.get(operand.identifier.id);
52299
+ if (operandMetadata === undefined) {
52300
+ continue;
52301
+ }
52302
+ typeOfValue = joinValue(typeOfValue, operandMetadata.typeOfValue);
52303
+ sourcesIds.add(operand.identifier.id);
52304
+ }
52305
+ if (typeOfValue !== 'ignored') {
52306
+ context.derivationCache.addDerivationEntry(phi.place, sourcesIds, typeOfValue);
52307
+ }
52308
+ }
52309
+ }
52310
+ function joinValue(lvalueType, valueType) {
52311
+ if (lvalueType === 'ignored')
52312
+ return valueType;
52313
+ if (valueType === 'ignored')
52314
+ return lvalueType;
52315
+ if (lvalueType === valueType)
52316
+ return lvalueType;
52317
+ return 'fromPropsAndState';
52318
+ }
52319
+ function recordInstructionDerivations(instr, context, isFirstPass) {
52320
+ let typeOfValue = 'ignored';
52321
+ const sources = new Set();
52322
+ const { lvalue, value } = instr;
52323
+ if (value.kind === 'FunctionExpression') {
52324
+ context.functions.set(lvalue.identifier.id, value);
52325
+ for (const [, block] of value.loweredFunc.func.body.blocks) {
52326
+ for (const instr of block.instructions) {
52327
+ recordInstructionDerivations(instr, context, isFirstPass);
52328
+ }
52329
+ }
52330
+ }
52331
+ else if (value.kind === 'CallExpression' || value.kind === 'MethodCall') {
52332
+ const callee = value.kind === 'CallExpression' ? value.callee : value.property;
52333
+ if (isUseEffectHookType(callee.identifier) &&
52334
+ value.args.length === 2 &&
52335
+ value.args[0].kind === 'Identifier' &&
52336
+ value.args[1].kind === 'Identifier') {
52337
+ const effectFunction = context.functions.get(value.args[0].identifier.id);
52338
+ if (effectFunction != null) {
52339
+ context.effects.add(effectFunction.loweredFunc.func);
52340
+ }
52341
+ }
52342
+ else if (isUseStateType(lvalue.identifier) && value.args.length > 0) {
52343
+ const stateValueSource = value.args[0];
52344
+ if (stateValueSource.kind === 'Identifier') {
52345
+ sources.add(stateValueSource.identifier.id);
52346
+ }
52347
+ typeOfValue = joinValue(typeOfValue, 'fromState');
52348
+ }
52349
+ }
52350
+ for (const operand of eachInstructionOperand(instr)) {
52351
+ if (isSetStateType(operand.identifier) &&
52352
+ operand.loc !== GeneratedSource &&
52353
+ isFirstPass) {
52354
+ if (context.setStateCache.has(operand.loc.identifierName)) {
52355
+ context.setStateCache.get(operand.loc.identifierName).push(operand);
52356
+ }
52357
+ else {
52358
+ context.setStateCache.set(operand.loc.identifierName, [operand]);
52359
+ }
52360
+ }
52361
+ const operandMetadata = context.derivationCache.cache.get(operand.identifier.id);
52362
+ if (operandMetadata === undefined) {
52363
+ continue;
52364
+ }
52365
+ typeOfValue = joinValue(typeOfValue, operandMetadata.typeOfValue);
52366
+ for (const id of operandMetadata.sourcesIds) {
52367
+ sources.add(id);
52368
+ }
52369
+ }
52370
+ if (typeOfValue === 'ignored') {
52371
+ return;
52372
+ }
52373
+ for (const lvalue of eachInstructionLValue(instr)) {
52374
+ context.derivationCache.addDerivationEntry(lvalue, sources, typeOfValue);
52375
+ }
52376
+ for (const operand of eachInstructionOperand(instr)) {
52377
+ switch (operand.effect) {
52378
+ case Effect.Capture:
52379
+ case Effect.Store:
52380
+ case Effect.ConditionallyMutate:
52381
+ case Effect.ConditionallyMutateIterator:
52382
+ case Effect.Mutate: {
52383
+ if (isMutable(instr, operand)) {
52384
+ context.derivationCache.addDerivationEntry(operand, sources, typeOfValue);
52385
+ }
52386
+ break;
52387
+ }
52388
+ case Effect.Freeze:
52389
+ case Effect.Read: {
52390
+ break;
52391
+ }
52392
+ case Effect.Unknown: {
52393
+ CompilerError.invariant(false, {
52394
+ reason: 'Unexpected unknown effect',
52395
+ description: null,
52396
+ details: [
52397
+ {
52398
+ kind: 'error',
52399
+ loc: operand.loc,
52400
+ message: 'Unexpected unknown effect',
52401
+ },
52402
+ ],
52403
+ });
52404
+ }
52405
+ default: {
52406
+ assertExhaustive$1(operand.effect, `Unexpected effect kind \`${operand.effect}\``);
52407
+ }
52408
+ }
52409
+ }
52410
+ }
52411
+ function validateEffect(effectFunction, context) {
52412
+ const seenBlocks = new Set();
52413
+ const effectDerivedSetStateCalls = [];
52414
+ const globals = new Set();
52415
+ for (const block of effectFunction.body.blocks.values()) {
52416
+ for (const pred of block.preds) {
52417
+ if (!seenBlocks.has(pred)) {
52418
+ return;
52419
+ }
52420
+ }
52421
+ for (const instr of block.instructions) {
52422
+ if (isUseRefType(instr.lvalue.identifier)) {
52423
+ return;
52424
+ }
52425
+ for (const operand of eachInstructionOperand(instr)) {
52426
+ if (isSetStateType(operand.identifier) &&
52427
+ operand.loc !== GeneratedSource) {
52428
+ if (context.effectSetStateCache.has(operand.loc.identifierName)) {
52429
+ context.effectSetStateCache
52430
+ .get(operand.loc.identifierName)
52431
+ .push(operand);
52432
+ }
52433
+ else {
52434
+ context.effectSetStateCache.set(operand.loc.identifierName, [
52435
+ operand,
52436
+ ]);
52437
+ }
52438
+ }
52439
+ }
52440
+ if (instr.value.kind === 'CallExpression' &&
52441
+ isSetStateType(instr.value.callee.identifier) &&
52442
+ instr.value.args.length === 1 &&
52443
+ instr.value.args[0].kind === 'Identifier') {
52444
+ const argMetadata = context.derivationCache.cache.get(instr.value.args[0].identifier.id);
52445
+ if (argMetadata !== undefined) {
52446
+ effectDerivedSetStateCalls.push({
52447
+ value: instr.value,
52448
+ loc: instr.value.callee.loc,
52449
+ sourceIds: argMetadata.sourcesIds,
52450
+ typeOfValue: argMetadata.typeOfValue,
52451
+ });
52452
+ }
52453
+ }
52454
+ else if (instr.value.kind === 'CallExpression') {
52455
+ const calleeMetadata = context.derivationCache.cache.get(instr.value.callee.identifier.id);
52456
+ if (calleeMetadata !== undefined &&
52457
+ (calleeMetadata.typeOfValue === 'fromProps' ||
52458
+ calleeMetadata.typeOfValue === 'fromPropsAndState')) {
52459
+ return;
52460
+ }
52461
+ if (globals.has(instr.value.callee.identifier.id)) {
52462
+ return;
52463
+ }
52464
+ }
52465
+ else if (instr.value.kind === 'LoadGlobal') {
52466
+ globals.add(instr.lvalue.identifier.id);
52467
+ for (const operand of eachInstructionOperand(instr)) {
52468
+ globals.add(operand.identifier.id);
52469
+ }
52470
+ }
52471
+ }
52472
+ seenBlocks.add(block.id);
52473
+ }
52474
+ for (const derivedSetStateCall of effectDerivedSetStateCalls) {
52475
+ if (derivedSetStateCall.loc !== GeneratedSource &&
52476
+ context.effectSetStateCache.has(derivedSetStateCall.loc.identifierName) &&
52477
+ context.setStateCache.has(derivedSetStateCall.loc.identifierName) &&
52478
+ context.effectSetStateCache.get(derivedSetStateCall.loc.identifierName)
52479
+ .length ===
52480
+ context.setStateCache.get(derivedSetStateCall.loc.identifierName)
52481
+ .length -
52482
+ 1) {
52483
+ const derivedDepsStr = Array.from(derivedSetStateCall.sourceIds)
52484
+ .map(sourceId => {
52485
+ var _a;
52486
+ const sourceMetadata = context.derivationCache.cache.get(sourceId);
52487
+ return (_a = sourceMetadata === null || sourceMetadata === void 0 ? void 0 : sourceMetadata.place.identifier.name) === null || _a === void 0 ? void 0 : _a.value;
52488
+ })
52489
+ .filter(Boolean)
52490
+ .join(', ');
52491
+ let description;
52492
+ if (derivedSetStateCall.typeOfValue === 'fromProps') {
52493
+ description = `From props: [${derivedDepsStr}]`;
52494
+ }
52495
+ else if (derivedSetStateCall.typeOfValue === 'fromState') {
52496
+ description = `From local state: [${derivedDepsStr}]`;
52497
+ }
52498
+ else {
52499
+ description = `From props and local state: [${derivedDepsStr}]`;
52500
+ }
52501
+ context.errors.pushDiagnostic(CompilerDiagnostic.create({
52502
+ description: `Derived values (${description}) should be computed during render, rather than in effects. Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user`,
52503
+ category: ErrorCategory.EffectDerivationsOfState,
52504
+ reason: 'You might not need an effect. Derive values in render, not effects.',
52505
+ }).withDetails({
52506
+ kind: 'error',
52507
+ loc: derivedSetStateCall.value.callee.loc,
52508
+ message: 'This should be computed during render, not in an effect',
52509
+ }));
52510
+ }
52511
+ }
52512
+ }
52513
+
51993
52514
  function nameAnonymousFunctions(fn) {
51994
52515
  if (fn.id == null) {
51995
52516
  return;
@@ -52231,6 +52752,9 @@ function runWithEnvironment(func, env) {
52231
52752
  if (env.config.validateNoDerivedComputationsInEffects) {
52232
52753
  validateNoDerivedComputationsInEffects(hir);
52233
52754
  }
52755
+ if (env.config.validateNoDerivedComputationsInEffects_exp) {
52756
+ validateNoDerivedComputationsInEffects_exp(hir);
52757
+ }
52234
52758
  if (env.config.validateNoSetStateInEffects) {
52235
52759
  env.logErrors(validateNoSetStateInEffects(hir, env));
52236
52760
  }
@@ -53686,27 +54210,27 @@ function isNonNamespacedImport(importDeclPath) {
53686
54210
  importDeclPath.node.importKind !== 'typeof');
53687
54211
  }
53688
54212
 
53689
- zod.z.enum([
54213
+ v4.z.enum([
53690
54214
  'all_errors',
53691
54215
  'critical_errors',
53692
54216
  'none',
53693
54217
  ]);
53694
- const DynamicGatingOptionsSchema = zod.z.object({
53695
- source: zod.z.string(),
54218
+ const DynamicGatingOptionsSchema = v4.z.object({
54219
+ source: v4.z.string(),
53696
54220
  });
53697
- const CustomOptOutDirectiveSchema = zod.z
53698
- .nullable(zod.z.array(zod.z.string()))
54221
+ const CustomOptOutDirectiveSchema = v4.z
54222
+ .nullable(v4.z.array(v4.z.string()))
53699
54223
  .default(null);
53700
- const CompilerReactTargetSchema = zod.z.union([
53701
- zod.z.literal('17'),
53702
- zod.z.literal('18'),
53703
- zod.z.literal('19'),
53704
- zod.z.object({
53705
- kind: zod.z.literal('donotuse_meta_internal'),
53706
- runtimeModule: zod.z.string().default('react'),
54224
+ const CompilerReactTargetSchema = v4.z.union([
54225
+ v4.z.literal('17'),
54226
+ v4.z.literal('18'),
54227
+ v4.z.literal('19'),
54228
+ v4.z.object({
54229
+ kind: v4.z.literal('donotuse_meta_internal'),
54230
+ runtimeModule: v4.z.string().default('react'),
53707
54231
  }),
53708
54232
  ]);
53709
- zod.z.enum([
54233
+ v4.z.enum([
53710
54234
  'infer',
53711
54235
  'syntax',
53712
54236
  'annotation',
@@ -53779,7 +54303,7 @@ function parsePluginOptions(obj) {
53779
54303
  else {
53780
54304
  CompilerError.throwInvalidConfig({
53781
54305
  reason: 'Could not parse dynamic gating. Update React Compiler config to fix the error',
53782
- description: `${zodValidationError.fromZodError(result.error)}`,
54306
+ description: `${v4$1.fromZodError(result.error)}`,
53783
54307
  loc: null,
53784
54308
  suggestions: null,
53785
54309
  });
@@ -53795,7 +54319,7 @@ function parsePluginOptions(obj) {
53795
54319
  else {
53796
54320
  CompilerError.throwInvalidConfig({
53797
54321
  reason: 'Could not parse custom opt out directives. Update React Compiler config to fix the error',
53798
- description: `${zodValidationError.fromZodError(result.error)}`,
54322
+ description: `${v4$1.fromZodError(result.error)}`,
53799
54323
  loc: null,
53800
54324
  suggestions: null,
53801
54325
  });
@@ -53818,7 +54342,7 @@ function parseTargetConfig(value) {
53818
54342
  else {
53819
54343
  CompilerError.throwInvalidConfig({
53820
54344
  reason: 'Not a valid target',
53821
- description: `${zodValidationError.fromZodError(parsed.error)}`,
54345
+ description: `${v4$1.fromZodError(parsed.error)}`,
53822
54346
  suggestions: null,
53823
54347
  loc: null,
53824
54348
  });
@@ -57332,6 +57856,10 @@ function isUseEffectEventIdentifier(node) {
57332
57856
  return node.type === 'Identifier' && node.name === 'useEffectEvent';
57333
57857
  }
57334
57858
  function useEffectEventError(fn, called) {
57859
+ if (fn === null) {
57860
+ return (`React Hook "useEffectEvent" can only be called at the top level of your component.` +
57861
+ ` It cannot be passed down.`);
57862
+ }
57335
57863
  return (`\`${fn}\` is a function created with React Hook "useEffectEvent", and can only be called from ` +
57336
57864
  'Effects and Effect Events in the same component.' +
57337
57865
  (called ? '' : ' It cannot be assigned to a variable or passed down.'));
@@ -57631,6 +58159,7 @@ const rule = {
57631
58159
  analyzer.leaveNode(node);
57632
58160
  },
57633
58161
  CallExpression(node) {
58162
+ var _a, _b;
57634
58163
  if (isHook(node.callee)) {
57635
58164
  const reactHooksMap = last(codePathReactHooksMapStack);
57636
58165
  const codePathSegment = last(codePathSegmentStack);
@@ -57647,6 +58176,15 @@ const rule = {
57647
58176
  node.arguments.length > 0) {
57648
58177
  lastEffect = node;
57649
58178
  }
58179
+ if (isUseEffectEventIdentifier(nodeWithoutNamespace) &&
58180
+ ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) !== 'VariableDeclarator' &&
58181
+ ((_b = node.parent) === null || _b === void 0 ? void 0 : _b.type) !== 'ExpressionStatement') {
58182
+ const message = useEffectEventError(null, false);
58183
+ context.report({
58184
+ node,
58185
+ message,
58186
+ });
58187
+ }
57650
58188
  },
57651
58189
  Identifier(node) {
57652
58190
  if (lastEffect == null && useEffectEventFunctions.has(node)) {