babel-plugin-react-compiler 19.1.0-rc.2 → 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 +345 -38
  2. package/dist/index.js +7150 -7621
  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,7 +440,8 @@ 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>;
@@ -360,6 +566,8 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
360
566
  source: string;
361
567
  importSpecifierName: string;
362
568
  }>>>;
569
+ validateNoVoidUseMemo: z.ZodDefault<z.ZodBoolean>;
570
+ validateNoDynamicallyCreatedComponentsOrHooks: z.ZodDefault<z.ZodBoolean>;
363
571
  }, "strip", z.ZodTypeAny, {
364
572
  customHooks: Map<string, {
365
573
  noAlias: boolean;
@@ -380,6 +588,7 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
380
588
  enablePreserveExistingManualUseMemo: boolean;
381
589
  enableForest: boolean;
382
590
  enableUseTypeAnnotations: boolean;
591
+ flowTypeProvider: ((args_0: string, ...args_1: unknown[]) => unknown) | null;
383
592
  enableOptionalDependencies: boolean;
384
593
  enableFire: boolean;
385
594
  inferEffectDependencies: {
@@ -387,7 +596,7 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
387
596
  source: string;
388
597
  importSpecifierName: string;
389
598
  };
390
- numRequiredArgs: number;
599
+ autodepsIndex: number;
391
600
  }[] | null;
392
601
  inlineJsxTransform: {
393
602
  elementSymbol: "react.element" | "react.transitional.element";
@@ -396,7 +605,8 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
396
605
  validateHooksUsage: boolean;
397
606
  validateRefAccessDuringRender: boolean;
398
607
  validateNoSetStateInRender: boolean;
399
- validateNoSetStateInPassiveEffects: boolean;
608
+ validateNoSetStateInEffects: boolean;
609
+ validateNoDerivedComputationsInEffects: boolean;
400
610
  validateNoJSXInTryStatements: boolean;
401
611
  validateStaticComponents: boolean;
402
612
  validateMemoizedEffectDependencies: boolean;
@@ -445,6 +655,8 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
445
655
  source: string;
446
656
  importSpecifierName: string;
447
657
  } | null;
658
+ validateNoVoidUseMemo: boolean;
659
+ validateNoDynamicallyCreatedComponentsOrHooks: boolean;
448
660
  }, {
449
661
  customHooks?: Map<string, {
450
662
  effectKind: Effect;
@@ -465,6 +677,7 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
465
677
  enablePreserveExistingManualUseMemo?: boolean | undefined;
466
678
  enableForest?: boolean | undefined;
467
679
  enableUseTypeAnnotations?: boolean | undefined;
680
+ flowTypeProvider?: ((args_0: string, ...args_1: unknown[]) => unknown) | null | undefined;
468
681
  enableOptionalDependencies?: boolean | undefined;
469
682
  enableFire?: boolean | undefined;
470
683
  inferEffectDependencies?: {
@@ -472,7 +685,7 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
472
685
  source: string;
473
686
  importSpecifierName: string;
474
687
  };
475
- numRequiredArgs: number;
688
+ autodepsIndex: number;
476
689
  }[] | null | undefined;
477
690
  inlineJsxTransform?: {
478
691
  elementSymbol: "react.element" | "react.transitional.element";
@@ -481,7 +694,8 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
481
694
  validateHooksUsage?: boolean | undefined;
482
695
  validateRefAccessDuringRender?: boolean | undefined;
483
696
  validateNoSetStateInRender?: boolean | undefined;
484
- validateNoSetStateInPassiveEffects?: boolean | undefined;
697
+ validateNoSetStateInEffects?: boolean | undefined;
698
+ validateNoDerivedComputationsInEffects?: boolean | undefined;
485
699
  validateNoJSXInTryStatements?: boolean | undefined;
486
700
  validateStaticComponents?: boolean | undefined;
487
701
  validateMemoizedEffectDependencies?: boolean | undefined;
@@ -530,6 +744,8 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
530
744
  source: string;
531
745
  importSpecifierName: string;
532
746
  } | null | undefined;
747
+ validateNoVoidUseMemo?: boolean | undefined;
748
+ validateNoDynamicallyCreatedComponentsOrHooks?: boolean | undefined;
533
749
  }>;
534
750
  type EnvironmentConfig = z.infer<typeof EnvironmentConfigSchema>;
535
751
  type PartialEnvironmentConfig = Partial<EnvironmentConfig>;
@@ -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;
@@ -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,16 +1841,28 @@ 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
1862
  eslintSuppressionRules: Array<string> | null | undefined;
1559
1863
  flowSuppressions: boolean;
1560
1864
  ignoreUseNoForget: boolean;
1865
+ customOptOutDirectives: CustomOptOutDirective;
1561
1866
  sources: Array<string> | ((filename: string) => boolean) | null;
1562
1867
  enableReanimatedCheck: boolean;
1563
1868
  target: CompilerReactTarget;
@@ -1579,7 +1884,7 @@ type LoggerEvent = CompileSuccessEvent | CompileErrorEvent | CompileDiagnosticEv
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';
@@ -1635,8 +1940,8 @@ type CompilerPass = {
1635
1940
  };
1636
1941
  declare const OPT_IN_DIRECTIVES: Set<string>;
1637
1942
  declare const OPT_OUT_DIRECTIVES: Set<string>;
1638
- declare function findDirectiveEnablingMemoization(directives: Array<t.Directive>): t.Directive | null;
1639
- declare function findDirectiveDisablingMemoization(directives: Array<t.Directive>): t.Directive | null;
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;
1640
1945
  type BabelFn = NodePath$1<t.FunctionDeclaration> | NodePath$1<t.FunctionExpression> | NodePath$1<t.ArrowFunctionExpression>;
1641
1946
  type CompileProgramMetadata = {
1642
1947
  retryErrors: Array<{
@@ -1693,7 +1998,9 @@ declare function runBabelPluginReactCompiler(text: string, file: string, languag
1693
1998
 
1694
1999
  declare function parseConfigPragmaForTests(pragma: string, defaults: {
1695
2000
  compilationMode: CompilationMode;
2001
+ environment?: PartialEnvironmentConfig;
1696
2002
  }): PluginOptions;
2003
+ declare function parseConfigPragmaAsString(pragma: string): string;
1697
2004
 
1698
2005
  declare function BabelPluginReactCompiler(_babel: typeof BabelCore): BabelCore.PluginObj;
1699
2006
 
@@ -1701,4 +2008,4 @@ declare global {
1701
2008
  let __DEV__: boolean | null | undefined;
1702
2009
  }
1703
2010
 
1704
- 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 };