babel-plugin-react-compiler 19.0.0-beta-decd7b8-20250118 → 19.0.0-beta-714736e-20250131

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.js CHANGED
@@ -121306,8 +121306,16 @@ addObject(BUILTIN_SHAPES, BuiltInMixedReadonlyId, [
121306
121306
  [
121307
121307
  "map",
121308
121308
  addFunction(BUILTIN_SHAPES, [], {
121309
+ /**
121310
+ * Note `map`'s arguments are annotated as Effect.ConditionallyMutate as
121311
+ * calling `<array>.map(fn)` might invoke `fn`, which means replaying its
121312
+ * effects.
121313
+ *
121314
+ * (Note that Effect.Read / Effect.Capture on a function type means
121315
+ * potential data dependency or aliasing respectively.)
121316
+ */
121309
121317
  positionalParams: [],
121310
- restParam: "read" /* Read */,
121318
+ restParam: "mutate?" /* ConditionallyMutate */,
121311
121319
  returnType: { kind: "Object", shapeId: BuiltInArrayId },
121312
121320
  calleeEffect: "mutate?" /* ConditionallyMutate */,
121313
121321
  returnValueKind: "mutable" /* Mutable */,
@@ -121318,7 +121326,7 @@ addObject(BUILTIN_SHAPES, BuiltInMixedReadonlyId, [
121318
121326
  "flatMap",
121319
121327
  addFunction(BUILTIN_SHAPES, [], {
121320
121328
  positionalParams: [],
121321
- restParam: "read" /* Read */,
121329
+ restParam: "mutate?" /* ConditionallyMutate */,
121322
121330
  returnType: { kind: "Object", shapeId: BuiltInArrayId },
121323
121331
  calleeEffect: "mutate?" /* ConditionallyMutate */,
121324
121332
  returnValueKind: "mutable" /* Mutable */,
@@ -121329,7 +121337,7 @@ addObject(BUILTIN_SHAPES, BuiltInMixedReadonlyId, [
121329
121337
  "filter",
121330
121338
  addFunction(BUILTIN_SHAPES, [], {
121331
121339
  positionalParams: [],
121332
- restParam: "read" /* Read */,
121340
+ restParam: "mutate?" /* ConditionallyMutate */,
121333
121341
  returnType: { kind: "Object", shapeId: BuiltInArrayId },
121334
121342
  calleeEffect: "mutate?" /* ConditionallyMutate */,
121335
121343
  returnValueKind: "mutable" /* Mutable */,
@@ -126588,6 +126596,7 @@ var EnvironmentConfigSchema = z.object({
126588
126596
  * original source will be disabled as well.
126589
126597
  */
126590
126598
  disableMemoizationForDebugging: z.boolean().default(false),
126599
+ enableMinimalTransformsForRetry: z.boolean().default(false),
126591
126600
  /**
126592
126601
  * When true, rather using memoized values, the compiler will always re-compute
126593
126602
  * values, and then use a heuristic to compare the memoized value to the newly
@@ -126654,6 +126663,17 @@ var EnvironmentConfigSchema = z.object({
126654
126663
  */
126655
126664
  lowerContextAccess: ExternalFunctionSchema.nullable().default(null)
126656
126665
  });
126666
+ var MINIMAL_RETRY_CONFIG = {
126667
+ validateHooksUsage: false,
126668
+ validateRefAccessDuringRender: false,
126669
+ validateNoSetStateInRender: false,
126670
+ validateNoSetStateInPassiveEffects: false,
126671
+ validateNoJSXInTryStatements: false,
126672
+ validateMemoizedEffectDependencies: false,
126673
+ validateNoCapitalizedCalls: null,
126674
+ validateBlocklistedImports: null,
126675
+ enableMinimalTransformsForRetry: true
126676
+ };
126657
126677
  var testComplexConfigDefaults = {
126658
126678
  validateNoCapitalizedCalls: [],
126659
126679
  enableChangeDetectionForDebugging: {
@@ -133744,7 +133764,7 @@ function codegenInstructionValue(cx, instrValue) {
133744
133764
  }
133745
133765
  return value;
133746
133766
  }
133747
- var STRING_REQUIRES_EXPR_CONTAINER_PATTERN = /[\u{0000}-\u{001F}\u{007F}\u{0080}-\u{FFFF}]|"/u;
133767
+ var STRING_REQUIRES_EXPR_CONTAINER_PATTERN = /[\u{0000}-\u{001F}\u{007F}\u{0080}-\u{FFFF}]|"|\\/u;
133748
133768
  function codegenJsxAttribute(cx, attribute) {
133749
133769
  switch (attribute.kind) {
133750
133770
  case "JsxAttribute": {
@@ -133789,7 +133809,7 @@ function codegenJsxAttribute(cx, attribute) {
133789
133809
  }
133790
133810
  }
133791
133811
  }
133792
- var JSX_TEXT_CHILD_REQUIRES_EXPR_CONTAINER_PATTERN = /[<>&]/;
133812
+ var JSX_TEXT_CHILD_REQUIRES_EXPR_CONTAINER_PATTERN = /[<>&{}]/;
133793
133813
  function codegenJsxElement(cx, place) {
133794
133814
  const value = codegenPlace(cx, place);
133795
133815
  switch (value.type) {
@@ -134985,11 +135005,15 @@ function inferOperandEffect(state, place) {
134985
135005
  if (isRefOrRefValue(place.identifier)) {
134986
135006
  break;
134987
135007
  } else if (value.kind === "context" /* Context */) {
135008
+ CompilerError.invariant(value.context.size > 0, {
135009
+ reason: "[InferFunctionEffects] Expected Context-kind value's capture list to be non-empty.",
135010
+ loc: place.loc
135011
+ });
134988
135012
  return {
134989
135013
  kind: "ContextMutation",
134990
135014
  loc: place.loc,
134991
135015
  effect: place.effect,
134992
- places: value.context.size === 0 ? /* @__PURE__ */ new Set([place]) : value.context
135016
+ places: value.context
134993
135017
  };
134994
135018
  } else if (value.kind !== "mutable" /* Mutable */ && // We ignore mutations of primitives since this is not a React-specific problem
134995
135019
  value.kind !== "primitive" /* Primitive */) {
@@ -135307,7 +135331,7 @@ function inferReferenceEffects(fn, options = { isFunctionExpression: false }) {
135307
135331
  }
135308
135332
  if (options.isFunctionExpression) {
135309
135333
  fn.effects = functionEffects;
135310
- } else {
135334
+ } else if (!fn.env.config.enableMinimalTransformsForRetry) {
135311
135335
  raiseFunctionEffectErrors(functionEffects);
135312
135336
  }
135313
135337
  }
@@ -135744,10 +135768,11 @@ function inferBlock(env, state, block, functionEffects) {
135744
135768
  break;
135745
135769
  }
135746
135770
  case "ArrayExpression": {
135747
- const valueKind = hasContextRefOperand(state, instrValue) ? {
135771
+ const contextRefOperands = getContextRefOperand(state, instrValue);
135772
+ const valueKind = contextRefOperands.length > 0 ? {
135748
135773
  kind: "context" /* Context */,
135749
135774
  reason: /* @__PURE__ */ new Set(["other" /* Other */]),
135750
- context: /* @__PURE__ */ new Set()
135775
+ context: new Set(contextRefOperands)
135751
135776
  } : {
135752
135777
  kind: "mutable" /* Mutable */,
135753
135778
  reason: /* @__PURE__ */ new Set(["other" /* Other */]),
@@ -135788,10 +135813,11 @@ function inferBlock(env, state, block, functionEffects) {
135788
135813
  break;
135789
135814
  }
135790
135815
  case "ObjectExpression": {
135791
- const valueKind = hasContextRefOperand(state, instrValue) ? {
135816
+ const contextRefOperands = getContextRefOperand(state, instrValue);
135817
+ const valueKind = contextRefOperands.length > 0 ? {
135792
135818
  kind: "context" /* Context */,
135793
135819
  reason: /* @__PURE__ */ new Set(["other" /* Other */]),
135794
- context: /* @__PURE__ */ new Set()
135820
+ context: new Set(contextRefOperands)
135795
135821
  } : {
135796
135822
  kind: "mutable" /* Mutable */,
135797
135823
  reason: /* @__PURE__ */ new Set(["other" /* Other */]),
@@ -136381,11 +136407,17 @@ function inferBlock(env, state, block, functionEffects) {
136381
136407
  }
136382
136408
  case "LoadLocal": {
136383
136409
  const lvalue = instr.lvalue;
136384
- const effect = state.isDefined(lvalue) && state.kind(lvalue).kind === "context" /* Context */ ? "mutate?" /* ConditionallyMutate */ : "capture" /* Capture */;
136410
+ CompilerError.invariant(
136411
+ !(state.isDefined(lvalue) && state.kind(lvalue).kind === "context" /* Context */),
136412
+ {
136413
+ reason: "[InferReferenceEffects] Unexpected LoadLocal with context kind",
136414
+ loc: lvalue.loc
136415
+ }
136416
+ );
136385
136417
  state.referenceAndRecordEffects(
136386
136418
  freezeActions,
136387
136419
  instrValue.place,
136388
- effect,
136420
+ "capture" /* Capture */,
136389
136421
  "other" /* Other */
136390
136422
  );
136391
136423
  lvalue.effect = "mutate?" /* ConditionallyMutate */;
@@ -136639,13 +136671,14 @@ function inferBlock(env, state, block, functionEffects) {
136639
136671
  ({ values, reason }) => state.freezeValues(values, reason)
136640
136672
  );
136641
136673
  }
136642
- function hasContextRefOperand(state, instrValue) {
136674
+ function getContextRefOperand(state, instrValue) {
136675
+ const result = [];
136643
136676
  for (const place of eachInstructionValueOperand(instrValue)) {
136644
136677
  if (state.isDefined(place) && state.kind(place).kind === "context" /* Context */) {
136645
- return true;
136678
+ result.push(place);
136646
136679
  }
136647
136680
  }
136648
- return false;
136681
+ return result;
136649
136682
  }
136650
136683
  function getFunctionCallSignature(env, type) {
136651
136684
  if (type.kind !== "Function") {
@@ -144673,7 +144706,7 @@ function runWithEnvironment(func, env) {
144673
144706
  log2({ kind: "hir", name: "PruneMaybeThrows", value: hir });
144674
144707
  validateContextVariableLValues(hir);
144675
144708
  validateUseMemo(hir);
144676
- if (!env.config.enablePreserveExistingManualUseMemo && !env.config.disableMemoizationForDebugging && !env.config.enableChangeDetectionForDebugging) {
144709
+ if (!env.config.enablePreserveExistingManualUseMemo && !env.config.disableMemoizationForDebugging && !env.config.enableChangeDetectionForDebugging && !env.config.enableMinimalTransformsForRetry) {
144677
144710
  dropManualMemoization(hir);
144678
144711
  log2({ kind: "hir", name: "DropManualMemoization", value: hir });
144679
144712
  }
@@ -144758,8 +144791,10 @@ function runWithEnvironment(func, env) {
144758
144791
  name: "PropagatePhiTypes",
144759
144792
  value: hir
144760
144793
  });
144761
- inferReactiveScopeVariables(hir);
144762
- log2({ kind: "hir", name: "InferReactiveScopeVariables", value: hir });
144794
+ if (!env.config.enableMinimalTransformsForRetry) {
144795
+ inferReactiveScopeVariables(hir);
144796
+ log2({ kind: "hir", name: "InferReactiveScopeVariables", value: hir });
144797
+ }
144763
144798
  const fbtOperands = memoizeFbtAndMacroOperandsInSameScope(hir);
144764
144799
  log2({
144765
144800
  kind: "hir",
@@ -145322,52 +145357,75 @@ function compileProgram(program, pass) {
145322
145357
  fn.node.body.directives
145323
145358
  );
145324
145359
  }
145325
- let compiledFn;
145326
- try {
145327
- const suppressionsInFunction = filterSuppressionsThatAffectFunction(
145328
- suppressions,
145329
- fn
145330
- );
145331
- if (suppressionsInFunction.length > 0) {
145332
- const lintError = suppressionsToCompilerError(suppressionsInFunction);
145333
- if (optOutDirectives.length > 0) {
145334
- logError(lintError, pass, fn.node.loc ?? null);
145335
- } else {
145336
- handleError(lintError, pass, fn.node.loc ?? null);
145337
- }
145338
- return null;
145360
+ const suppressionsInFunction = filterSuppressionsThatAffectFunction(
145361
+ suppressions,
145362
+ fn
145363
+ );
145364
+ let compileResult;
145365
+ if (suppressionsInFunction.length > 0) {
145366
+ compileResult = {
145367
+ kind: "error",
145368
+ error: suppressionsToCompilerError(suppressionsInFunction)
145369
+ };
145370
+ } else {
145371
+ try {
145372
+ compileResult = {
145373
+ kind: "compile",
145374
+ compiledFn: compileFn(
145375
+ fn,
145376
+ environment,
145377
+ fnType,
145378
+ useMemoCacheIdentifier.name,
145379
+ pass.opts.logger,
145380
+ pass.filename,
145381
+ pass.code
145382
+ )
145383
+ };
145384
+ } catch (err) {
145385
+ compileResult = { kind: "error", error: err };
145339
145386
  }
145340
- compiledFn = compileFn(
145341
- fn,
145342
- environment,
145343
- fnType,
145344
- useMemoCacheIdentifier.name,
145345
- pass.opts.logger,
145346
- pass.filename,
145347
- pass.code
145348
- );
145349
- pass.opts.logger?.logEvent(pass.filename, {
145350
- kind: "CompileSuccess",
145351
- fnLoc: fn.node.loc ?? null,
145352
- fnName: compiledFn.id?.name ?? null,
145353
- memoSlots: compiledFn.memoSlotsUsed,
145354
- memoBlocks: compiledFn.memoBlocks,
145355
- memoValues: compiledFn.memoValues,
145356
- prunedMemoBlocks: compiledFn.prunedMemoBlocks,
145357
- prunedMemoValues: compiledFn.prunedMemoValues
145358
- });
145359
- } catch (err) {
145360
- if (fn.node.body.type === "BlockStatement") {
145361
- if (optOutDirectives.length > 0) {
145362
- logError(err, pass, fn.node.loc ?? null);
145363
- return null;
145364
- }
145387
+ }
145388
+ if (compileResult.kind === "error" && environment.enableFire) {
145389
+ try {
145390
+ compileResult = {
145391
+ kind: "compile",
145392
+ compiledFn: compileFn(
145393
+ fn,
145394
+ {
145395
+ ...environment,
145396
+ ...MINIMAL_RETRY_CONFIG
145397
+ },
145398
+ fnType,
145399
+ useMemoCacheIdentifier.name,
145400
+ pass.opts.logger,
145401
+ pass.filename,
145402
+ pass.code
145403
+ )
145404
+ };
145405
+ } catch (err) {
145406
+ compileResult = { kind: "error", error: err };
145407
+ }
145408
+ }
145409
+ if (compileResult.kind === "error") {
145410
+ if (optOutDirectives.length > 0) {
145411
+ logError(compileResult.error, pass, fn.node.loc ?? null);
145412
+ } else {
145413
+ handleError(compileResult.error, pass, fn.node.loc ?? null);
145365
145414
  }
145366
- handleError(err, pass, fn.node.loc ?? null);
145367
145415
  return null;
145368
145416
  }
145417
+ pass.opts.logger?.logEvent(pass.filename, {
145418
+ kind: "CompileSuccess",
145419
+ fnLoc: fn.node.loc ?? null,
145420
+ fnName: compileResult.compiledFn.id?.name ?? null,
145421
+ memoSlots: compileResult.compiledFn.memoSlotsUsed,
145422
+ memoBlocks: compileResult.compiledFn.memoBlocks,
145423
+ memoValues: compileResult.compiledFn.memoValues,
145424
+ prunedMemoBlocks: compileResult.compiledFn.prunedMemoBlocks,
145425
+ prunedMemoValues: compileResult.compiledFn.prunedMemoValues
145426
+ });
145369
145427
  if (optInDirectives.length > 0) {
145370
- return compiledFn;
145428
+ return compileResult.compiledFn;
145371
145429
  } else if (pass.opts.compilationMode === "annotation") {
145372
145430
  return null;
145373
145431
  }
@@ -145383,7 +145441,7 @@ function compileProgram(program, pass) {
145383
145441
  return null;
145384
145442
  }
145385
145443
  if (!pass.opts.noEmit) {
145386
- return compiledFn;
145444
+ return compileResult.compiledFn;
145387
145445
  }
145388
145446
  return null;
145389
145447
  };