babel-plugin-react-compiler 0.0.0-experimental-a9d296d-20250326 → 0.0.0-experimental-b6140c1-20250328

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.
package/dist/index.d.ts CHANGED
@@ -545,6 +545,7 @@ declare class Environment {
545
545
  programContext: ProgramContext;
546
546
  hasFireRewrite: boolean;
547
547
  hasInferredEffect: boolean;
548
+ inferredEffectLocations: Set<SourceLocation>;
548
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);
549
550
  get isInferredMemoEnabled(): boolean;
550
551
  get nextIdentifierId(): IdentifierId;
@@ -1126,13 +1127,18 @@ type InstructionValue = LoadLocal | LoadContext | {
1126
1127
  operator: Exclude<t.UnaryExpression['operator'], 'throw' | 'delete'>;
1127
1128
  value: Place;
1128
1129
  loc: SourceLocation;
1129
- } | {
1130
+ } | ({
1130
1131
  kind: 'TypeCastExpression';
1131
1132
  value: Place;
1132
- typeAnnotation: t.FlowType | t.TSType;
1133
1133
  type: Type;
1134
1134
  loc: SourceLocation;
1135
- } | JsxExpression | {
1135
+ } & ({
1136
+ typeAnnotation: t.FlowType;
1137
+ typeAnnotationKind: 'cast';
1138
+ } | {
1139
+ typeAnnotation: t.TSType;
1140
+ typeAnnotationKind: 'as' | 'satisfies';
1141
+ })) | JsxExpression | {
1136
1142
  kind: 'ObjectExpression';
1137
1143
  properties: Array<ObjectProperty | SpreadPattern>;
1138
1144
  loc: SourceLocation;
@@ -1432,6 +1438,7 @@ type InstructionId = number & {
1432
1438
  type Options = {
1433
1439
  indent: number;
1434
1440
  };
1441
+ declare function printFunctionWithOutlined(fn: HIRFunction): string;
1435
1442
  declare function printHIR(ir: HIR, options?: Options | null): string;
1436
1443
 
1437
1444
  declare enum ErrorSeverity {
@@ -1513,9 +1520,11 @@ type CodegenFunction = {
1513
1520
  type: ReactFunctionType | null;
1514
1521
  }>;
1515
1522
  hasInferredEffect: boolean;
1523
+ inferredEffectLocations: Set<SourceLocation>;
1516
1524
  hasFireRewrite: boolean;
1517
1525
  };
1518
1526
 
1527
+ declare function printReactiveFunctionWithOutlined(fn: ReactiveFunction): string;
1519
1528
  declare function printReactiveFunction(fn: ReactiveFunction): string;
1520
1529
 
1521
1530
  type CompilerPipelineValue = {
@@ -1640,6 +1649,7 @@ type CompileProgramResult = {
1640
1649
  fn: BabelFn;
1641
1650
  error: CompilerError;
1642
1651
  }>;
1652
+ inferredEffectLocations: Set<t.SourceLocation>;
1643
1653
  };
1644
1654
  declare function compileProgram(program: NodePath$1<t.Program>, pass: CompilerPass): CompileProgramResult | null;
1645
1655
 
@@ -1651,4 +1661,4 @@ declare global {
1651
1661
  let __DEV__: boolean | null | undefined;
1652
1662
  }
1653
1663
 
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 };
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 };
package/dist/index.js CHANGED
@@ -110434,8 +110434,10 @@ __export(index_exports, {
110434
110434
  findDirectiveEnablingMemoization: () => findDirectiveEnablingMemoization,
110435
110435
  parseConfigPragmaForTests: () => parseConfigPragmaForTests,
110436
110436
  parsePluginOptions: () => parsePluginOptions,
110437
+ printFunctionWithOutlined: () => printFunctionWithOutlined,
110437
110438
  printHIR: () => printHIR,
110438
110439
  printReactiveFunction: () => printReactiveFunction,
110440
+ printReactiveFunctionWithOutlined: () => printReactiveFunctionWithOutlined,
110439
110441
  runBabelPluginReactCompiler: () => runBabelPluginReactCompiler,
110440
110442
  validateEnvironmentConfig: () => validateEnvironmentConfig
110441
110443
  });
@@ -114959,6 +114961,14 @@ function getHookKindForType(env, type) {
114959
114961
  var import_generator = __toESM(require_lib26());
114960
114962
 
114961
114963
  // src/ReactiveScopes/PrintReactiveFunction.ts
114964
+ function printReactiveFunctionWithOutlined(fn) {
114965
+ const writer = new Writer();
114966
+ writeReactiveFunction(fn, writer);
114967
+ for (const outlined of fn.env.getOutlinedFunctions()) {
114968
+ writer.writeLine("\nfunction " + printFunction(outlined.fn));
114969
+ }
114970
+ return writer.complete();
114971
+ }
114962
114972
  function printReactiveFunction(fn) {
114963
114973
  const writer = new Writer();
114964
114974
  writeReactiveFunction(fn, writer);
@@ -115326,6 +115336,15 @@ _line = new WeakMap();
115326
115336
  _depth = new WeakMap();
115327
115337
 
115328
115338
  // src/HIR/PrintHIR.ts
115339
+ function printFunctionWithOutlined(fn) {
115340
+ const output = [printFunction(fn)];
115341
+ for (const outlined of fn.env.getOutlinedFunctions()) {
115342
+ output.push(`
115343
+ function ${outlined.fn.id}:
115344
+ ${printHIR(outlined.fn.body)}`);
115345
+ }
115346
+ return output.join("\n");
115347
+ }
115329
115348
  function printFunction(fn) {
115330
115349
  const output = [];
115331
115350
  let definition = "";
@@ -120998,6 +121017,19 @@ function lowerExpression(builder, exprPath) {
120998
121017
  kind: "TypeCastExpression",
120999
121018
  value: lowerExpressionToTemporary(builder, expr.get("expression")),
121000
121019
  typeAnnotation: typeAnnotation2.node,
121020
+ typeAnnotationKind: "cast",
121021
+ type: lowerType(typeAnnotation2.node),
121022
+ loc: exprLoc
121023
+ };
121024
+ }
121025
+ case "TSSatisfiesExpression": {
121026
+ let expr = exprPath;
121027
+ const typeAnnotation2 = expr.get("typeAnnotation");
121028
+ return {
121029
+ kind: "TypeCastExpression",
121030
+ value: lowerExpressionToTemporary(builder, expr.get("expression")),
121031
+ typeAnnotation: typeAnnotation2.node,
121032
+ typeAnnotationKind: "satisfies",
121001
121033
  type: lowerType(typeAnnotation2.node),
121002
121034
  loc: exprLoc
121003
121035
  };
@@ -121009,6 +121041,7 @@ function lowerExpression(builder, exprPath) {
121009
121041
  kind: "TypeCastExpression",
121010
121042
  value: lowerExpressionToTemporary(builder, expr.get("expression")),
121011
121043
  typeAnnotation: typeAnnotation2.node,
121044
+ typeAnnotationKind: "as",
121012
121045
  type: lowerType(typeAnnotation2.node),
121013
121046
  loc: exprLoc
121014
121047
  };
@@ -124417,6 +124450,7 @@ function parseConfigPragmaForTests(pragma, defaults) {
124417
124450
  const environment = parseConfigPragmaEnvironmentForTest(pragma);
124418
124451
  let compilationMode = defaults.compilationMode;
124419
124452
  let panicThreshold = "all_errors";
124453
+ let noEmit = defaultOptions.noEmit;
124420
124454
  for (const token2 of pragma.split(" ")) {
124421
124455
  if (!token2.startsWith("@")) {
124422
124456
  continue;
@@ -124442,12 +124476,17 @@ function parseConfigPragmaForTests(pragma, defaults) {
124442
124476
  panicThreshold = "none";
124443
124477
  break;
124444
124478
  }
124479
+ case "@noEmit": {
124480
+ noEmit = true;
124481
+ break;
124482
+ }
124445
124483
  }
124446
124484
  }
124447
124485
  return parsePluginOptions({
124448
124486
  environment,
124449
124487
  compilationMode,
124450
- panicThreshold
124488
+ panicThreshold,
124489
+ noEmit
124451
124490
  });
124452
124491
  }
124453
124492
  var _globals, _shapes, _moduleTypes, _nextIdentifer, _nextBlock, _nextScope, _scope, _outlinedFunctions, _contextIdentifiers, _hoistedIdentifiers, _Environment_instances, resolveModuleType_fn, isKnownReactModule_fn, getCustomHookType_fn;
@@ -124462,6 +124501,7 @@ var Environment = class {
124462
124501
  __privateAdd(this, _nextScope, 0);
124463
124502
  __privateAdd(this, _scope);
124464
124503
  __privateAdd(this, _outlinedFunctions, []);
124504
+ this.inferredEffectLocations = /* @__PURE__ */ new Set();
124465
124505
  __privateAdd(this, _contextIdentifiers);
124466
124506
  __privateAdd(this, _hoistedIdentifiers);
124467
124507
  __privateSet(this, _scope, scope);
@@ -129590,7 +129630,8 @@ function codegenReactiveFunction(cx, fn) {
129590
129630
  prunedMemoValues: countMemoBlockVisitor.prunedMemoValues,
129591
129631
  outlined: [],
129592
129632
  hasFireRewrite: fn.env.hasFireRewrite,
129593
- hasInferredEffect: fn.env.hasInferredEffect
129633
+ hasInferredEffect: fn.env.hasInferredEffect,
129634
+ inferredEffectLocations: fn.env.inferredEffectLocations
129594
129635
  });
129595
129636
  }
129596
129637
  var CountMemoBlockVisitor = class extends ReactiveFunctionVisitor {
@@ -131079,10 +131120,17 @@ function codegenInstructionValue(cx, instrValue) {
131079
131120
  }
131080
131121
  case "TypeCastExpression": {
131081
131122
  if (t3.isTSType(instrValue.typeAnnotation)) {
131082
- value = t3.tsAsExpression(
131083
- codegenPlaceToExpression(cx, instrValue.value),
131084
- instrValue.typeAnnotation
131085
- );
131123
+ if (instrValue.typeAnnotationKind === "satisfies") {
131124
+ value = t3.tsSatisfiesExpression(
131125
+ codegenPlaceToExpression(cx, instrValue.value),
131126
+ instrValue.typeAnnotation
131127
+ );
131128
+ } else {
131129
+ value = t3.tsAsExpression(
131130
+ codegenPlaceToExpression(cx, instrValue.value),
131131
+ instrValue.typeAnnotation
131132
+ );
131133
+ }
131086
131134
  } else {
131087
131135
  value = t3.typeCastExpression(
131088
131136
  codegenPlaceToExpression(cx, instrValue.value),
@@ -136458,6 +136506,7 @@ function inferEffectDependencies(fn) {
136458
136506
  });
136459
136507
  value.args.push(__spreadProps(__spreadValues({}, depsPlace), { effect: "freeze" /* Freeze */ }));
136460
136508
  rewriteInstrs.set(instr.id, newInstructions);
136509
+ fn.env.inferredEffectLocations.add(callee.loc);
136461
136510
  } else if (loadGlobals.has(value.args[0].identifier.id)) {
136462
136511
  newInstructions.push({
136463
136512
  id: makeInstructionId(0),
@@ -136467,6 +136516,7 @@ function inferEffectDependencies(fn) {
136467
136516
  });
136468
136517
  value.args.push(__spreadProps(__spreadValues({}, depsPlace), { effect: "freeze" /* Freeze */ }));
136469
136518
  rewriteInstrs.set(instr.id, newInstructions);
136519
+ fn.env.inferredEffectLocations.add(callee.loc);
136470
136520
  }
136471
136521
  }
136472
136522
  }
@@ -143028,6 +143078,7 @@ function compileProgram(program, pass) {
143028
143078
  })
143029
143079
  );
143030
143080
  const retryErrors = [];
143081
+ const inferredEffectLocations = /* @__PURE__ */ new Set();
143031
143082
  const processFn = (fn, fnType) => {
143032
143083
  var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
143033
143084
  let optInDirectives = [];
@@ -143131,6 +143182,9 @@ function compileProgram(program, pass) {
143131
143182
  if (!pass.opts.noEmit) {
143132
143183
  return compileResult.compiledFn;
143133
143184
  }
143185
+ for (const loc of compileResult.compiledFn.inferredEffectLocations) {
143186
+ if (loc !== GeneratedSource) inferredEffectLocations.add(loc);
143187
+ }
143134
143188
  return null;
143135
143189
  };
143136
143190
  while (queue.length !== 0) {
@@ -143194,7 +143248,7 @@ function compileProgram(program, pass) {
143194
143248
  if (compiledFns.length > 0) {
143195
143249
  addImportsToProgram(program, programContext);
143196
143250
  }
143197
- return { retryErrors };
143251
+ return { retryErrors, inferredEffectLocations };
143198
143252
  }
143199
143253
  function shouldSkipCompilation(program, pass) {
143200
143254
  if (pass.opts.sources) {
@@ -143888,7 +143942,9 @@ function assertValidEffectImportReference(numArgs, paths, context) {
143888
143942
  const parent = path.parentPath;
143889
143943
  if (parent != null && parent.isCallExpression()) {
143890
143944
  const args = parent.get("arguments");
143891
- if (args.length === numArgs) {
143945
+ const maybeCalleeLoc = path.node.loc;
143946
+ const hasInferredEffect = maybeCalleeLoc != null && context.inferredEffectLocations.has(maybeCalleeLoc);
143947
+ if (args.length === numArgs && !hasInferredEffect) {
143892
143948
  const maybeErrorDiagnostic = matchCompilerDiagnostic(
143893
143949
  path,
143894
143950
  context.transformErrors
@@ -143922,7 +143978,7 @@ function assertValidFireImportReference(paths, context) {
143922
143978
  );
143923
143979
  }
143924
143980
  }
143925
- function validateNoUntransformedReferences(path, filename, logger, env, transformErrors) {
143981
+ function validateNoUntransformedReferences(path, filename, logger, env, compileResult) {
143926
143982
  const moduleLoadChecks = /* @__PURE__ */ new Map();
143927
143983
  if (env.enableFire) {
143928
143984
  for (const module2 of Environment.knownReactModules) {
@@ -143943,7 +143999,7 @@ function validateNoUntransformedReferences(path, filename, logger, env, transfor
143943
143999
  }
143944
144000
  }
143945
144001
  if (moduleLoadChecks.size > 0) {
143946
- transformProgram(path, moduleLoadChecks, filename, logger, transformErrors);
144002
+ transformProgram(path, moduleLoadChecks, filename, logger, compileResult);
143947
144003
  }
143948
144004
  }
143949
144005
  function validateImportSpecifier(specifier, importSpecifierChecks, state) {
@@ -144001,13 +144057,15 @@ function validateNamespacedImport(specifier, importSpecifierChecks, state) {
144001
144057
  checkFn(references, state);
144002
144058
  }
144003
144059
  }
144004
- function transformProgram(path, moduleLoadChecks, filename, logger, transformErrors) {
144060
+ function transformProgram(path, moduleLoadChecks, filename, logger, compileResult) {
144061
+ var _a, _b;
144005
144062
  const traversalState = {
144006
144063
  shouldInvalidateScopes: true,
144007
144064
  program: path,
144008
144065
  filename,
144009
144066
  logger,
144010
- transformErrors
144067
+ transformErrors: (_a = compileResult == null ? void 0 : compileResult.retryErrors) != null ? _a : [],
144068
+ inferredEffectLocations: (_b = compileResult == null ? void 0 : compileResult.inferredEffectLocations) != null ? _b : /* @__PURE__ */ new Set()
144011
144069
  };
144012
144070
  path.traverse({
144013
144071
  ImportDeclaration(path2) {
@@ -144058,7 +144116,7 @@ function BabelPluginReactCompiler(_babel) {
144058
144116
  */
144059
144117
  Program: {
144060
144118
  enter(prog, pass) {
144061
- var _a, _b, _c, _d, _e;
144119
+ var _a, _b, _c, _d;
144062
144120
  const filename = (_a = pass.filename) != null ? _a : "unknown";
144063
144121
  if (ENABLE_REACT_COMPILER_TIMINGS === true) {
144064
144122
  performance.mark(`${filename}:start`, {
@@ -144088,7 +144146,7 @@ function BabelPluginReactCompiler(_babel) {
144088
144146
  (_d = pass.filename) != null ? _d : null,
144089
144147
  opts.logger,
144090
144148
  opts.environment,
144091
- (_e = result == null ? void 0 : result.retryErrors) != null ? _e : []
144149
+ result
144092
144150
  );
144093
144151
  if (ENABLE_REACT_COMPILER_TIMINGS === true) {
144094
144152
  performance.mark(`${filename}:end`, {
@@ -144166,8 +144224,10 @@ var index_default = BabelPluginReactCompiler;
144166
144224
  findDirectiveEnablingMemoization,
144167
144225
  parseConfigPragmaForTests,
144168
144226
  parsePluginOptions,
144227
+ printFunctionWithOutlined,
144169
144228
  printHIR,
144170
144229
  printReactiveFunction,
144230
+ printReactiveFunctionWithOutlined,
144171
144231
  runBabelPluginReactCompiler,
144172
144232
  validateEnvironmentConfig
144173
144233
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-plugin-react-compiler",
3
- "version": "0.0.0-experimental-a9d296d-20250326",
3
+ "version": "0.0.0-experimental-b6140c1-20250328",
4
4
  "description": "Babel plugin for React Compiler.",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",
@@ -12,12 +12,12 @@
12
12
  "build": "rimraf dist && tsup",
13
13
  "test": "./scripts/link-react-compiler-runtime.sh && yarn snap:ci",
14
14
  "jest": "yarn build && ts-node node_modules/.bin/jest",
15
- "snap": "node ../snap/dist/main.js",
15
+ "snap": "yarn workspace snap run snap",
16
16
  "snap:build": "yarn workspace snap run build",
17
17
  "snap:ci": "yarn snap:build && yarn snap",
18
18
  "ts:analyze-trace": "scripts/ts-analyze-trace.sh",
19
19
  "lint": "yarn eslint src",
20
- "watch": "yarn build --watch"
20
+ "watch": "yarn build --dts --watch"
21
21
  },
22
22
  "dependencies": {
23
23
  "@babel/types": "^7.26.0"