babel-plugin-react-compiler 19.1.0-rc.1 → 19.1.0-rc.3

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +410 -63
  2. package/dist/index.js +39785 -85852
  3. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import * as BabelCore from '@babel/core';
2
2
  import { NodePath as NodePath$1 } from '@babel/core';
3
3
  import * as t from '@babel/types';
4
4
  import { z } from 'zod';
5
- import { Scope, NodePath } from '@babel/traverse';
5
+ import { NodePath, Scope } from '@babel/traverse';
6
6
 
7
7
  interface Result<T, E> {
8
8
  map<U>(fn: (val: T) => U): Result<U, E>;
@@ -23,7 +23,7 @@ interface Result<T, E> {
23
23
  unwrapErr(): E;
24
24
  }
25
25
  declare class OkImpl<T> implements Result<T, never> {
26
- private val;
26
+ #private;
27
27
  constructor(val: T);
28
28
  map<U>(fn: (val: T) => U): Result<U, never>;
29
29
  mapErr<F>(_fn: (val: never) => F): Result<T, F>;
@@ -43,7 +43,7 @@ declare class OkImpl<T> implements Result<T, never> {
43
43
  unwrapErr(): never;
44
44
  }
45
45
  declare class ErrImpl<E> implements Result<never, E> {
46
- private val;
46
+ #private;
47
47
  constructor(val: E);
48
48
  map<U>(_fn: (val: never) => U): Result<U, E>;
49
49
  mapErr<F>(fn: (val: E) => F): Result<never, F>;
@@ -63,6 +63,94 @@ declare class ErrImpl<E> implements Result<never, E> {
63
63
  unwrapErr(): E;
64
64
  }
65
65
 
66
+ type AliasingEffect = {
67
+ kind: 'Freeze';
68
+ value: Place;
69
+ reason: ValueReason;
70
+ } | {
71
+ kind: 'Mutate';
72
+ value: Place;
73
+ reason?: MutationReason | null;
74
+ } | {
75
+ kind: 'MutateConditionally';
76
+ value: Place;
77
+ } | {
78
+ kind: 'MutateTransitive';
79
+ value: Place;
80
+ } | {
81
+ kind: 'MutateTransitiveConditionally';
82
+ value: Place;
83
+ } | {
84
+ kind: 'Capture';
85
+ from: Place;
86
+ into: Place;
87
+ } | {
88
+ kind: 'Alias';
89
+ from: Place;
90
+ into: Place;
91
+ } | {
92
+ kind: 'MaybeAlias';
93
+ from: Place;
94
+ into: Place;
95
+ } | {
96
+ kind: 'Assign';
97
+ from: Place;
98
+ into: Place;
99
+ } | {
100
+ kind: 'Create';
101
+ into: Place;
102
+ value: ValueKind;
103
+ reason: ValueReason;
104
+ } | {
105
+ kind: 'CreateFrom';
106
+ from: Place;
107
+ into: Place;
108
+ } | {
109
+ kind: 'ImmutableCapture';
110
+ from: Place;
111
+ into: Place;
112
+ } | {
113
+ kind: 'Apply';
114
+ receiver: Place;
115
+ function: Place;
116
+ mutatesFunction: boolean;
117
+ args: Array<Place | SpreadPattern | Hole>;
118
+ into: Place;
119
+ signature: FunctionSignature | null;
120
+ loc: SourceLocation;
121
+ } | {
122
+ kind: 'CreateFunction';
123
+ captures: Array<Place>;
124
+ function: FunctionExpression | ObjectMethod;
125
+ into: Place;
126
+ } | {
127
+ kind: 'MutateFrozen';
128
+ place: Place;
129
+ error: CompilerDiagnostic;
130
+ } | {
131
+ kind: 'MutateGlobal';
132
+ place: Place;
133
+ error: CompilerDiagnostic;
134
+ } | {
135
+ kind: 'Impure';
136
+ place: Place;
137
+ error: CompilerDiagnostic;
138
+ } | {
139
+ kind: 'Render';
140
+ place: Place;
141
+ };
142
+ type MutationReason = {
143
+ kind: 'AssignCurrentProperty';
144
+ };
145
+ type AliasingSignature = {
146
+ receiver: IdentifierId;
147
+ params: Array<IdentifierId>;
148
+ rest: IdentifierId | null;
149
+ returns: IdentifierId;
150
+ effects: Array<AliasingEffect>;
151
+ temporaries: Array<Place>;
152
+ };
153
+
66
154
  type BuiltInType = PrimitiveType | FunctionType | ObjectType;
67
155
  type Type = BuiltInType | PhiType | TypeVar | PolyType | PropType | ObjectMethod$1;
68
156
  type PrimitiveType = {
@@ -109,7 +197,7 @@ type TypeId = number & {
109
197
  [opaqueTypeId]: 'IdentifierId';
110
198
  };
111
199
 
112
- type HookKind = 'useContext' | 'useState' | 'useActionState' | 'useReducer' | 'useRef' | 'useEffect' | 'useLayoutEffect' | 'useInsertionEffect' | 'useMemo' | 'useCallback' | 'useTransition' | 'useImperativeHandle' | 'Custom';
200
+ type HookKind = 'useContext' | 'useState' | 'useActionState' | 'useReducer' | 'useRef' | 'useEffect' | 'useLayoutEffect' | 'useInsertionEffect' | 'useMemo' | 'useCallback' | 'useTransition' | 'useImperativeHandle' | 'useEffectEvent' | 'Custom';
113
201
  type FunctionSignature = {
114
202
  positionalParams: Array<Effect>;
115
203
  restParam: Effect | null;
@@ -122,10 +210,126 @@ type FunctionSignature = {
122
210
  mutableOnlyIfOperandsAreMutable?: boolean;
123
211
  impure?: boolean;
124
212
  canonicalName?: string;
213
+ aliasing?: AliasingSignature | null | undefined;
125
214
  };
126
215
 
127
216
  type Global = BuiltInType | PolyType;
128
217
 
218
+ type ResolvedType = {
219
+ kind: 'Concrete';
220
+ type: ConcreteType<ResolvedType>;
221
+ platform: Platform;
222
+ };
223
+ type ComponentType<T> = {
224
+ kind: 'Component';
225
+ props: Map<string, T>;
226
+ children: null | T;
227
+ };
228
+ type ConcreteType<T> = {
229
+ kind: 'Enum';
230
+ } | {
231
+ kind: 'Mixed';
232
+ } | {
233
+ kind: 'Number';
234
+ } | {
235
+ kind: 'String';
236
+ } | {
237
+ kind: 'Boolean';
238
+ } | {
239
+ kind: 'Void';
240
+ } | {
241
+ kind: 'Nullable';
242
+ type: T;
243
+ } | {
244
+ kind: 'Array';
245
+ element: T;
246
+ } | {
247
+ kind: 'Set';
248
+ element: T;
249
+ } | {
250
+ kind: 'Map';
251
+ key: T;
252
+ value: T;
253
+ } | {
254
+ kind: 'Function';
255
+ typeParameters: null | Array<TypeParameter<T>>;
256
+ params: Array<T>;
257
+ returnType: T;
258
+ } | ComponentType<T> | {
259
+ kind: 'Generic';
260
+ id: TypeParameterId;
261
+ bound: T;
262
+ } | {
263
+ kind: 'Object';
264
+ id: NominalId;
265
+ members: Map<string, ResolvedType>;
266
+ } | {
267
+ kind: 'Tuple';
268
+ id: NominalId;
269
+ members: Array<T>;
270
+ } | {
271
+ kind: 'Structural';
272
+ id: LinearId;
273
+ } | {
274
+ kind: 'Union';
275
+ members: Array<T>;
276
+ } | {
277
+ kind: 'Instance';
278
+ name: string;
279
+ members: Map<string, ResolvedType>;
280
+ };
281
+ type TypeParameter<T> = {
282
+ name: string;
283
+ id: TypeParameterId;
284
+ bound: T;
285
+ };
286
+ declare const opaqueLinearId: unique symbol;
287
+ type LinearId = number & {
288
+ [opaqueLinearId]: 'LinearId';
289
+ };
290
+ declare const opaqueTypeParameterId: unique symbol;
291
+ type TypeParameterId = number & {
292
+ [opaqueTypeParameterId]: 'TypeParameterId';
293
+ };
294
+ declare const opaqueNominalId: unique symbol;
295
+ type NominalId = number & {
296
+ [opaqueNominalId]: 'NominalId';
297
+ };
298
+ type Platform = 'client' | 'server' | 'shared';
299
+ interface ITypeEnv {
300
+ popGeneric(name: string): void;
301
+ getGeneric(name: string): null | TypeParameter<ResolvedType>;
302
+ pushGeneric(name: string, binding: {
303
+ name: string;
304
+ id: TypeParameterId;
305
+ bound: ResolvedType;
306
+ }): void;
307
+ getType(id: Identifier): ResolvedType;
308
+ getTypeOrNull(id: Identifier): ResolvedType | null;
309
+ setType(id: Identifier, type: ResolvedType): void;
310
+ nextNominalId(): NominalId;
311
+ nextTypeParameterId(): TypeParameterId;
312
+ moduleEnv: Map<string, ResolvedType>;
313
+ addBinding(bindingIdentifier: t.Identifier, type: ResolvedType): void;
314
+ resolveBinding(bindingIdentifier: t.Identifier): ResolvedType | null;
315
+ }
316
+ declare class FlowTypeEnv implements ITypeEnv {
317
+ #private;
318
+ moduleEnv: Map<string, ResolvedType>;
319
+ init(env: Environment, source: string): void;
320
+ setType(identifier: Identifier, type: ResolvedType): void;
321
+ getType(identifier: Identifier): ResolvedType;
322
+ getTypeOrNull(identifier: Identifier): ResolvedType | null;
323
+ getTypeByLoc(loc: SourceLocation): ResolvedType | null;
324
+ nextNominalId(): NominalId;
325
+ nextTypeParameterId(): TypeParameterId;
326
+ addBinding(bindingIdentifier: t.Identifier, type: ResolvedType): void;
327
+ resolveBinding(bindingIdentifier: t.Identifier): ResolvedType | null;
328
+ pushGeneric(name: string, generic: TypeParameter<ResolvedType>): void;
329
+ popGeneric(name: string): void;
330
+ getGeneric(name: string): null | TypeParameter<ResolvedType>;
331
+ }
332
+
129
333
  declare const ExternalFunctionSchema: z.ZodObject<{
130
334
  source: z.ZodString;
131
335
  importSpecifierName: z.ZodString;
@@ -195,6 +399,7 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
195
399
  enablePreserveExistingManualUseMemo: z.ZodDefault<z.ZodBoolean>;
196
400
  enableForest: z.ZodDefault<z.ZodBoolean>;
197
401
  enableUseTypeAnnotations: z.ZodDefault<z.ZodBoolean>;
402
+ flowTypeProvider: z.ZodDefault<z.ZodNullable<z.ZodFunction<z.ZodTuple<[z.ZodString], z.ZodUnknown>, z.ZodUnknown>>>;
198
403
  enableOptionalDependencies: z.ZodDefault<z.ZodBoolean>;
199
404
  enableFire: z.ZodDefault<z.ZodBoolean>;
200
405
  inferEffectDependencies: z.ZodDefault<z.ZodNullable<z.ZodArray<z.ZodObject<{
@@ -208,19 +413,19 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
208
413
  source: string;
209
414
  importSpecifierName: string;
210
415
  }>;
211
- numRequiredArgs: z.ZodNumber;
416
+ autodepsIndex: z.ZodNumber;
212
417
  }, "strip", z.ZodTypeAny, {
213
418
  function: {
214
419
  source: string;
215
420
  importSpecifierName: string;
216
421
  };
217
- numRequiredArgs: number;
422
+ autodepsIndex: number;
218
423
  }, {
219
424
  function: {
220
425
  source: string;
221
426
  importSpecifierName: string;
222
427
  };
223
- numRequiredArgs: number;
428
+ autodepsIndex: number;
224
429
  }>, "many">>>;
225
430
  inlineJsxTransform: z.ZodDefault<z.ZodNullable<z.ZodObject<{
226
431
  elementSymbol: z.ZodUnion<[z.ZodLiteral<"react.element">, z.ZodLiteral<"react.transitional.element">]>;
@@ -235,13 +440,15 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
235
440
  validateHooksUsage: z.ZodDefault<z.ZodBoolean>;
236
441
  validateRefAccessDuringRender: z.ZodDefault<z.ZodBoolean>;
237
442
  validateNoSetStateInRender: z.ZodDefault<z.ZodBoolean>;
238
- validateNoSetStateInPassiveEffects: z.ZodDefault<z.ZodBoolean>;
443
+ validateNoSetStateInEffects: z.ZodDefault<z.ZodBoolean>;
444
+ validateNoDerivedComputationsInEffects: z.ZodDefault<z.ZodBoolean>;
239
445
  validateNoJSXInTryStatements: z.ZodDefault<z.ZodBoolean>;
240
446
  validateStaticComponents: z.ZodDefault<z.ZodBoolean>;
241
447
  validateMemoizedEffectDependencies: z.ZodDefault<z.ZodBoolean>;
242
448
  validateNoCapitalizedCalls: z.ZodDefault<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
243
449
  validateBlocklistedImports: z.ZodDefault<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
244
450
  validateNoImpureFunctionsInRender: z.ZodDefault<z.ZodBoolean>;
451
+ validateNoFreezingKnownMutableFunctions: z.ZodDefault<z.ZodBoolean>;
245
452
  enableAssumeHooksFollowRulesOfReact: z.ZodDefault<z.ZodBoolean>;
246
453
  enableTransitivelyFreezeFunctionExpressions: z.ZodDefault<z.ZodBoolean>;
247
454
  enableEmitFreeze: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -359,6 +566,8 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
359
566
  source: string;
360
567
  importSpecifierName: string;
361
568
  }>>>;
569
+ validateNoVoidUseMemo: z.ZodDefault<z.ZodBoolean>;
570
+ validateNoDynamicallyCreatedComponentsOrHooks: z.ZodDefault<z.ZodBoolean>;
362
571
  }, "strip", z.ZodTypeAny, {
363
572
  customHooks: Map<string, {
364
573
  noAlias: boolean;
@@ -379,6 +588,7 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
379
588
  enablePreserveExistingManualUseMemo: boolean;
380
589
  enableForest: boolean;
381
590
  enableUseTypeAnnotations: boolean;
591
+ flowTypeProvider: ((args_0: string, ...args_1: unknown[]) => unknown) | null;
382
592
  enableOptionalDependencies: boolean;
383
593
  enableFire: boolean;
384
594
  inferEffectDependencies: {
@@ -386,7 +596,7 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
386
596
  source: string;
387
597
  importSpecifierName: string;
388
598
  };
389
- numRequiredArgs: number;
599
+ autodepsIndex: number;
390
600
  }[] | null;
391
601
  inlineJsxTransform: {
392
602
  elementSymbol: "react.element" | "react.transitional.element";
@@ -395,13 +605,15 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
395
605
  validateHooksUsage: boolean;
396
606
  validateRefAccessDuringRender: boolean;
397
607
  validateNoSetStateInRender: boolean;
398
- validateNoSetStateInPassiveEffects: boolean;
608
+ validateNoSetStateInEffects: boolean;
609
+ validateNoDerivedComputationsInEffects: boolean;
399
610
  validateNoJSXInTryStatements: boolean;
400
611
  validateStaticComponents: boolean;
401
612
  validateMemoizedEffectDependencies: boolean;
402
613
  validateNoCapitalizedCalls: string[] | null;
403
614
  validateBlocklistedImports: string[] | null;
404
615
  validateNoImpureFunctionsInRender: boolean;
616
+ validateNoFreezingKnownMutableFunctions: boolean;
405
617
  enableAssumeHooksFollowRulesOfReact: boolean;
406
618
  enableTransitivelyFreezeFunctionExpressions: boolean;
407
619
  enableEmitFreeze: {
@@ -443,6 +655,8 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
443
655
  source: string;
444
656
  importSpecifierName: string;
445
657
  } | null;
658
+ validateNoVoidUseMemo: boolean;
659
+ validateNoDynamicallyCreatedComponentsOrHooks: boolean;
446
660
  }, {
447
661
  customHooks?: Map<string, {
448
662
  effectKind: Effect;
@@ -463,6 +677,7 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
463
677
  enablePreserveExistingManualUseMemo?: boolean | undefined;
464
678
  enableForest?: boolean | undefined;
465
679
  enableUseTypeAnnotations?: boolean | undefined;
680
+ flowTypeProvider?: ((args_0: string, ...args_1: unknown[]) => unknown) | null | undefined;
466
681
  enableOptionalDependencies?: boolean | undefined;
467
682
  enableFire?: boolean | undefined;
468
683
  inferEffectDependencies?: {
@@ -470,7 +685,7 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
470
685
  source: string;
471
686
  importSpecifierName: string;
472
687
  };
473
- numRequiredArgs: number;
688
+ autodepsIndex: number;
474
689
  }[] | null | undefined;
475
690
  inlineJsxTransform?: {
476
691
  elementSymbol: "react.element" | "react.transitional.element";
@@ -479,13 +694,15 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
479
694
  validateHooksUsage?: boolean | undefined;
480
695
  validateRefAccessDuringRender?: boolean | undefined;
481
696
  validateNoSetStateInRender?: boolean | undefined;
482
- validateNoSetStateInPassiveEffects?: boolean | undefined;
697
+ validateNoSetStateInEffects?: boolean | undefined;
698
+ validateNoDerivedComputationsInEffects?: boolean | undefined;
483
699
  validateNoJSXInTryStatements?: boolean | undefined;
484
700
  validateStaticComponents?: boolean | undefined;
485
701
  validateMemoizedEffectDependencies?: boolean | undefined;
486
702
  validateNoCapitalizedCalls?: string[] | null | undefined;
487
703
  validateBlocklistedImports?: string[] | null | undefined;
488
704
  validateNoImpureFunctionsInRender?: boolean | undefined;
705
+ validateNoFreezingKnownMutableFunctions?: boolean | undefined;
489
706
  enableAssumeHooksFollowRulesOfReact?: boolean | undefined;
490
707
  enableTransitivelyFreezeFunctionExpressions?: boolean | undefined;
491
708
  enableEmitFreeze?: {
@@ -527,11 +744,10 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
527
744
  source: string;
528
745
  importSpecifierName: string;
529
746
  } | null | undefined;
747
+ validateNoVoidUseMemo?: boolean | undefined;
748
+ validateNoDynamicallyCreatedComponentsOrHooks?: boolean | undefined;
530
749
  }>;
531
750
  type EnvironmentConfig = z.infer<typeof EnvironmentConfigSchema>;
532
- declare function parseConfigPragmaForTests(pragma: string, defaults: {
533
- compilationMode: CompilationMode;
534
- }): PluginOptions;
535
751
  type PartialEnvironmentConfig = Partial<EnvironmentConfig>;
536
752
  type ReactFunctionType = 'Component' | 'Hook' | 'Other';
537
753
  declare class Environment {
@@ -546,7 +762,9 @@ declare class Environment {
546
762
  hasFireRewrite: boolean;
547
763
  hasInferredEffect: boolean;
548
764
  inferredEffectLocations: Set<SourceLocation>;
549
- constructor(scope: Scope, fnType: ReactFunctionType, compilerMode: CompilerMode, config: EnvironmentConfig, contextIdentifiers: Set<t.Identifier>, logger: Logger | null, filename: string | null, code: string | null, programContext: ProgramContext);
765
+ parentFunction: NodePath<t.Function>;
766
+ constructor(scope: Scope, fnType: ReactFunctionType, compilerMode: CompilerMode, config: EnvironmentConfig, contextIdentifiers: Set<t.Identifier>, parentFunction: NodePath<t.Function>, logger: Logger | null, filename: string | null, code: string | null, programContext: ProgramContext);
767
+ get typeContext(): FlowTypeEnv;
550
768
  get isInferredMemoEnabled(): boolean;
551
769
  get nextIdentifierId(): IdentifierId;
552
770
  get nextBlockId(): BlockId;
@@ -610,6 +828,7 @@ type ReactiveInstruction = {
610
828
  id: InstructionId;
611
829
  lvalue: Place | null;
612
830
  value: ReactiveValue;
831
+ effects?: Array<AliasingEffect> | null;
613
832
  loc: SourceLocation;
614
833
  };
615
834
  type ReactiveValue = InstructionValue | ReactiveLogicalValue | ReactiveSequenceValue | ReactiveTernaryValue | ReactiveOptionalCallValue;
@@ -746,25 +965,13 @@ type HIRFunction = {
746
965
  env: Environment;
747
966
  params: Array<Place | SpreadPattern>;
748
967
  returnTypeAnnotation: t.FlowType | t.TSType | null;
749
- returnType: Type;
968
+ returns: Place;
750
969
  context: Array<Place>;
751
- effects: Array<FunctionEffect> | null;
752
970
  body: HIR;
753
971
  generator: boolean;
754
972
  async: boolean;
755
973
  directives: Array<string>;
756
- };
757
- type FunctionEffect = {
758
- kind: 'GlobalMutation';
759
- error: CompilerErrorDetailOptions;
760
- } | {
761
- kind: 'ReactMutation';
762
- error: CompilerErrorDetailOptions;
763
- } | {
764
- kind: 'ContextMutation';
765
- places: ReadonlySet<Place>;
766
- effect: Effect;
767
- loc: SourceLocation;
974
+ aliasingEffects: Array<AliasingEffect> | null;
768
975
  };
769
976
  type HIR = {
770
977
  entry: BlockId;
@@ -803,12 +1010,15 @@ type Case = {
803
1010
  test: Place | null;
804
1011
  block: BlockId;
805
1012
  };
1013
+ type ReturnVariant = 'Void' | 'Implicit' | 'Explicit';
806
1014
  type ReturnTerminal = {
807
1015
  kind: 'return';
1016
+ returnVariant: ReturnVariant;
808
1017
  loc: SourceLocation;
809
1018
  value: Place;
810
1019
  id: InstructionId;
811
1020
  fallthrough?: never;
1021
+ effects: Array<AliasingEffect> | null;
812
1022
  };
813
1023
  type GotoTerminal = {
814
1024
  kind: 'goto';
@@ -945,6 +1155,7 @@ type MaybeThrowTerminal = {
945
1155
  id: InstructionId;
946
1156
  loc: SourceLocation;
947
1157
  fallthrough?: never;
1158
+ effects: Array<AliasingEffect> | null;
948
1159
  };
949
1160
  type ReactiveScopeTerminal = {
950
1161
  kind: 'scope';
@@ -967,6 +1178,7 @@ type Instruction = {
967
1178
  lvalue: Place;
968
1179
  value: InstructionValue;
969
1180
  loc: SourceLocation;
1181
+ effects: Array<AliasingEffect> | null;
970
1182
  };
971
1183
  type LValue = {
972
1184
  place: Place;
@@ -1107,7 +1319,7 @@ type InstructionValue = LoadLocal | LoadContext | {
1107
1319
  } | StoreLocal | {
1108
1320
  kind: 'StoreContext';
1109
1321
  lvalue: {
1110
- kind: InstructionKind.Reassign;
1322
+ kind: InstructionKind.Reassign | InstructionKind.Const | InstructionKind.Let | InstructionKind.Function;
1111
1323
  place: Place;
1112
1324
  };
1113
1325
  value: Place;
@@ -1357,6 +1569,9 @@ type ValidIdentifierName = string & {
1357
1569
  declare enum ValueReason {
1358
1570
  Global = "global",
1359
1571
  JsxCaptured = "jsx-captured",
1572
+ HookCaptured = "hook-captured",
1573
+ HookReturn = "hook-return",
1574
+ Effect = "effect",
1360
1575
  KnownReturnSignature = "known-return-signature",
1361
1576
  Context = "context",
1362
1577
  State = "state",
@@ -1412,6 +1627,7 @@ type DependencyPathEntry = {
1412
1627
  type DependencyPath = Array<DependencyPathEntry>;
1413
1628
  type ReactiveScopeDependency = {
1414
1629
  identifier: Identifier;
1630
+ reactive: boolean;
1415
1631
  path: DependencyPath;
1416
1632
  };
1417
1633
  declare const opaqueBlockId: unique symbol;
@@ -1443,12 +1659,29 @@ declare function printHIR(ir: HIR, options?: Options | null): string;
1443
1659
 
1444
1660
  declare enum ErrorSeverity {
1445
1661
  InvalidJS = "InvalidJS",
1662
+ UnsupportedJS = "UnsupportedJS",
1446
1663
  InvalidReact = "InvalidReact",
1447
1664
  InvalidConfig = "InvalidConfig",
1448
1665
  CannotPreserveMemoization = "CannotPreserveMemoization",
1449
1666
  Todo = "Todo",
1450
1667
  Invariant = "Invariant"
1451
1668
  }
1669
+ type CompilerDiagnosticOptions = {
1670
+ category: ErrorCategory;
1671
+ severity: ErrorSeverity;
1672
+ reason: string;
1673
+ description: string;
1674
+ details: Array<CompilerDiagnosticDetail>;
1675
+ suggestions?: Array<CompilerSuggestion> | null | undefined;
1676
+ };
1677
+ type CompilerDiagnosticDetail = {
1678
+ kind: 'error';
1679
+ loc: SourceLocation | null;
1680
+ message: string;
1681
+ } | {
1682
+ kind: 'hint';
1683
+ message: string;
1684
+ };
1452
1685
  declare enum CompilerSuggestionOperation {
1453
1686
  InsertBefore = 0,
1454
1687
  InsertAfter = 1,
@@ -1466,12 +1699,30 @@ type CompilerSuggestion = {
1466
1699
  description: string;
1467
1700
  };
1468
1701
  type CompilerErrorDetailOptions = {
1702
+ category: ErrorCategory;
1703
+ severity: ErrorSeverity;
1469
1704
  reason: string;
1470
1705
  description?: string | null | undefined;
1471
- severity: ErrorSeverity;
1472
1706
  loc: SourceLocation | null;
1473
1707
  suggestions?: Array<CompilerSuggestion> | null | undefined;
1474
1708
  };
1709
+ type PrintErrorMessageOptions = {
1710
+ eslint: boolean;
1711
+ };
1712
+ declare class CompilerDiagnostic {
1713
+ options: CompilerDiagnosticOptions;
1714
+ constructor(options: CompilerDiagnosticOptions);
1715
+ static create(options: Omit<CompilerDiagnosticOptions, 'details'>): CompilerDiagnostic;
1716
+ get reason(): CompilerDiagnosticOptions['reason'];
1717
+ get description(): CompilerDiagnosticOptions['description'];
1718
+ get severity(): CompilerDiagnosticOptions['severity'];
1719
+ get suggestions(): CompilerDiagnosticOptions['suggestions'];
1720
+ get category(): ErrorCategory;
1721
+ withDetail(detail: CompilerDiagnosticDetail): CompilerDiagnostic;
1722
+ primaryLocation(): SourceLocation | null;
1723
+ printErrorMessage(source: string, options: PrintErrorMessageOptions): string;
1724
+ toString(): string;
1725
+ }
1475
1726
  declare class CompilerErrorDetail {
1476
1727
  options: CompilerErrorDetailOptions;
1477
1728
  constructor(options: CompilerErrorDetailOptions);
@@ -1480,27 +1731,69 @@ declare class CompilerErrorDetail {
1480
1731
  get severity(): CompilerErrorDetailOptions['severity'];
1481
1732
  get loc(): CompilerErrorDetailOptions['loc'];
1482
1733
  get suggestions(): CompilerErrorDetailOptions['suggestions'];
1483
- printErrorMessage(): string;
1734
+ get category(): ErrorCategory;
1735
+ primaryLocation(): SourceLocation | null;
1736
+ printErrorMessage(source: string, options: PrintErrorMessageOptions): string;
1484
1737
  toString(): string;
1485
1738
  }
1486
1739
  declare class CompilerError extends Error {
1487
- details: Array<CompilerErrorDetail>;
1488
- static invariant(condition: unknown, options: Omit<CompilerErrorDetailOptions, 'severity'>): asserts condition;
1489
- static throwTodo(options: Omit<CompilerErrorDetailOptions, 'severity'>): never;
1490
- static throwInvalidJS(options: Omit<CompilerErrorDetailOptions, 'severity'>): never;
1740
+ details: Array<CompilerErrorDetail | CompilerDiagnostic>;
1741
+ printedMessage: string | null;
1742
+ static invariant(condition: unknown, options: Omit<CompilerErrorDetailOptions, 'severity' | 'category'>): asserts condition;
1743
+ static throwDiagnostic(options: CompilerDiagnosticOptions): never;
1744
+ static throwTodo(options: Omit<CompilerErrorDetailOptions, 'severity' | 'category'>): never;
1745
+ static throwInvalidJS(options: Omit<CompilerErrorDetailOptions, 'severity' | 'category'>): never;
1491
1746
  static throwInvalidReact(options: Omit<CompilerErrorDetailOptions, 'severity'>): never;
1492
- static throwInvalidConfig(options: Omit<CompilerErrorDetailOptions, 'severity'>): never;
1747
+ static throwInvalidConfig(options: Omit<CompilerErrorDetailOptions, 'severity' | 'category'>): never;
1493
1748
  static throw(options: CompilerErrorDetailOptions): never;
1494
1749
  constructor(...args: Array<any>);
1495
1750
  get message(): string;
1496
1751
  set message(_message: string);
1497
1752
  toString(): string;
1753
+ withPrintedMessage(source: string, options: PrintErrorMessageOptions): CompilerError;
1754
+ printErrorMessage(source: string, options: PrintErrorMessageOptions): string;
1755
+ merge(other: CompilerError): void;
1756
+ pushDiagnostic(diagnostic: CompilerDiagnostic): void;
1498
1757
  push(options: CompilerErrorDetailOptions): CompilerErrorDetail;
1499
1758
  pushErrorDetail(detail: CompilerErrorDetail): CompilerErrorDetail;
1500
1759
  hasErrors(): boolean;
1501
1760
  asResult(): Result<void, CompilerError>;
1502
1761
  isCritical(): boolean;
1503
1762
  }
1763
+ declare enum ErrorCategory {
1764
+ Hooks = "Hooks",
1765
+ CapitalizedCalls = "CapitalizedCalls",
1766
+ StaticComponents = "StaticComponents",
1767
+ UseMemo = "UseMemo",
1768
+ Factories = "Factories",
1769
+ PreserveManualMemo = "PreserveManualMemo",
1770
+ Immutability = "Immutability",
1771
+ Globals = "Globals",
1772
+ Refs = "Refs",
1773
+ EffectDependencies = "EffectDependencies",
1774
+ EffectSetState = "EffectSetState",
1775
+ EffectDerivationsOfState = "EffectDerivationsOfState",
1776
+ ErrorBoundaries = "ErrorBoundaries",
1777
+ Purity = "Purity",
1778
+ RenderSetState = "RenderSetState",
1779
+ Invariant = "Invariant",
1780
+ Todo = "Todo",
1781
+ Syntax = "Syntax",
1782
+ UnsupportedSyntax = "UnsupportedSyntax",
1783
+ Config = "Config",
1784
+ Gating = "Gating",
1785
+ Suppression = "Suppression",
1786
+ AutomaticEffectDependencies = "AutomaticEffectDependencies",
1787
+ Fire = "Fire",
1788
+ FBT = "FBT"
1789
+ }
1790
+ type LintRule = {
1791
+ category: ErrorCategory;
1792
+ name: string;
1793
+ description: string;
1794
+ recommended: boolean;
1795
+ };
1796
+ declare const LintRules: Array<LintRule>;
1504
1797
 
1505
1798
  type CodegenFunction = {
1506
1799
  type: 'CodegenFunction';
@@ -1548,17 +1841,29 @@ declare function compileFn(func: NodePath<t.FunctionDeclaration | t.ArrowFunctio
1548
1841
 
1549
1842
  declare const PanicThresholdOptionsSchema: z.ZodEnum<["all_errors", "critical_errors", "none"]>;
1550
1843
  type PanicThresholdOptions = z.infer<typeof PanicThresholdOptionsSchema>;
1844
+ declare const DynamicGatingOptionsSchema: z.ZodObject<{
1845
+ source: z.ZodString;
1846
+ }, "strip", z.ZodTypeAny, {
1847
+ source: string;
1848
+ }, {
1849
+ source: string;
1850
+ }>;
1851
+ type DynamicGatingOptions = z.infer<typeof DynamicGatingOptionsSchema>;
1852
+ declare const CustomOptOutDirectiveSchema: z.ZodDefault<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
1853
+ type CustomOptOutDirective = z.infer<typeof CustomOptOutDirectiveSchema>;
1551
1854
  type PluginOptions = {
1552
1855
  environment: EnvironmentConfig;
1553
1856
  logger: Logger | null;
1554
1857
  gating: ExternalFunction | null;
1858
+ dynamicGating: DynamicGatingOptions | null;
1555
1859
  panicThreshold: PanicThresholdOptions;
1556
1860
  noEmit: boolean;
1557
1861
  compilationMode: CompilationMode;
1558
- eslintSuppressionRules?: Array<string> | null | undefined;
1862
+ eslintSuppressionRules: Array<string> | null | undefined;
1559
1863
  flowSuppressions: boolean;
1560
1864
  ignoreUseNoForget: boolean;
1561
- sources?: Array<string> | ((filename: string) => boolean) | null;
1865
+ customOptOutDirectives: CustomOptOutDirective;
1866
+ sources: Array<string> | ((filename: string) => boolean) | null;
1562
1867
  enableReanimatedCheck: boolean;
1563
1868
  target: CompilerReactTarget;
1564
1869
  };
@@ -1575,11 +1880,11 @@ declare const CompilerReactTargetSchema: z.ZodUnion<[z.ZodLiteral<"17">, z.ZodLi
1575
1880
  type CompilerReactTarget = z.infer<typeof CompilerReactTargetSchema>;
1576
1881
  declare const CompilationModeSchema: z.ZodEnum<["infer", "syntax", "annotation", "all"]>;
1577
1882
  type CompilationMode = z.infer<typeof CompilationModeSchema>;
1578
- type LoggerEvent = CompileSuccessEvent | CompileErrorEvent | CompileDiagnosticEvent | CompileSkipEvent | PipelineErrorEvent | TimingEvent;
1883
+ type LoggerEvent = CompileSuccessEvent | CompileErrorEvent | CompileDiagnosticEvent | CompileSkipEvent | PipelineErrorEvent | TimingEvent | AutoDepsDecorationsEvent | AutoDepsEligibleEvent;
1579
1884
  type CompileErrorEvent = {
1580
1885
  kind: 'CompileError';
1581
1886
  fnLoc: t.SourceLocation | null;
1582
- detail: CompilerErrorDetailOptions;
1887
+ detail: CompilerErrorDetail | CompilerDiagnostic;
1583
1888
  };
1584
1889
  type CompileDiagnosticEvent = {
1585
1890
  kind: 'CompileDiagnostic';
@@ -1611,28 +1916,22 @@ type TimingEvent = {
1611
1916
  kind: 'Timing';
1612
1917
  measurement: PerformanceMeasure;
1613
1918
  };
1919
+ type AutoDepsDecorationsEvent = {
1920
+ kind: 'AutoDepsDecorations';
1921
+ fnLoc: t.SourceLocation;
1922
+ decorations: Array<t.SourceLocation>;
1923
+ };
1924
+ type AutoDepsEligibleEvent = {
1925
+ kind: 'AutoDepsEligible';
1926
+ fnLoc: t.SourceLocation;
1927
+ depArrayLoc: t.SourceLocation;
1928
+ };
1614
1929
  type Logger = {
1615
1930
  logEvent: (filename: string | null, event: LoggerEvent) => void;
1616
1931
  debugLogIRs?: (value: CompilerPipelineValue) => void;
1617
1932
  };
1618
1933
  declare function parsePluginOptions(obj: unknown): PluginOptions;
1619
1934
 
1620
- declare class ProgramContext {
1621
- scope: Scope;
1622
- reactRuntimeModule: string;
1623
- hookPattern: string | null;
1624
- knownReferencedNames: Set<string>;
1625
- imports: Map<string, Map<string, NonLocalImportSpecifier>>;
1626
- constructor(program: NodePath$1<t.Program>, reactRuntimeModule: CompilerReactTarget, hookPattern: string | null);
1627
- isHookName(name: string): boolean;
1628
- hasReference(name: string): boolean;
1629
- newUid(name: string): string;
1630
- addMemoCacheImport(): NonLocalImportSpecifier;
1631
- addImportSpecifier({ source: module, importSpecifierName: specifier }: ExternalFunction, nameHint?: string): NonLocalImportSpecifier;
1632
- addNewReference(name: string): void;
1633
- assertGlobalBinding(name: string, localScope?: Scope): Result<void, CompilerError>;
1634
- }
1635
-
1636
1935
  type CompilerPass = {
1637
1936
  opts: PluginOptions;
1638
1937
  filename: string | null;
@@ -1641,24 +1940,72 @@ type CompilerPass = {
1641
1940
  };
1642
1941
  declare const OPT_IN_DIRECTIVES: Set<string>;
1643
1942
  declare const OPT_OUT_DIRECTIVES: Set<string>;
1644
- declare function findDirectiveEnablingMemoization(directives: Array<t.Directive>): Array<t.Directive>;
1645
- declare function findDirectiveDisablingMemoization(directives: Array<t.Directive>): Array<t.Directive>;
1943
+ declare function tryFindDirectiveEnablingMemoization(directives: Array<t.Directive>, opts: PluginOptions): Result<t.Directive | null, CompilerError>;
1944
+ declare function findDirectiveDisablingMemoization(directives: Array<t.Directive>, { customOptOutDirectives }: PluginOptions): t.Directive | null;
1646
1945
  type BabelFn = NodePath$1<t.FunctionDeclaration> | NodePath$1<t.FunctionExpression> | NodePath$1<t.ArrowFunctionExpression>;
1647
- type CompileProgramResult = {
1946
+ type CompileProgramMetadata = {
1648
1947
  retryErrors: Array<{
1649
1948
  fn: BabelFn;
1650
1949
  error: CompilerError;
1651
1950
  }>;
1652
1951
  inferredEffectLocations: Set<t.SourceLocation>;
1653
1952
  };
1654
- declare function compileProgram(program: NodePath$1<t.Program>, pass: CompilerPass): CompileProgramResult | null;
1953
+ declare function compileProgram(program: NodePath$1<t.Program>, pass: CompilerPass): CompileProgramMetadata | null;
1954
+
1955
+ type SuppressionRange = {
1956
+ disableComment: t.Comment;
1957
+ enableComment: t.Comment | null;
1958
+ source: SuppressionSource;
1959
+ };
1960
+ type SuppressionSource = 'Eslint' | 'Flow';
1961
+
1962
+ type ProgramContextOptions = {
1963
+ program: NodePath$1<t.Program>;
1964
+ suppressions: Array<SuppressionRange>;
1965
+ opts: PluginOptions;
1966
+ filename: string | null;
1967
+ code: string | null;
1968
+ hasModuleScopeOptOut: boolean;
1969
+ };
1970
+ declare class ProgramContext {
1971
+ scope: Scope;
1972
+ opts: PluginOptions;
1973
+ filename: string | null;
1974
+ code: string | null;
1975
+ reactRuntimeModule: string;
1976
+ suppressions: Array<SuppressionRange>;
1977
+ hasModuleScopeOptOut: boolean;
1978
+ alreadyCompiled: WeakSet<object> | Set<object>;
1979
+ knownReferencedNames: Set<string>;
1980
+ imports: Map<string, Map<string, NonLocalImportSpecifier>>;
1981
+ retryErrors: Array<{
1982
+ fn: BabelFn;
1983
+ error: CompilerError;
1984
+ }>;
1985
+ inferredEffectLocations: Set<t.SourceLocation>;
1986
+ constructor({ program, suppressions, opts, filename, code, hasModuleScopeOptOut, }: ProgramContextOptions);
1987
+ isHookName(name: string): boolean;
1988
+ hasReference(name: string): boolean;
1989
+ newUid(name: string): string;
1990
+ addMemoCacheImport(): NonLocalImportSpecifier;
1991
+ addImportSpecifier({ source: module, importSpecifierName: specifier }: ExternalFunction, nameHint?: string): NonLocalImportSpecifier;
1992
+ addNewReference(name: string): void;
1993
+ assertGlobalBinding(name: string, localScope?: Scope): Result<void, CompilerError>;
1994
+ logEvent(event: LoggerEvent): void;
1995
+ }
1655
1996
 
1656
1997
  declare function runBabelPluginReactCompiler(text: string, file: string, language: 'flow' | 'typescript', options: Partial<PluginOptions> | null, includeAst?: boolean): BabelCore.BabelFileResult;
1657
1998
 
1999
+ declare function parseConfigPragmaForTests(pragma: string, defaults: {
2000
+ compilationMode: CompilationMode;
2001
+ environment?: PartialEnvironmentConfig;
2002
+ }): PluginOptions;
2003
+ declare function parseConfigPragmaAsString(pragma: string): string;
2004
+
1658
2005
  declare function BabelPluginReactCompiler(_babel: typeof BabelCore): BabelCore.PluginObj;
1659
2006
 
1660
2007
  declare global {
1661
2008
  let __DEV__: boolean | null | undefined;
1662
2009
  }
1663
2010
 
1664
- export { CompilerError, CompilerErrorDetail, type CompilerErrorDetailOptions, type CompilerPipelineValue, CompilerSuggestionOperation, Effect, type EnvironmentConfig, ErrorSeverity, type ExternalFunction, type Hook, type Logger, type LoggerEvent, OPT_IN_DIRECTIVES, OPT_OUT_DIRECTIVES, type PluginOptions, ProgramContext, type SourceLocation, ValueKind, compileFn as compile, compileProgram, BabelPluginReactCompiler as default, findDirectiveDisablingMemoization, findDirectiveEnablingMemoization, parseConfigPragmaForTests, parsePluginOptions, printFunctionWithOutlined, printHIR, printReactiveFunction, printReactiveFunctionWithOutlined, runBabelPluginReactCompiler, validateEnvironmentConfig };
2011
+ export { CompilerDiagnostic, type CompilerDiagnosticDetail, type CompilerDiagnosticOptions, CompilerError, CompilerErrorDetail, type CompilerErrorDetailOptions, type CompilerPipelineValue, CompilerSuggestionOperation, Effect, type EnvironmentConfig, ErrorSeverity, type ExternalFunction, type Hook, type LintRule, LintRules, type Logger, type LoggerEvent, OPT_IN_DIRECTIVES, OPT_OUT_DIRECTIVES, type PluginOptions, ProgramContext, type SourceLocation, ValueKind, ValueReason, compileFn as compile, compileProgram, BabelPluginReactCompiler as default, findDirectiveDisablingMemoization, tryFindDirectiveEnablingMemoization as findDirectiveEnablingMemoization, parseConfigPragmaAsString, parseConfigPragmaForTests, parsePluginOptions, printFunctionWithOutlined, printHIR, printReactiveFunction, printReactiveFunctionWithOutlined, runBabelPluginReactCompiler, validateEnvironmentConfig };