babel-plugin-react-compiler 0.0.0-experimental-3452ff1-20250321 → 0.0.0-experimental-a9d296d-20250325

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 +39 -18
  2. package/dist/index.js +1434 -897
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -7408,7 +7408,7 @@ var require_expressions = __commonJS({
7408
7408
  exports2.MemberExpression = MemberExpression;
7409
7409
  exports2.MetaProperty = MetaProperty;
7410
7410
  exports2.ModuleExpression = ModuleExpression;
7411
- exports2.NewExpression = NewExpression;
7411
+ exports2.NewExpression = NewExpression2;
7412
7412
  exports2.OptionalCallExpression = OptionalCallExpression;
7413
7413
  exports2.OptionalMemberExpression = OptionalMemberExpression;
7414
7414
  exports2.ParenthesizedExpression = ParenthesizedExpression;
@@ -7478,7 +7478,7 @@ var require_expressions = __commonJS({
7478
7478
  this.space();
7479
7479
  this.print(node.alternate);
7480
7480
  }
7481
- function NewExpression(node, parent) {
7481
+ function NewExpression2(node, parent) {
7482
7482
  this.word("new");
7483
7483
  this.space();
7484
7484
  this.print(node.callee);
@@ -12152,7 +12152,7 @@ var require_inferers = __commonJS({
12152
12152
  }
12153
12153
  });
12154
12154
  exports2.LogicalExpression = LogicalExpression;
12155
- exports2.NewExpression = NewExpression;
12155
+ exports2.NewExpression = NewExpression2;
12156
12156
  exports2.NullLiteral = NullLiteral;
12157
12157
  exports2.NumericLiteral = NumericLiteral;
12158
12158
  exports2.ObjectExpression = ObjectExpression;
@@ -12207,7 +12207,7 @@ var require_inferers = __commonJS({
12207
12207
  function TSNonNullExpression() {
12208
12208
  return this.get("expression").getTypeAnnotation();
12209
12209
  }
12210
- function NewExpression(node) {
12210
+ function NewExpression2(node) {
12211
12211
  if (node.callee.type === "Identifier") {
12212
12212
  return genericTypeAnnotation(node.callee);
12213
12213
  }
@@ -53254,7 +53254,7 @@ var require_expressions2 = __commonJS({
53254
53254
  exports2.MemberExpression = MemberExpression;
53255
53255
  exports2.MetaProperty = MetaProperty;
53256
53256
  exports2.ModuleExpression = ModuleExpression;
53257
- exports2.NewExpression = NewExpression;
53257
+ exports2.NewExpression = NewExpression2;
53258
53258
  exports2.OptionalCallExpression = OptionalCallExpression;
53259
53259
  exports2.OptionalMemberExpression = OptionalMemberExpression;
53260
53260
  exports2.ParenthesizedExpression = ParenthesizedExpression;
@@ -53324,7 +53324,7 @@ var require_expressions2 = __commonJS({
53324
53324
  this.space();
53325
53325
  this.print(node.alternate);
53326
53326
  }
53327
- function NewExpression(node, parent) {
53327
+ function NewExpression2(node, parent) {
53328
53328
  this.word("new");
53329
53329
  this.space();
53330
53330
  this.print(node.callee);
@@ -58020,7 +58020,7 @@ var require_inferers2 = __commonJS({
58020
58020
  });
58021
58021
  exports2.VariableDeclarator = VariableDeclarator;
58022
58022
  exports2.TypeCastExpression = TypeCastExpression;
58023
- exports2.NewExpression = NewExpression;
58023
+ exports2.NewExpression = NewExpression2;
58024
58024
  exports2.TemplateLiteral = TemplateLiteral;
58025
58025
  exports2.UnaryExpression = UnaryExpression;
58026
58026
  exports2.BinaryExpression = BinaryExpression;
@@ -58107,7 +58107,7 @@ var require_inferers2 = __commonJS({
58107
58107
  return node.typeAnnotation;
58108
58108
  }
58109
58109
  TypeCastExpression.validParent = true;
58110
- function NewExpression(node) {
58110
+ function NewExpression2(node) {
58111
58111
  if (this.get("callee").isIdentifier()) {
58112
58112
  return t5.genericTypeAnnotation(node.callee);
58113
58113
  }
@@ -97512,7 +97512,7 @@ var require_parentheses3 = __commonJS({
97512
97512
  exports2.ConditionalExpression = ConditionalExpression;
97513
97513
  exports2.OptionalMemberExpression = OptionalMemberExpression;
97514
97514
  exports2.AssignmentExpression = AssignmentExpression;
97515
- exports2.NewExpression = NewExpression;
97515
+ exports2.NewExpression = NewExpression2;
97516
97516
  function t5() {
97517
97517
  const data = _interopRequireWildcard(require("@babel/types"));
97518
97518
  t5 = function() {
@@ -97675,7 +97675,7 @@ var require_parentheses3 = __commonJS({
97675
97675
  return ConditionalExpression(...arguments);
97676
97676
  }
97677
97677
  }
97678
- function NewExpression(node, parent) {
97678
+ function NewExpression2(node, parent) {
97679
97679
  return isClassExtendsClause(node, parent);
97680
97680
  }
97681
97681
  function isFirstInStatement(printStack, {
@@ -97879,7 +97879,7 @@ var require_expressions3 = __commonJS({
97879
97879
  exports2.ParenthesizedExpression = ParenthesizedExpression;
97880
97880
  exports2.UpdateExpression = UpdateExpression;
97881
97881
  exports2.ConditionalExpression = ConditionalExpression;
97882
- exports2.NewExpression = NewExpression;
97882
+ exports2.NewExpression = NewExpression2;
97883
97883
  exports2.SequenceExpression = SequenceExpression;
97884
97884
  exports2.ThisExpression = ThisExpression;
97885
97885
  exports2.Super = Super;
@@ -97967,7 +97967,7 @@ var require_expressions3 = __commonJS({
97967
97967
  this.space();
97968
97968
  this.print(node.alternate, node);
97969
97969
  }
97970
- function NewExpression(node, parent) {
97970
+ function NewExpression2(node, parent) {
97971
97971
  this.word("new");
97972
97972
  this.space();
97973
97973
  this.print(node.callee, node);
@@ -110425,6 +110425,7 @@ __export(index_exports, {
110425
110425
  ErrorSeverity: () => ErrorSeverity,
110426
110426
  OPT_IN_DIRECTIVES: () => OPT_IN_DIRECTIVES,
110427
110427
  OPT_OUT_DIRECTIVES: () => OPT_OUT_DIRECTIVES,
110428
+ ProgramContext: () => ProgramContext2,
110428
110429
  ValueKind: () => ValueKind,
110429
110430
  compile: () => compileFn,
110430
110431
  compileProgram: () => compileProgram,
@@ -110829,7 +110830,7 @@ var CompilerError = class _CompilerError extends Error {
110829
110830
  };
110830
110831
 
110831
110832
  // src/Entrypoint/Gating.ts
110832
- function insertAdditionalFunctionDeclaration(fnPath, compiled, gating) {
110833
+ function insertAdditionalFunctionDeclaration(fnPath, compiled, programContext, gatingFunctionIdentifierName) {
110833
110834
  var _a, _b;
110834
110835
  const originalFnName = fnPath.node.id;
110835
110836
  const originalFnParams = fnPath.node.params;
@@ -110842,14 +110843,14 @@ function insertAdditionalFunctionDeclaration(fnPath, compiled, gating) {
110842
110843
  reason: "Expected React Compiler optimized function declarations to have the same number of parameters as source",
110843
110844
  loc: (_b = fnPath.node.loc) != null ? _b : null
110844
110845
  });
110845
- const gatingCondition = fnPath.scope.generateUidIdentifier(
110846
- `${gating.importSpecifierName}_result`
110846
+ const gatingCondition = t.identifier(
110847
+ programContext.newUid(`${gatingFunctionIdentifierName}_result`)
110847
110848
  );
110848
- const unoptimizedFnName = fnPath.scope.generateUidIdentifier(
110849
- `${originalFnName.name}_unoptimized`
110849
+ const unoptimizedFnName = t.identifier(
110850
+ programContext.newUid(`${originalFnName.name}_unoptimized`)
110850
110851
  );
110851
- const optimizedFnName = fnPath.scope.generateUidIdentifier(
110852
- `${originalFnName.name}_optimized`
110852
+ const optimizedFnName = t.identifier(
110853
+ programContext.newUid(`${originalFnName.name}_optimized`)
110853
110854
  );
110854
110855
  compiled.id.name = optimizedFnName.name;
110855
110856
  fnPath.get("id").replaceInline(unoptimizedFnName);
@@ -110892,24 +110893,30 @@ function insertAdditionalFunctionDeclaration(fnPath, compiled, gating) {
110892
110893
  t.variableDeclaration("const", [
110893
110894
  t.variableDeclarator(
110894
110895
  gatingCondition,
110895
- t.callExpression(t.identifier(gating.importSpecifierName), [])
110896
+ t.callExpression(t.identifier(gatingFunctionIdentifierName), [])
110896
110897
  )
110897
110898
  ])
110898
110899
  );
110899
110900
  fnPath.insertBefore(compiled);
110900
110901
  }
110901
- function insertGatedFunctionDeclaration(fnPath, compiled, gating, referencedBeforeDeclaration) {
110902
+ function insertGatedFunctionDeclaration(fnPath, compiled, programContext, gating, referencedBeforeDeclaration) {
110902
110903
  var _a;
110904
+ const gatingImportedName = programContext.addImportSpecifier(gating).name;
110903
110905
  if (referencedBeforeDeclaration && fnPath.isFunctionDeclaration()) {
110904
110906
  CompilerError.invariant(compiled.type === "FunctionDeclaration", {
110905
110907
  reason: "Expected compiled node type to match input type",
110906
110908
  description: `Got ${compiled.type} but expected FunctionDeclaration`,
110907
110909
  loc: (_a = fnPath.node.loc) != null ? _a : null
110908
110910
  });
110909
- insertAdditionalFunctionDeclaration(fnPath, compiled, gating);
110911
+ insertAdditionalFunctionDeclaration(
110912
+ fnPath,
110913
+ compiled,
110914
+ programContext,
110915
+ gatingImportedName
110916
+ );
110910
110917
  } else {
110911
110918
  const gatingExpression = t.conditionalExpression(
110912
- t.callExpression(t.identifier(gating.importSpecifierName), []),
110919
+ t.callExpression(t.identifier(gatingImportedName), []),
110913
110920
  buildFunctionExpression(compiled),
110914
110921
  buildFunctionExpression(fnPath.node)
110915
110922
  );
@@ -110955,7 +110962,7 @@ function buildFunctionExpression(node) {
110955
110962
  }
110956
110963
 
110957
110964
  // src/Entrypoint/Imports.ts
110958
- var t3 = __toESM(require("@babel/types"));
110965
+ var t4 = __toESM(require("@babel/types"));
110959
110966
 
110960
110967
  // src/HIR/HIR.ts
110961
110968
  var t2 = __toESM(require("@babel/types"));
@@ -114763,6 +114770,7 @@ var Effect = /* @__PURE__ */ ((Effect2) => {
114763
114770
  Effect2["Freeze"] = "freeze";
114764
114771
  Effect2["Read"] = "read";
114765
114772
  Effect2["Capture"] = "capture";
114773
+ Effect2["ConditionallyMutateIterator"] = "mutate-iterator?";
114766
114774
  Effect2["ConditionallyMutate"] = "mutate?";
114767
114775
  Effect2["Mutate"] = "mutate";
114768
114776
  Effect2["Store"] = "store";
@@ -114772,6 +114780,7 @@ var EffectSchema = z.enum([
114772
114780
  "read" /* Read */,
114773
114781
  "mutate" /* Mutate */,
114774
114782
  "mutate?" /* ConditionallyMutate */,
114783
+ "mutate-iterator?" /* ConditionallyMutateIterator */,
114775
114784
  "capture" /* Capture */,
114776
114785
  "store" /* Store */,
114777
114786
  "freeze" /* Freeze */
@@ -114781,6 +114790,7 @@ function isMutableEffect(effect, location) {
114781
114790
  case "capture" /* Capture */:
114782
114791
  case "store" /* Store */:
114783
114792
  case "mutate?" /* ConditionallyMutate */:
114793
+ case "mutate-iterator?" /* ConditionallyMutateIterator */:
114784
114794
  case "mutate" /* Mutate */: {
114785
114795
  return true;
114786
114796
  }
@@ -114882,6 +114892,12 @@ function isPrimitiveType(id) {
114882
114892
  function isArrayType(id) {
114883
114893
  return id.type.kind === "Object" && id.type.shapeId === "BuiltInArray";
114884
114894
  }
114895
+ function isMapType(id) {
114896
+ return id.type.kind === "Object" && id.type.shapeId === "BuiltInMap";
114897
+ }
114898
+ function isSetType(id) {
114899
+ return id.type.kind === "Object" && id.type.shapeId === "BuiltInSet";
114900
+ }
114885
114901
  function isPropsType(id) {
114886
114902
  return id.type.kind === "Object" && id.type.shapeId === "BuiltInProps";
114887
114903
  }
@@ -117561,6 +117577,7 @@ var HIRBuilder = class {
117561
117577
  type: makeType(),
117562
117578
  loc: (_b = node.loc) != null ? _b : GeneratedSource
117563
117579
  };
117580
+ __privateGet(this, _env).programContext.addNewReference(name);
117564
117581
  __privateGet(this, _bindings).set(name, { node, identifier: identifier4 });
117565
117582
  return identifier4;
117566
117583
  } else if (mapping.node === node) {
@@ -117994,7 +118011,7 @@ var nextAnonId = 0;
117994
118011
  function createAnonId() {
117995
118012
  return `<generated_${nextAnonId++}>`;
117996
118013
  }
117997
- function addFunction(registry, properties, fn, id = null) {
118014
+ function addFunction(registry, properties, fn, id = null, isConstructor = false) {
117998
118015
  const shapeId = id != null ? id : createAnonId();
117999
118016
  addShape(registry, shapeId, properties, __spreadProps(__spreadValues({}, fn), {
118000
118017
  hookKind: null
@@ -118002,7 +118019,8 @@ function addFunction(registry, properties, fn, id = null) {
118002
118019
  return {
118003
118020
  kind: "Function",
118004
118021
  return: fn.returnType,
118005
- shapeId
118022
+ shapeId,
118023
+ isConstructor
118006
118024
  };
118007
118025
  }
118008
118026
  function addHook(registry, fn, id = null) {
@@ -118011,7 +118029,8 @@ function addHook(registry, fn, id = null) {
118011
118029
  return {
118012
118030
  kind: "Function",
118013
118031
  return: fn.returnType,
118014
- shapeId
118032
+ shapeId,
118033
+ isConstructor: false
118015
118034
  };
118016
118035
  }
118017
118036
  function addObject(registry, id, properties) {
@@ -118038,6 +118057,8 @@ function addShape(registry, id, properties, functionType2) {
118038
118057
  }
118039
118058
  var BuiltInPropsId = "BuiltInProps";
118040
118059
  var BuiltInArrayId = "BuiltInArray";
118060
+ var BuiltInSetId = "BuiltInSet";
118061
+ var BuiltInMapId = "BuiltInMap";
118041
118062
  var BuiltInFunctionId = "BuiltInFunction";
118042
118063
  var BuiltInJsxId = "BuiltInJsx";
118043
118064
  var BuiltInObjectId = "BuiltInObject";
@@ -118282,6 +118303,311 @@ addObject(BUILTIN_SHAPES, BuiltInObjectId, [
118282
118303
  * hasOwnProperty, isPrototypeOf, propertyIsEnumerable, toLocaleString, valueOf
118283
118304
  */
118284
118305
  ]);
118306
+ addObject(BUILTIN_SHAPES, BuiltInSetId, [
118307
+ [
118308
+ /**
118309
+ * add(value)
118310
+ * Parameters
118311
+ * value: the value of the element to add to the Set object.
118312
+ * Returns the Set object with added value.
118313
+ */
118314
+ "add",
118315
+ addFunction(BUILTIN_SHAPES, [], {
118316
+ positionalParams: ["capture" /* Capture */],
118317
+ restParam: null,
118318
+ returnType: { kind: "Object", shapeId: BuiltInSetId },
118319
+ calleeEffect: "store" /* Store */,
118320
+ // returnValueKind is technically dependent on the ValueKind of the set itself
118321
+ returnValueKind: "mutable" /* Mutable */
118322
+ })
118323
+ ],
118324
+ [
118325
+ /**
118326
+ * clear()
118327
+ * Parameters none
118328
+ * Returns undefined
118329
+ */
118330
+ "clear",
118331
+ addFunction(BUILTIN_SHAPES, [], {
118332
+ positionalParams: [],
118333
+ restParam: null,
118334
+ returnType: PRIMITIVE_TYPE,
118335
+ calleeEffect: "store" /* Store */,
118336
+ returnValueKind: "primitive" /* Primitive */
118337
+ })
118338
+ ],
118339
+ [
118340
+ /**
118341
+ * setInstance.delete(value)
118342
+ * Returns true if value was already in Set; otherwise false.
118343
+ */
118344
+ "delete",
118345
+ addFunction(BUILTIN_SHAPES, [], {
118346
+ positionalParams: ["read" /* Read */],
118347
+ restParam: null,
118348
+ returnType: PRIMITIVE_TYPE,
118349
+ calleeEffect: "store" /* Store */,
118350
+ returnValueKind: "primitive" /* Primitive */
118351
+ })
118352
+ ],
118353
+ [
118354
+ "has",
118355
+ addFunction(BUILTIN_SHAPES, [], {
118356
+ positionalParams: ["read" /* Read */],
118357
+ restParam: null,
118358
+ returnType: PRIMITIVE_TYPE,
118359
+ calleeEffect: "read" /* Read */,
118360
+ returnValueKind: "primitive" /* Primitive */
118361
+ })
118362
+ ],
118363
+ ["size", PRIMITIVE_TYPE],
118364
+ [
118365
+ /**
118366
+ * difference(other)
118367
+ * Parameters
118368
+ * other: A Set object, or set-like object.
118369
+ * Returns a new Set object containing elements in this set but not in the other set.
118370
+ */
118371
+ "difference",
118372
+ addFunction(BUILTIN_SHAPES, [], {
118373
+ positionalParams: ["capture" /* Capture */],
118374
+ restParam: null,
118375
+ returnType: { kind: "Object", shapeId: BuiltInSetId },
118376
+ calleeEffect: "capture" /* Capture */,
118377
+ returnValueKind: "mutable" /* Mutable */
118378
+ })
118379
+ ],
118380
+ [
118381
+ /**
118382
+ * union(other)
118383
+ * Parameters
118384
+ * other: A Set object, or set-like object.
118385
+ * Returns a new Set object containing elements in either this set or the other set.
118386
+ */
118387
+ "union",
118388
+ addFunction(BUILTIN_SHAPES, [], {
118389
+ positionalParams: ["capture" /* Capture */],
118390
+ restParam: null,
118391
+ returnType: { kind: "Object", shapeId: BuiltInSetId },
118392
+ calleeEffect: "capture" /* Capture */,
118393
+ returnValueKind: "mutable" /* Mutable */
118394
+ })
118395
+ ],
118396
+ [
118397
+ /**
118398
+ * symmetricalDifference(other)
118399
+ * Parameters
118400
+ * other: A Set object, or set-like object.
118401
+ * A new Set object containing elements which are in either this set or the other set, but not in both.
118402
+ */
118403
+ "symmetricalDifference",
118404
+ addFunction(BUILTIN_SHAPES, [], {
118405
+ positionalParams: ["capture" /* Capture */],
118406
+ restParam: null,
118407
+ returnType: { kind: "Object", shapeId: BuiltInSetId },
118408
+ calleeEffect: "capture" /* Capture */,
118409
+ returnValueKind: "mutable" /* Mutable */
118410
+ })
118411
+ ],
118412
+ [
118413
+ /**
118414
+ * isSubsetOf(other)
118415
+ * Parameters
118416
+ * other: A Set object, or set-like object.
118417
+ * Returns true if all elements in this set are also in the other set, and false otherwise.
118418
+ */
118419
+ "isSubsetOf",
118420
+ addFunction(BUILTIN_SHAPES, [], {
118421
+ positionalParams: ["read" /* Read */],
118422
+ restParam: null,
118423
+ returnType: PRIMITIVE_TYPE,
118424
+ calleeEffect: "read" /* Read */,
118425
+ returnValueKind: "primitive" /* Primitive */
118426
+ })
118427
+ ],
118428
+ [
118429
+ /**
118430
+ * isSupersetOf(other)
118431
+ * Parameters
118432
+ * other: A Set object, or set-like object.
118433
+ * Returns true if all elements in the other set are also in this set, and false otherwise.
118434
+ */
118435
+ "isSupersetOf",
118436
+ addFunction(BUILTIN_SHAPES, [], {
118437
+ positionalParams: ["read" /* Read */],
118438
+ restParam: null,
118439
+ returnType: PRIMITIVE_TYPE,
118440
+ calleeEffect: "read" /* Read */,
118441
+ returnValueKind: "primitive" /* Primitive */
118442
+ })
118443
+ ],
118444
+ [
118445
+ /**
118446
+ * forEach(callbackFn)
118447
+ * forEach(callbackFn, thisArg)
118448
+ */
118449
+ "forEach",
118450
+ addFunction(BUILTIN_SHAPES, [], {
118451
+ /**
118452
+ * see Array.map explanation for why arguments are marked `ConditionallyMutate`
118453
+ */
118454
+ positionalParams: [],
118455
+ restParam: "mutate?" /* ConditionallyMutate */,
118456
+ returnType: PRIMITIVE_TYPE,
118457
+ calleeEffect: "mutate?" /* ConditionallyMutate */,
118458
+ returnValueKind: "primitive" /* Primitive */,
118459
+ noAlias: true,
118460
+ mutableOnlyIfOperandsAreMutable: true
118461
+ })
118462
+ ],
118463
+ /**
118464
+ * Iterators
118465
+ */
118466
+ [
118467
+ "entries",
118468
+ addFunction(BUILTIN_SHAPES, [], {
118469
+ positionalParams: [],
118470
+ restParam: null,
118471
+ returnType: { kind: "Poly" },
118472
+ calleeEffect: "capture" /* Capture */,
118473
+ returnValueKind: "mutable" /* Mutable */
118474
+ })
118475
+ ],
118476
+ [
118477
+ "keys",
118478
+ addFunction(BUILTIN_SHAPES, [], {
118479
+ positionalParams: [],
118480
+ restParam: null,
118481
+ returnType: { kind: "Poly" },
118482
+ calleeEffect: "capture" /* Capture */,
118483
+ returnValueKind: "mutable" /* Mutable */
118484
+ })
118485
+ ],
118486
+ [
118487
+ "values",
118488
+ addFunction(BUILTIN_SHAPES, [], {
118489
+ positionalParams: [],
118490
+ restParam: null,
118491
+ returnType: { kind: "Poly" },
118492
+ calleeEffect: "capture" /* Capture */,
118493
+ returnValueKind: "mutable" /* Mutable */
118494
+ })
118495
+ ]
118496
+ ]);
118497
+ addObject(BUILTIN_SHAPES, BuiltInMapId, [
118498
+ [
118499
+ /**
118500
+ * clear()
118501
+ * Parameters none
118502
+ * Returns undefined
118503
+ */
118504
+ "clear",
118505
+ addFunction(BUILTIN_SHAPES, [], {
118506
+ positionalParams: [],
118507
+ restParam: null,
118508
+ returnType: PRIMITIVE_TYPE,
118509
+ calleeEffect: "store" /* Store */,
118510
+ returnValueKind: "primitive" /* Primitive */
118511
+ })
118512
+ ],
118513
+ [
118514
+ "delete",
118515
+ addFunction(BUILTIN_SHAPES, [], {
118516
+ positionalParams: ["read" /* Read */],
118517
+ restParam: null,
118518
+ returnType: PRIMITIVE_TYPE,
118519
+ calleeEffect: "store" /* Store */,
118520
+ returnValueKind: "primitive" /* Primitive */
118521
+ })
118522
+ ],
118523
+ [
118524
+ "get",
118525
+ addFunction(BUILTIN_SHAPES, [], {
118526
+ positionalParams: ["read" /* Read */],
118527
+ restParam: null,
118528
+ returnType: { kind: "Poly" },
118529
+ calleeEffect: "capture" /* Capture */,
118530
+ returnValueKind: "mutable" /* Mutable */
118531
+ })
118532
+ ],
118533
+ [
118534
+ "has",
118535
+ addFunction(BUILTIN_SHAPES, [], {
118536
+ positionalParams: ["read" /* Read */],
118537
+ restParam: null,
118538
+ returnType: PRIMITIVE_TYPE,
118539
+ calleeEffect: "read" /* Read */,
118540
+ returnValueKind: "primitive" /* Primitive */
118541
+ })
118542
+ ],
118543
+ [
118544
+ /**
118545
+ * Params
118546
+ * key: the key of the element to add to the Map object. The key may be
118547
+ * any JavaScript type (any primitive value or any type of JavaScript
118548
+ * object).
118549
+ * value: the value of the element to add to the Map object.
118550
+ * Returns the Map object.
118551
+ */
118552
+ "set",
118553
+ addFunction(BUILTIN_SHAPES, [], {
118554
+ positionalParams: ["capture" /* Capture */, "capture" /* Capture */],
118555
+ restParam: null,
118556
+ returnType: { kind: "Object", shapeId: BuiltInMapId },
118557
+ calleeEffect: "store" /* Store */,
118558
+ returnValueKind: "mutable" /* Mutable */
118559
+ })
118560
+ ],
118561
+ ["size", PRIMITIVE_TYPE],
118562
+ [
118563
+ "forEach",
118564
+ addFunction(BUILTIN_SHAPES, [], {
118565
+ /**
118566
+ * see Array.map explanation for why arguments are marked `ConditionallyMutate`
118567
+ */
118568
+ positionalParams: [],
118569
+ restParam: "mutate?" /* ConditionallyMutate */,
118570
+ returnType: PRIMITIVE_TYPE,
118571
+ calleeEffect: "mutate?" /* ConditionallyMutate */,
118572
+ returnValueKind: "primitive" /* Primitive */,
118573
+ noAlias: true,
118574
+ mutableOnlyIfOperandsAreMutable: true
118575
+ })
118576
+ ],
118577
+ /**
118578
+ * Iterators
118579
+ */
118580
+ [
118581
+ "entries",
118582
+ addFunction(BUILTIN_SHAPES, [], {
118583
+ positionalParams: [],
118584
+ restParam: null,
118585
+ returnType: { kind: "Poly" },
118586
+ calleeEffect: "capture" /* Capture */,
118587
+ returnValueKind: "mutable" /* Mutable */
118588
+ })
118589
+ ],
118590
+ [
118591
+ "keys",
118592
+ addFunction(BUILTIN_SHAPES, [], {
118593
+ positionalParams: [],
118594
+ restParam: null,
118595
+ returnType: { kind: "Poly" },
118596
+ calleeEffect: "capture" /* Capture */,
118597
+ returnValueKind: "mutable" /* Mutable */
118598
+ })
118599
+ ],
118600
+ [
118601
+ "values",
118602
+ addFunction(BUILTIN_SHAPES, [], {
118603
+ positionalParams: [],
118604
+ restParam: null,
118605
+ returnType: { kind: "Poly" },
118606
+ calleeEffect: "capture" /* Capture */,
118607
+ returnValueKind: "mutable" /* Mutable */
118608
+ })
118609
+ ]
118610
+ ]);
118285
118611
  addObject(BUILTIN_SHAPES, BuiltInUseStateId, [
118286
118612
  ["0", { kind: "Poly" }],
118287
118613
  [
@@ -122561,29 +122887,23 @@ function fromZodError(zodError, options = {}) {
122561
122887
  // src/HIR/Globals.ts
122562
122888
  var DEFAULT_SHAPES = new Map(BUILTIN_SHAPES);
122563
122889
  var UNTYPED_GLOBALS = /* @__PURE__ */ new Set([
122564
- "String",
122565
122890
  "Object",
122566
122891
  "Function",
122567
- "Number",
122568
122892
  "RegExp",
122569
122893
  "Date",
122570
122894
  "Error",
122571
- "Function",
122572
122895
  "TypeError",
122573
122896
  "RangeError",
122574
122897
  "ReferenceError",
122575
122898
  "SyntaxError",
122576
122899
  "URIError",
122577
122900
  "EvalError",
122578
- "Boolean",
122579
122901
  "DataView",
122580
122902
  "Float32Array",
122581
122903
  "Float64Array",
122582
122904
  "Int8Array",
122583
122905
  "Int16Array",
122584
122906
  "Int32Array",
122585
- "Map",
122586
- "Set",
122587
122907
  "WeakMap",
122588
122908
  "Uint8Array",
122589
122909
  "Uint8ClampedArray",
@@ -122591,16 +122911,8 @@ var UNTYPED_GLOBALS = /* @__PURE__ */ new Set([
122591
122911
  "Uint32Array",
122592
122912
  "ArrayBuffer",
122593
122913
  "JSON",
122594
- "parseFloat",
122595
- "parseInt",
122596
122914
  "console",
122597
- "isNaN",
122598
- "eval",
122599
- "isFinite",
122600
- "encodeURI",
122601
- "decodeURI",
122602
- "encodeURIComponent",
122603
- "decodeURIComponent"
122915
+ "eval"
122604
122916
  ]);
122605
122917
  var TYPED_GLOBALS = [
122606
122918
  [
@@ -122615,6 +122927,23 @@ var TYPED_GLOBALS = [
122615
122927
  calleeEffect: "read" /* Read */,
122616
122928
  returnValueKind: "mutable" /* Mutable */
122617
122929
  })
122930
+ ],
122931
+ [
122932
+ /**
122933
+ * Object.fromEntries(iterable)
122934
+ * iterable: An iterable, such as an Array or Map, containing a list of
122935
+ * objects. Each object should have two properties.
122936
+ * Returns a new object whose properties are given by the entries of the
122937
+ * iterable.
122938
+ */
122939
+ "fromEntries",
122940
+ addFunction(DEFAULT_SHAPES, [], {
122941
+ positionalParams: ["mutate?" /* ConditionallyMutate */],
122942
+ restParam: null,
122943
+ returnType: { kind: "Object", shapeId: BuiltInObjectId },
122944
+ calleeEffect: "read" /* Read */,
122945
+ returnValueKind: "mutable" /* Mutable */
122946
+ })
122618
122947
  ]
122619
122948
  ])
122620
122949
  ],
@@ -122647,7 +122976,7 @@ var TYPED_GLOBALS = [
122647
122976
  "from",
122648
122977
  addFunction(DEFAULT_SHAPES, [], {
122649
122978
  positionalParams: [
122650
- "mutate?" /* ConditionallyMutate */,
122979
+ "mutate-iterator?" /* ConditionallyMutateIterator */,
122651
122980
  "mutate?" /* ConditionallyMutate */,
122652
122981
  "mutate?" /* ConditionallyMutate */
122653
122982
  ],
@@ -122892,6 +123221,118 @@ var TYPED_GLOBALS = [
122892
123221
  calleeEffect: "read" /* Read */,
122893
123222
  returnValueKind: "primitive" /* Primitive */
122894
123223
  })
123224
+ ],
123225
+ [
123226
+ "parseInt",
123227
+ addFunction(DEFAULT_SHAPES, [], {
123228
+ positionalParams: [],
123229
+ restParam: "read" /* Read */,
123230
+ returnType: { kind: "Primitive" },
123231
+ calleeEffect: "read" /* Read */,
123232
+ returnValueKind: "primitive" /* Primitive */
123233
+ })
123234
+ ],
123235
+ [
123236
+ "parseFloat",
123237
+ addFunction(DEFAULT_SHAPES, [], {
123238
+ positionalParams: [],
123239
+ restParam: "read" /* Read */,
123240
+ returnType: { kind: "Primitive" },
123241
+ calleeEffect: "read" /* Read */,
123242
+ returnValueKind: "primitive" /* Primitive */
123243
+ })
123244
+ ],
123245
+ [
123246
+ "isNaN",
123247
+ addFunction(DEFAULT_SHAPES, [], {
123248
+ positionalParams: [],
123249
+ restParam: "read" /* Read */,
123250
+ returnType: { kind: "Primitive" },
123251
+ calleeEffect: "read" /* Read */,
123252
+ returnValueKind: "primitive" /* Primitive */
123253
+ })
123254
+ ],
123255
+ [
123256
+ "isFinite",
123257
+ addFunction(DEFAULT_SHAPES, [], {
123258
+ positionalParams: [],
123259
+ restParam: "read" /* Read */,
123260
+ returnType: { kind: "Primitive" },
123261
+ calleeEffect: "read" /* Read */,
123262
+ returnValueKind: "primitive" /* Primitive */
123263
+ })
123264
+ ],
123265
+ [
123266
+ "encodeURI",
123267
+ addFunction(DEFAULT_SHAPES, [], {
123268
+ positionalParams: [],
123269
+ restParam: "read" /* Read */,
123270
+ returnType: { kind: "Primitive" },
123271
+ calleeEffect: "read" /* Read */,
123272
+ returnValueKind: "primitive" /* Primitive */
123273
+ })
123274
+ ],
123275
+ [
123276
+ "encodeURIComponent",
123277
+ addFunction(DEFAULT_SHAPES, [], {
123278
+ positionalParams: [],
123279
+ restParam: "read" /* Read */,
123280
+ returnType: { kind: "Primitive" },
123281
+ calleeEffect: "read" /* Read */,
123282
+ returnValueKind: "primitive" /* Primitive */
123283
+ })
123284
+ ],
123285
+ [
123286
+ "decodeURI",
123287
+ addFunction(DEFAULT_SHAPES, [], {
123288
+ positionalParams: [],
123289
+ restParam: "read" /* Read */,
123290
+ returnType: { kind: "Primitive" },
123291
+ calleeEffect: "read" /* Read */,
123292
+ returnValueKind: "primitive" /* Primitive */
123293
+ })
123294
+ ],
123295
+ [
123296
+ "decodeURIComponent",
123297
+ addFunction(DEFAULT_SHAPES, [], {
123298
+ positionalParams: [],
123299
+ restParam: "read" /* Read */,
123300
+ returnType: { kind: "Primitive" },
123301
+ calleeEffect: "read" /* Read */,
123302
+ returnValueKind: "primitive" /* Primitive */
123303
+ })
123304
+ ],
123305
+ [
123306
+ "Map",
123307
+ addFunction(
123308
+ DEFAULT_SHAPES,
123309
+ [],
123310
+ {
123311
+ positionalParams: ["mutate-iterator?" /* ConditionallyMutateIterator */],
123312
+ restParam: null,
123313
+ returnType: { kind: "Object", shapeId: BuiltInMapId },
123314
+ calleeEffect: "read" /* Read */,
123315
+ returnValueKind: "mutable" /* Mutable */
123316
+ },
123317
+ null,
123318
+ true
123319
+ )
123320
+ ],
123321
+ [
123322
+ "Set",
123323
+ addFunction(
123324
+ DEFAULT_SHAPES,
123325
+ [],
123326
+ {
123327
+ positionalParams: ["mutate-iterator?" /* ConditionallyMutateIterator */],
123328
+ restParam: null,
123329
+ returnType: { kind: "Object", shapeId: BuiltInSetId },
123330
+ calleeEffect: "read" /* Read */,
123331
+ returnValueKind: "mutable" /* Mutable */
123332
+ },
123333
+ null,
123334
+ true
123335
+ )
122895
123336
  ]
122896
123337
  // TODO: rest of Global objects
122897
123338
  ];
@@ -123385,6 +123826,8 @@ var InstrumentationSchema = z.object({
123385
123826
  (opts) => opts.gating != null || opts.globalGating != null,
123386
123827
  "Expected at least one of gating or globalGating"
123387
123828
  );
123829
+ var USE_FIRE_FUNCTION_NAME = "useFire";
123830
+ var EMIT_FREEZE_GLOBAL_GATING = "__DEV__";
123388
123831
  var MacroMethodSchema = z.union([
123389
123832
  z.object({ type: z.literal("wildcard") }),
123390
123833
  z.object({ type: z.literal("name"), name: z.string() })
@@ -124009,7 +124452,7 @@ function parseConfigPragmaForTests(pragma, defaults) {
124009
124452
  }
124010
124453
  var _globals, _shapes, _moduleTypes, _nextIdentifer, _nextBlock, _nextScope, _scope, _outlinedFunctions, _contextIdentifiers, _hoistedIdentifiers, _Environment_instances, resolveModuleType_fn, isKnownReactModule_fn, getCustomHookType_fn;
124011
124454
  var Environment = class {
124012
- constructor(scope, fnType, compilerMode, config, contextIdentifiers, logger, filename, code, useMemoCacheIdentifier) {
124455
+ constructor(scope, fnType, compilerMode, config, contextIdentifiers, logger, filename, code, programContext) {
124013
124456
  __privateAdd(this, _Environment_instances);
124014
124457
  __privateAdd(this, _globals);
124015
124458
  __privateAdd(this, _shapes);
@@ -124028,11 +124471,11 @@ var Environment = class {
124028
124471
  this.filename = filename;
124029
124472
  this.code = code;
124030
124473
  this.logger = logger;
124031
- this.useMemoCacheIdentifier = useMemoCacheIdentifier;
124474
+ this.programContext = programContext;
124032
124475
  __privateSet(this, _shapes, new Map(DEFAULT_SHAPES));
124033
124476
  __privateSet(this, _globals, new Map(DEFAULT_GLOBALS));
124034
- this.hasLoweredContextAccess = false;
124035
124477
  this.hasFireRewrite = false;
124478
+ this.hasInferredEffect = false;
124036
124479
  if (config.disableMemoizationForDebugging && config.enableChangeDetectionForDebugging != null) {
124037
124480
  CompilerError.throwInvalidConfig({
124038
124481
  reason: `Invalid environment config: the 'disableMemoizationForDebugging' and 'enableChangeDetectionForDebugging' options cannot be used together`,
@@ -124080,6 +124523,9 @@ var Environment = class {
124080
124523
  get nextScopeId() {
124081
124524
  return makeScopeId(__privateWrapper(this, _nextScope)._++);
124082
124525
  }
124526
+ get scope() {
124527
+ return __privateGet(this, _scope);
124528
+ }
124083
124529
  logErrors(errors) {
124084
124530
  if (errors.isOk() || this.logger == null) {
124085
124531
  return;
@@ -124630,7 +125076,7 @@ function isMutable2(instr, place) {
124630
125076
  function inRange({ id }, range) {
124631
125077
  return id >= range.start && id < range.end;
124632
125078
  }
124633
- function mayAllocate(_env5, instruction) {
125079
+ function mayAllocate(_env4, instruction) {
124634
125080
  const { value } = instruction;
124635
125081
  switch (value.kind) {
124636
125082
  case "Destructure": {
@@ -124968,260 +125414,14 @@ function pruneUnusedLabelsHIR(fn) {
124968
125414
  }
124969
125415
  }
124970
125416
 
124971
- // src/Entrypoint/Imports.ts
124972
- function validateRestrictedImports(path, { validateBlocklistedImports }) {
124973
- if (validateBlocklistedImports == null || validateBlocklistedImports.length === 0) {
124974
- return null;
124975
- }
124976
- const error = new CompilerError();
124977
- const restrictedImports = new Set(validateBlocklistedImports);
124978
- path.traverse({
124979
- ImportDeclaration(importDeclPath) {
124980
- var _a;
124981
- if (restrictedImports.has(importDeclPath.node.source.value)) {
124982
- error.push({
124983
- severity: "Todo" /* Todo */,
124984
- reason: "Bailing out due to blocklisted import",
124985
- description: `Import from module ${importDeclPath.node.source.value}`,
124986
- loc: (_a = importDeclPath.node.loc) != null ? _a : null
124987
- });
124988
- }
124989
- }
124990
- });
124991
- if (error.hasErrors()) {
124992
- return error;
124993
- } else {
124994
- return null;
124995
- }
124996
- }
124997
- function addImportsToProgram(path, importList) {
124998
- const identifiers = /* @__PURE__ */ new Set();
124999
- const sortedImports = /* @__PURE__ */ new Map();
125000
- for (const { importSpecifierName, source: source2 } of importList) {
125001
- CompilerError.invariant(identifiers.has(importSpecifierName) === false, {
125002
- reason: `Encountered conflicting import specifier for ${importSpecifierName} in Forget config.`,
125003
- description: null,
125004
- loc: GeneratedSource,
125005
- suggestions: null
125006
- });
125007
- CompilerError.invariant(
125008
- path.scope.hasBinding(importSpecifierName) === false,
125009
- {
125010
- reason: `Encountered conflicting import specifiers for ${importSpecifierName} in generated program.`,
125011
- description: null,
125012
- loc: GeneratedSource,
125013
- suggestions: null
125014
- }
125015
- );
125016
- identifiers.add(importSpecifierName);
125017
- const importSpecifierNameList = getOrInsertDefault(
125018
- sortedImports,
125019
- source2,
125020
- []
125021
- );
125022
- importSpecifierNameList.push(importSpecifierName);
125023
- }
125024
- const stmts = [];
125025
- for (const [source2, importSpecifierNameList] of sortedImports) {
125026
- const importSpecifiers = importSpecifierNameList.map((name) => {
125027
- const id = t3.identifier(name);
125028
- return t3.importSpecifier(id, id);
125029
- });
125030
- stmts.push(t3.importDeclaration(importSpecifiers, t3.stringLiteral(source2)));
125031
- }
125032
- path.unshiftContainer("body", stmts);
125033
- }
125034
- function isNonNamespacedImport(importDeclPath, moduleName) {
125035
- return importDeclPath.get("source").node.value === moduleName && importDeclPath.get("specifiers").every((specifier) => specifier.isImportSpecifier()) && importDeclPath.node.importKind !== "type" && importDeclPath.node.importKind !== "typeof";
125036
- }
125037
- function hasExistingNonNamespacedImportOfModule(program, moduleName) {
125038
- let hasExistingImport = false;
125039
- program.traverse({
125040
- ImportDeclaration(importDeclPath) {
125041
- if (isNonNamespacedImport(importDeclPath, moduleName)) {
125042
- hasExistingImport = true;
125043
- }
125044
- }
125045
- });
125046
- return hasExistingImport;
125047
- }
125048
- function addMemoCacheFunctionSpecifierToExistingImport(program, moduleName, identifierName) {
125049
- let didInsertUseMemoCache = false;
125050
- program.traverse({
125051
- ImportDeclaration(importDeclPath) {
125052
- if (!didInsertUseMemoCache && isNonNamespacedImport(importDeclPath, moduleName)) {
125053
- importDeclPath.pushContainer(
125054
- "specifiers",
125055
- t3.importSpecifier(t3.identifier(identifierName), t3.identifier("c"))
125056
- );
125057
- didInsertUseMemoCache = true;
125058
- }
125059
- }
125060
- });
125061
- return didInsertUseMemoCache;
125062
- }
125063
- function updateMemoCacheFunctionImport(program, moduleName, useMemoCacheIdentifier) {
125064
- const hasExistingImport = hasExistingNonNamespacedImportOfModule(
125065
- program,
125066
- moduleName
125067
- );
125068
- if (hasExistingImport) {
125069
- const didUpdateImport = addMemoCacheFunctionSpecifierToExistingImport(
125070
- program,
125071
- moduleName,
125072
- useMemoCacheIdentifier
125073
- );
125074
- if (!didUpdateImport) {
125075
- throw new Error(
125076
- `Expected an ImportDeclaration of \`${moduleName}\` in order to update ImportSpecifiers with useMemoCache`
125077
- );
125078
- }
125079
- } else {
125080
- addMemoCacheFunctionImportDeclaration(
125081
- program,
125082
- moduleName,
125083
- useMemoCacheIdentifier
125084
- );
125085
- }
125086
- }
125087
- function addMemoCacheFunctionImportDeclaration(program, moduleName, localName) {
125088
- program.unshiftContainer(
125089
- "body",
125090
- t3.importDeclaration(
125091
- [t3.importSpecifier(t3.identifier(localName), t3.identifier("c"))],
125092
- t3.stringLiteral(moduleName)
125093
- )
125094
- );
125417
+ // src/Utils/ComponentDeclaration.ts
125418
+ function isComponentDeclaration(node) {
125419
+ return Object.prototype.hasOwnProperty.call(node, "__componentDeclaration");
125095
125420
  }
125096
125421
 
125097
- // src/Entrypoint/Options.ts
125098
- var PanicThresholdOptionsSchema = z.enum([
125099
- /*
125100
- * Any errors will panic the compiler by throwing an exception, which will
125101
- * bubble up to the nearest exception handler above the Forget transform.
125102
- * If Forget is invoked through `BabelPluginReactCompiler`, this will at the least
125103
- * skip Forget compilation for the rest of current file.
125104
- */
125105
- "all_errors",
125106
- /*
125107
- * Panic by throwing an exception only on critical or unrecognized errors.
125108
- * For all other errors, skip the erroring function without inserting
125109
- * a Forget-compiled version (i.e. same behavior as noEmit).
125110
- */
125111
- "critical_errors",
125112
- // Never panic by throwing an exception.
125113
- "none"
125114
- ]);
125115
- var CompilerReactTargetSchema = z.union([
125116
- z.literal("17"),
125117
- z.literal("18"),
125118
- z.literal("19"),
125119
- /**
125120
- * Used exclusively for Meta apps which are guaranteed to have compatible
125121
- * react runtime and compiler versions. Note that only the FB-internal bundles
125122
- * re-export useMemoCache (see
125123
- * https://github.com/facebook/react/blob/5b0ef217ef32333a8e56f39be04327c89efa346f/packages/react/index.fb.js#L68-L70),
125124
- * so this option is invalid / creates runtime errors for open-source users.
125125
- */
125126
- z.object({
125127
- kind: z.literal("donotuse_meta_internal"),
125128
- runtimeModule: z.string().default("react")
125129
- })
125130
- ]);
125131
- var CompilationModeSchema = z.enum([
125132
- /*
125133
- * Compiles functions annotated with "use forget" or component/hook-like functions.
125134
- * This latter includes:
125135
- * * Components declared with component syntax.
125136
- * * Functions which can be inferred to be a component or hook:
125137
- * - Be named like a hook or component. This logic matches the ESLint rule.
125138
- * - *and* create JSX and/or call a hook. This is an additional check to help prevent
125139
- * false positives, since compilation has a greater impact than linting.
125140
- * This is the default mode
125141
- */
125142
- "infer",
125143
- // Compile only components using Flow component syntax and hooks using hook syntax.
125144
- "syntax",
125145
- // Compile only functions which are explicitly annotated with "use forget"
125146
- "annotation",
125147
- // Compile all top-level functions
125148
- "all"
125149
- ]);
125150
- var defaultOptions = {
125151
- compilationMode: "infer",
125152
- panicThreshold: "none",
125153
- environment: parseEnvironmentConfig({}).unwrap(),
125154
- logger: null,
125155
- gating: null,
125156
- noEmit: false,
125157
- eslintSuppressionRules: null,
125158
- flowSuppressions: true,
125159
- ignoreUseNoForget: false,
125160
- sources: (filename) => {
125161
- return filename.indexOf("node_modules") === -1;
125162
- },
125163
- enableReanimatedCheck: true,
125164
- target: "19"
125165
- };
125166
- function parsePluginOptions(obj) {
125167
- if (obj == null || typeof obj !== "object") {
125168
- return defaultOptions;
125169
- }
125170
- const parsedOptions = /* @__PURE__ */ Object.create(null);
125171
- for (let [key2, value] of Object.entries(obj)) {
125172
- if (typeof value === "string") {
125173
- value = value.toLowerCase();
125174
- }
125175
- if (isCompilerFlag(key2)) {
125176
- switch (key2) {
125177
- case "environment": {
125178
- const environmentResult = parseEnvironmentConfig(value);
125179
- if (environmentResult.isErr()) {
125180
- CompilerError.throwInvalidConfig({
125181
- reason: "Error in validating environment config. This is an advanced setting and not meant to be used directly",
125182
- description: environmentResult.unwrapErr().toString(),
125183
- suggestions: null,
125184
- loc: null
125185
- });
125186
- }
125187
- parsedOptions[key2] = environmentResult.unwrap();
125188
- break;
125189
- }
125190
- case "target": {
125191
- parsedOptions[key2] = parseTargetConfig(value);
125192
- break;
125193
- }
125194
- case "gating": {
125195
- if (value == null) {
125196
- parsedOptions[key2] = null;
125197
- } else {
125198
- parsedOptions[key2] = tryParseExternalFunction(value);
125199
- }
125200
- break;
125201
- }
125202
- default: {
125203
- parsedOptions[key2] = value;
125204
- }
125205
- }
125206
- }
125207
- }
125208
- return __spreadValues(__spreadValues({}, defaultOptions), parsedOptions);
125209
- }
125210
- function parseTargetConfig(value) {
125211
- const parsed = CompilerReactTargetSchema.safeParse(value);
125212
- if (parsed.success) {
125213
- return parsed.data;
125214
- } else {
125215
- CompilerError.throwInvalidConfig({
125216
- reason: "Not a valid target",
125217
- description: `${fromZodError(parsed.error)}`,
125218
- suggestions: null,
125219
- loc: null
125220
- });
125221
- }
125222
- }
125223
- function isCompilerFlag(s) {
125224
- return hasOwnProperty2(defaultOptions, s);
125422
+ // src/Utils/HookDeclaration.ts
125423
+ function isHookDeclaration(node) {
125424
+ return Object.prototype.hasOwnProperty.call(node, "__hookDeclaration");
125225
125425
  }
125226
125426
 
125227
125427
  // src/Entrypoint/Pipeline.ts
@@ -129030,7 +129230,7 @@ _catchHandlers = new WeakMap();
129030
129230
  _controlFlowStack = new WeakMap();
129031
129231
 
129032
129232
  // src/ReactiveScopes/CodegenReactiveFunction.ts
129033
- var t4 = __toESM(require("@babel/types"));
129233
+ var t3 = __toESM(require("@babel/types"));
129034
129234
  var import_crypto = require("crypto");
129035
129235
 
129036
129236
  // src/ReactiveScopes/MemoizeFbtAndMacroOperandsInSameScope.ts
@@ -129196,9 +129396,10 @@ function codegenFunction(fn, {
129196
129396
  const compiled = compileResult.unwrap();
129197
129397
  const hookGuard = fn.env.config.enableEmitHookGuards;
129198
129398
  if (hookGuard != null && fn.env.isInferredMemoEnabled) {
129199
- compiled.body = t4.blockStatement([
129399
+ compiled.body = t3.blockStatement([
129200
129400
  createHookGuard(
129201
129401
  hookGuard,
129402
+ fn.env.programContext,
129202
129403
  compiled.body.body,
129203
129404
  0 /* PushHookGuard */,
129204
129405
  1 /* PopHookGuard */
@@ -129208,12 +129409,13 @@ function codegenFunction(fn, {
129208
129409
  const cacheCount = compiled.memoSlotsUsed;
129209
129410
  if (cacheCount !== 0) {
129210
129411
  const preface = [];
129412
+ const useMemoCacheIdentifier = fn.env.programContext.addMemoCacheImport().name;
129211
129413
  preface.push(
129212
- t4.variableDeclaration("const", [
129213
- t4.variableDeclarator(
129214
- t4.identifier(cx.synthesizeName("$")),
129215
- t4.callExpression(t4.identifier(fn.env.useMemoCacheIdentifier), [
129216
- t4.numericLiteral(cacheCount)
129414
+ t3.variableDeclaration("const", [
129415
+ t3.variableDeclarator(
129416
+ t3.identifier(cx.synthesizeName("$")),
129417
+ t3.callExpression(t3.identifier(useMemoCacheIdentifier), [
129418
+ t3.numericLiteral(cacheCount)
129217
129419
  ])
129218
129420
  )
129219
129421
  ])
@@ -129221,60 +129423,60 @@ function codegenFunction(fn, {
129221
129423
  if (fastRefreshState !== null) {
129222
129424
  const index = cx.synthesizeName("$i");
129223
129425
  preface.push(
129224
- t4.ifStatement(
129225
- t4.binaryExpression(
129426
+ t3.ifStatement(
129427
+ t3.binaryExpression(
129226
129428
  "!==",
129227
- t4.memberExpression(
129228
- t4.identifier(cx.synthesizeName("$")),
129229
- t4.numericLiteral(fastRefreshState.cacheIndex),
129429
+ t3.memberExpression(
129430
+ t3.identifier(cx.synthesizeName("$")),
129431
+ t3.numericLiteral(fastRefreshState.cacheIndex),
129230
129432
  true
129231
129433
  ),
129232
- t4.stringLiteral(fastRefreshState.hash)
129434
+ t3.stringLiteral(fastRefreshState.hash)
129233
129435
  ),
129234
- t4.blockStatement([
129235
- t4.forStatement(
129236
- t4.variableDeclaration("let", [
129237
- t4.variableDeclarator(t4.identifier(index), t4.numericLiteral(0))
129436
+ t3.blockStatement([
129437
+ t3.forStatement(
129438
+ t3.variableDeclaration("let", [
129439
+ t3.variableDeclarator(t3.identifier(index), t3.numericLiteral(0))
129238
129440
  ]),
129239
- t4.binaryExpression(
129441
+ t3.binaryExpression(
129240
129442
  "<",
129241
- t4.identifier(index),
129242
- t4.numericLiteral(cacheCount)
129443
+ t3.identifier(index),
129444
+ t3.numericLiteral(cacheCount)
129243
129445
  ),
129244
- t4.assignmentExpression(
129446
+ t3.assignmentExpression(
129245
129447
  "+=",
129246
- t4.identifier(index),
129247
- t4.numericLiteral(1)
129448
+ t3.identifier(index),
129449
+ t3.numericLiteral(1)
129248
129450
  ),
129249
- t4.blockStatement([
129250
- t4.expressionStatement(
129251
- t4.assignmentExpression(
129451
+ t3.blockStatement([
129452
+ t3.expressionStatement(
129453
+ t3.assignmentExpression(
129252
129454
  "=",
129253
- t4.memberExpression(
129254
- t4.identifier(cx.synthesizeName("$")),
129255
- t4.identifier(index),
129455
+ t3.memberExpression(
129456
+ t3.identifier(cx.synthesizeName("$")),
129457
+ t3.identifier(index),
129256
129458
  true
129257
129459
  ),
129258
- t4.callExpression(
129259
- t4.memberExpression(
129260
- t4.identifier("Symbol"),
129261
- t4.identifier("for")
129460
+ t3.callExpression(
129461
+ t3.memberExpression(
129462
+ t3.identifier("Symbol"),
129463
+ t3.identifier("for")
129262
129464
  ),
129263
- [t4.stringLiteral(MEMO_CACHE_SENTINEL)]
129465
+ [t3.stringLiteral(MEMO_CACHE_SENTINEL)]
129264
129466
  )
129265
129467
  )
129266
129468
  )
129267
129469
  ])
129268
129470
  ),
129269
- t4.expressionStatement(
129270
- t4.assignmentExpression(
129471
+ t3.expressionStatement(
129472
+ t3.assignmentExpression(
129271
129473
  "=",
129272
- t4.memberExpression(
129273
- t4.identifier(cx.synthesizeName("$")),
129274
- t4.numericLiteral(fastRefreshState.cacheIndex),
129474
+ t3.memberExpression(
129475
+ t3.identifier(cx.synthesizeName("$")),
129476
+ t3.numericLiteral(fastRefreshState.cacheIndex),
129275
129477
  true
129276
129478
  ),
129277
- t4.stringLiteral(fastRefreshState.hash)
129479
+ t3.stringLiteral(fastRefreshState.hash)
129278
129480
  )
129279
129481
  )
129280
129482
  ])
@@ -129285,30 +129487,43 @@ function codegenFunction(fn, {
129285
129487
  }
129286
129488
  const emitInstrumentForget = fn.env.config.enableEmitInstrumentForget;
129287
129489
  if (emitInstrumentForget != null && fn.id != null && fn.env.isInferredMemoEnabled) {
129288
- let gating;
129289
- if (emitInstrumentForget.gating != null && emitInstrumentForget.globalGating != null) {
129290
- gating = t4.logicalExpression(
129291
- "&&",
129292
- t4.identifier(emitInstrumentForget.globalGating),
129293
- t4.identifier(emitInstrumentForget.gating.importSpecifierName)
129490
+ const gating = emitInstrumentForget.gating != null ? t3.identifier(
129491
+ fn.env.programContext.addImportSpecifier(
129492
+ emitInstrumentForget.gating
129493
+ ).name
129494
+ ) : null;
129495
+ const globalGating = emitInstrumentForget.globalGating != null ? t3.identifier(emitInstrumentForget.globalGating) : null;
129496
+ if (emitInstrumentForget.globalGating != null) {
129497
+ const assertResult = fn.env.programContext.assertGlobalBinding(
129498
+ emitInstrumentForget.globalGating
129294
129499
  );
129295
- } else if (emitInstrumentForget.gating != null) {
129296
- gating = t4.identifier(emitInstrumentForget.gating.importSpecifierName);
129500
+ if (assertResult.isErr()) {
129501
+ return assertResult;
129502
+ }
129503
+ }
129504
+ let ifTest;
129505
+ if (gating != null && globalGating != null) {
129506
+ ifTest = t3.logicalExpression("&&", globalGating, gating);
129507
+ } else if (gating != null) {
129508
+ ifTest = gating;
129297
129509
  } else {
129298
- CompilerError.invariant(emitInstrumentForget.globalGating != null, {
129510
+ CompilerError.invariant(globalGating != null, {
129299
129511
  reason: "Bad config not caught! Expected at least one of gating or globalGating",
129300
129512
  loc: null,
129301
129513
  suggestions: null
129302
129514
  });
129303
- gating = t4.identifier(emitInstrumentForget.globalGating);
129304
- }
129305
- const test = t4.ifStatement(
129306
- gating,
129307
- t4.expressionStatement(
129308
- t4.callExpression(
129309
- t4.identifier(emitInstrumentForget.fn.importSpecifierName),
129310
- [t4.stringLiteral(fn.id), t4.stringLiteral((_b = fn.env.filename) != null ? _b : "")]
129311
- )
129515
+ ifTest = globalGating;
129516
+ }
129517
+ const instrumentFnIdentifier = fn.env.programContext.addImportSpecifier(
129518
+ emitInstrumentForget.fn
129519
+ ).name;
129520
+ const test = t3.ifStatement(
129521
+ ifTest,
129522
+ t3.expressionStatement(
129523
+ t3.callExpression(t3.identifier(instrumentFnIdentifier), [
129524
+ t3.stringLiteral(fn.id),
129525
+ t3.stringLiteral((_b = fn.env.filename) != null ? _b : "")
129526
+ ])
129312
129527
  )
129313
129528
  );
129314
129529
  compiled.body.body.unshift(test);
@@ -129347,7 +129562,7 @@ function codegenReactiveFunction(cx, fn) {
129347
129562
  }
129348
129563
  const params = fn.params.map((param) => convertParameter(param));
129349
129564
  const body = codegenBlock(cx, fn.body);
129350
- body.directives = fn.directives.map((d) => t4.directive(t4.directiveLiteral(d)));
129565
+ body.directives = fn.directives.map((d) => t3.directive(t3.directiveLiteral(d)));
129351
129566
  const statements = body.body;
129352
129567
  if (statements.length !== 0) {
129353
129568
  const last = statements[statements.length - 1];
@@ -129363,7 +129578,7 @@ function codegenReactiveFunction(cx, fn) {
129363
129578
  return Ok({
129364
129579
  type: "CodegenFunction",
129365
129580
  loc: fn.loc,
129366
- id: fn.id !== null ? t4.identifier(fn.id) : null,
129581
+ id: fn.id !== null ? t3.identifier(fn.id) : null,
129367
129582
  params,
129368
129583
  body,
129369
129584
  generator: fn.generator,
@@ -129374,8 +129589,8 @@ function codegenReactiveFunction(cx, fn) {
129374
129589
  prunedMemoBlocks: countMemoBlockVisitor.prunedMemoBlocks,
129375
129590
  prunedMemoValues: countMemoBlockVisitor.prunedMemoValues,
129376
129591
  outlined: [],
129377
- hasLoweredContextAccess: fn.env.hasLoweredContextAccess,
129378
- hasFireRewrite: fn.env.hasFireRewrite
129592
+ hasFireRewrite: fn.env.hasFireRewrite,
129593
+ hasInferredEffect: fn.env.hasInferredEffect
129379
129594
  });
129380
129595
  }
129381
129596
  var CountMemoBlockVisitor = class extends ReactiveFunctionVisitor {
@@ -129402,7 +129617,7 @@ function convertParameter(param) {
129402
129617
  if (param.kind === "Identifier") {
129403
129618
  return convertIdentifier(param.identifier);
129404
129619
  } else {
129405
- return t4.restElement(convertIdentifier(param.place.identifier));
129620
+ return t3.restElement(convertIdentifier(param.place.identifier));
129406
129621
  }
129407
129622
  }
129408
129623
  var _nextCacheIndex, _declarations;
@@ -129496,8 +129711,8 @@ function codegenBlockNoReset(cx, block) {
129496
129711
  if (item.label !== null && !item.label.implicit) {
129497
129712
  const block2 = statement.type === "BlockStatement" && statement.body.length === 1 ? statement.body[0] : statement;
129498
129713
  statements.push(
129499
- t4.labeledStatement(
129500
- t4.identifier(codegenLabel(item.label.id)),
129714
+ t3.labeledStatement(
129715
+ t3.identifier(codegenLabel(item.label.id)),
129501
129716
  block2
129502
129717
  )
129503
129718
  );
@@ -129516,16 +129731,20 @@ function codegenBlockNoReset(cx, block) {
129516
129731
  }
129517
129732
  }
129518
129733
  }
129519
- return t4.blockStatement(statements);
129734
+ return t3.blockStatement(statements);
129520
129735
  }
129521
129736
  function wrapCacheDep(cx, value) {
129522
129737
  if (cx.env.config.enableEmitFreeze != null && cx.env.isInferredMemoEnabled) {
129523
- return t4.conditionalExpression(
129524
- t4.identifier("__DEV__"),
129525
- t4.callExpression(
129526
- t4.identifier(cx.env.config.enableEmitFreeze.importSpecifierName),
129527
- [value, t4.stringLiteral(cx.fnName)]
129528
- ),
129738
+ const emitFreezeIdentifier = cx.env.programContext.addImportSpecifier(
129739
+ cx.env.config.enableEmitFreeze
129740
+ ).name;
129741
+ cx.env.programContext.assertGlobalBinding(EMIT_FREEZE_GLOBAL_GATING, cx.env.scope).unwrap();
129742
+ return t3.conditionalExpression(
129743
+ t3.identifier(EMIT_FREEZE_GLOBAL_GATING),
129744
+ t3.callExpression(t3.identifier(emitFreezeIdentifier), [
129745
+ value,
129746
+ t3.stringLiteral(cx.fnName)
129747
+ ]),
129529
129748
  value
129530
129749
  );
129531
129750
  } else {
@@ -129542,20 +129761,20 @@ function codegenReactiveScope(cx, statements, scope, block) {
129542
129761
  for (const dep of [...scope.dependencies].sort(compareScopeDependency)) {
129543
129762
  const index = cx.nextCacheIndex;
129544
129763
  changeExpressionComments.push(printDependencyComment(dep));
129545
- const comparison = t4.binaryExpression(
129764
+ const comparison = t3.binaryExpression(
129546
129765
  "!==",
129547
- t4.memberExpression(
129548
- t4.identifier(cx.synthesizeName("$")),
129549
- t4.numericLiteral(index),
129766
+ t3.memberExpression(
129767
+ t3.identifier(cx.synthesizeName("$")),
129768
+ t3.numericLiteral(index),
129550
129769
  true
129551
129770
  ),
129552
129771
  codegenDependency(cx, dep)
129553
129772
  );
129554
129773
  if (cx.env.config.enableChangeVariableCodegen) {
129555
- const changeIdentifier = t4.identifier(cx.synthesizeName(`c_${index}`));
129774
+ const changeIdentifier = t3.identifier(cx.synthesizeName(`c_${index}`));
129556
129775
  statements.push(
129557
- t4.variableDeclaration("const", [
129558
- t4.variableDeclarator(changeIdentifier, comparison)
129776
+ t3.variableDeclaration("const", [
129777
+ t3.variableDeclarator(changeIdentifier, comparison)
129559
129778
  ])
129560
129779
  );
129561
129780
  changeExpressions.push(changeIdentifier);
@@ -129563,12 +129782,12 @@ function codegenReactiveScope(cx, statements, scope, block) {
129563
129782
  changeExpressions.push(comparison);
129564
129783
  }
129565
129784
  cacheStoreStatements.push(
129566
- t4.expressionStatement(
129567
- t4.assignmentExpression(
129785
+ t3.expressionStatement(
129786
+ t3.assignmentExpression(
129568
129787
  "=",
129569
- t4.memberExpression(
129570
- t4.identifier(cx.synthesizeName("$")),
129571
- t4.numericLiteral(index),
129788
+ t3.memberExpression(
129789
+ t3.identifier(cx.synthesizeName("$")),
129790
+ t3.numericLiteral(index),
129572
129791
  true
129573
129792
  ),
129574
129793
  codegenDependency(cx, dep)
@@ -129596,7 +129815,7 @@ function codegenReactiveScope(cx, statements, scope, block) {
129596
129815
  outputComments.push(name.name);
129597
129816
  if (!cx.hasDeclared(identifier4)) {
129598
129817
  statements.push(
129599
- t4.variableDeclaration("let", [t4.variableDeclarator(name)])
129818
+ t3.variableDeclaration("let", [t3.variableDeclarator(name)])
129600
129819
  );
129601
129820
  }
129602
129821
  cacheLoads.push({ name, index, value: wrapCacheDep(cx, name) });
@@ -129616,7 +129835,7 @@ function codegenReactiveScope(cx, statements, scope, block) {
129616
129835
  if (acc == null) {
129617
129836
  return ident;
129618
129837
  }
129619
- return t4.logicalExpression("||", acc, ident);
129838
+ return t3.logicalExpression("||", acc, ident);
129620
129839
  },
129621
129840
  null
129622
129841
  );
@@ -129627,16 +129846,16 @@ function codegenReactiveScope(cx, statements, scope, block) {
129627
129846
  loc: null,
129628
129847
  suggestions: null
129629
129848
  });
129630
- testCondition = t4.binaryExpression(
129849
+ testCondition = t3.binaryExpression(
129631
129850
  "===",
129632
- t4.memberExpression(
129633
- t4.identifier(cx.synthesizeName("$")),
129634
- t4.numericLiteral(firstOutputIndex),
129851
+ t3.memberExpression(
129852
+ t3.identifier(cx.synthesizeName("$")),
129853
+ t3.numericLiteral(firstOutputIndex),
129635
129854
  true
129636
129855
  ),
129637
- t4.callExpression(
129638
- t4.memberExpression(t4.identifier("Symbol"), t4.identifier("for")),
129639
- [t4.stringLiteral(MEMO_CACHE_SENTINEL)]
129856
+ t3.callExpression(
129857
+ t3.memberExpression(t3.identifier("Symbol"), t3.identifier("for")),
129858
+ [t3.stringLiteral(MEMO_CACHE_SENTINEL)]
129640
129859
  )
129641
129860
  );
129642
129861
  }
@@ -129649,81 +129868,82 @@ function codegenReactiveScope(cx, statements, scope, block) {
129649
129868
  loc: null
129650
129869
  }
129651
129870
  );
129652
- testCondition = t4.logicalExpression(
129871
+ testCondition = t3.logicalExpression(
129653
129872
  "||",
129654
129873
  testCondition,
129655
- t4.booleanLiteral(true)
129874
+ t3.booleanLiteral(true)
129656
129875
  );
129657
129876
  }
129658
129877
  let computationBlock = codegenBlock(cx, block);
129659
129878
  let memoStatement;
129660
- if (cx.env.config.enableChangeDetectionForDebugging != null && changeExpressions.length > 0) {
129879
+ const detectionFunction = cx.env.config.enableChangeDetectionForDebugging;
129880
+ if (detectionFunction != null && changeExpressions.length > 0) {
129661
129881
  const loc = typeof scope.loc === "symbol" ? "unknown location" : `(${scope.loc.start.line}:${scope.loc.end.line})`;
129662
- const detectionFunction = cx.env.config.enableChangeDetectionForDebugging.importSpecifierName;
129882
+ const importedDetectionFunctionIdentifier = cx.env.programContext.addImportSpecifier(detectionFunction).name;
129663
129883
  const cacheLoadOldValueStatements = [];
129664
129884
  const changeDetectionStatements = [];
129665
129885
  const idempotenceDetectionStatements = [];
129666
129886
  for (const { name, index, value } of cacheLoads) {
129667
129887
  const loadName = cx.synthesizeName(`old$${name.name}`);
129668
- const slot = t4.memberExpression(
129669
- t4.identifier(cx.synthesizeName("$")),
129670
- t4.numericLiteral(index),
129888
+ const slot = t3.memberExpression(
129889
+ t3.identifier(cx.synthesizeName("$")),
129890
+ t3.numericLiteral(index),
129671
129891
  true
129672
129892
  );
129673
129893
  cacheStoreStatements.push(
129674
- t4.expressionStatement(t4.assignmentExpression("=", slot, value))
129894
+ t3.expressionStatement(t3.assignmentExpression("=", slot, value))
129675
129895
  );
129676
129896
  cacheLoadOldValueStatements.push(
129677
- t4.variableDeclaration("let", [
129678
- t4.variableDeclarator(t4.identifier(loadName), slot)
129897
+ t3.variableDeclaration("let", [
129898
+ t3.variableDeclarator(t3.identifier(loadName), slot)
129679
129899
  ])
129680
129900
  );
129681
129901
  changeDetectionStatements.push(
129682
- t4.expressionStatement(
129683
- t4.callExpression(t4.identifier(detectionFunction), [
129684
- t4.identifier(loadName),
129685
- t4.cloneNode(name, true),
129686
- t4.stringLiteral(name.name),
129687
- t4.stringLiteral(cx.fnName),
129688
- t4.stringLiteral("cached"),
129689
- t4.stringLiteral(loc)
129902
+ t3.expressionStatement(
129903
+ t3.callExpression(t3.identifier(importedDetectionFunctionIdentifier), [
129904
+ t3.identifier(loadName),
129905
+ t3.cloneNode(name, true),
129906
+ t3.stringLiteral(name.name),
129907
+ t3.stringLiteral(cx.fnName),
129908
+ t3.stringLiteral("cached"),
129909
+ t3.stringLiteral(loc)
129690
129910
  ])
129691
129911
  )
129692
129912
  );
129693
129913
  idempotenceDetectionStatements.push(
129694
- t4.expressionStatement(
129695
- t4.callExpression(t4.identifier(detectionFunction), [
129696
- t4.cloneNode(slot, true),
129697
- t4.cloneNode(name, true),
129698
- t4.stringLiteral(name.name),
129699
- t4.stringLiteral(cx.fnName),
129700
- t4.stringLiteral("recomputed"),
129701
- t4.stringLiteral(loc)
129914
+ t3.expressionStatement(
129915
+ t3.callExpression(t3.identifier(importedDetectionFunctionIdentifier), [
129916
+ t3.cloneNode(slot, true),
129917
+ t3.cloneNode(name, true),
129918
+ t3.stringLiteral(name.name),
129919
+ t3.stringLiteral(cx.fnName),
129920
+ t3.stringLiteral("recomputed"),
129921
+ t3.stringLiteral(loc)
129702
129922
  ])
129703
129923
  )
129704
129924
  );
129705
129925
  idempotenceDetectionStatements.push(
129706
- t4.expressionStatement(t4.assignmentExpression("=", name, slot))
129926
+ t3.expressionStatement(t3.assignmentExpression("=", name, slot))
129707
129927
  );
129708
129928
  }
129709
129929
  const condition = cx.synthesizeName("condition");
129710
- const recomputationBlock = t4.cloneNode(computationBlock, true);
129711
- memoStatement = t4.blockStatement([
129930
+ const recomputationBlock = t3.cloneNode(computationBlock, true);
129931
+ memoStatement = t3.blockStatement([
129712
129932
  ...computationBlock.body,
129713
- t4.variableDeclaration("let", [
129714
- t4.variableDeclarator(t4.identifier(condition), testCondition)
129933
+ t3.variableDeclaration("let", [
129934
+ t3.variableDeclarator(t3.identifier(condition), testCondition)
129715
129935
  ]),
129716
- t4.ifStatement(
129717
- t4.unaryExpression("!", t4.identifier(condition)),
129718
- t4.blockStatement([
129936
+ t3.ifStatement(
129937
+ t3.unaryExpression("!", t3.identifier(condition)),
129938
+ t3.blockStatement([
129719
129939
  ...cacheLoadOldValueStatements,
129720
129940
  ...changeDetectionStatements
129721
129941
  ])
129722
129942
  ),
129723
129943
  ...cacheStoreStatements,
129724
- t4.ifStatement(
129725
- t4.identifier(condition),
129726
- t4.blockStatement([
129944
+ t3.ifStatement(
129945
+ t3.identifier(condition),
129946
+ t3.blockStatement([
129727
129947
  ...recomputationBlock.body,
129728
129948
  ...idempotenceDetectionStatements
129729
129949
  ])
@@ -129732,12 +129952,12 @@ function codegenReactiveScope(cx, statements, scope, block) {
129732
129952
  } else {
129733
129953
  for (const { name, index, value } of cacheLoads) {
129734
129954
  cacheStoreStatements.push(
129735
- t4.expressionStatement(
129736
- t4.assignmentExpression(
129955
+ t3.expressionStatement(
129956
+ t3.assignmentExpression(
129737
129957
  "=",
129738
- t4.memberExpression(
129739
- t4.identifier(cx.synthesizeName("$")),
129740
- t4.numericLiteral(index),
129958
+ t3.memberExpression(
129959
+ t3.identifier(cx.synthesizeName("$")),
129960
+ t3.numericLiteral(index),
129741
129961
  true
129742
129962
  ),
129743
129963
  value
@@ -129745,13 +129965,13 @@ function codegenReactiveScope(cx, statements, scope, block) {
129745
129965
  )
129746
129966
  );
129747
129967
  cacheLoadStatements.push(
129748
- t4.expressionStatement(
129749
- t4.assignmentExpression(
129968
+ t3.expressionStatement(
129969
+ t3.assignmentExpression(
129750
129970
  "=",
129751
129971
  name,
129752
- t4.memberExpression(
129753
- t4.identifier(cx.synthesizeName("$")),
129754
- t4.numericLiteral(index),
129972
+ t3.memberExpression(
129973
+ t3.identifier(cx.synthesizeName("$")),
129974
+ t3.numericLiteral(index),
129755
129975
  true
129756
129976
  )
129757
129977
  )
@@ -129759,15 +129979,15 @@ function codegenReactiveScope(cx, statements, scope, block) {
129759
129979
  );
129760
129980
  }
129761
129981
  computationBlock.body.push(...cacheStoreStatements);
129762
- memoStatement = t4.ifStatement(
129982
+ memoStatement = t3.ifStatement(
129763
129983
  testCondition,
129764
129984
  computationBlock,
129765
- t4.blockStatement(cacheLoadStatements)
129985
+ t3.blockStatement(cacheLoadStatements)
129766
129986
  );
129767
129987
  }
129768
129988
  if (cx.env.config.enableMemoizationComments) {
129769
129989
  if (changeExpressionComments.length) {
129770
- t4.addComment(
129990
+ t3.addComment(
129771
129991
  memoStatement,
129772
129992
  "leading",
129773
129993
  ` check if ${printDelimitedCommentList(
@@ -129776,20 +129996,20 @@ function codegenReactiveScope(cx, statements, scope, block) {
129776
129996
  )} changed`,
129777
129997
  true
129778
129998
  );
129779
- t4.addComment(
129999
+ t3.addComment(
129780
130000
  memoStatement,
129781
130001
  "leading",
129782
130002
  ` "useMemo" for ${printDelimitedCommentList(outputComments, "and")}:`,
129783
130003
  true
129784
130004
  );
129785
130005
  } else {
129786
- t4.addComment(
130006
+ t3.addComment(
129787
130007
  memoStatement,
129788
130008
  "leading",
129789
130009
  " cache value with no dependencies",
129790
130010
  true
129791
130011
  );
129792
- t4.addComment(
130012
+ t3.addComment(
129793
130013
  memoStatement,
129794
130014
  "leading",
129795
130015
  ` "useMemo" for ${printDelimitedCommentList(outputComments, "and")}:`,
@@ -129797,7 +130017,7 @@ function codegenReactiveScope(cx, statements, scope, block) {
129797
130017
  );
129798
130018
  }
129799
130019
  if (computationBlock.body.length > 0) {
129800
- t4.addComment(
130020
+ t3.addComment(
129801
130021
  computationBlock.body[0],
129802
130022
  "leading",
129803
130023
  ` Inputs changed, recompute`,
@@ -129805,7 +130025,7 @@ function codegenReactiveScope(cx, statements, scope, block) {
129805
130025
  );
129806
130026
  }
129807
130027
  if (cacheLoadStatements.length > 0) {
129808
- t4.addComment(
130028
+ t3.addComment(
129809
130029
  cacheLoadStatements[0],
129810
130030
  "leading",
129811
130031
  ` Inputs did not change, use cached value`,
@@ -129827,16 +130047,16 @@ function codegenReactiveScope(cx, statements, scope, block) {
129827
130047
  );
129828
130048
  const name = earlyReturnValue.value.name.value;
129829
130049
  statements.push(
129830
- t4.ifStatement(
129831
- t4.binaryExpression(
130050
+ t3.ifStatement(
130051
+ t3.binaryExpression(
129832
130052
  "!==",
129833
- t4.identifier(name),
129834
- t4.callExpression(
129835
- t4.memberExpression(t4.identifier("Symbol"), t4.identifier("for")),
129836
- [t4.stringLiteral(EARLY_RETURN_SENTINEL)]
130053
+ t3.identifier(name),
130054
+ t3.callExpression(
130055
+ t3.memberExpression(t3.identifier("Symbol"), t3.identifier("for")),
130056
+ [t3.stringLiteral(EARLY_RETURN_SENTINEL)]
129837
130057
  )
129838
130058
  ),
129839
- t4.blockStatement([t4.returnStatement(t4.identifier(name))])
130059
+ t3.blockStatement([t3.returnStatement(t3.identifier(name))])
129840
130060
  )
129841
130061
  );
129842
130062
  }
@@ -129847,20 +130067,20 @@ function codegenTerminal(cx, terminal) {
129847
130067
  if (terminal.targetKind === "implicit") {
129848
130068
  return null;
129849
130069
  }
129850
- return t4.breakStatement(
129851
- terminal.targetKind === "labeled" ? t4.identifier(codegenLabel(terminal.target)) : null
130070
+ return t3.breakStatement(
130071
+ terminal.targetKind === "labeled" ? t3.identifier(codegenLabel(terminal.target)) : null
129852
130072
  );
129853
130073
  }
129854
130074
  case "continue": {
129855
130075
  if (terminal.targetKind === "implicit") {
129856
130076
  return null;
129857
130077
  }
129858
- return t4.continueStatement(
129859
- terminal.targetKind === "labeled" ? t4.identifier(codegenLabel(terminal.target)) : null
130078
+ return t3.continueStatement(
130079
+ terminal.targetKind === "labeled" ? t3.identifier(codegenLabel(terminal.target)) : null
129860
130080
  );
129861
130081
  }
129862
130082
  case "for": {
129863
- return t4.forStatement(
130083
+ return t3.forStatement(
129864
130084
  codegenForInit(cx, terminal.init),
129865
130085
  codegenInstructionValueToExpression(cx, terminal.test),
129866
130086
  terminal.update !== null ? codegenInstructionValueToExpression(cx, terminal.update) : null,
@@ -129934,13 +130154,13 @@ function codegenTerminal(cx, terminal) {
129934
130154
  `Unhandled lvalue kind: ${iterableItem.value.lvalue.kind}`
129935
130155
  );
129936
130156
  }
129937
- return t4.forInStatement(
130157
+ return t3.forInStatement(
129938
130158
  /*
129939
130159
  * Special handling here since we only want the VariableDeclarators without any inits
129940
130160
  * This needs to be updated when we handle non-trivial ForOf inits
129941
130161
  */
129942
130162
  createVariableDeclaration(iterableItem.value.loc, varDeclKind, [
129943
- t4.variableDeclarator(lval, null)
130163
+ t3.variableDeclarator(lval, null)
129944
130164
  ]),
129945
130165
  codegenInstructionValueToExpression(cx, iterableCollection.value),
129946
130166
  codegenBlock(cx, terminal.loop)
@@ -130016,13 +130236,13 @@ function codegenTerminal(cx, terminal) {
130016
130236
  `Unhandled lvalue kind: ${iterableItem.value.lvalue.kind}`
130017
130237
  );
130018
130238
  }
130019
- return t4.forOfStatement(
130239
+ return t3.forOfStatement(
130020
130240
  /*
130021
130241
  * Special handling here since we only want the VariableDeclarators without any inits
130022
130242
  * This needs to be updated when we handle non-trivial ForOf inits
130023
130243
  */
130024
130244
  createVariableDeclaration(iterableItem.value.loc, varDeclKind, [
130025
- t4.variableDeclarator(lval, null)
130245
+ t3.variableDeclarator(lval, null)
130026
130246
  ]),
130027
130247
  codegenInstructionValueToExpression(cx, iterableCollection),
130028
130248
  codegenBlock(cx, terminal.loop)
@@ -130038,35 +130258,35 @@ function codegenTerminal(cx, terminal) {
130038
130258
  alternate = block;
130039
130259
  }
130040
130260
  }
130041
- return t4.ifStatement(test, consequent, alternate);
130261
+ return t3.ifStatement(test, consequent, alternate);
130042
130262
  }
130043
130263
  case "return": {
130044
130264
  const value = codegenPlaceToExpression(cx, terminal.value);
130045
130265
  if (value.type === "Identifier" && value.name === "undefined") {
130046
- return t4.returnStatement();
130266
+ return t3.returnStatement();
130047
130267
  }
130048
- return t4.returnStatement(value);
130268
+ return t3.returnStatement(value);
130049
130269
  }
130050
130270
  case "switch": {
130051
- return t4.switchStatement(
130271
+ return t3.switchStatement(
130052
130272
  codegenPlaceToExpression(cx, terminal.test),
130053
130273
  terminal.cases.map((case_) => {
130054
130274
  const test = case_.test !== null ? codegenPlaceToExpression(cx, case_.test) : null;
130055
130275
  const block = codegenBlock(cx, case_.block);
130056
- return t4.switchCase(test, [block]);
130276
+ return t3.switchCase(test, [block]);
130057
130277
  })
130058
130278
  );
130059
130279
  }
130060
130280
  case "throw": {
130061
- return t4.throwStatement(codegenPlaceToExpression(cx, terminal.value));
130281
+ return t3.throwStatement(codegenPlaceToExpression(cx, terminal.value));
130062
130282
  }
130063
130283
  case "do-while": {
130064
130284
  const test = codegenInstructionValueToExpression(cx, terminal.test);
130065
- return t4.doWhileStatement(test, codegenBlock(cx, terminal.loop));
130285
+ return t3.doWhileStatement(test, codegenBlock(cx, terminal.loop));
130066
130286
  }
130067
130287
  case "while": {
130068
130288
  const test = codegenInstructionValueToExpression(cx, terminal.test);
130069
- return t4.whileStatement(test, codegenBlock(cx, terminal.loop));
130289
+ return t3.whileStatement(test, codegenBlock(cx, terminal.loop));
130070
130290
  }
130071
130291
  case "label": {
130072
130292
  return codegenBlock(cx, terminal.block);
@@ -130077,9 +130297,9 @@ function codegenTerminal(cx, terminal) {
130077
130297
  catchParam = convertIdentifier(terminal.handlerBinding.identifier);
130078
130298
  cx.temp.set(terminal.handlerBinding.identifier.declarationId, null);
130079
130299
  }
130080
- return t4.tryStatement(
130300
+ return t3.tryStatement(
130081
130301
  codegenBlock(cx, terminal.block),
130082
- t4.catchClause(catchParam, codegenBlock(cx, terminal.handler))
130302
+ t3.catchClause(catchParam, codegenBlock(cx, terminal.handler))
130083
130303
  );
130084
130304
  }
130085
130305
  default: {
@@ -130142,7 +130362,7 @@ function codegenInstructionNullable(cx, instr) {
130142
130362
  suggestions: null
130143
130363
  });
130144
130364
  return createVariableDeclaration(instr.loc, "const", [
130145
- t4.variableDeclarator(codegenLValue(cx, lvalue), value)
130365
+ t3.variableDeclarator(codegenLValue(cx, lvalue), value)
130146
130366
  ]);
130147
130367
  }
130148
130368
  case "Function" /* Function */: {
@@ -130182,7 +130402,7 @@ function codegenInstructionNullable(cx, instr) {
130182
130402
  suggestions: null
130183
130403
  });
130184
130404
  return createVariableDeclaration(instr.loc, "let", [
130185
- t4.variableDeclarator(codegenLValue(cx, lvalue), value)
130405
+ t3.variableDeclarator(codegenLValue(cx, lvalue), value)
130186
130406
  ]);
130187
130407
  }
130188
130408
  case "Reassign" /* Reassign */: {
@@ -130192,7 +130412,7 @@ function codegenInstructionNullable(cx, instr) {
130192
130412
  loc: instr.value.loc,
130193
130413
  suggestions: null
130194
130414
  });
130195
- const expr = t4.assignmentExpression(
130415
+ const expr = t3.assignmentExpression(
130196
130416
  "=",
130197
130417
  codegenLValue(cx, lvalue),
130198
130418
  value
@@ -130213,7 +130433,7 @@ function codegenInstructionNullable(cx, instr) {
130213
130433
  }
130214
130434
  }
130215
130435
  case "Catch" /* Catch */: {
130216
- return t4.emptyStatement();
130436
+ return t3.emptyStatement();
130217
130437
  }
130218
130438
  case "HoistedLet" /* HoistedLet */:
130219
130439
  case "HoistedConst" /* HoistedConst */:
@@ -130232,7 +130452,7 @@ function codegenInstructionNullable(cx, instr) {
130232
130452
  } else if (instr.value.kind === "StartMemoize" || instr.value.kind === "FinishMemoize") {
130233
130453
  return null;
130234
130454
  } else if (instr.value.kind === "Debugger") {
130235
- return t4.debuggerStatement();
130455
+ return t3.debuggerStatement();
130236
130456
  } else if (instr.value.kind === "ObjectMethod") {
130237
130457
  CompilerError.invariant(instr.lvalue, {
130238
130458
  reason: "Expected object methods to have a temp lvalue",
@@ -130288,7 +130508,7 @@ function codegenForInit(cx, init) {
130288
130508
  description: null,
130289
130509
  suggestions: null
130290
130510
  });
130291
- return t4.variableDeclaration(kind, declarators);
130511
+ return t3.variableDeclaration(kind, declarators);
130292
130512
  } else {
130293
130513
  return codegenInstructionValueToExpression(cx, init);
130294
130514
  }
@@ -130327,17 +130547,17 @@ function codegenDependency(cx, dependency) {
130327
130547
  if (dependency.path.length !== 0) {
130328
130548
  const hasOptional = dependency.path.some((path) => path.optional);
130329
130549
  for (const path of dependency.path) {
130330
- const property = typeof path.property === "string" ? t4.identifier(path.property) : t4.numericLiteral(path.property);
130550
+ const property = typeof path.property === "string" ? t3.identifier(path.property) : t3.numericLiteral(path.property);
130331
130551
  const isComputed = typeof path.property !== "string";
130332
130552
  if (hasOptional) {
130333
- object = t4.optionalMemberExpression(
130553
+ object = t3.optionalMemberExpression(
130334
130554
  object,
130335
130555
  property,
130336
130556
  isComputed,
130337
130557
  path.optional
130338
130558
  );
130339
130559
  } else {
130340
- object = t4.memberExpression(object, property, isComputed);
130560
+ object = t3.memberExpression(object, property, isComputed);
130341
130561
  }
130342
130562
  }
130343
130563
  }
@@ -130352,60 +130572,60 @@ function withLoc(fn) {
130352
130572
  return node;
130353
130573
  };
130354
130574
  }
130355
- var createBinaryExpression = withLoc(t4.binaryExpression);
130356
- var createExpressionStatement = withLoc(t4.expressionStatement);
130357
- var _createLabelledStatement = withLoc(t4.labeledStatement);
130358
- var createVariableDeclaration = withLoc(t4.variableDeclaration);
130359
- var createFunctionDeclaration = withLoc(t4.functionDeclaration);
130360
- var _createWhileStatement = withLoc(t4.whileStatement);
130361
- var createTaggedTemplateExpression = withLoc(t4.taggedTemplateExpression);
130362
- var createLogicalExpression = withLoc(t4.logicalExpression);
130363
- var createSequenceExpression = withLoc(t4.sequenceExpression);
130364
- var createConditionalExpression = withLoc(t4.conditionalExpression);
130365
- var createTemplateLiteral = withLoc(t4.templateLiteral);
130366
- var createJsxNamespacedName = withLoc(t4.jsxNamespacedName);
130367
- var createJsxElement = withLoc(t4.jsxElement);
130368
- var createJsxAttribute = withLoc(t4.jsxAttribute);
130369
- var createJsxIdentifier = withLoc(t4.jsxIdentifier);
130370
- var createJsxExpressionContainer = withLoc(t4.jsxExpressionContainer);
130371
- var createJsxText = withLoc(t4.jsxText);
130372
- var createJsxClosingElement = withLoc(t4.jsxClosingElement);
130373
- var createJsxOpeningElement = withLoc(t4.jsxOpeningElement);
130374
- var createStringLiteral = withLoc(t4.stringLiteral);
130375
- function createHookGuard(guard, stmts, before, after) {
130575
+ var createBinaryExpression = withLoc(t3.binaryExpression);
130576
+ var createExpressionStatement = withLoc(t3.expressionStatement);
130577
+ var _createLabelledStatement = withLoc(t3.labeledStatement);
130578
+ var createVariableDeclaration = withLoc(t3.variableDeclaration);
130579
+ var createFunctionDeclaration = withLoc(t3.functionDeclaration);
130580
+ var _createWhileStatement = withLoc(t3.whileStatement);
130581
+ var createTaggedTemplateExpression = withLoc(t3.taggedTemplateExpression);
130582
+ var createLogicalExpression = withLoc(t3.logicalExpression);
130583
+ var createSequenceExpression = withLoc(t3.sequenceExpression);
130584
+ var createConditionalExpression = withLoc(t3.conditionalExpression);
130585
+ var createTemplateLiteral = withLoc(t3.templateLiteral);
130586
+ var createJsxNamespacedName = withLoc(t3.jsxNamespacedName);
130587
+ var createJsxElement = withLoc(t3.jsxElement);
130588
+ var createJsxAttribute = withLoc(t3.jsxAttribute);
130589
+ var createJsxIdentifier = withLoc(t3.jsxIdentifier);
130590
+ var createJsxExpressionContainer = withLoc(t3.jsxExpressionContainer);
130591
+ var createJsxText = withLoc(t3.jsxText);
130592
+ var createJsxClosingElement = withLoc(t3.jsxClosingElement);
130593
+ var createJsxOpeningElement = withLoc(t3.jsxOpeningElement);
130594
+ var createStringLiteral = withLoc(t3.stringLiteral);
130595
+ function createHookGuard(guard, context, stmts, before, after) {
130596
+ const guardFnName = context.addImportSpecifier(guard).name;
130376
130597
  function createHookGuardImpl(kind) {
130377
- return t4.expressionStatement(
130378
- t4.callExpression(t4.identifier(guard.importSpecifierName), [
130379
- t4.numericLiteral(kind)
130380
- ])
130598
+ return t3.expressionStatement(
130599
+ t3.callExpression(t3.identifier(guardFnName), [t3.numericLiteral(kind)])
130381
130600
  );
130382
130601
  }
130383
- return t4.tryStatement(
130384
- t4.blockStatement([createHookGuardImpl(before), ...stmts]),
130602
+ return t3.tryStatement(
130603
+ t3.blockStatement([createHookGuardImpl(before), ...stmts]),
130385
130604
  null,
130386
- t4.blockStatement([createHookGuardImpl(after)])
130605
+ t3.blockStatement([createHookGuardImpl(after)])
130387
130606
  );
130388
130607
  }
130389
130608
  function createCallExpression(env, callee, args, loc, isHook2) {
130390
- const callExpr = t4.callExpression(callee, args);
130609
+ const callExpr = t3.callExpression(callee, args);
130391
130610
  if (loc != null && loc != GeneratedSource) {
130392
130611
  callExpr.loc = loc;
130393
130612
  }
130394
130613
  const hookGuard = env.config.enableEmitHookGuards;
130395
130614
  if (hookGuard != null && isHook2 && env.isInferredMemoEnabled) {
130396
- const iife = t4.functionExpression(
130615
+ const iife = t3.functionExpression(
130397
130616
  null,
130398
130617
  [],
130399
- t4.blockStatement([
130618
+ t3.blockStatement([
130400
130619
  createHookGuard(
130401
130620
  hookGuard,
130402
- [t4.returnStatement(callExpr)],
130621
+ env.programContext,
130622
+ [t3.returnStatement(callExpr)],
130403
130623
  2 /* AllowHook */,
130404
130624
  3 /* DisallowHook */
130405
130625
  )
130406
130626
  ])
130407
130627
  );
130408
- return t4.callExpression(iife, []);
130628
+ return t3.callExpression(iife, []);
130409
130629
  } else {
130410
130630
  return callExpr;
130411
130631
  }
@@ -130414,21 +130634,21 @@ function codegenLabel(id) {
130414
130634
  return `bb${id}`;
130415
130635
  }
130416
130636
  function codegenInstruction(cx, instr, value) {
130417
- if (t4.isStatement(value)) {
130637
+ if (t3.isStatement(value)) {
130418
130638
  return value;
130419
130639
  }
130420
130640
  if (instr.lvalue === null) {
130421
- return t4.expressionStatement(convertValueToExpression(value));
130641
+ return t3.expressionStatement(convertValueToExpression(value));
130422
130642
  }
130423
130643
  if (instr.lvalue.identifier.name === null) {
130424
130644
  cx.temp.set(instr.lvalue.identifier.declarationId, value);
130425
- return t4.emptyStatement();
130645
+ return t3.emptyStatement();
130426
130646
  } else {
130427
130647
  const expressionValue = convertValueToExpression(value);
130428
130648
  if (cx.hasDeclared(instr.lvalue.identifier)) {
130429
130649
  return createExpressionStatement(
130430
130650
  instr.loc,
130431
- t4.assignmentExpression(
130651
+ t3.assignmentExpression(
130432
130652
  "=",
130433
130653
  convertIdentifier(instr.lvalue.identifier),
130434
130654
  expressionValue
@@ -130436,7 +130656,7 @@ function codegenInstruction(cx, instr, value) {
130436
130656
  );
130437
130657
  } else {
130438
130658
  return createVariableDeclaration(instr.loc, "const", [
130439
- t4.variableDeclarator(
130659
+ t3.variableDeclarator(
130440
130660
  convertIdentifier(instr.lvalue.identifier),
130441
130661
  expressionValue
130442
130662
  )
@@ -130463,12 +130683,12 @@ function codegenInstructionValue(cx, instrValue) {
130463
130683
  if (element.kind === "Identifier") {
130464
130684
  return codegenPlaceToExpression(cx, element);
130465
130685
  } else if (element.kind === "Spread") {
130466
- return t4.spreadElement(codegenPlaceToExpression(cx, element.place));
130686
+ return t3.spreadElement(codegenPlaceToExpression(cx, element.place));
130467
130687
  } else {
130468
130688
  return null;
130469
130689
  }
130470
130690
  });
130471
- value = t4.arrayExpression(elements);
130691
+ value = t3.arrayExpression(elements);
130472
130692
  break;
130473
130693
  }
130474
130694
  case "BinaryExpression": {
@@ -130483,7 +130703,7 @@ function codegenInstructionValue(cx, instrValue) {
130483
130703
  break;
130484
130704
  }
130485
130705
  case "UnaryExpression": {
130486
- value = t4.unaryExpression(
130706
+ value = t3.unaryExpression(
130487
130707
  instrValue.operator,
130488
130708
  // todo
130489
130709
  codegenPlaceToExpression(cx, instrValue.value)
@@ -130498,9 +130718,9 @@ function codegenInstructionValue(cx, instrValue) {
130498
130718
  if (cx.env.config.enableForest) {
130499
130719
  const callee2 = codegenPlaceToExpression(cx, instrValue.callee);
130500
130720
  const args2 = instrValue.args.map((arg) => codegenArgument(cx, arg));
130501
- value = t4.callExpression(callee2, args2);
130721
+ value = t3.callExpression(callee2, args2);
130502
130722
  if (instrValue.typeArguments != null) {
130503
- value.typeArguments = t4.typeParameterInstantiation(
130723
+ value.typeArguments = t3.typeParameterInstantiation(
130504
130724
  instrValue.typeArguments
130505
130725
  );
130506
130726
  }
@@ -130526,13 +130746,13 @@ function codegenInstructionValue(cx, instrValue) {
130526
130746
  switch (optionalValue.type) {
130527
130747
  case "OptionalCallExpression":
130528
130748
  case "CallExpression": {
130529
- CompilerError.invariant(t4.isExpression(optionalValue.callee), {
130749
+ CompilerError.invariant(t3.isExpression(optionalValue.callee), {
130530
130750
  reason: "v8 intrinsics are validated during lowering",
130531
130751
  description: null,
130532
130752
  loc: (_a = optionalValue.callee.loc) != null ? _a : null,
130533
130753
  suggestions: null
130534
130754
  });
130535
- value = t4.optionalCallExpression(
130755
+ value = t3.optionalCallExpression(
130536
130756
  optionalValue.callee,
130537
130757
  optionalValue.arguments,
130538
130758
  instrValue.optional
@@ -130542,13 +130762,13 @@ function codegenInstructionValue(cx, instrValue) {
130542
130762
  case "OptionalMemberExpression":
130543
130763
  case "MemberExpression": {
130544
130764
  const property = optionalValue.property;
130545
- CompilerError.invariant(t4.isExpression(property), {
130765
+ CompilerError.invariant(t3.isExpression(property), {
130546
130766
  reason: "Private names are validated during lowering",
130547
130767
  description: null,
130548
130768
  loc: (_b = property.loc) != null ? _b : null,
130549
130769
  suggestions: null
130550
130770
  });
130551
- value = t4.optionalMemberExpression(
130771
+ value = t3.optionalMemberExpression(
130552
130772
  optionalValue.object,
130553
130773
  property,
130554
130774
  optionalValue.computed,
@@ -130571,7 +130791,7 @@ function codegenInstructionValue(cx, instrValue) {
130571
130791
  const isHook2 = getHookKind(cx.env, instrValue.property.identifier) != null;
130572
130792
  const memberExpr = codegenPlaceToExpression(cx, instrValue.property);
130573
130793
  CompilerError.invariant(
130574
- t4.isMemberExpression(memberExpr) || t4.isOptionalMemberExpression(memberExpr),
130794
+ t3.isMemberExpression(memberExpr) || t3.isOptionalMemberExpression(memberExpr),
130575
130795
  {
130576
130796
  reason: `[Codegen] Internal error: MethodCall::property must be an unpromoted + unmemoized MemberExpression. Got a \`${memberExpr.type}\``,
130577
130797
  description: null,
@@ -130580,7 +130800,7 @@ function codegenInstructionValue(cx, instrValue) {
130580
130800
  }
130581
130801
  );
130582
130802
  CompilerError.invariant(
130583
- t4.isNodesEquivalent(
130803
+ t3.isNodesEquivalent(
130584
130804
  memberExpr.object,
130585
130805
  codegenPlaceToExpression(cx, instrValue.receiver)
130586
130806
  ),
@@ -130604,7 +130824,7 @@ function codegenInstructionValue(cx, instrValue) {
130604
130824
  case "NewExpression": {
130605
130825
  const callee = codegenPlaceToExpression(cx, instrValue.callee);
130606
130826
  const args = instrValue.args.map((arg) => codegenArgument(cx, arg));
130607
- value = t4.newExpression(callee, args);
130827
+ value = t3.newExpression(callee, args);
130608
130828
  break;
130609
130829
  }
130610
130830
  case "ObjectExpression": {
@@ -130616,7 +130836,7 @@ function codegenInstructionValue(cx, instrValue) {
130616
130836
  case "property": {
130617
130837
  const value2 = codegenPlaceToExpression(cx, property.place);
130618
130838
  properties.push(
130619
- t4.objectProperty(
130839
+ t3.objectProperty(
130620
130840
  key2,
130621
130841
  value2,
130622
130842
  property.key.kind === "computed",
@@ -130646,7 +130866,7 @@ function codegenInstructionValue(cx, instrValue) {
130646
130866
  ),
130647
130867
  reactiveFunction
130648
130868
  ).unwrap();
130649
- const babelNode = t4.objectMethod(
130869
+ const babelNode = t3.objectMethod(
130650
130870
  "method",
130651
130871
  key2,
130652
130872
  fn.params,
@@ -130666,11 +130886,11 @@ function codegenInstructionValue(cx, instrValue) {
130666
130886
  }
130667
130887
  } else {
130668
130888
  properties.push(
130669
- t4.spreadElement(codegenPlaceToExpression(cx, property.place))
130889
+ t3.spreadElement(codegenPlaceToExpression(cx, property.place))
130670
130890
  );
130671
130891
  }
130672
130892
  }
130673
- value = t4.objectExpression(properties);
130893
+ value = t3.objectExpression(properties);
130674
130894
  break;
130675
130895
  }
130676
130896
  case "JSXText": {
@@ -130682,7 +130902,7 @@ function codegenInstructionValue(cx, instrValue) {
130682
130902
  for (const attribute of instrValue.props) {
130683
130903
  attributes.push(codegenJsxAttribute(cx, attribute));
130684
130904
  }
130685
- let tagValue = instrValue.tag.kind === "Identifier" ? codegenPlaceToExpression(cx, instrValue.tag) : t4.stringLiteral(instrValue.tag.name);
130905
+ let tagValue = instrValue.tag.kind === "Identifier" ? codegenPlaceToExpression(cx, instrValue.tag) : t3.stringLiteral(instrValue.tag.name);
130686
130906
  let tag;
130687
130907
  if (tagValue.type === "Identifier") {
130688
130908
  tag = createJsxIdentifier(instrValue.tag.loc, tagValue.name);
@@ -130735,16 +130955,16 @@ function codegenInstructionValue(cx, instrValue) {
130735
130955
  break;
130736
130956
  }
130737
130957
  case "JsxFragment": {
130738
- value = t4.jsxFragment(
130739
- t4.jsxOpeningFragment(),
130740
- t4.jsxClosingFragment(),
130958
+ value = t3.jsxFragment(
130959
+ t3.jsxOpeningFragment(),
130960
+ t3.jsxClosingFragment(),
130741
130961
  instrValue.children.map((child) => codegenJsxElement(cx, child))
130742
130962
  );
130743
130963
  break;
130744
130964
  }
130745
130965
  case "UnsupportedNode": {
130746
130966
  const node = instrValue.node;
130747
- if (!t4.isExpression(node)) {
130967
+ if (!t3.isExpression(node)) {
130748
130968
  return node;
130749
130969
  }
130750
130970
  value = node;
@@ -130755,19 +130975,19 @@ function codegenInstructionValue(cx, instrValue) {
130755
130975
  case "PropertyDelete": {
130756
130976
  let memberExpr;
130757
130977
  if (typeof instrValue.property === "string") {
130758
- memberExpr = t4.memberExpression(
130978
+ memberExpr = t3.memberExpression(
130759
130979
  codegenPlaceToExpression(cx, instrValue.object),
130760
- t4.identifier(instrValue.property)
130980
+ t3.identifier(instrValue.property)
130761
130981
  );
130762
130982
  } else {
130763
- memberExpr = t4.memberExpression(
130983
+ memberExpr = t3.memberExpression(
130764
130984
  codegenPlaceToExpression(cx, instrValue.object),
130765
- t4.numericLiteral(instrValue.property),
130985
+ t3.numericLiteral(instrValue.property),
130766
130986
  true
130767
130987
  );
130768
130988
  }
130769
130989
  if (instrValue.kind === "PropertyStore") {
130770
- value = t4.assignmentExpression(
130990
+ value = t3.assignmentExpression(
130771
130991
  "=",
130772
130992
  memberExpr,
130773
130993
  codegenPlaceToExpression(cx, instrValue.value)
@@ -130775,14 +130995,14 @@ function codegenInstructionValue(cx, instrValue) {
130775
130995
  } else if (instrValue.kind === "PropertyLoad") {
130776
130996
  value = memberExpr;
130777
130997
  } else {
130778
- value = t4.unaryExpression("delete", memberExpr);
130998
+ value = t3.unaryExpression("delete", memberExpr);
130779
130999
  }
130780
131000
  break;
130781
131001
  }
130782
131002
  case "ComputedStore": {
130783
- value = t4.assignmentExpression(
131003
+ value = t3.assignmentExpression(
130784
131004
  "=",
130785
- t4.memberExpression(
131005
+ t3.memberExpression(
130786
131006
  codegenPlaceToExpression(cx, instrValue.object),
130787
131007
  codegenPlaceToExpression(cx, instrValue.property),
130788
131008
  true
@@ -130794,13 +131014,13 @@ function codegenInstructionValue(cx, instrValue) {
130794
131014
  case "ComputedLoad": {
130795
131015
  const object = codegenPlaceToExpression(cx, instrValue.object);
130796
131016
  const property = codegenPlaceToExpression(cx, instrValue.property);
130797
- value = t4.memberExpression(object, property, true);
131017
+ value = t3.memberExpression(object, property, true);
130798
131018
  break;
130799
131019
  }
130800
131020
  case "ComputedDelete": {
130801
- value = t4.unaryExpression(
131021
+ value = t3.unaryExpression(
130802
131022
  "delete",
130803
- t4.memberExpression(
131023
+ t3.memberExpression(
130804
131024
  codegenPlaceToExpression(cx, instrValue.object),
130805
131025
  codegenPlaceToExpression(cx, instrValue.property),
130806
131026
  true
@@ -130837,10 +131057,10 @@ function codegenInstructionValue(cx, instrValue) {
130837
131057
  body = stmt.argument;
130838
131058
  }
130839
131059
  }
130840
- value = t4.arrowFunctionExpression(fn.params, body, fn.async);
131060
+ value = t3.arrowFunctionExpression(fn.params, body, fn.async);
130841
131061
  } else {
130842
- value = t4.functionExpression(
130843
- (_h = fn.id) != null ? _h : instrValue.name != null ? t4.identifier(instrValue.name) : null,
131062
+ value = t3.functionExpression(
131063
+ (_h = fn.id) != null ? _h : instrValue.name != null ? t3.identifier(instrValue.name) : null,
130844
131064
  fn.params,
130845
131065
  fn.body,
130846
131066
  fn.generator,
@@ -130853,20 +131073,20 @@ function codegenInstructionValue(cx, instrValue) {
130853
131073
  value = createTaggedTemplateExpression(
130854
131074
  instrValue.loc,
130855
131075
  codegenPlaceToExpression(cx, instrValue.tag),
130856
- t4.templateLiteral([t4.templateElement(instrValue.value)], [])
131076
+ t3.templateLiteral([t3.templateElement(instrValue.value)], [])
130857
131077
  );
130858
131078
  break;
130859
131079
  }
130860
131080
  case "TypeCastExpression": {
130861
- if (t4.isTSType(instrValue.typeAnnotation)) {
130862
- value = t4.tsAsExpression(
131081
+ if (t3.isTSType(instrValue.typeAnnotation)) {
131082
+ value = t3.tsAsExpression(
130863
131083
  codegenPlaceToExpression(cx, instrValue.value),
130864
131084
  instrValue.typeAnnotation
130865
131085
  );
130866
131086
  } else {
130867
- value = t4.typeCastExpression(
131087
+ value = t3.typeCastExpression(
130868
131088
  codegenPlaceToExpression(cx, instrValue.value),
130869
- t4.typeAnnotation(instrValue.typeAnnotation)
131089
+ t3.typeAnnotation(instrValue.typeAnnotation)
130870
131090
  );
130871
131091
  }
130872
131092
  break;
@@ -130902,7 +131122,7 @@ function codegenInstructionValue(cx, instrValue) {
130902
131122
  if (stmt.type === "ExpressionStatement") {
130903
131123
  return stmt.expression;
130904
131124
  } else {
130905
- if (t4.isVariableDeclaration(stmt)) {
131125
+ if (t3.isVariableDeclaration(stmt)) {
130906
131126
  const declarator = stmt.declarations[0];
130907
131127
  cx.errors.push({
130908
131128
  reason: `(CodegenReactiveFunction::codegenInstructionValue) Cannot declare variables in a value block, tried to declare '${declarator.id.name}'`,
@@ -130910,7 +131130,7 @@ function codegenInstructionValue(cx, instrValue) {
130910
131130
  loc: (_a2 = declarator.loc) != null ? _a2 : null,
130911
131131
  suggestions: null
130912
131132
  });
130913
- return t4.stringLiteral(`TODO handle ${declarator.id}`);
131133
+ return t3.stringLiteral(`TODO handle ${declarator.id}`);
130914
131134
  } else {
130915
131135
  cx.errors.push({
130916
131136
  reason: `(CodegenReactiveFunction::codegenInstructionValue) Handle conversion of ${stmt.type} to expression`,
@@ -130918,7 +131138,7 @@ function codegenInstructionValue(cx, instrValue) {
130918
131138
  loc: (_b2 = stmt.loc) != null ? _b2 : null,
130919
131139
  suggestions: null
130920
131140
  });
130921
- return t4.stringLiteral(`TODO handle ${stmt.type}`);
131141
+ return t3.stringLiteral(`TODO handle ${stmt.type}`);
130922
131142
  }
130923
131143
  }
130924
131144
  });
@@ -130935,28 +131155,28 @@ function codegenInstructionValue(cx, instrValue) {
130935
131155
  case "TemplateLiteral": {
130936
131156
  value = createTemplateLiteral(
130937
131157
  instrValue.loc,
130938
- instrValue.quasis.map((q) => t4.templateElement(q)),
131158
+ instrValue.quasis.map((q) => t3.templateElement(q)),
130939
131159
  instrValue.subexprs.map((p) => codegenPlaceToExpression(cx, p))
130940
131160
  );
130941
131161
  break;
130942
131162
  }
130943
131163
  case "LoadGlobal": {
130944
- value = t4.identifier(instrValue.binding.name);
131164
+ value = t3.identifier(instrValue.binding.name);
130945
131165
  break;
130946
131166
  }
130947
131167
  case "RegExpLiteral": {
130948
- value = t4.regExpLiteral(instrValue.pattern, instrValue.flags);
131168
+ value = t3.regExpLiteral(instrValue.pattern, instrValue.flags);
130949
131169
  break;
130950
131170
  }
130951
131171
  case "MetaProperty": {
130952
- value = t4.metaProperty(
130953
- t4.identifier(instrValue.meta),
130954
- t4.identifier(instrValue.property)
131172
+ value = t3.metaProperty(
131173
+ t3.identifier(instrValue.meta),
131174
+ t3.identifier(instrValue.property)
130955
131175
  );
130956
131176
  break;
130957
131177
  }
130958
131178
  case "Await": {
130959
- value = t4.awaitExpression(codegenPlaceToExpression(cx, instrValue.value));
131179
+ value = t3.awaitExpression(codegenPlaceToExpression(cx, instrValue.value));
130960
131180
  break;
130961
131181
  }
130962
131182
  case "GetIterator": {
@@ -130972,7 +131192,7 @@ function codegenInstructionValue(cx, instrValue) {
130972
131192
  break;
130973
131193
  }
130974
131194
  case "PostfixUpdate": {
130975
- value = t4.updateExpression(
131195
+ value = t3.updateExpression(
130976
131196
  instrValue.operation,
130977
131197
  codegenPlaceToExpression(cx, instrValue.lvalue),
130978
131198
  false
@@ -130980,7 +131200,7 @@ function codegenInstructionValue(cx, instrValue) {
130980
131200
  break;
130981
131201
  }
130982
131202
  case "PrefixUpdate": {
130983
- value = t4.updateExpression(
131203
+ value = t3.updateExpression(
130984
131204
  instrValue.operation,
130985
131205
  codegenPlaceToExpression(cx, instrValue.lvalue),
130986
131206
  true
@@ -130997,7 +131217,7 @@ function codegenInstructionValue(cx, instrValue) {
130997
131217
  suggestions: null
130998
131218
  }
130999
131219
  );
131000
- value = t4.assignmentExpression(
131220
+ value = t3.assignmentExpression(
131001
131221
  "=",
131002
131222
  codegenLValue(cx, instrValue.lvalue.place),
131003
131223
  codegenPlaceToExpression(cx, instrValue.value)
@@ -131005,9 +131225,9 @@ function codegenInstructionValue(cx, instrValue) {
131005
131225
  break;
131006
131226
  }
131007
131227
  case "StoreGlobal": {
131008
- value = t4.assignmentExpression(
131228
+ value = t3.assignmentExpression(
131009
131229
  "=",
131010
- t4.identifier(instrValue.name),
131230
+ t3.identifier(instrValue.name),
131011
131231
  codegenPlaceToExpression(cx, instrValue.value)
131012
131232
  );
131013
131233
  break;
@@ -131069,7 +131289,7 @@ function codegenJsxAttribute(cx, attribute) {
131069
131289
  return createJsxAttribute(attribute.place.loc, propName, value);
131070
131290
  }
131071
131291
  case "JsxSpreadAttribute": {
131072
- return t4.jsxSpreadAttribute(
131292
+ return t3.jsxSpreadAttribute(
131073
131293
  codegenPlaceToExpression(cx, attribute.argument)
131074
131294
  );
131075
131295
  }
@@ -131124,9 +131344,9 @@ function convertMemberExpressionToJsx(expr) {
131124
131344
  loc: (_a = expr.loc) != null ? _a : null,
131125
131345
  suggestions: null
131126
131346
  });
131127
- const property = t4.jsxIdentifier(expr.property.name);
131347
+ const property = t3.jsxIdentifier(expr.property.name);
131128
131348
  if (expr.object.type === "Identifier") {
131129
- return t4.jsxMemberExpression(t4.jsxIdentifier(expr.object.name), property);
131349
+ return t3.jsxMemberExpression(t3.jsxIdentifier(expr.object.name), property);
131130
131350
  } else {
131131
131351
  CompilerError.invariant(expr.object.type === "MemberExpression", {
131132
131352
  reason: "Expected JSX member expression to be an identifier or nested member expression",
@@ -131135,20 +131355,20 @@ function convertMemberExpressionToJsx(expr) {
131135
131355
  suggestions: null
131136
131356
  });
131137
131357
  const object = convertMemberExpressionToJsx(expr.object);
131138
- return t4.jsxMemberExpression(object, property);
131358
+ return t3.jsxMemberExpression(object, property);
131139
131359
  }
131140
131360
  }
131141
131361
  function codegenObjectPropertyKey(cx, key2) {
131142
131362
  switch (key2.kind) {
131143
131363
  case "string": {
131144
- return t4.stringLiteral(key2.name);
131364
+ return t3.stringLiteral(key2.name);
131145
131365
  }
131146
131366
  case "identifier": {
131147
- return t4.identifier(key2.name);
131367
+ return t3.identifier(key2.name);
131148
131368
  }
131149
131369
  case "computed": {
131150
131370
  const expr = codegenPlace(cx, key2.name);
131151
- CompilerError.invariant(t4.isExpression(expr), {
131371
+ CompilerError.invariant(t3.isExpression(expr), {
131152
131372
  reason: "Expected object property key to be an expression",
131153
131373
  description: null,
131154
131374
  loc: key2.name.loc,
@@ -131157,14 +131377,14 @@ function codegenObjectPropertyKey(cx, key2) {
131157
131377
  return expr;
131158
131378
  }
131159
131379
  case "number": {
131160
- return t4.numericLiteral(key2.name);
131380
+ return t3.numericLiteral(key2.name);
131161
131381
  }
131162
131382
  }
131163
131383
  }
131164
131384
  function codegenArrayPattern(cx, pattern) {
131165
131385
  const hasHoles = !pattern.items.every((e) => e.kind !== "Hole");
131166
131386
  if (hasHoles) {
131167
- const result = t4.arrayPattern([]);
131387
+ const result = t3.arrayPattern([]);
131168
131388
  for (const item of pattern.items) {
131169
131389
  if (item.kind === "Hole") {
131170
131390
  result.elements.push(null);
@@ -131174,7 +131394,7 @@ function codegenArrayPattern(cx, pattern) {
131174
131394
  }
131175
131395
  return result;
131176
131396
  } else {
131177
- return t4.arrayPattern(
131397
+ return t3.arrayPattern(
131178
131398
  pattern.items.map((item) => {
131179
131399
  if (item.kind === "Hole") {
131180
131400
  return null;
@@ -131190,25 +131410,25 @@ function codegenLValue(cx, pattern) {
131190
131410
  return codegenArrayPattern(cx, pattern);
131191
131411
  }
131192
131412
  case "ObjectPattern": {
131193
- return t4.objectPattern(
131413
+ return t3.objectPattern(
131194
131414
  pattern.properties.map((property) => {
131195
131415
  if (property.kind === "ObjectProperty") {
131196
131416
  const key2 = codegenObjectPropertyKey(cx, property.key);
131197
131417
  const value = codegenLValue(cx, property.place);
131198
- return t4.objectProperty(
131418
+ return t3.objectProperty(
131199
131419
  key2,
131200
131420
  value,
131201
131421
  property.key.kind === "computed",
131202
131422
  key2.type === "Identifier" && value.type === "Identifier" && value.name === key2.name
131203
131423
  );
131204
131424
  } else {
131205
- return t4.restElement(codegenLValue(cx, property.place));
131425
+ return t3.restElement(codegenLValue(cx, property.place));
131206
131426
  }
131207
131427
  })
131208
131428
  );
131209
131429
  }
131210
131430
  case "Spread": {
131211
- return t4.restElement(codegenLValue(cx, pattern.place));
131431
+ return t3.restElement(codegenLValue(cx, pattern.place));
131212
131432
  }
131213
131433
  case "Identifier": {
131214
131434
  return convertIdentifier(pattern.identifier);
@@ -131223,15 +131443,15 @@ function codegenLValue(cx, pattern) {
131223
131443
  }
131224
131444
  function codegenValue(cx, loc, value) {
131225
131445
  if (typeof value === "number") {
131226
- return t4.numericLiteral(value);
131446
+ return t3.numericLiteral(value);
131227
131447
  } else if (typeof value === "boolean") {
131228
- return t4.booleanLiteral(value);
131448
+ return t3.booleanLiteral(value);
131229
131449
  } else if (typeof value === "string") {
131230
131450
  return createStringLiteral(loc, value);
131231
131451
  } else if (value === null) {
131232
- return t4.nullLiteral();
131452
+ return t3.nullLiteral();
131233
131453
  } else if (value === void 0) {
131234
- return t4.identifier("undefined");
131454
+ return t3.identifier("undefined");
131235
131455
  } else {
131236
131456
  assertExhaustive(value, "Unexpected primitive value kind");
131237
131457
  }
@@ -131240,7 +131460,7 @@ function codegenArgument(cx, arg) {
131240
131460
  if (arg.kind === "Identifier") {
131241
131461
  return codegenPlaceToExpression(cx, arg);
131242
131462
  } else {
131243
- return t4.spreadElement(codegenPlaceToExpression(cx, arg.place));
131463
+ return t3.spreadElement(codegenPlaceToExpression(cx, arg.place));
131244
131464
  }
131245
131465
  }
131246
131466
  function codegenPlaceToExpression(cx, place) {
@@ -131274,7 +131494,7 @@ function convertIdentifier(identifier4) {
131274
131494
  suggestions: null
131275
131495
  }
131276
131496
  );
131277
- return t4.identifier(identifier4.name.value);
131497
+ return t3.identifier(identifier4.name.value);
131278
131498
  }
131279
131499
  function compareScopeDependency(a, b) {
131280
131500
  var _a, _b;
@@ -132224,6 +132444,10 @@ function pruneHoistedContexts(fn) {
132224
132444
  const hoistedIdentifiers = /* @__PURE__ */ new Map();
132225
132445
  visitReactiveFunction(fn, new Visitor3(), hoistedIdentifiers);
132226
132446
  }
132447
+ var REWRITTEN_HOISTED_CONST = Symbol(
132448
+ "REWRITTEN_HOISTED_CONST"
132449
+ );
132450
+ var REWRITTEN_HOISTED_LET = Symbol("REWRITTEN_HOISTED_LET");
132227
132451
  var Visitor3 = class extends ReactiveFunctionTransform {
132228
132452
  transformInstruction(instruction, state) {
132229
132453
  this.visitInstruction(instruction, state);
@@ -132248,25 +132472,64 @@ var Visitor3 = class extends ReactiveFunctionTransform {
132248
132472
  );
132249
132473
  return { kind: "remove" };
132250
132474
  }
132251
- if (instruction.value.kind === "StoreContext" && state.has(instruction.value.lvalue.place.identifier.declarationId)) {
132475
+ if (instruction.value.kind === "StoreContext") {
132252
132476
  const kind = state.get(
132253
132477
  instruction.value.lvalue.place.identifier.declarationId
132254
132478
  );
132255
- return {
132256
- kind: "replace",
132257
- value: {
132258
- kind: "instruction",
132259
- instruction: __spreadProps(__spreadValues({}, instruction), {
132260
- value: __spreadProps(__spreadValues({}, instruction.value), {
132261
- lvalue: __spreadProps(__spreadValues({}, instruction.value.lvalue), {
132262
- kind
132263
- }),
132264
- type: null,
132265
- kind: "StoreLocal"
132266
- })
132267
- })
132479
+ if (kind != null) {
132480
+ CompilerError.invariant(kind !== REWRITTEN_HOISTED_CONST, {
132481
+ reason: "Expected exactly one store to a hoisted const variable",
132482
+ loc: instruction.loc
132483
+ });
132484
+ if (kind === "Const" /* Const */ || kind === "Function" /* Function */) {
132485
+ state.set(
132486
+ instruction.value.lvalue.place.identifier.declarationId,
132487
+ REWRITTEN_HOISTED_CONST
132488
+ );
132489
+ return {
132490
+ kind: "replace",
132491
+ value: {
132492
+ kind: "instruction",
132493
+ instruction: __spreadProps(__spreadValues({}, instruction), {
132494
+ value: __spreadProps(__spreadValues({}, instruction.value), {
132495
+ lvalue: __spreadProps(__spreadValues({}, instruction.value.lvalue), {
132496
+ kind
132497
+ }),
132498
+ type: null,
132499
+ kind: "StoreLocal"
132500
+ })
132501
+ })
132502
+ }
132503
+ };
132504
+ } else if (kind !== REWRITTEN_HOISTED_LET) {
132505
+ state.set(
132506
+ instruction.value.lvalue.place.identifier.declarationId,
132507
+ REWRITTEN_HOISTED_LET
132508
+ );
132509
+ return {
132510
+ kind: "replace-many",
132511
+ value: [
132512
+ {
132513
+ kind: "instruction",
132514
+ instruction: {
132515
+ id: instruction.id,
132516
+ lvalue: null,
132517
+ value: {
132518
+ kind: "DeclareContext",
132519
+ lvalue: {
132520
+ kind: "Let" /* Let */,
132521
+ place: __spreadValues({}, instruction.value.lvalue.place)
132522
+ },
132523
+ loc: instruction.value.loc
132524
+ },
132525
+ loc: instruction.loc
132526
+ }
132527
+ },
132528
+ { kind: "instruction", instruction }
132529
+ ]
132530
+ };
132268
132531
  }
132269
- };
132532
+ }
132270
132533
  }
132271
132534
  return { kind: "keep" };
132272
132535
  }
@@ -132618,10 +132881,9 @@ function inferReferenceEffects(fn, options = { isFunctionExpression: false }) {
132618
132881
  return transformFunctionEffectErrors(functionEffects);
132619
132882
  }
132620
132883
  }
132621
- var _env3, _values, _variables;
132884
+ var _values, _variables;
132622
132885
  var _InferenceState = class _InferenceState {
132623
132886
  constructor(env, values, variables) {
132624
- __privateAdd(this, _env3);
132625
132887
  // The kind of each value, based on its allocation site
132626
132888
  __privateAdd(this, _values);
132627
132889
  /*
@@ -132630,7 +132892,7 @@ var _InferenceState = class _InferenceState {
132630
132892
  * values from different control flow paths).
132631
132893
  */
132632
132894
  __privateAdd(this, _variables);
132633
- __privateSet(this, _env3, env);
132895
+ this.env = env;
132634
132896
  __privateSet(this, _values, values);
132635
132897
  __privateSet(this, _variables, variables);
132636
132898
  }
@@ -132742,7 +133004,7 @@ var _InferenceState = class _InferenceState {
132742
133004
  reason,
132743
133005
  context: /* @__PURE__ */ new Set()
132744
133006
  });
132745
- if (value.kind === "FunctionExpression" && (__privateGet(this, _env3).config.enablePreserveExistingMemoizationGuarantees || __privateGet(this, _env3).config.enableTransitivelyFreezeFunctionExpressions)) {
133007
+ if (value.kind === "FunctionExpression" && (this.env.config.enablePreserveExistingMemoizationGuarantees || this.env.config.enableTransitivelyFreezeFunctionExpressions)) {
132746
133008
  for (const operand of value.loweredFunc.func.context) {
132747
133009
  const operandValues = __privateGet(this, _variables).get(operand.identifier.id);
132748
133010
  if (operandValues !== void 0) {
@@ -132787,6 +133049,18 @@ var _InferenceState = class _InferenceState {
132787
133049
  }
132788
133050
  break;
132789
133051
  }
133052
+ case "mutate-iterator?" /* ConditionallyMutateIterator */: {
133053
+ if (valueKind.kind === "mutable" /* Mutable */ || valueKind.kind === "context" /* Context */) {
133054
+ if (isArrayType(place.identifier) || isSetType(place.identifier) || isMapType(place.identifier)) {
133055
+ effect = "capture" /* Capture */;
133056
+ } else {
133057
+ effect = "mutate?" /* ConditionallyMutate */;
133058
+ }
133059
+ } else {
133060
+ effect = "read" /* Read */;
133061
+ }
133062
+ break;
133063
+ }
132790
133064
  case "mutate" /* Mutate */: {
132791
133065
  effect = "mutate" /* Mutate */;
132792
133066
  break;
@@ -132890,7 +133164,7 @@ var _InferenceState = class _InferenceState {
132890
133164
  return null;
132891
133165
  } else {
132892
133166
  return new _InferenceState(
132893
- __privateGet(this, _env3),
133167
+ this.env,
132894
133168
  nextValues != null ? nextValues : new Map(__privateGet(this, _values)),
132895
133169
  nextVariables != null ? nextVariables : new Map(__privateGet(this, _variables))
132896
133170
  );
@@ -132903,7 +133177,7 @@ var _InferenceState = class _InferenceState {
132903
133177
  */
132904
133178
  clone() {
132905
133179
  return new _InferenceState(
132906
- __privateGet(this, _env3),
133180
+ this.env,
132907
133181
  new Map(__privateGet(this, _values)),
132908
133182
  new Map(__privateGet(this, _variables))
132909
133183
  );
@@ -132946,7 +133220,6 @@ var _InferenceState = class _InferenceState {
132946
133220
  }
132947
133221
  }
132948
133222
  };
132949
- _env3 = new WeakMap();
132950
133223
  _values = new WeakMap();
132951
133224
  _variables = new WeakMap();
132952
133225
  var InferenceState = _InferenceState;
@@ -133030,7 +133303,7 @@ function mergeAbstractValues(a, b) {
133030
133303
  return { kind, reason, context };
133031
133304
  }
133032
133305
  function inferBlock(env, state, block, functionEffects) {
133033
- var _a, _b, _c, _d, _e;
133306
+ var _a, _b, _c;
133034
133307
  for (const phi of block.phis) {
133035
133308
  state.inferPhi(phi);
133036
133309
  }
@@ -133071,7 +133344,7 @@ function inferBlock(env, state, block, functionEffects) {
133071
133344
  state.referenceAndRecordEffects(
133072
133345
  freezeActions,
133073
133346
  element.place,
133074
- isArrayType(element.place.identifier) ? "capture" /* Capture */ : "mutate?" /* ConditionallyMutate */,
133347
+ "mutate-iterator?" /* ConditionallyMutateIterator */,
133075
133348
  "other" /* Other */
133076
133349
  );
133077
133350
  } else if (element.kind === "Identifier") {
@@ -133094,28 +133367,12 @@ function inferBlock(env, state, block, functionEffects) {
133094
133367
  break;
133095
133368
  }
133096
133369
  case "NewExpression": {
133097
- const valueKind = {
133098
- kind: "mutable" /* Mutable */,
133099
- reason: /* @__PURE__ */ new Set(["other" /* Other */]),
133100
- context: /* @__PURE__ */ new Set()
133101
- };
133102
- state.referenceAndRecordEffects(
133370
+ inferCallEffects(
133371
+ state,
133372
+ instr,
133103
133373
  freezeActions,
133104
- instrValue.callee,
133105
- "read" /* Read */,
133106
- "other" /* Other */
133374
+ getFunctionCallSignature(env, instrValue.callee.identifier.type)
133107
133375
  );
133108
- for (const operand of eachCallArgument(instrValue.args)) {
133109
- state.referenceAndRecordEffects(
133110
- freezeActions,
133111
- operand,
133112
- "mutate?" /* ConditionallyMutate */,
133113
- "other" /* Other */
133114
- );
133115
- }
133116
- state.initialize(instrValue, valueKind);
133117
- state.define(instr.lvalue, instrValue);
133118
- instr.lvalue.effect = "mutate?" /* ConditionallyMutate */;
133119
133376
  continuation = { kind: "funeffects" };
133120
133377
  break;
133121
133378
  }
@@ -133388,53 +133645,12 @@ function inferBlock(env, state, block, functionEffects) {
133388
133645
  break;
133389
133646
  }
133390
133647
  case "CallExpression": {
133391
- const signature = getFunctionCallSignature(
133392
- env,
133393
- instrValue.callee.identifier.type
133648
+ inferCallEffects(
133649
+ state,
133650
+ instr,
133651
+ freezeActions,
133652
+ getFunctionCallSignature(env, instrValue.callee.identifier.type)
133394
133653
  );
133395
- const effects = signature !== null ? getFunctionEffects(instrValue, signature) : null;
133396
- const returnValueKind = signature !== null ? {
133397
- kind: signature.returnValueKind,
133398
- reason: /* @__PURE__ */ new Set([
133399
- (_c = signature.returnValueReason) != null ? _c : "known-return-signature" /* KnownReturnSignature */
133400
- ]),
133401
- context: /* @__PURE__ */ new Set()
133402
- } : {
133403
- kind: "mutable" /* Mutable */,
133404
- reason: /* @__PURE__ */ new Set(["other" /* Other */]),
133405
- context: /* @__PURE__ */ new Set()
133406
- };
133407
- let hasCaptureArgument = false;
133408
- for (let i = 0; i < instrValue.args.length; i++) {
133409
- const arg = instrValue.args[i];
133410
- const place = arg.kind === "Identifier" ? arg : arg.place;
133411
- state.referenceAndRecordEffects(
133412
- freezeActions,
133413
- place,
133414
- getArgumentEffect(effects != null ? effects[i] : null, arg),
133415
- "other" /* Other */
133416
- );
133417
- hasCaptureArgument || (hasCaptureArgument = place.effect === "capture" /* Capture */);
133418
- }
133419
- if (signature !== null) {
133420
- state.referenceAndRecordEffects(
133421
- freezeActions,
133422
- instrValue.callee,
133423
- signature.calleeEffect,
133424
- "other" /* Other */
133425
- );
133426
- } else {
133427
- state.referenceAndRecordEffects(
133428
- freezeActions,
133429
- instrValue.callee,
133430
- "mutate?" /* ConditionallyMutate */,
133431
- "other" /* Other */
133432
- );
133433
- }
133434
- hasCaptureArgument || (hasCaptureArgument = instrValue.callee.effect === "capture" /* Capture */);
133435
- state.initialize(instrValue, returnValueKind);
133436
- state.define(instr.lvalue, instrValue);
133437
- instr.lvalue.effect = hasCaptureArgument ? "store" /* Store */ : "mutate?" /* ConditionallyMutate */;
133438
133654
  continuation = { kind: "funeffects" };
133439
133655
  break;
133440
133656
  }
@@ -133451,75 +133667,12 @@ function inferBlock(env, state, block, functionEffects) {
133451
133667
  "read" /* Read */,
133452
133668
  "other" /* Other */
133453
133669
  );
133454
- const signature = getFunctionCallSignature(
133455
- env,
133456
- instrValue.property.identifier.type
133670
+ inferCallEffects(
133671
+ state,
133672
+ instr,
133673
+ freezeActions,
133674
+ getFunctionCallSignature(env, instrValue.property.identifier.type)
133457
133675
  );
133458
- const returnValueKind = signature !== null ? {
133459
- kind: signature.returnValueKind,
133460
- reason: /* @__PURE__ */ new Set([
133461
- (_d = signature.returnValueReason) != null ? _d : "known-return-signature" /* KnownReturnSignature */
133462
- ]),
133463
- context: /* @__PURE__ */ new Set()
133464
- } : {
133465
- kind: "mutable" /* Mutable */,
133466
- reason: /* @__PURE__ */ new Set(["other" /* Other */]),
133467
- context: /* @__PURE__ */ new Set()
133468
- };
133469
- if (signature !== null && signature.mutableOnlyIfOperandsAreMutable && areArgumentsImmutableAndNonMutating(state, instrValue.args)) {
133470
- for (const arg of instrValue.args) {
133471
- const place = arg.kind === "Identifier" ? arg : arg.place;
133472
- state.referenceAndRecordEffects(
133473
- freezeActions,
133474
- place,
133475
- "read" /* Read */,
133476
- "other" /* Other */
133477
- );
133478
- }
133479
- state.referenceAndRecordEffects(
133480
- freezeActions,
133481
- instrValue.receiver,
133482
- "capture" /* Capture */,
133483
- "other" /* Other */
133484
- );
133485
- state.initialize(instrValue, returnValueKind);
133486
- state.define(instr.lvalue, instrValue);
133487
- instr.lvalue.effect = instrValue.receiver.effect === "capture" /* Capture */ ? "store" /* Store */ : "mutate?" /* ConditionallyMutate */;
133488
- continuation = { kind: "funeffects" };
133489
- break;
133490
- }
133491
- const effects = signature !== null ? getFunctionEffects(instrValue, signature) : null;
133492
- let hasCaptureArgument = false;
133493
- for (let i = 0; i < instrValue.args.length; i++) {
133494
- const arg = instrValue.args[i];
133495
- const place = arg.kind === "Identifier" ? arg : arg.place;
133496
- state.referenceAndRecordEffects(
133497
- freezeActions,
133498
- place,
133499
- getArgumentEffect(effects != null ? effects[i] : null, arg),
133500
- "other" /* Other */
133501
- );
133502
- hasCaptureArgument || (hasCaptureArgument = place.effect === "capture" /* Capture */);
133503
- }
133504
- if (signature !== null) {
133505
- state.referenceAndRecordEffects(
133506
- freezeActions,
133507
- instrValue.receiver,
133508
- signature.calleeEffect,
133509
- "other" /* Other */
133510
- );
133511
- } else {
133512
- state.referenceAndRecordEffects(
133513
- freezeActions,
133514
- instrValue.receiver,
133515
- "mutate?" /* ConditionallyMutate */,
133516
- "other" /* Other */
133517
- );
133518
- }
133519
- hasCaptureArgument || (hasCaptureArgument = instrValue.receiver.effect === "capture" /* Capture */);
133520
- state.initialize(instrValue, returnValueKind);
133521
- state.define(instr.lvalue, instrValue);
133522
- instr.lvalue.effect = hasCaptureArgument ? "store" /* Store */ : "mutate?" /* ConditionallyMutate */;
133523
133676
  continuation = { kind: "funeffects" };
133524
133677
  break;
133525
133678
  }
@@ -133846,7 +133999,8 @@ function inferBlock(env, state, block, functionEffects) {
133846
133999
  const isMutable3 = kind === "mutable" /* Mutable */ || kind === "context" /* Context */;
133847
134000
  let effect;
133848
134001
  let valueKind;
133849
- if (!isMutable3 || isArrayType(instrValue.collection.identifier)) {
134002
+ const iterator = instrValue.collection.identifier;
134003
+ if (!isMutable3 || isArrayType(iterator) || isMapType(iterator) || isSetType(iterator)) {
133850
134004
  effect = {
133851
134005
  kind: "read" /* Read */,
133852
134006
  reason: "other" /* Other */
@@ -133875,7 +134029,7 @@ function inferBlock(env, state, block, functionEffects) {
133875
134029
  state.referenceAndRecordEffects(
133876
134030
  freezeActions,
133877
134031
  instrValue.iterator,
133878
- "mutate?" /* ConditionallyMutate */,
134032
+ "mutate-iterator?" /* ConditionallyMutateIterator */,
133879
134033
  "other" /* Other */
133880
134034
  );
133881
134035
  state.referenceAndRecordEffects(
@@ -133924,7 +134078,7 @@ function inferBlock(env, state, block, functionEffects) {
133924
134078
  }
133925
134079
  state.initialize(instrValue, continuation.valueKind);
133926
134080
  state.define(instr.lvalue, instrValue);
133927
- instr.lvalue.effect = (_e = continuation.lvalueEffect) != null ? _e : defaultLvalueEffect;
134081
+ instr.lvalue.effect = (_c = continuation.lvalueEffect) != null ? _c : defaultLvalueEffect;
133928
134082
  }
133929
134083
  functionEffects.push(...inferInstructionFunctionEffects(env, state, instr));
133930
134084
  freezeActions.forEach(
@@ -133988,12 +134142,43 @@ function getFunctionEffects(fn, sig) {
133988
134142
  }
133989
134143
  return results;
133990
134144
  }
134145
+ function isKnownMutableEffect(effect) {
134146
+ switch (effect) {
134147
+ case "store" /* Store */:
134148
+ case "mutate?" /* ConditionallyMutate */:
134149
+ case "mutate-iterator?" /* ConditionallyMutateIterator */:
134150
+ case "mutate" /* Mutate */: {
134151
+ return true;
134152
+ }
134153
+ case "<unknown>" /* Unknown */: {
134154
+ CompilerError.invariant(false, {
134155
+ reason: "Unexpected unknown effect",
134156
+ description: null,
134157
+ loc: GeneratedSource,
134158
+ suggestions: null
134159
+ });
134160
+ }
134161
+ case "read" /* Read */:
134162
+ case "capture" /* Capture */:
134163
+ case "freeze" /* Freeze */: {
134164
+ return false;
134165
+ }
134166
+ default: {
134167
+ assertExhaustive(effect, `Unexpected effect \`${effect}\``);
134168
+ }
134169
+ }
134170
+ }
133991
134171
  function areArgumentsImmutableAndNonMutating(state, args) {
133992
134172
  for (const arg of args) {
134173
+ if (arg.kind === "Identifier" && arg.identifier.type.kind === "Function") {
134174
+ const fnShape = state.env.getFunctionSignature(arg.identifier.type);
134175
+ if (fnShape != null) {
134176
+ return !fnShape.positionalParams.some(isKnownMutableEffect) && (fnShape.restParam == null || !isKnownMutableEffect(fnShape.restParam));
134177
+ }
134178
+ }
133993
134179
  const place = arg.kind === "Identifier" ? arg : arg.place;
133994
134180
  const kind = state.kind(place).kind;
133995
134181
  switch (kind) {
133996
- case "global" /* Global */:
133997
134182
  case "primitive" /* Primitive */:
133998
134183
  case "frozen" /* Frozen */: {
133999
134184
  break;
@@ -134028,12 +134213,81 @@ function getArgumentEffect(signatureEffect, arg) {
134028
134213
  loc: arg.place.loc
134029
134214
  });
134030
134215
  }
134031
- return "mutate?" /* ConditionallyMutate */;
134216
+ return "mutate-iterator?" /* ConditionallyMutateIterator */;
134032
134217
  }
134033
134218
  } else {
134034
134219
  return "mutate?" /* ConditionallyMutate */;
134035
134220
  }
134036
134221
  }
134222
+ function inferCallEffects(state, instr, freezeActions, signature) {
134223
+ var _a;
134224
+ const instrValue = instr.value;
134225
+ const returnValueKind = signature !== null ? {
134226
+ kind: signature.returnValueKind,
134227
+ reason: /* @__PURE__ */ new Set([
134228
+ (_a = signature.returnValueReason) != null ? _a : "known-return-signature" /* KnownReturnSignature */
134229
+ ]),
134230
+ context: /* @__PURE__ */ new Set()
134231
+ } : {
134232
+ kind: "mutable" /* Mutable */,
134233
+ reason: /* @__PURE__ */ new Set(["other" /* Other */]),
134234
+ context: /* @__PURE__ */ new Set()
134235
+ };
134236
+ if (instrValue.kind === "MethodCall" && signature !== null && signature.mutableOnlyIfOperandsAreMutable && areArgumentsImmutableAndNonMutating(state, instrValue.args)) {
134237
+ for (const arg of instrValue.args) {
134238
+ const place = arg.kind === "Identifier" ? arg : arg.place;
134239
+ state.referenceAndRecordEffects(
134240
+ freezeActions,
134241
+ place,
134242
+ "read" /* Read */,
134243
+ "other" /* Other */
134244
+ );
134245
+ }
134246
+ state.referenceAndRecordEffects(
134247
+ freezeActions,
134248
+ instrValue.receiver,
134249
+ "capture" /* Capture */,
134250
+ "other" /* Other */
134251
+ );
134252
+ state.initialize(instrValue, returnValueKind);
134253
+ state.define(instr.lvalue, instrValue);
134254
+ instr.lvalue.effect = instrValue.receiver.effect === "capture" /* Capture */ ? "store" /* Store */ : "mutate?" /* ConditionallyMutate */;
134255
+ return;
134256
+ }
134257
+ const effects = signature !== null ? getFunctionEffects(instrValue, signature) : null;
134258
+ let hasCaptureArgument = false;
134259
+ for (let i = 0; i < instrValue.args.length; i++) {
134260
+ const arg = instrValue.args[i];
134261
+ const place = arg.kind === "Identifier" ? arg : arg.place;
134262
+ state.referenceAndRecordEffects(
134263
+ freezeActions,
134264
+ place,
134265
+ getArgumentEffect(effects != null ? effects[i] : null, arg),
134266
+ "other" /* Other */
134267
+ );
134268
+ hasCaptureArgument || (hasCaptureArgument = place.effect === "capture" /* Capture */);
134269
+ }
134270
+ const callee = instrValue.kind === "MethodCall" ? instrValue.receiver : instrValue.callee;
134271
+ if (signature !== null) {
134272
+ state.referenceAndRecordEffects(
134273
+ freezeActions,
134274
+ callee,
134275
+ signature.calleeEffect,
134276
+ "other" /* Other */
134277
+ );
134278
+ } else {
134279
+ state.referenceAndRecordEffects(
134280
+ freezeActions,
134281
+ callee,
134282
+ instrValue.kind === "NewExpression" ? "read" /* Read */ : "mutate?" /* ConditionallyMutate */,
134283
+ "other" /* Other */
134284
+ );
134285
+ }
134286
+ hasCaptureArgument || (hasCaptureArgument = callee.effect === "capture" /* Capture */);
134287
+ state.initialize(instrValue, returnValueKind);
134288
+ state.define(instr.lvalue, instrValue);
134289
+ instr.lvalue.effect = hasCaptureArgument ? "store" /* Store */ : "mutate?" /* ConditionallyMutate */;
134290
+ }
134037
134291
 
134038
134292
  // src/ReactiveScopes/PruneNonEscapingScopes.ts
134039
134293
  function pruneNonEscapingScopes(fn) {
@@ -134929,7 +135183,7 @@ var Visitor7 = class extends ReactiveFunctionVisitor {
134929
135183
  // src/ReactiveScopes/RenameVariables.ts
134930
135184
  function renameVariables(fn) {
134931
135185
  const globals = collectReferencedGlobals(fn);
134932
- const scopes = new Scopes(globals);
135186
+ const scopes = new Scopes(globals, fn.env.programContext);
134933
135187
  renameVariablesImpl(fn, new Visitor8(), scopes);
134934
135188
  return /* @__PURE__ */ new Set([...scopes.names, ...globals]);
134935
135189
  }
@@ -134979,15 +135233,17 @@ var Visitor8 = class extends ReactiveFunctionVisitor {
134979
135233
  renameVariablesImpl(_fn, this, _state);
134980
135234
  }
134981
135235
  };
134982
- var _seen, _stack, _globals3, _Scopes_instances, lookup_fn;
135236
+ var _seen, _stack, _globals3, _programContext, _Scopes_instances, lookup_fn;
134983
135237
  var Scopes = class {
134984
- constructor(globals) {
135238
+ constructor(globals, programContext) {
134985
135239
  __privateAdd(this, _Scopes_instances);
134986
135240
  __privateAdd(this, _seen, /* @__PURE__ */ new Map());
134987
135241
  __privateAdd(this, _stack, [/* @__PURE__ */ new Map()]);
134988
135242
  __privateAdd(this, _globals3);
135243
+ __privateAdd(this, _programContext);
134989
135244
  this.names = /* @__PURE__ */ new Set();
134990
135245
  __privateSet(this, _globals3, globals);
135246
+ __privateSet(this, _programContext, programContext);
134991
135247
  }
134992
135248
  visit(identifier4) {
134993
135249
  const originalName = identifier4.name;
@@ -135015,6 +135271,7 @@ var Scopes = class {
135015
135271
  name = `${originalName.value}$${id++}`;
135016
135272
  }
135017
135273
  }
135274
+ __privateGet(this, _programContext).addNewReference(name);
135018
135275
  const identifierName = makeIdentifierName(name);
135019
135276
  identifier4.name = identifierName;
135020
135277
  __privateGet(this, _seen).set(identifier4.declarationId, identifierName);
@@ -135037,6 +135294,7 @@ var Scopes = class {
135037
135294
  _seen = new WeakMap();
135038
135295
  _stack = new WeakMap();
135039
135296
  _globals3 = new WeakMap();
135297
+ _programContext = new WeakMap();
135040
135298
  _Scopes_instances = new WeakSet();
135041
135299
  lookup_fn = function(name) {
135042
135300
  for (let i = __privateGet(this, _stack).length - 1; i >= 0; i--) {
@@ -135220,6 +135478,13 @@ function inferPlace(place, instrId, inferMutableRangeForStores) {
135220
135478
  infer(place, instrId);
135221
135479
  }
135222
135480
  return;
135481
+ case "mutate-iterator?" /* ConditionallyMutateIterator */: {
135482
+ const identifier4 = place.identifier;
135483
+ if (!isArrayType(identifier4) && !isSetType(identifier4) && !isMapType(identifier4)) {
135484
+ infer(place, instrId);
135485
+ }
135486
+ return;
135487
+ }
135223
135488
  case "mutate?" /* ConditionallyMutate */:
135224
135489
  case "mutate" /* Mutate */: {
135225
135490
  infer(place, instrId);
@@ -135855,6 +136120,7 @@ function inferReactivePlaces(fn) {
135855
136120
  case "capture" /* Capture */:
135856
136121
  case "store" /* Store */:
135857
136122
  case "mutate?" /* ConditionallyMutate */:
136123
+ case "mutate-iterator?" /* ConditionallyMutateIterator */:
135858
136124
  case "mutate" /* Mutate */: {
135859
136125
  if (isMutable2(instruction, operand)) {
135860
136126
  reactiveIdentifiers.markReactive(operand);
@@ -136222,6 +136488,7 @@ function inferEffectDependencies(fn) {
136222
136488
  if (hasRewrite) {
136223
136489
  markInstructionIds(fn.body);
136224
136490
  fixScopeAndIdentifierRanges(fn.body);
136491
+ fn.env.hasInferredEffect = true;
136225
136492
  }
136226
136493
  }
136227
136494
  function writeDependencyToInstructions(dep, reactive, env, loc) {
@@ -137310,7 +137577,8 @@ function* generateInstructionTypes(env, names, instr) {
137310
137577
  yield equation(value.callee.identifier.type, {
137311
137578
  kind: "Function",
137312
137579
  shapeId: null,
137313
- return: returnType
137580
+ return: returnType,
137581
+ isConstructor: false
137314
137582
  });
137315
137583
  yield equation(left, returnType);
137316
137584
  break;
@@ -137320,7 +137588,8 @@ function* generateInstructionTypes(env, names, instr) {
137320
137588
  yield equation(value.tag.identifier.type, {
137321
137589
  kind: "Function",
137322
137590
  shapeId: null,
137323
- return: returnType
137591
+ return: returnType,
137592
+ isConstructor: false
137324
137593
  });
137325
137594
  yield equation(left, returnType);
137326
137595
  break;
@@ -137369,7 +137638,8 @@ function* generateInstructionTypes(env, names, instr) {
137369
137638
  yield equation(value.property.identifier.type, {
137370
137639
  kind: "Function",
137371
137640
  return: returnType,
137372
- shapeId: null
137641
+ shapeId: null,
137642
+ isConstructor: false
137373
137643
  });
137374
137644
  yield equation(left, returnType);
137375
137645
  break;
@@ -137432,7 +137702,8 @@ function* generateInstructionTypes(env, names, instr) {
137432
137702
  yield equation(left, {
137433
137703
  kind: "Function",
137434
137704
  shapeId: BuiltInFunctionId,
137435
- return: value.loweredFunc.func.returnType
137705
+ return: value.loweredFunc.func.returnType,
137706
+ isConstructor: false
137436
137707
  });
137437
137708
  break;
137438
137709
  }
@@ -137450,9 +137721,19 @@ function* generateInstructionTypes(env, names, instr) {
137450
137721
  yield equation(left, { kind: "Object", shapeId: BuiltInJsxId });
137451
137722
  break;
137452
137723
  }
137724
+ case "NewExpression": {
137725
+ const returnType = makeType();
137726
+ yield equation(value.callee.identifier.type, {
137727
+ kind: "Function",
137728
+ return: returnType,
137729
+ shapeId: null,
137730
+ isConstructor: true
137731
+ });
137732
+ yield equation(left, returnType);
137733
+ break;
137734
+ }
137453
137735
  case "PropertyStore":
137454
137736
  case "DeclareLocal":
137455
- case "NewExpression":
137456
137737
  case "RegExpLiteral":
137457
137738
  case "MetaProperty":
137458
137739
  case "ComputedStore":
@@ -137511,7 +137792,7 @@ var Unifier = class {
137511
137792
  this.bindVariableTo(tB, tA);
137512
137793
  return;
137513
137794
  }
137514
- if (tB.kind === "Function" && tA.kind === "Function") {
137795
+ if (tB.kind === "Function" && tA.kind === "Function" && tA.isConstructor === tB.isConstructor) {
137515
137796
  this.unify(tA.return, tB.return);
137516
137797
  return;
137517
137798
  }
@@ -137612,7 +137893,8 @@ var Unifier = class {
137612
137893
  return {
137613
137894
  kind: "Function",
137614
137895
  return: returnType,
137615
- shapeId: type.shapeId
137896
+ shapeId: type.shapeId,
137897
+ isConstructor: type.isConstructor
137616
137898
  };
137617
137899
  }
137618
137900
  case "ObjectMethod":
@@ -139414,7 +139696,7 @@ function propagatePhiTypes(fn) {
139414
139696
  }
139415
139697
 
139416
139698
  // src/Optimization/LowerContextAccess.ts
139417
- function lowerContextAccess(fn, loweredContextCallee) {
139699
+ function lowerContextAccess(fn, loweredContextCalleeConfig) {
139418
139700
  const contextAccess = /* @__PURE__ */ new Map();
139419
139701
  const contextKeys = /* @__PURE__ */ new Map();
139420
139702
  for (const [, block] of fn.body.blocks) {
@@ -139442,6 +139724,7 @@ function lowerContextAccess(fn, loweredContextCallee) {
139442
139724
  }
139443
139725
  }
139444
139726
  }
139727
+ let importLoweredContextCallee = null;
139445
139728
  if (contextAccess.size > 0 && contextKeys.size > 0) {
139446
139729
  for (const [, block] of fn.body.blocks) {
139447
139730
  let nextInstructions = null;
@@ -139449,9 +139732,12 @@ function lowerContextAccess(fn, loweredContextCallee) {
139449
139732
  const instr = block.instructions[i];
139450
139733
  const { lvalue, value } = instr;
139451
139734
  if (value.kind === "CallExpression" && isUseContextHookType(value.callee.identifier) && contextKeys.has(lvalue.identifier.id)) {
139735
+ importLoweredContextCallee != null ? importLoweredContextCallee : importLoweredContextCallee = fn.env.programContext.addImportSpecifier(
139736
+ loweredContextCalleeConfig
139737
+ );
139452
139738
  const loweredContextCalleeInstr = emitLoadLoweredContextCallee(
139453
139739
  fn.env,
139454
- loweredContextCallee
139740
+ importLoweredContextCallee
139455
139741
  );
139456
139742
  if (nextInstructions === null) {
139457
139743
  nextInstructions = block.instructions.slice(0, i);
@@ -139475,17 +139761,12 @@ function lowerContextAccess(fn, loweredContextCallee) {
139475
139761
  }
139476
139762
  markInstructionIds(fn.body);
139477
139763
  inferTypes(fn);
139478
- fn.env.hasLoweredContextAccess = true;
139479
139764
  }
139480
139765
  }
139481
- function emitLoadLoweredContextCallee(env, loweredContextCallee) {
139766
+ function emitLoadLoweredContextCallee(env, importedLowerContextCallee) {
139482
139767
  const loadGlobal = {
139483
139768
  kind: "LoadGlobal",
139484
- binding: {
139485
- kind: "ImportNamespace",
139486
- module: loweredContextCallee.source,
139487
- name: loweredContextCallee.importSpecifierName
139488
- },
139769
+ binding: __spreadValues({}, importedLowerContextCallee),
139489
139770
  loc: GeneratedSource
139490
139771
  };
139491
139772
  return {
@@ -141192,7 +141473,7 @@ function process2(fn, jsx, globals) {
141192
141473
  if (fn.fnType === "Component") {
141193
141474
  return null;
141194
141475
  }
141195
- const props = collectProps(jsx);
141476
+ const props = collectProps(fn.env, jsx);
141196
141477
  if (!props) return null;
141197
141478
  const outlinedTag = fn.env.generateGloballyUniqueIdentifierName(null).value;
141198
141479
  const newInstrs = emitOutlinedJsx(fn.env, jsx, props, outlinedTag);
@@ -141202,7 +141483,7 @@ function process2(fn, jsx, globals) {
141202
141483
  outlinedFn.id = outlinedTag;
141203
141484
  return { instrs: newInstrs, fn: outlinedFn };
141204
141485
  }
141205
- function collectProps(instructions) {
141486
+ function collectProps(env, instructions) {
141206
141487
  let id = 1;
141207
141488
  function generateName(oldName) {
141208
141489
  let newName = oldName;
@@ -141210,6 +141491,7 @@ function collectProps(instructions) {
141210
141491
  newName = `${oldName}${id++}`;
141211
141492
  }
141212
141493
  seen.add(newName);
141494
+ env.programContext.addNewReference(newName);
141213
141495
  return newName;
141214
141496
  }
141215
141497
  const attributes = [];
@@ -141472,6 +141754,7 @@ function transformFire(fn) {
141472
141754
  context.throwIfErrorsFound();
141473
141755
  }
141474
141756
  function replaceFireFunctions(fn, context) {
141757
+ let importedUseFire = null;
141475
141758
  let hasRewrite = false;
141476
141759
  for (const [, block] of fn.body.blocks) {
141477
141760
  const rewriteInstrs = /* @__PURE__ */ new Map();
@@ -141495,7 +141778,14 @@ function replaceFireFunctions(fn, context) {
141495
141778
  ] of capturedCallees.entries()) {
141496
141779
  if (!context.hasCalleeWithInsertedFire(fireCalleePlace)) {
141497
141780
  context.addCalleeWithInsertedFire(fireCalleePlace);
141498
- const loadUseFireInstr = makeLoadUseFireInstruction(fn.env);
141781
+ importedUseFire != null ? importedUseFire : importedUseFire = fn.env.programContext.addImportSpecifier({
141782
+ source: fn.env.programContext.reactRuntimeModule,
141783
+ importSpecifierName: USE_FIRE_FUNCTION_NAME
141784
+ });
141785
+ const loadUseFireInstr = makeLoadUseFireInstruction(
141786
+ fn.env,
141787
+ importedUseFire
141788
+ );
141499
141789
  const loadFireCalleeInstr = makeLoadFireCalleeInstruction(
141500
141790
  fn.env,
141501
141791
  fireCalleeInfo.capturedCalleeIdentifier
@@ -141715,18 +142005,13 @@ function ensureNoMoreFireUses(fn, context) {
141715
142005
  }
141716
142006
  }
141717
142007
  }
141718
- function makeLoadUseFireInstruction(env) {
142008
+ function makeLoadUseFireInstruction(env, importedLoadUseFire) {
141719
142009
  const useFirePlace = createTemporaryPlace(env, GeneratedSource);
141720
142010
  useFirePlace.effect = "read" /* Read */;
141721
142011
  useFirePlace.identifier.type = DefaultNonmutatingHook;
141722
142012
  const instrValue = {
141723
142013
  kind: "LoadGlobal",
141724
- binding: {
141725
- kind: "ImportSpecifier",
141726
- name: "useFire",
141727
- module: "react",
141728
- imported: "useFire"
141729
- },
142014
+ binding: __spreadValues({}, importedLoadUseFire),
141730
142015
  loc: GeneratedSource
141731
142016
  };
141732
142017
  return {
@@ -141794,10 +142079,10 @@ function makeStoreUseFireInstruction(env, useFireCallResultPlace, fireFunctionBi
141794
142079
  loc: GeneratedSource
141795
142080
  };
141796
142081
  }
141797
- var _env4, _errors, _callExpressions, _functionExpressions, _loadLocals, _fireCalleesToFireFunctions, _calleesWithInsertedFire, _capturedCalleeIdentifierIds, _inUseEffectLambda, _loadGlobalInstructionIds, _arrayExpressions;
142082
+ var _env3, _errors, _callExpressions, _functionExpressions, _loadLocals, _fireCalleesToFireFunctions, _calleesWithInsertedFire, _capturedCalleeIdentifierIds, _inUseEffectLambda, _loadGlobalInstructionIds, _arrayExpressions;
141798
142083
  var Context4 = class {
141799
142084
  constructor(env) {
141800
- __privateAdd(this, _env4);
142085
+ __privateAdd(this, _env3);
141801
142086
  __privateAdd(this, _errors, new CompilerError());
141802
142087
  /*
141803
142088
  * Used to look up the call expression passed to a `fire(callExpr())`. Gives back
@@ -141846,7 +142131,7 @@ var Context4 = class {
141846
142131
  * to use the fire functions
141847
142132
  */
141848
142133
  __privateAdd(this, _arrayExpressions, /* @__PURE__ */ new Map());
141849
- __privateSet(this, _env4, env);
142134
+ __privateSet(this, _env3, env);
141850
142135
  }
141851
142136
  pushError(error) {
141852
142137
  __privateGet(this, _errors).push(error);
@@ -141881,7 +142166,7 @@ var Context4 = class {
141881
142166
  const fireFunctionBinding = getOrInsertWith(
141882
142167
  __privateGet(this, _fireCalleesToFireFunctions),
141883
142168
  callee.identifier.id,
141884
- () => createTemporaryPlace(__privateGet(this, _env4), GeneratedSource)
142169
+ () => createTemporaryPlace(__privateGet(this, _env3), GeneratedSource)
141885
142170
  );
141886
142171
  __privateGet(this, _capturedCalleeIdentifierIds).set(callee.identifier.id, {
141887
142172
  fireFunctionBinding,
@@ -141929,7 +142214,7 @@ var Context4 = class {
141929
142214
  if (this.hasErrors()) throw __privateGet(this, _errors);
141930
142215
  }
141931
142216
  };
141932
- _env4 = new WeakMap();
142217
+ _env3 = new WeakMap();
141933
142218
  _errors = new WeakMap();
141934
142219
  _callExpressions = new WeakMap();
141935
142220
  _functionExpressions = new WeakMap();
@@ -142059,7 +142344,7 @@ function validateStaticComponents(fn) {
142059
142344
  }
142060
142345
 
142061
142346
  // src/Entrypoint/Pipeline.ts
142062
- function run(func, config, fnType, mode, useMemoCacheIdentifier, logger, filename, code) {
142347
+ function run(func, config, fnType, mode, programContext, logger, filename, code) {
142063
142348
  var _a, _b;
142064
142349
  const contextIdentifiers = findContextIdentifiers(func);
142065
142350
  const env = new Environment(
@@ -142071,7 +142356,7 @@ function run(func, config, fnType, mode, useMemoCacheIdentifier, logger, filenam
142071
142356
  logger,
142072
142357
  filename,
142073
142358
  code,
142074
- useMemoCacheIdentifier
142359
+ programContext
142075
142360
  );
142076
142361
  (_b = (_a = env.logger) == null ? void 0 : _a.debugLogIRs) == null ? void 0 : _b.call(_a, {
142077
142362
  kind: "debug",
@@ -142387,29 +142672,19 @@ function runWithEnvironment(func, env) {
142387
142672
  }
142388
142673
  return ast;
142389
142674
  }
142390
- function compileFn(func, config, fnType, mode, useMemoCacheIdentifier, logger, filename, code) {
142675
+ function compileFn(func, config, fnType, mode, programContext, logger, filename, code) {
142391
142676
  return run(
142392
142677
  func,
142393
142678
  config,
142394
142679
  fnType,
142395
142680
  mode,
142396
- useMemoCacheIdentifier,
142681
+ programContext,
142397
142682
  logger,
142398
142683
  filename,
142399
142684
  code
142400
142685
  );
142401
142686
  }
142402
142687
 
142403
- // src/Utils/ComponentDeclaration.ts
142404
- function isComponentDeclaration(node) {
142405
- return Object.prototype.hasOwnProperty.call(node, "__componentDeclaration");
142406
- }
142407
-
142408
- // src/Utils/HookDeclaration.ts
142409
- function isHookDeclaration(node) {
142410
- return Object.prototype.hasOwnProperty.call(node, "__hookDeclaration");
142411
- }
142412
-
142413
142688
  // src/Entrypoint/Suppression.ts
142414
142689
  function filterSuppressionsThatAffectFunction(suppressionRanges, fn) {
142415
142690
  const suppressionsInScope = [];
@@ -142712,7 +142987,11 @@ function compileProgram(program, pass) {
142712
142987
  handleError(restrictedImportsErr, pass, null);
142713
142988
  return null;
142714
142989
  }
142715
- const useMemoCacheIdentifier = program.scope.generateUidIdentifier("c");
142990
+ const programContext = new ProgramContext2(
142991
+ program,
142992
+ pass.opts.target,
142993
+ environment.hookPattern
142994
+ );
142716
142995
  const suppressions = findProgramSuppressions(
142717
142996
  pass.comments,
142718
142997
  (_a = pass.opts.eslintSuppressionRules) != null ? _a : DEFAULT_ESLINT_SUPPRESSIONS,
@@ -142780,7 +143059,7 @@ function compileProgram(program, pass) {
142780
143059
  environment,
142781
143060
  fnType,
142782
143061
  "all_features",
142783
- useMemoCacheIdentifier.name,
143062
+ programContext,
142784
143063
  pass.opts.logger,
142785
143064
  pass.filename,
142786
143065
  pass.code
@@ -142807,13 +143086,13 @@ function compileProgram(program, pass) {
142807
143086
  environment,
142808
143087
  fnType,
142809
143088
  "no_inferred_memo",
142810
- useMemoCacheIdentifier.name,
143089
+ programContext,
142811
143090
  pass.opts.logger,
142812
143091
  pass.filename,
142813
143092
  pass.code
142814
143093
  )
142815
143094
  };
142816
- if (!compileResult.compiledFn.hasFireRewrite && !compileResult.compiledFn.hasLoweredContextAccess) {
143095
+ if (!compileResult.compiledFn.hasFireRewrite && !compileResult.compiledFn.hasInferredEffect) {
142817
143096
  return null;
142818
143097
  }
142819
143098
  } catch (err) {
@@ -142892,82 +143171,28 @@ function compileProgram(program, pass) {
142892
143171
  if (moduleScopeOptOutDirectives.length > 0) {
142893
143172
  return null;
142894
143173
  }
142895
- let gating = null;
142896
- if (pass.opts.gating != null) {
142897
- gating = {
142898
- gatingFn: pass.opts.gating,
142899
- referencedBeforeDeclared: getFunctionReferencedBeforeDeclarationAtTopLevel(program, compiledFns)
142900
- };
142901
- }
142902
- const hasLoweredContextAccess = compiledFns.some(
142903
- (c2) => c2.compiledFn.hasLoweredContextAccess
142904
- );
142905
- const externalFunctions = [];
142906
- try {
142907
- if (gating != null) {
142908
- externalFunctions.push(gating.gatingFn);
142909
- }
142910
- const lowerContextAccess2 = environment.lowerContextAccess;
142911
- if (lowerContextAccess2 && hasLoweredContextAccess) {
142912
- externalFunctions.push(lowerContextAccess2);
142913
- }
142914
- const enableEmitInstrumentForget = environment.enableEmitInstrumentForget;
142915
- if (enableEmitInstrumentForget != null) {
142916
- externalFunctions.push(enableEmitInstrumentForget.fn);
142917
- if (enableEmitInstrumentForget.gating != null) {
142918
- externalFunctions.push(enableEmitInstrumentForget.gating);
142919
- }
142920
- }
142921
- if (environment.enableEmitFreeze != null) {
142922
- externalFunctions.push(environment.enableEmitFreeze);
142923
- }
142924
- if (environment.enableEmitHookGuards != null) {
142925
- externalFunctions.push(environment.enableEmitHookGuards);
142926
- }
142927
- if (environment.enableChangeDetectionForDebugging != null) {
142928
- externalFunctions.push(environment.enableChangeDetectionForDebugging);
142929
- }
142930
- const hasFireRewrite = compiledFns.some((c2) => c2.compiledFn.hasFireRewrite);
142931
- if (environment.enableFire && hasFireRewrite) {
142932
- externalFunctions.push({
142933
- source: getReactCompilerRuntimeModule(pass.opts),
142934
- importSpecifierName: "useFire"
142935
- });
142936
- }
142937
- } catch (err) {
142938
- handleError(err, pass, null);
142939
- return null;
142940
- }
143174
+ const referencedBeforeDeclared = pass.opts.gating != null ? getFunctionReferencedBeforeDeclarationAtTopLevel(program, compiledFns) : null;
142941
143175
  for (const result of compiledFns) {
142942
143176
  const { kind, originalFn, compiledFn } = result;
142943
143177
  const transformedFn = createNewFunctionNode(originalFn, compiledFn);
142944
- if (gating != null && kind === "original") {
143178
+ if (referencedBeforeDeclared != null && kind === "original") {
143179
+ CompilerError.invariant(pass.opts.gating != null, {
143180
+ reason: "Expected 'gating' import to be present",
143181
+ loc: null
143182
+ });
142945
143183
  insertGatedFunctionDeclaration(
142946
143184
  originalFn,
142947
143185
  transformedFn,
142948
- gating.gatingFn,
142949
- gating.referencedBeforeDeclared.has(result)
143186
+ programContext,
143187
+ pass.opts.gating,
143188
+ referencedBeforeDeclared.has(result)
142950
143189
  );
142951
143190
  } else {
142952
143191
  originalFn.replaceWith(transformedFn);
142953
143192
  }
142954
143193
  }
142955
143194
  if (compiledFns.length > 0) {
142956
- let needsMemoCacheFunctionImport = false;
142957
- for (const fn of compiledFns) {
142958
- if (fn.compiledFn.memoSlotsUsed > 0) {
142959
- needsMemoCacheFunctionImport = true;
142960
- break;
142961
- }
142962
- }
142963
- if (needsMemoCacheFunctionImport) {
142964
- updateMemoCacheFunctionImport(
142965
- program,
142966
- getReactCompilerRuntimeModule(pass.opts),
142967
- useMemoCacheIdentifier.name
142968
- );
142969
- }
142970
- addImportsToProgram(program, externalFunctions);
143195
+ addImportsToProgram(program, programContext);
142971
143196
  }
142972
143197
  return { retryErrors };
142973
143198
  }
@@ -142992,7 +143217,7 @@ function shouldSkipCompilation(program, pass) {
142992
143217
  }
142993
143218
  if (hasMemoCacheFunctionImport(
142994
143219
  program,
142995
- getReactCompilerRuntimeModule(pass.opts)
143220
+ getReactCompilerRuntimeModule(pass.opts.target)
142996
143221
  )) {
142997
143222
  return true;
142998
143223
  }
@@ -143186,26 +143411,32 @@ function callsHooksOrCreatesJsx(node, hookPattern) {
143186
143411
  });
143187
143412
  return invokesHooks || createsJsx;
143188
143413
  }
143414
+ function isNonNode(node) {
143415
+ if (!node) {
143416
+ return true;
143417
+ }
143418
+ switch (node.type) {
143419
+ case "ObjectExpression":
143420
+ case "ArrowFunctionExpression":
143421
+ case "FunctionExpression":
143422
+ case "BigIntLiteral":
143423
+ case "ClassExpression":
143424
+ case "NewExpression":
143425
+ return true;
143426
+ }
143427
+ return false;
143428
+ }
143189
143429
  function returnsNonNode(node) {
143190
- let hasReturn = false;
143191
143430
  let returnsNonNode2 = false;
143431
+ if (
143432
+ // node.traverse#ArrowFunctionExpression isn't called for the root node
143433
+ node.type === "ArrowFunctionExpression" && node.node.body.type !== "BlockStatement"
143434
+ ) {
143435
+ returnsNonNode2 = isNonNode(node.node.body);
143436
+ }
143192
143437
  node.traverse({
143193
143438
  ReturnStatement(ret) {
143194
- hasReturn = true;
143195
- const argument = ret.node.argument;
143196
- if (argument == null) {
143197
- returnsNonNode2 = true;
143198
- } else {
143199
- switch (argument.type) {
143200
- case "ObjectExpression":
143201
- case "ArrowFunctionExpression":
143202
- case "FunctionExpression":
143203
- case "BigIntLiteral":
143204
- case "ClassExpression":
143205
- case "NewExpression":
143206
- returnsNonNode2 = true;
143207
- }
143208
- }
143439
+ returnsNonNode2 = isNonNode(ret.node.argument);
143209
143440
  },
143210
143441
  // Skip traversing all nested functions and their return statements
143211
143442
  ArrowFunctionExpression: skipNestedFunctions(node),
@@ -143213,7 +143444,7 @@ function returnsNonNode(node) {
143213
143444
  FunctionDeclaration: skipNestedFunctions(node),
143214
143445
  ObjectMethod: (node2) => node2.skip()
143215
143446
  });
143216
- return !hasReturn || returnsNonNode2;
143447
+ return returnsNonNode2;
143217
143448
  }
143218
143449
  function getFunctionName2(path) {
143219
143450
  if (path.isFunctionDeclaration()) {
@@ -143280,14 +143511,14 @@ function getFunctionReferencedBeforeDeclarationAtTopLevel(program, fns) {
143280
143511
  });
143281
143512
  return referencedBeforeDeclaration;
143282
143513
  }
143283
- function getReactCompilerRuntimeModule(opts) {
143284
- if (opts.target === "19") {
143514
+ function getReactCompilerRuntimeModule(target) {
143515
+ if (target === "19") {
143285
143516
  return "react/compiler-runtime";
143286
- } else if (opts.target === "17" || opts.target === "18") {
143517
+ } else if (target === "17" || target === "18") {
143287
143518
  return "react-compiler-runtime";
143288
143519
  } else {
143289
143520
  CompilerError.invariant(
143290
- opts.target != null && opts.target.kind === "donotuse_meta_internal" && typeof opts.target.runtimeModule === "string",
143521
+ target != null && target.kind === "donotuse_meta_internal" && typeof target.runtimeModule === "string",
143291
143522
  {
143292
143523
  reason: "Expected target to already be validated",
143293
143524
  description: null,
@@ -143295,8 +143526,313 @@ function getReactCompilerRuntimeModule(opts) {
143295
143526
  suggestions: null
143296
143527
  }
143297
143528
  );
143298
- return opts.target.runtimeModule;
143529
+ return target.runtimeModule;
143530
+ }
143531
+ }
143532
+
143533
+ // src/Entrypoint/Imports.ts
143534
+ function validateRestrictedImports(path, { validateBlocklistedImports }) {
143535
+ if (validateBlocklistedImports == null || validateBlocklistedImports.length === 0) {
143536
+ return null;
143299
143537
  }
143538
+ const error = new CompilerError();
143539
+ const restrictedImports = new Set(validateBlocklistedImports);
143540
+ path.traverse({
143541
+ ImportDeclaration(importDeclPath) {
143542
+ var _a;
143543
+ if (restrictedImports.has(importDeclPath.node.source.value)) {
143544
+ error.push({
143545
+ severity: "Todo" /* Todo */,
143546
+ reason: "Bailing out due to blocklisted import",
143547
+ description: `Import from module ${importDeclPath.node.source.value}`,
143548
+ loc: (_a = importDeclPath.node.loc) != null ? _a : null
143549
+ });
143550
+ }
143551
+ }
143552
+ });
143553
+ if (error.hasErrors()) {
143554
+ return error;
143555
+ } else {
143556
+ return null;
143557
+ }
143558
+ }
143559
+ var ProgramContext2 = class {
143560
+ constructor(program, reactRuntimeModule, hookPattern) {
143561
+ // known generated or referenced identifiers in the program
143562
+ this.knownReferencedNames = /* @__PURE__ */ new Set();
143563
+ // generated imports
143564
+ this.imports = /* @__PURE__ */ new Map();
143565
+ this.hookPattern = hookPattern;
143566
+ this.scope = program.scope;
143567
+ this.reactRuntimeModule = getReactCompilerRuntimeModule(reactRuntimeModule);
143568
+ }
143569
+ isHookName(name) {
143570
+ if (this.hookPattern == null) {
143571
+ return isHookName(name);
143572
+ } else {
143573
+ const match = new RegExp(this.hookPattern).exec(name);
143574
+ return match != null && typeof match[1] === "string" && isHookName(match[1]);
143575
+ }
143576
+ }
143577
+ hasReference(name) {
143578
+ return this.knownReferencedNames.has(name) || this.scope.hasBinding(name) || this.scope.hasGlobal(name) || this.scope.hasReference(name);
143579
+ }
143580
+ newUid(name) {
143581
+ let uid;
143582
+ if (this.isHookName(name)) {
143583
+ uid = name;
143584
+ let i = 0;
143585
+ while (this.hasReference(uid)) {
143586
+ this.knownReferencedNames.add(uid);
143587
+ uid = `${name}_${i++}`;
143588
+ }
143589
+ } else if (!this.hasReference(name)) {
143590
+ uid = name;
143591
+ } else {
143592
+ uid = this.scope.generateUid(name);
143593
+ }
143594
+ this.knownReferencedNames.add(uid);
143595
+ return uid;
143596
+ }
143597
+ addMemoCacheImport() {
143598
+ return this.addImportSpecifier(
143599
+ {
143600
+ source: this.reactRuntimeModule,
143601
+ importSpecifierName: "c"
143602
+ },
143603
+ "_c"
143604
+ );
143605
+ }
143606
+ /**
143607
+ *
143608
+ * @param externalFunction
143609
+ * @param nameHint if defined, will be used as the name of the import specifier
143610
+ * @returns
143611
+ */
143612
+ addImportSpecifier({ source: module2, importSpecifierName: specifier }, nameHint) {
143613
+ var _a;
143614
+ const maybeBinding = (_a = this.imports.get(module2)) == null ? void 0 : _a.get(specifier);
143615
+ if (maybeBinding != null) {
143616
+ return __spreadValues({}, maybeBinding);
143617
+ }
143618
+ const binding = {
143619
+ kind: "ImportSpecifier",
143620
+ name: this.newUid(nameHint != null ? nameHint : specifier),
143621
+ module: module2,
143622
+ imported: specifier
143623
+ };
143624
+ getOrInsertWith(this.imports, module2, () => /* @__PURE__ */ new Map()).set(specifier, __spreadValues({}, binding));
143625
+ return binding;
143626
+ }
143627
+ addNewReference(name) {
143628
+ this.knownReferencedNames.add(name);
143629
+ }
143630
+ assertGlobalBinding(name, localScope) {
143631
+ var _a, _b;
143632
+ const scope = localScope != null ? localScope : this.scope;
143633
+ if (!scope.hasReference(name) && !scope.hasBinding(name)) {
143634
+ return Ok(void 0);
143635
+ }
143636
+ const error = new CompilerError();
143637
+ error.push({
143638
+ severity: "Todo" /* Todo */,
143639
+ reason: "Encountered conflicting global in generated program",
143640
+ description: `Conflict from local binding ${name}`,
143641
+ loc: (_b = (_a = scope.getBinding(name)) == null ? void 0 : _a.path.node.loc) != null ? _b : null,
143642
+ suggestions: null
143643
+ });
143644
+ return Err(error);
143645
+ }
143646
+ };
143647
+ function getExistingImports(program) {
143648
+ const existingImports = /* @__PURE__ */ new Map();
143649
+ program.traverse({
143650
+ ImportDeclaration(path) {
143651
+ if (isNonNamespacedImport(path)) {
143652
+ existingImports.set(path.node.source.value, path);
143653
+ }
143654
+ }
143655
+ });
143656
+ return existingImports;
143657
+ }
143658
+ function addImportsToProgram(path, programContext) {
143659
+ const existingImports = getExistingImports(path);
143660
+ const stmts = [];
143661
+ const sortedModules = [...programContext.imports.entries()].sort(
143662
+ ([a], [b]) => a.localeCompare(b)
143663
+ );
143664
+ for (const [moduleName, importsMap] of sortedModules) {
143665
+ for (const [specifierName, loweredImport] of importsMap) {
143666
+ CompilerError.invariant(
143667
+ path.scope.getBinding(loweredImport.name) == null,
143668
+ {
143669
+ reason: "Encountered conflicting import specifiers in generated program",
143670
+ description: `Conflict from import ${loweredImport.module}:(${loweredImport.imported} as ${loweredImport.name}).`,
143671
+ loc: GeneratedSource,
143672
+ suggestions: null
143673
+ }
143674
+ );
143675
+ CompilerError.invariant(
143676
+ loweredImport.module === moduleName && loweredImport.imported === specifierName,
143677
+ {
143678
+ reason: "Found inconsistent import specifier. This is an internal bug.",
143679
+ description: `Expected import ${moduleName}:${specifierName} but found ${loweredImport.module}:${loweredImport.imported}`,
143680
+ loc: GeneratedSource
143681
+ }
143682
+ );
143683
+ }
143684
+ const sortedImport = [
143685
+ ...importsMap.values()
143686
+ ].sort(({ imported: a }, { imported: b }) => a.localeCompare(b));
143687
+ const importSpecifiers = sortedImport.map((specifier) => {
143688
+ return t4.importSpecifier(
143689
+ t4.identifier(specifier.name),
143690
+ t4.identifier(specifier.imported)
143691
+ );
143692
+ });
143693
+ const maybeExistingImports = existingImports.get(moduleName);
143694
+ if (maybeExistingImports != null) {
143695
+ maybeExistingImports.pushContainer("specifiers", importSpecifiers);
143696
+ } else {
143697
+ stmts.push(
143698
+ t4.importDeclaration(importSpecifiers, t4.stringLiteral(moduleName))
143699
+ );
143700
+ }
143701
+ }
143702
+ path.unshiftContainer("body", stmts);
143703
+ }
143704
+ function isNonNamespacedImport(importDeclPath) {
143705
+ return importDeclPath.get("specifiers").every((specifier) => specifier.isImportSpecifier()) && importDeclPath.node.importKind !== "type" && importDeclPath.node.importKind !== "typeof";
143706
+ }
143707
+
143708
+ // src/Entrypoint/Options.ts
143709
+ var PanicThresholdOptionsSchema = z.enum([
143710
+ /*
143711
+ * Any errors will panic the compiler by throwing an exception, which will
143712
+ * bubble up to the nearest exception handler above the Forget transform.
143713
+ * If Forget is invoked through `BabelPluginReactCompiler`, this will at the least
143714
+ * skip Forget compilation for the rest of current file.
143715
+ */
143716
+ "all_errors",
143717
+ /*
143718
+ * Panic by throwing an exception only on critical or unrecognized errors.
143719
+ * For all other errors, skip the erroring function without inserting
143720
+ * a Forget-compiled version (i.e. same behavior as noEmit).
143721
+ */
143722
+ "critical_errors",
143723
+ // Never panic by throwing an exception.
143724
+ "none"
143725
+ ]);
143726
+ var CompilerReactTargetSchema = z.union([
143727
+ z.literal("17"),
143728
+ z.literal("18"),
143729
+ z.literal("19"),
143730
+ /**
143731
+ * Used exclusively for Meta apps which are guaranteed to have compatible
143732
+ * react runtime and compiler versions. Note that only the FB-internal bundles
143733
+ * re-export useMemoCache (see
143734
+ * https://github.com/facebook/react/blob/5b0ef217ef32333a8e56f39be04327c89efa346f/packages/react/index.fb.js#L68-L70),
143735
+ * so this option is invalid / creates runtime errors for open-source users.
143736
+ */
143737
+ z.object({
143738
+ kind: z.literal("donotuse_meta_internal"),
143739
+ runtimeModule: z.string().default("react")
143740
+ })
143741
+ ]);
143742
+ var CompilationModeSchema = z.enum([
143743
+ /*
143744
+ * Compiles functions annotated with "use forget" or component/hook-like functions.
143745
+ * This latter includes:
143746
+ * * Components declared with component syntax.
143747
+ * * Functions which can be inferred to be a component or hook:
143748
+ * - Be named like a hook or component. This logic matches the ESLint rule.
143749
+ * - *and* create JSX and/or call a hook. This is an additional check to help prevent
143750
+ * false positives, since compilation has a greater impact than linting.
143751
+ * This is the default mode
143752
+ */
143753
+ "infer",
143754
+ // Compile only components using Flow component syntax and hooks using hook syntax.
143755
+ "syntax",
143756
+ // Compile only functions which are explicitly annotated with "use forget"
143757
+ "annotation",
143758
+ // Compile all top-level functions
143759
+ "all"
143760
+ ]);
143761
+ var defaultOptions = {
143762
+ compilationMode: "infer",
143763
+ panicThreshold: "none",
143764
+ environment: parseEnvironmentConfig({}).unwrap(),
143765
+ logger: null,
143766
+ gating: null,
143767
+ noEmit: false,
143768
+ eslintSuppressionRules: null,
143769
+ flowSuppressions: true,
143770
+ ignoreUseNoForget: false,
143771
+ sources: (filename) => {
143772
+ return filename.indexOf("node_modules") === -1;
143773
+ },
143774
+ enableReanimatedCheck: true,
143775
+ target: "19"
143776
+ };
143777
+ function parsePluginOptions(obj) {
143778
+ if (obj == null || typeof obj !== "object") {
143779
+ return defaultOptions;
143780
+ }
143781
+ const parsedOptions = /* @__PURE__ */ Object.create(null);
143782
+ for (let [key2, value] of Object.entries(obj)) {
143783
+ if (typeof value === "string") {
143784
+ value = value.toLowerCase();
143785
+ }
143786
+ if (isCompilerFlag(key2)) {
143787
+ switch (key2) {
143788
+ case "environment": {
143789
+ const environmentResult = parseEnvironmentConfig(value);
143790
+ if (environmentResult.isErr()) {
143791
+ CompilerError.throwInvalidConfig({
143792
+ reason: "Error in validating environment config. This is an advanced setting and not meant to be used directly",
143793
+ description: environmentResult.unwrapErr().toString(),
143794
+ suggestions: null,
143795
+ loc: null
143796
+ });
143797
+ }
143798
+ parsedOptions[key2] = environmentResult.unwrap();
143799
+ break;
143800
+ }
143801
+ case "target": {
143802
+ parsedOptions[key2] = parseTargetConfig(value);
143803
+ break;
143804
+ }
143805
+ case "gating": {
143806
+ if (value == null) {
143807
+ parsedOptions[key2] = null;
143808
+ } else {
143809
+ parsedOptions[key2] = tryParseExternalFunction(value);
143810
+ }
143811
+ break;
143812
+ }
143813
+ default: {
143814
+ parsedOptions[key2] = value;
143815
+ }
143816
+ }
143817
+ }
143818
+ }
143819
+ return __spreadValues(__spreadValues({}, defaultOptions), parsedOptions);
143820
+ }
143821
+ function parseTargetConfig(value) {
143822
+ const parsed = CompilerReactTargetSchema.safeParse(value);
143823
+ if (parsed.success) {
143824
+ return parsed.data;
143825
+ } else {
143826
+ CompilerError.throwInvalidConfig({
143827
+ reason: "Not a valid target",
143828
+ description: `${fromZodError(parsed.error)}`,
143829
+ suggestions: null,
143830
+ loc: null
143831
+ });
143832
+ }
143833
+ }
143834
+ function isCompilerFlag(s) {
143835
+ return hasOwnProperty2(defaultOptions, s);
143300
143836
  }
143301
143837
 
143302
143838
  // src/Entrypoint/Reanimated.ts
@@ -143622,6 +144158,7 @@ var index_default = BabelPluginReactCompiler;
143622
144158
  ErrorSeverity,
143623
144159
  OPT_IN_DIRECTIVES,
143624
144160
  OPT_OUT_DIRECTIVES,
144161
+ ProgramContext,
143625
144162
  ValueKind,
143626
144163
  compile,
143627
144164
  compileProgram,