babel-plugin-react-compiler 0.0.0-experimental-afa1d5a-20250319 → 0.0.0-experimental-3cea1f4-20250324

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 +103 -18
  2. package/dist/index.js +1625 -1047
  3. package/package.json +1 -1
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';
@@ -177,6 +237,7 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
177
237
  validateNoSetStateInRender: z.ZodDefault<z.ZodBoolean>;
178
238
  validateNoSetStateInPassiveEffects: z.ZodDefault<z.ZodBoolean>;
179
239
  validateNoJSXInTryStatements: z.ZodDefault<z.ZodBoolean>;
240
+ validateStaticComponents: z.ZodDefault<z.ZodBoolean>;
180
241
  validateMemoizedEffectDependencies: z.ZodDefault<z.ZodBoolean>;
181
242
  validateNoCapitalizedCalls: z.ZodDefault<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
182
243
  validateBlocklistedImports: z.ZodDefault<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
@@ -336,6 +397,7 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
336
397
  validateNoSetStateInRender: boolean;
337
398
  validateNoSetStateInPassiveEffects: boolean;
338
399
  validateNoJSXInTryStatements: boolean;
400
+ validateStaticComponents: boolean;
339
401
  validateMemoizedEffectDependencies: boolean;
340
402
  validateNoCapitalizedCalls: string[] | null;
341
403
  validateBlocklistedImports: string[] | null;
@@ -419,6 +481,7 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
419
481
  validateNoSetStateInRender?: boolean | undefined;
420
482
  validateNoSetStateInPassiveEffects?: boolean | undefined;
421
483
  validateNoJSXInTryStatements?: boolean | undefined;
484
+ validateStaticComponents?: boolean | undefined;
422
485
  validateMemoizedEffectDependencies?: boolean | undefined;
423
486
  validateNoCapitalizedCalls?: string[] | null | undefined;
424
487
  validateBlocklistedImports?: string[] | null | undefined;
@@ -479,14 +542,16 @@ declare class Environment {
479
542
  config: EnvironmentConfig;
480
543
  fnType: ReactFunctionType;
481
544
  compilerMode: CompilerMode;
482
- useMemoCacheIdentifier: string;
483
- hasLoweredContextAccess: boolean;
545
+ programContext: ProgramContext;
484
546
  hasFireRewrite: boolean;
485
- constructor(scope: Scope, fnType: ReactFunctionType, compilerMode: CompilerMode, config: EnvironmentConfig, contextIdentifiers: Set<t.Identifier>, logger: Logger | null, filename: string | null, code: string | null, useMemoCacheIdentifier: string);
547
+ hasInferredEffect: boolean;
548
+ constructor(scope: Scope, fnType: ReactFunctionType, compilerMode: CompilerMode, config: EnvironmentConfig, contextIdentifiers: Set<t.Identifier>, logger: Logger | null, filename: string | null, code: string | null, programContext: ProgramContext);
486
549
  get isInferredMemoEnabled(): boolean;
487
550
  get nextIdentifierId(): IdentifierId;
488
551
  get nextBlockId(): BlockId;
489
552
  get nextScopeId(): ScopeId;
553
+ get scope(): Scope;
554
+ logErrors(errors: Result<void, CompilerError>): void;
490
555
  isContextIdentifier(node: t.Identifier): boolean;
491
556
  isHoistedIdentifier(node: t.Identifier): boolean;
492
557
  generateGloballyUniqueIdentifierName(name: string | null): ValidatedIdentifier;
@@ -1010,6 +1075,12 @@ type CallExpression = {
1010
1075
  loc: SourceLocation;
1011
1076
  typeArguments?: Array<t.FlowType>;
1012
1077
  };
1078
+ type NewExpression = {
1079
+ kind: 'NewExpression';
1080
+ callee: Place;
1081
+ args: Array<Place | SpreadPattern>;
1082
+ loc: SourceLocation;
1083
+ };
1013
1084
  type LoadLocal = {
1014
1085
  kind: 'LoadLocal';
1015
1086
  place: Place;
@@ -1050,12 +1121,7 @@ type InstructionValue = LoadLocal | LoadContext | {
1050
1121
  left: Place;
1051
1122
  right: Place;
1052
1123
  loc: SourceLocation;
1053
- } | {
1054
- kind: 'NewExpression';
1055
- callee: Place;
1056
- args: Array<Place | SpreadPattern>;
1057
- loc: SourceLocation;
1058
- } | CallExpression | MethodCall | {
1124
+ } | NewExpression | CallExpression | MethodCall | {
1059
1125
  kind: 'UnaryExpression';
1060
1126
  operator: Exclude<t.UnaryExpression['operator'], 'throw' | 'delete'>;
1061
1127
  value: Place;
@@ -1239,6 +1305,12 @@ type MutableRange = {
1239
1305
  start: InstructionId;
1240
1306
  end: InstructionId;
1241
1307
  };
1308
+ type NonLocalImportSpecifier = {
1309
+ kind: 'ImportSpecifier';
1310
+ name: string;
1311
+ module: string;
1312
+ imported: string;
1313
+ };
1242
1314
  type NonLocalBinding = {
1243
1315
  kind: 'ImportDefault';
1244
1316
  name: string;
@@ -1247,12 +1319,7 @@ type NonLocalBinding = {
1247
1319
  kind: 'ImportNamespace';
1248
1320
  name: string;
1249
1321
  module: string;
1250
- } | {
1251
- kind: 'ImportSpecifier';
1252
- name: string;
1253
- module: string;
1254
- imported: string;
1255
- } | {
1322
+ } | NonLocalImportSpecifier | {
1256
1323
  kind: 'ModuleLocal';
1257
1324
  name: string;
1258
1325
  } | {
@@ -1304,6 +1371,7 @@ declare enum Effect {
1304
1371
  Freeze = "freeze",
1305
1372
  Read = "read",
1306
1373
  Capture = "capture",
1374
+ ConditionallyMutateIterator = "mutate-iterator?",
1307
1375
  ConditionallyMutate = "mutate?",
1308
1376
  Mutate = "mutate",
1309
1377
  Store = "store"
@@ -1423,6 +1491,7 @@ declare class CompilerError extends Error {
1423
1491
  push(options: CompilerErrorDetailOptions): CompilerErrorDetail;
1424
1492
  pushErrorDetail(detail: CompilerErrorDetail): CompilerErrorDetail;
1425
1493
  hasErrors(): boolean;
1494
+ asResult(): Result<void, CompilerError>;
1426
1495
  isCritical(): boolean;
1427
1496
  }
1428
1497
 
@@ -1443,7 +1512,7 @@ type CodegenFunction = {
1443
1512
  fn: CodegenFunction;
1444
1513
  type: ReactFunctionType | null;
1445
1514
  }>;
1446
- hasLoweredContextAccess: boolean;
1515
+ hasInferredEffect: boolean;
1447
1516
  hasFireRewrite: boolean;
1448
1517
  };
1449
1518
 
@@ -1466,7 +1535,7 @@ type CompilerPipelineValue = {
1466
1535
  name: string;
1467
1536
  value: string;
1468
1537
  };
1469
- 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;
1538
+ declare function compileFn(func: NodePath<t.FunctionDeclaration | t.ArrowFunctionExpression | t.FunctionExpression>, config: EnvironmentConfig, fnType: ReactFunctionType, mode: CompilerMode, programContext: ProgramContext, logger: Logger | null, filename: string | null, code: string | null): CodegenFunction;
1470
1539
 
1471
1540
  declare const PanicThresholdOptionsSchema: z.ZodEnum<["all_errors", "critical_errors", "none"]>;
1472
1541
  type PanicThresholdOptions = z.infer<typeof PanicThresholdOptionsSchema>;
@@ -1539,6 +1608,22 @@ type Logger = {
1539
1608
  };
1540
1609
  declare function parsePluginOptions(obj: unknown): PluginOptions;
1541
1610
 
1611
+ declare class ProgramContext {
1612
+ scope: Scope;
1613
+ reactRuntimeModule: string;
1614
+ hookPattern: string | null;
1615
+ knownReferencedNames: Set<string>;
1616
+ imports: Map<string, Map<string, NonLocalImportSpecifier>>;
1617
+ constructor(program: NodePath$1<t.Program>, reactRuntimeModule: CompilerReactTarget, hookPattern: string | null);
1618
+ isHookName(name: string): boolean;
1619
+ hasReference(name: string): boolean;
1620
+ newUid(name: string): string;
1621
+ addMemoCacheImport(): NonLocalImportSpecifier;
1622
+ addImportSpecifier({ source: module, importSpecifierName: specifier }: ExternalFunction, nameHint?: string): NonLocalImportSpecifier;
1623
+ addNewReference(name: string): void;
1624
+ assertGlobalBinding(name: string, localScope?: Scope): Result<void, CompilerError>;
1625
+ }
1626
+
1542
1627
  type CompilerPass = {
1543
1628
  opts: PluginOptions;
1544
1629
  filename: string | null;
@@ -1566,4 +1651,4 @@ declare global {
1566
1651
  let __DEV__: boolean | null | undefined;
1567
1652
  }
1568
1653
 
1569
- 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 };
1654
+ 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, printHIR, printReactiveFunction, runBabelPluginReactCompiler, validateEnvironmentConfig };