babel-plugin-react-compiler 19.0.0-beta-bafa41b-20250307 → 19.0.0-beta-aeaed83-20250323

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 +100 -15
  2. package/dist/index.js +3674 -1784
  3. package/package.json +2 -2
package/dist/index.d.ts CHANGED
@@ -4,6 +4,65 @@ import * as t from '@babel/types';
4
4
  import { z } from 'zod';
5
5
  import { Scope, NodePath } from '@babel/traverse';
6
6
 
7
+ interface Result<T, E> {
8
+ map<U>(fn: (val: T) => U): Result<U, E>;
9
+ mapErr<F>(fn: (val: E) => F): Result<T, F>;
10
+ mapOr<U>(fallback: U, fn: (val: T) => U): U;
11
+ mapOrElse<U>(fallback: () => U, fn: (val: T) => U): U;
12
+ andThen<U>(fn: (val: T) => Result<U, E>): Result<U, E>;
13
+ and<U>(res: Result<U, E>): Result<U, E>;
14
+ or(res: Result<T, E>): Result<T, E>;
15
+ orElse<F>(fn: (val: E) => Result<T, F>): Result<T, F>;
16
+ isOk(): this is OkImpl<T>;
17
+ isErr(): this is ErrImpl<E>;
18
+ expect(msg: string): T;
19
+ expectErr(msg: string): E;
20
+ unwrap(): T;
21
+ unwrapOr(fallback: T): T;
22
+ unwrapOrElse(fallback: (val: E) => T): T;
23
+ unwrapErr(): E;
24
+ }
25
+ declare class OkImpl<T> implements Result<T, never> {
26
+ private val;
27
+ constructor(val: T);
28
+ map<U>(fn: (val: T) => U): Result<U, never>;
29
+ mapErr<F>(_fn: (val: never) => F): Result<T, F>;
30
+ mapOr<U>(_fallback: U, fn: (val: T) => U): U;
31
+ mapOrElse<U>(_fallback: () => U, fn: (val: T) => U): U;
32
+ andThen<U>(fn: (val: T) => Result<U, never>): Result<U, never>;
33
+ and<U>(res: Result<U, never>): Result<U, never>;
34
+ or(_res: Result<T, never>): Result<T, never>;
35
+ orElse<F>(_fn: (val: never) => Result<T, F>): Result<T, F>;
36
+ isOk(): this is OkImpl<T>;
37
+ isErr(): this is ErrImpl<never>;
38
+ expect(_msg: string): T;
39
+ expectErr(msg: string): never;
40
+ unwrap(): T;
41
+ unwrapOr(_fallback: T): T;
42
+ unwrapOrElse(_fallback: (val: never) => T): T;
43
+ unwrapErr(): never;
44
+ }
45
+ declare class ErrImpl<E> implements Result<never, E> {
46
+ private val;
47
+ constructor(val: E);
48
+ map<U>(_fn: (val: never) => U): Result<U, E>;
49
+ mapErr<F>(fn: (val: E) => F): Result<never, F>;
50
+ mapOr<U>(fallback: U, _fn: (val: never) => U): U;
51
+ mapOrElse<U>(fallback: () => U, _fn: (val: never) => U): U;
52
+ andThen<U>(_fn: (val: never) => Result<U, E>): Result<U, E>;
53
+ and<U>(_res: Result<U, E>): Result<U, E>;
54
+ or(res: Result<never, E>): Result<never, E>;
55
+ orElse<F>(fn: (val: E) => ErrImpl<F>): Result<never, F>;
56
+ isOk(): this is OkImpl<never>;
57
+ isErr(): this is ErrImpl<E>;
58
+ expect(msg: string): never;
59
+ expectErr(_msg: string): E;
60
+ unwrap(): never;
61
+ unwrapOr<T>(fallback: T): T;
62
+ unwrapOrElse<T>(fallback: (val: E) => T): T;
63
+ unwrapErr(): E;
64
+ }
65
+
7
66
  type BuiltInType = PrimitiveType | FunctionType | ObjectType;
8
67
  type Type = BuiltInType | PhiType | TypeVar | PolyType | PropType | ObjectMethod$1;
9
68
  type PrimitiveType = {
@@ -13,6 +72,7 @@ type FunctionType = {
13
72
  kind: 'Function';
14
73
  shapeId: string | null;
15
74
  return: Type;
75
+ isConstructor: boolean;
16
76
  };
17
77
  type ObjectType = {
18
78
  kind: 'Object';
@@ -33,7 +93,13 @@ type PropType = {
33
93
  kind: 'Property';
34
94
  objectType: Type;
35
95
  objectName: string;
36
- propertyName: PropertyLiteral;
96
+ propertyName: {
97
+ kind: 'literal';
98
+ value: PropertyLiteral;
99
+ } | {
100
+ kind: 'computed';
101
+ value: Type;
102
+ };
37
103
  };
38
104
  type ObjectMethod$1 = {
39
105
  kind: 'ObjectMethod';
@@ -71,6 +137,7 @@ declare const ExternalFunctionSchema: z.ZodObject<{
71
137
  importSpecifierName: string;
72
138
  }>;
73
139
  type ExternalFunction = z.infer<typeof ExternalFunctionSchema>;
140
+ type CompilerMode = 'all_features' | 'no_inferred_memo';
74
141
  declare const HookSchema: z.ZodObject<{
75
142
  effectKind: z.ZodNativeEnum<typeof Effect>;
76
143
  valueKind: z.ZodNativeEnum<typeof ValueKind>;
@@ -170,6 +237,7 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
170
237
  validateNoSetStateInRender: z.ZodDefault<z.ZodBoolean>;
171
238
  validateNoSetStateInPassiveEffects: z.ZodDefault<z.ZodBoolean>;
172
239
  validateNoJSXInTryStatements: z.ZodDefault<z.ZodBoolean>;
240
+ validateStaticComponents: z.ZodDefault<z.ZodBoolean>;
173
241
  validateMemoizedEffectDependencies: z.ZodDefault<z.ZodBoolean>;
174
242
  validateNoCapitalizedCalls: z.ZodDefault<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
175
243
  validateBlocklistedImports: z.ZodDefault<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
@@ -268,7 +336,6 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
268
336
  throwUnknownException__testonly: z.ZodDefault<z.ZodBoolean>;
269
337
  enableTreatFunctionDepsAsConditional: z.ZodDefault<z.ZodBoolean>;
270
338
  disableMemoizationForDebugging: z.ZodDefault<z.ZodBoolean>;
271
- enableMinimalTransformsForRetry: z.ZodDefault<z.ZodBoolean>;
272
339
  enableChangeDetectionForDebugging: z.ZodDefault<z.ZodNullable<z.ZodObject<{
273
340
  source: z.ZodString;
274
341
  importSpecifierName: z.ZodString;
@@ -330,6 +397,7 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
330
397
  validateNoSetStateInRender: boolean;
331
398
  validateNoSetStateInPassiveEffects: boolean;
332
399
  validateNoJSXInTryStatements: boolean;
400
+ validateStaticComponents: boolean;
333
401
  validateMemoizedEffectDependencies: boolean;
334
402
  validateNoCapitalizedCalls: string[] | null;
335
403
  validateBlocklistedImports: string[] | null;
@@ -364,7 +432,6 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
364
432
  throwUnknownException__testonly: boolean;
365
433
  enableTreatFunctionDepsAsConditional: boolean;
366
434
  disableMemoizationForDebugging: boolean;
367
- enableMinimalTransformsForRetry: boolean;
368
435
  enableChangeDetectionForDebugging: {
369
436
  source: string;
370
437
  importSpecifierName: string;
@@ -414,6 +481,7 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
414
481
  validateNoSetStateInRender?: boolean | undefined;
415
482
  validateNoSetStateInPassiveEffects?: boolean | undefined;
416
483
  validateNoJSXInTryStatements?: boolean | undefined;
484
+ validateStaticComponents?: boolean | undefined;
417
485
  validateMemoizedEffectDependencies?: boolean | undefined;
418
486
  validateNoCapitalizedCalls?: string[] | null | undefined;
419
487
  validateBlocklistedImports?: string[] | null | undefined;
@@ -448,7 +516,6 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
448
516
  throwUnknownException__testonly?: boolean | undefined;
449
517
  enableTreatFunctionDepsAsConditional?: boolean | undefined;
450
518
  disableMemoizationForDebugging?: boolean | undefined;
451
- enableMinimalTransformsForRetry?: boolean | undefined;
452
519
  enableChangeDetectionForDebugging?: {
453
520
  source: string;
454
521
  importSpecifierName: string;
@@ -474,13 +541,16 @@ declare class Environment {
474
541
  code: string | null;
475
542
  config: EnvironmentConfig;
476
543
  fnType: ReactFunctionType;
544
+ compilerMode: CompilerMode;
477
545
  useMemoCacheIdentifier: string;
478
546
  hasLoweredContextAccess: boolean;
479
547
  hasFireRewrite: boolean;
480
- constructor(scope: Scope, fnType: ReactFunctionType, config: EnvironmentConfig, contextIdentifiers: Set<t.Identifier>, logger: Logger | null, filename: string | null, code: string | null, useMemoCacheIdentifier: string);
548
+ constructor(scope: Scope, fnType: ReactFunctionType, compilerMode: CompilerMode, config: EnvironmentConfig, contextIdentifiers: Set<t.Identifier>, logger: Logger | null, filename: string | null, code: string | null, useMemoCacheIdentifier: string);
549
+ get isInferredMemoEnabled(): boolean;
481
550
  get nextIdentifierId(): IdentifierId;
482
551
  get nextBlockId(): BlockId;
483
552
  get nextScopeId(): ScopeId;
553
+ logErrors(errors: Result<void, CompilerError>): void;
484
554
  isContextIdentifier(node: t.Identifier): boolean;
485
555
  isHoistedIdentifier(node: t.Identifier): boolean;
486
556
  generateGloballyUniqueIdentifierName(name: string | null): ValidatedIdentifier;
@@ -490,7 +560,9 @@ declare class Environment {
490
560
  type: ReactFunctionType | null;
491
561
  }>;
492
562
  getGlobalDeclaration(binding: NonLocalBinding, loc: SourceLocation): Global | null;
493
- getPropertyType(receiver: Type, property: string): BuiltInType | PolyType | null;
563
+ static knownReactModules: ReadonlyArray<string>;
564
+ getFallthroughPropertyType(receiver: Type, _property: Type): BuiltInType | PolyType | null;
565
+ getPropertyType(receiver: Type, property: string | number): BuiltInType | PolyType | null;
494
566
  getFunctionSignature(type: FunctionType): FunctionSignature | null;
495
567
  addHoistedIdentifier(node: t.Identifier): void;
496
568
  }
@@ -932,6 +1004,9 @@ type ObjectPropertyKey = {
932
1004
  } | {
933
1005
  kind: 'computed';
934
1006
  name: Place;
1007
+ } | {
1008
+ kind: 'number';
1009
+ name: number;
935
1010
  };
936
1011
  type ObjectProperty = {
937
1012
  kind: 'ObjectProperty';
@@ -999,6 +1074,12 @@ type CallExpression = {
999
1074
  loc: SourceLocation;
1000
1075
  typeArguments?: Array<t.FlowType>;
1001
1076
  };
1077
+ type NewExpression = {
1078
+ kind: 'NewExpression';
1079
+ callee: Place;
1080
+ args: Array<Place | SpreadPattern>;
1081
+ loc: SourceLocation;
1082
+ };
1002
1083
  type LoadLocal = {
1003
1084
  kind: 'LoadLocal';
1004
1085
  place: Place;
@@ -1039,12 +1120,7 @@ type InstructionValue = LoadLocal | LoadContext | {
1039
1120
  left: Place;
1040
1121
  right: Place;
1041
1122
  loc: SourceLocation;
1042
- } | {
1043
- kind: 'NewExpression';
1044
- callee: Place;
1045
- args: Array<Place | SpreadPattern>;
1046
- loc: SourceLocation;
1047
- } | CallExpression | MethodCall | {
1123
+ } | NewExpression | CallExpression | MethodCall | {
1048
1124
  kind: 'UnaryExpression';
1049
1125
  operator: Exclude<t.UnaryExpression['operator'], 'throw' | 'delete'>;
1050
1126
  value: Place;
@@ -1293,6 +1369,7 @@ declare enum Effect {
1293
1369
  Freeze = "freeze",
1294
1370
  Read = "read",
1295
1371
  Capture = "capture",
1372
+ ConditionallyMutateIterator = "mutate-iterator?",
1296
1373
  ConditionallyMutate = "mutate?",
1297
1374
  Mutate = "mutate",
1298
1375
  Store = "store"
@@ -1412,6 +1489,7 @@ declare class CompilerError extends Error {
1412
1489
  push(options: CompilerErrorDetailOptions): CompilerErrorDetail;
1413
1490
  pushErrorDetail(detail: CompilerErrorDetail): CompilerErrorDetail;
1414
1491
  hasErrors(): boolean;
1492
+ asResult(): Result<void, CompilerError>;
1415
1493
  isCritical(): boolean;
1416
1494
  }
1417
1495
 
@@ -1455,7 +1533,7 @@ type CompilerPipelineValue = {
1455
1533
  name: string;
1456
1534
  value: string;
1457
1535
  };
1458
- declare function compileFn(func: NodePath<t.FunctionDeclaration | t.ArrowFunctionExpression | t.FunctionExpression>, config: EnvironmentConfig, fnType: ReactFunctionType, useMemoCacheIdentifier: string, logger: Logger | null, filename: string | null, code: string | null): CodegenFunction;
1536
+ declare function compileFn(func: NodePath<t.FunctionDeclaration | t.ArrowFunctionExpression | t.FunctionExpression>, config: EnvironmentConfig, fnType: ReactFunctionType, mode: CompilerMode, useMemoCacheIdentifier: string, logger: Logger | null, filename: string | null, code: string | null): CodegenFunction;
1459
1537
 
1460
1538
  declare const PanicThresholdOptionsSchema: z.ZodEnum<["all_errors", "critical_errors", "none"]>;
1461
1539
  type PanicThresholdOptions = z.infer<typeof PanicThresholdOptionsSchema>;
@@ -1538,7 +1616,14 @@ declare const OPT_IN_DIRECTIVES: Set<string>;
1538
1616
  declare const OPT_OUT_DIRECTIVES: Set<string>;
1539
1617
  declare function findDirectiveEnablingMemoization(directives: Array<t.Directive>): Array<t.Directive>;
1540
1618
  declare function findDirectiveDisablingMemoization(directives: Array<t.Directive>): Array<t.Directive>;
1541
- declare function compileProgram(program: NodePath$1<t.Program>, pass: CompilerPass): void;
1619
+ type BabelFn = NodePath$1<t.FunctionDeclaration> | NodePath$1<t.FunctionExpression> | NodePath$1<t.ArrowFunctionExpression>;
1620
+ type CompileProgramResult = {
1621
+ retryErrors: Array<{
1622
+ fn: BabelFn;
1623
+ error: CompilerError;
1624
+ }>;
1625
+ };
1626
+ declare function compileProgram(program: NodePath$1<t.Program>, pass: CompilerPass): CompileProgramResult | null;
1542
1627
 
1543
1628
  declare function runBabelPluginReactCompiler(text: string, file: string, language: 'flow' | 'typescript', options: Partial<PluginOptions> | null, includeAst?: boolean): BabelCore.BabelFileResult;
1544
1629
 
@@ -1548,4 +1633,4 @@ declare global {
1548
1633
  let __DEV__: boolean | null | undefined;
1549
1634
  }
1550
1635
 
1551
- export { CompilerError, CompilerErrorDetail, type CompilerErrorDetailOptions, type CompilerPipelineValue, CompilerSuggestionOperation, Effect, type EnvironmentConfig, ErrorSeverity, type ExternalFunction, type Hook, OPT_IN_DIRECTIVES, OPT_OUT_DIRECTIVES, type PluginOptions, type SourceLocation, ValueKind, compileFn as compile, compileProgram, BabelPluginReactCompiler as default, findDirectiveDisablingMemoization, findDirectiveEnablingMemoization, parseConfigPragmaForTests, parsePluginOptions, printHIR, printReactiveFunction, runBabelPluginReactCompiler, validateEnvironmentConfig };
1636
+ 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, type SourceLocation, ValueKind, compileFn as compile, compileProgram, BabelPluginReactCompiler as default, findDirectiveDisablingMemoization, findDirectiveEnablingMemoization, parseConfigPragmaForTests, parsePluginOptions, printHIR, printReactiveFunction, runBabelPluginReactCompiler, validateEnvironmentConfig };