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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.d.ts +103 -18
  2. package/dist/index.js +1625 -1047
  3. package/package.json +1 -1
package/dist/index.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,
@@ -110448,6 +110449,126 @@ var import_invariant4 = __toESM(require_invariant());
110448
110449
  // src/Entrypoint/Gating.ts
110449
110450
  var t = __toESM(require("@babel/types"));
110450
110451
 
110452
+ // src/Utils/Result.ts
110453
+ function Ok(val) {
110454
+ return new OkImpl(val);
110455
+ }
110456
+ var OkImpl = class _OkImpl {
110457
+ constructor(val) {
110458
+ this.val = val;
110459
+ }
110460
+ map(fn) {
110461
+ return new _OkImpl(fn(this.val));
110462
+ }
110463
+ mapErr(_fn) {
110464
+ return this;
110465
+ }
110466
+ mapOr(_fallback, fn) {
110467
+ return fn(this.val);
110468
+ }
110469
+ mapOrElse(_fallback, fn) {
110470
+ return fn(this.val);
110471
+ }
110472
+ andThen(fn) {
110473
+ return fn(this.val);
110474
+ }
110475
+ and(res) {
110476
+ return res;
110477
+ }
110478
+ or(_res) {
110479
+ return this;
110480
+ }
110481
+ orElse(_fn) {
110482
+ return this;
110483
+ }
110484
+ isOk() {
110485
+ return true;
110486
+ }
110487
+ isErr() {
110488
+ return false;
110489
+ }
110490
+ expect(_msg) {
110491
+ return this.val;
110492
+ }
110493
+ expectErr(msg) {
110494
+ throw new Error(`${msg}: ${this.val}`);
110495
+ }
110496
+ unwrap() {
110497
+ return this.val;
110498
+ }
110499
+ unwrapOr(_fallback) {
110500
+ return this.val;
110501
+ }
110502
+ unwrapOrElse(_fallback) {
110503
+ return this.val;
110504
+ }
110505
+ unwrapErr() {
110506
+ if (this.val instanceof Error) {
110507
+ throw this.val;
110508
+ }
110509
+ throw new Error(`Can't unwrap \`Ok\` to \`Err\`: ${this.val}`);
110510
+ }
110511
+ };
110512
+ function Err(val) {
110513
+ return new ErrImpl(val);
110514
+ }
110515
+ var ErrImpl = class _ErrImpl {
110516
+ constructor(val) {
110517
+ this.val = val;
110518
+ }
110519
+ map(_fn) {
110520
+ return this;
110521
+ }
110522
+ mapErr(fn) {
110523
+ return new _ErrImpl(fn(this.val));
110524
+ }
110525
+ mapOr(fallback, _fn) {
110526
+ return fallback;
110527
+ }
110528
+ mapOrElse(fallback, _fn) {
110529
+ return fallback();
110530
+ }
110531
+ andThen(_fn) {
110532
+ return this;
110533
+ }
110534
+ and(_res) {
110535
+ return this;
110536
+ }
110537
+ or(res) {
110538
+ return res;
110539
+ }
110540
+ orElse(fn) {
110541
+ return fn(this.val);
110542
+ }
110543
+ isOk() {
110544
+ return false;
110545
+ }
110546
+ isErr() {
110547
+ return true;
110548
+ }
110549
+ expect(msg) {
110550
+ throw new Error(`${msg}: ${this.val}`);
110551
+ }
110552
+ expectErr(_msg) {
110553
+ return this.val;
110554
+ }
110555
+ unwrap() {
110556
+ if (this.val instanceof Error) {
110557
+ throw this.val;
110558
+ }
110559
+ throw new Error(`Can't unwrap \`Err\` to \`Ok\`: ${this.val}`);
110560
+ }
110561
+ unwrapOr(fallback) {
110562
+ return fallback;
110563
+ }
110564
+ unwrapOrElse(fallback) {
110565
+ return fallback(this.val);
110566
+ }
110567
+ unwrapErr() {
110568
+ return this.val;
110569
+ }
110570
+ };
110571
+
110451
110572
  // src/Utils/utils.ts
110452
110573
  function assertExhaustive(_, errorMsg) {
110453
110574
  throw new Error(errorMsg);
@@ -110682,6 +110803,9 @@ var CompilerError = class _CompilerError extends Error {
110682
110803
  hasErrors() {
110683
110804
  return this.details.length > 0;
110684
110805
  }
110806
+ asResult() {
110807
+ return this.hasErrors() ? Err(this) : Ok(void 0);
110808
+ }
110685
110809
  /*
110686
110810
  * An error is critical if it means the compiler has entered into a broken state and cannot
110687
110811
  * continue safely. Other expected errors such as Todos mean that we can skip over that component
@@ -110706,7 +110830,7 @@ var CompilerError = class _CompilerError extends Error {
110706
110830
  };
110707
110831
 
110708
110832
  // src/Entrypoint/Gating.ts
110709
- function insertAdditionalFunctionDeclaration(fnPath, compiled, gating) {
110833
+ function insertAdditionalFunctionDeclaration(fnPath, compiled, programContext, gatingFunctionIdentifierName) {
110710
110834
  var _a, _b;
110711
110835
  const originalFnName = fnPath.node.id;
110712
110836
  const originalFnParams = fnPath.node.params;
@@ -110719,14 +110843,14 @@ function insertAdditionalFunctionDeclaration(fnPath, compiled, gating) {
110719
110843
  reason: "Expected React Compiler optimized function declarations to have the same number of parameters as source",
110720
110844
  loc: (_b = fnPath.node.loc) != null ? _b : null
110721
110845
  });
110722
- const gatingCondition = fnPath.scope.generateUidIdentifier(
110723
- `${gating.importSpecifierName}_result`
110846
+ const gatingCondition = t.identifier(
110847
+ programContext.newUid(`${gatingFunctionIdentifierName}_result`)
110724
110848
  );
110725
- const unoptimizedFnName = fnPath.scope.generateUidIdentifier(
110726
- `${originalFnName.name}_unoptimized`
110849
+ const unoptimizedFnName = t.identifier(
110850
+ programContext.newUid(`${originalFnName.name}_unoptimized`)
110727
110851
  );
110728
- const optimizedFnName = fnPath.scope.generateUidIdentifier(
110729
- `${originalFnName.name}_optimized`
110852
+ const optimizedFnName = t.identifier(
110853
+ programContext.newUid(`${originalFnName.name}_optimized`)
110730
110854
  );
110731
110855
  compiled.id.name = optimizedFnName.name;
110732
110856
  fnPath.get("id").replaceInline(unoptimizedFnName);
@@ -110769,24 +110893,30 @@ function insertAdditionalFunctionDeclaration(fnPath, compiled, gating) {
110769
110893
  t.variableDeclaration("const", [
110770
110894
  t.variableDeclarator(
110771
110895
  gatingCondition,
110772
- t.callExpression(t.identifier(gating.importSpecifierName), [])
110896
+ t.callExpression(t.identifier(gatingFunctionIdentifierName), [])
110773
110897
  )
110774
110898
  ])
110775
110899
  );
110776
110900
  fnPath.insertBefore(compiled);
110777
110901
  }
110778
- function insertGatedFunctionDeclaration(fnPath, compiled, gating, referencedBeforeDeclaration) {
110902
+ function insertGatedFunctionDeclaration(fnPath, compiled, programContext, gating, referencedBeforeDeclaration) {
110779
110903
  var _a;
110904
+ const gatingImportedName = programContext.addImportSpecifier(gating).name;
110780
110905
  if (referencedBeforeDeclaration && fnPath.isFunctionDeclaration()) {
110781
110906
  CompilerError.invariant(compiled.type === "FunctionDeclaration", {
110782
110907
  reason: "Expected compiled node type to match input type",
110783
110908
  description: `Got ${compiled.type} but expected FunctionDeclaration`,
110784
110909
  loc: (_a = fnPath.node.loc) != null ? _a : null
110785
110910
  });
110786
- insertAdditionalFunctionDeclaration(fnPath, compiled, gating);
110911
+ insertAdditionalFunctionDeclaration(
110912
+ fnPath,
110913
+ compiled,
110914
+ programContext,
110915
+ gatingImportedName
110916
+ );
110787
110917
  } else {
110788
110918
  const gatingExpression = t.conditionalExpression(
110789
- t.callExpression(t.identifier(gating.importSpecifierName), []),
110919
+ t.callExpression(t.identifier(gatingImportedName), []),
110790
110920
  buildFunctionExpression(compiled),
110791
110921
  buildFunctionExpression(fnPath.node)
110792
110922
  );
@@ -110832,7 +110962,7 @@ function buildFunctionExpression(node) {
110832
110962
  }
110833
110963
 
110834
110964
  // src/Entrypoint/Imports.ts
110835
- var t3 = __toESM(require("@babel/types"));
110965
+ var t4 = __toESM(require("@babel/types"));
110836
110966
 
110837
110967
  // src/HIR/HIR.ts
110838
110968
  var t2 = __toESM(require("@babel/types"));
@@ -114640,6 +114770,7 @@ var Effect = /* @__PURE__ */ ((Effect2) => {
114640
114770
  Effect2["Freeze"] = "freeze";
114641
114771
  Effect2["Read"] = "read";
114642
114772
  Effect2["Capture"] = "capture";
114773
+ Effect2["ConditionallyMutateIterator"] = "mutate-iterator?";
114643
114774
  Effect2["ConditionallyMutate"] = "mutate?";
114644
114775
  Effect2["Mutate"] = "mutate";
114645
114776
  Effect2["Store"] = "store";
@@ -114649,6 +114780,7 @@ var EffectSchema = z.enum([
114649
114780
  "read" /* Read */,
114650
114781
  "mutate" /* Mutate */,
114651
114782
  "mutate?" /* ConditionallyMutate */,
114783
+ "mutate-iterator?" /* ConditionallyMutateIterator */,
114652
114784
  "capture" /* Capture */,
114653
114785
  "store" /* Store */,
114654
114786
  "freeze" /* Freeze */
@@ -114658,6 +114790,7 @@ function isMutableEffect(effect, location) {
114658
114790
  case "capture" /* Capture */:
114659
114791
  case "store" /* Store */:
114660
114792
  case "mutate?" /* ConditionallyMutate */:
114793
+ case "mutate-iterator?" /* ConditionallyMutateIterator */:
114661
114794
  case "mutate" /* Mutate */: {
114662
114795
  return true;
114663
114796
  }
@@ -114759,6 +114892,12 @@ function isPrimitiveType(id) {
114759
114892
  function isArrayType(id) {
114760
114893
  return id.type.kind === "Object" && id.type.shapeId === "BuiltInArray";
114761
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
+ }
114762
114901
  function isPropsType(id) {
114763
114902
  return id.type.kind === "Object" && id.type.shapeId === "BuiltInProps";
114764
114903
  }
@@ -117244,126 +117383,6 @@ function validateMutableRange(mutableRange) {
117244
117383
  // src/HIR/BuildHIR.ts
117245
117384
  var import_invariant2 = __toESM(require_invariant());
117246
117385
 
117247
- // src/Utils/Result.ts
117248
- function Ok(val) {
117249
- return new OkImpl(val);
117250
- }
117251
- var OkImpl = class _OkImpl {
117252
- constructor(val) {
117253
- this.val = val;
117254
- }
117255
- map(fn) {
117256
- return new _OkImpl(fn(this.val));
117257
- }
117258
- mapErr(_fn) {
117259
- return this;
117260
- }
117261
- mapOr(_fallback, fn) {
117262
- return fn(this.val);
117263
- }
117264
- mapOrElse(_fallback, fn) {
117265
- return fn(this.val);
117266
- }
117267
- andThen(fn) {
117268
- return fn(this.val);
117269
- }
117270
- and(res) {
117271
- return res;
117272
- }
117273
- or(_res) {
117274
- return this;
117275
- }
117276
- orElse(_fn) {
117277
- return this;
117278
- }
117279
- isOk() {
117280
- return true;
117281
- }
117282
- isErr() {
117283
- return false;
117284
- }
117285
- expect(_msg) {
117286
- return this.val;
117287
- }
117288
- expectErr(msg) {
117289
- throw new Error(`${msg}: ${this.val}`);
117290
- }
117291
- unwrap() {
117292
- return this.val;
117293
- }
117294
- unwrapOr(_fallback) {
117295
- return this.val;
117296
- }
117297
- unwrapOrElse(_fallback) {
117298
- return this.val;
117299
- }
117300
- unwrapErr() {
117301
- if (this.val instanceof Error) {
117302
- throw this.val;
117303
- }
117304
- throw new Error(`Can't unwrap \`Ok\` to \`Err\`: ${this.val}`);
117305
- }
117306
- };
117307
- function Err(val) {
117308
- return new ErrImpl(val);
117309
- }
117310
- var ErrImpl = class _ErrImpl {
117311
- constructor(val) {
117312
- this.val = val;
117313
- }
117314
- map(_fn) {
117315
- return this;
117316
- }
117317
- mapErr(fn) {
117318
- return new _ErrImpl(fn(this.val));
117319
- }
117320
- mapOr(fallback, _fn) {
117321
- return fallback;
117322
- }
117323
- mapOrElse(fallback, _fn) {
117324
- return fallback();
117325
- }
117326
- andThen(_fn) {
117327
- return this;
117328
- }
117329
- and(_res) {
117330
- return this;
117331
- }
117332
- or(res) {
117333
- return res;
117334
- }
117335
- orElse(fn) {
117336
- return fn(this.val);
117337
- }
117338
- isOk() {
117339
- return false;
117340
- }
117341
- isErr() {
117342
- return true;
117343
- }
117344
- expect(msg) {
117345
- throw new Error(`${msg}: ${this.val}`);
117346
- }
117347
- expectErr(_msg) {
117348
- return this.val;
117349
- }
117350
- unwrap() {
117351
- if (this.val instanceof Error) {
117352
- throw this.val;
117353
- }
117354
- throw new Error(`Can't unwrap \`Err\` to \`Ok\`: ${this.val}`);
117355
- }
117356
- unwrapOr(fallback) {
117357
- return fallback;
117358
- }
117359
- unwrapOrElse(fallback) {
117360
- return fallback(this.val);
117361
- }
117362
- unwrapErr() {
117363
- return this.val;
117364
- }
117365
- };
117366
-
117367
117386
  // src/HIR/HIRBuilder.ts
117368
117387
  function newBlock(id, kind) {
117369
117388
  return { id, kind, instructions: [] };
@@ -117558,6 +117577,7 @@ var HIRBuilder = class {
117558
117577
  type: makeType(),
117559
117578
  loc: (_b = node.loc) != null ? _b : GeneratedSource
117560
117579
  };
117580
+ __privateGet(this, _env).programContext.addNewReference(name);
117561
117581
  __privateGet(this, _bindings).set(name, { node, identifier: identifier4 });
117562
117582
  return identifier4;
117563
117583
  } else if (mapping.node === node) {
@@ -117991,7 +118011,7 @@ var nextAnonId = 0;
117991
118011
  function createAnonId() {
117992
118012
  return `<generated_${nextAnonId++}>`;
117993
118013
  }
117994
- function addFunction(registry, properties, fn, id = null) {
118014
+ function addFunction(registry, properties, fn, id = null, isConstructor = false) {
117995
118015
  const shapeId = id != null ? id : createAnonId();
117996
118016
  addShape(registry, shapeId, properties, __spreadProps(__spreadValues({}, fn), {
117997
118017
  hookKind: null
@@ -117999,7 +118019,8 @@ function addFunction(registry, properties, fn, id = null) {
117999
118019
  return {
118000
118020
  kind: "Function",
118001
118021
  return: fn.returnType,
118002
- shapeId
118022
+ shapeId,
118023
+ isConstructor
118003
118024
  };
118004
118025
  }
118005
118026
  function addHook(registry, fn, id = null) {
@@ -118008,7 +118029,8 @@ function addHook(registry, fn, id = null) {
118008
118029
  return {
118009
118030
  kind: "Function",
118010
118031
  return: fn.returnType,
118011
- shapeId
118032
+ shapeId,
118033
+ isConstructor: false
118012
118034
  };
118013
118035
  }
118014
118036
  function addObject(registry, id, properties) {
@@ -118035,6 +118057,8 @@ function addShape(registry, id, properties, functionType2) {
118035
118057
  }
118036
118058
  var BuiltInPropsId = "BuiltInProps";
118037
118059
  var BuiltInArrayId = "BuiltInArray";
118060
+ var BuiltInSetId = "BuiltInSet";
118061
+ var BuiltInMapId = "BuiltInMap";
118038
118062
  var BuiltInFunctionId = "BuiltInFunction";
118039
118063
  var BuiltInJsxId = "BuiltInJsx";
118040
118064
  var BuiltInObjectId = "BuiltInObject";
@@ -118279,6 +118303,311 @@ addObject(BUILTIN_SHAPES, BuiltInObjectId, [
118279
118303
  * hasOwnProperty, isPrototypeOf, propertyIsEnumerable, toLocaleString, valueOf
118280
118304
  */
118281
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
+ ]);
118282
118611
  addObject(BUILTIN_SHAPES, BuiltInUseStateId, [
118283
118612
  ["0", { kind: "Poly" }],
118284
118613
  [
@@ -122558,29 +122887,23 @@ function fromZodError(zodError, options = {}) {
122558
122887
  // src/HIR/Globals.ts
122559
122888
  var DEFAULT_SHAPES = new Map(BUILTIN_SHAPES);
122560
122889
  var UNTYPED_GLOBALS = /* @__PURE__ */ new Set([
122561
- "String",
122562
122890
  "Object",
122563
122891
  "Function",
122564
- "Number",
122565
122892
  "RegExp",
122566
122893
  "Date",
122567
122894
  "Error",
122568
- "Function",
122569
122895
  "TypeError",
122570
122896
  "RangeError",
122571
122897
  "ReferenceError",
122572
122898
  "SyntaxError",
122573
122899
  "URIError",
122574
122900
  "EvalError",
122575
- "Boolean",
122576
122901
  "DataView",
122577
122902
  "Float32Array",
122578
122903
  "Float64Array",
122579
122904
  "Int8Array",
122580
122905
  "Int16Array",
122581
122906
  "Int32Array",
122582
- "Map",
122583
- "Set",
122584
122907
  "WeakMap",
122585
122908
  "Uint8Array",
122586
122909
  "Uint8ClampedArray",
@@ -122588,16 +122911,8 @@ var UNTYPED_GLOBALS = /* @__PURE__ */ new Set([
122588
122911
  "Uint32Array",
122589
122912
  "ArrayBuffer",
122590
122913
  "JSON",
122591
- "parseFloat",
122592
- "parseInt",
122593
122914
  "console",
122594
- "isNaN",
122595
- "eval",
122596
- "isFinite",
122597
- "encodeURI",
122598
- "decodeURI",
122599
- "encodeURIComponent",
122600
- "decodeURIComponent"
122915
+ "eval"
122601
122916
  ]);
122602
122917
  var TYPED_GLOBALS = [
122603
122918
  [
@@ -122612,6 +122927,23 @@ var TYPED_GLOBALS = [
122612
122927
  calleeEffect: "read" /* Read */,
122613
122928
  returnValueKind: "mutable" /* Mutable */
122614
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
+ })
122615
122947
  ]
122616
122948
  ])
122617
122949
  ],
@@ -122644,7 +122976,7 @@ var TYPED_GLOBALS = [
122644
122976
  "from",
122645
122977
  addFunction(DEFAULT_SHAPES, [], {
122646
122978
  positionalParams: [
122647
- "mutate?" /* ConditionallyMutate */,
122979
+ "mutate-iterator?" /* ConditionallyMutateIterator */,
122648
122980
  "mutate?" /* ConditionallyMutate */,
122649
122981
  "mutate?" /* ConditionallyMutate */
122650
122982
  ],
@@ -122889,6 +123221,118 @@ var TYPED_GLOBALS = [
122889
123221
  calleeEffect: "read" /* Read */,
122890
123222
  returnValueKind: "primitive" /* Primitive */
122891
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
+ )
122892
123336
  ]
122893
123337
  // TODO: rest of Global objects
122894
123338
  ];
@@ -123382,6 +123826,8 @@ var InstrumentationSchema = z.object({
123382
123826
  (opts) => opts.gating != null || opts.globalGating != null,
123383
123827
  "Expected at least one of gating or globalGating"
123384
123828
  );
123829
+ var USE_FIRE_FUNCTION_NAME = "useFire";
123830
+ var EMIT_FREEZE_GLOBAL_GATING = "__DEV__";
123385
123831
  var MacroMethodSchema = z.union([
123386
123832
  z.object({ type: z.literal("wildcard") }),
123387
123833
  z.object({ type: z.literal("name"), name: z.string() })
@@ -123583,6 +124029,10 @@ var EnvironmentConfigSchema = z.object({
123583
124029
  * instead.
123584
124030
  */
123585
124031
  validateNoJSXInTryStatements: z.boolean().default(false),
124032
+ /**
124033
+ * Validates against dynamically creating components during render.
124034
+ */
124035
+ validateStaticComponents: z.boolean().default(false),
123586
124036
  /**
123587
124037
  * Validates that the dependencies of all effect hooks are memoized. This helps ensure
123588
124038
  * that Forget does not introduce infinite renders caused by a dependency changing,
@@ -124002,7 +124452,7 @@ function parseConfigPragmaForTests(pragma, defaults) {
124002
124452
  }
124003
124453
  var _globals, _shapes, _moduleTypes, _nextIdentifer, _nextBlock, _nextScope, _scope, _outlinedFunctions, _contextIdentifiers, _hoistedIdentifiers, _Environment_instances, resolveModuleType_fn, isKnownReactModule_fn, getCustomHookType_fn;
124004
124454
  var Environment = class {
124005
- constructor(scope, fnType, compilerMode, config, contextIdentifiers, logger, filename, code, useMemoCacheIdentifier) {
124455
+ constructor(scope, fnType, compilerMode, config, contextIdentifiers, logger, filename, code, programContext) {
124006
124456
  __privateAdd(this, _Environment_instances);
124007
124457
  __privateAdd(this, _globals);
124008
124458
  __privateAdd(this, _shapes);
@@ -124021,11 +124471,11 @@ var Environment = class {
124021
124471
  this.filename = filename;
124022
124472
  this.code = code;
124023
124473
  this.logger = logger;
124024
- this.useMemoCacheIdentifier = useMemoCacheIdentifier;
124474
+ this.programContext = programContext;
124025
124475
  __privateSet(this, _shapes, new Map(DEFAULT_SHAPES));
124026
124476
  __privateSet(this, _globals, new Map(DEFAULT_GLOBALS));
124027
- this.hasLoweredContextAccess = false;
124028
124477
  this.hasFireRewrite = false;
124478
+ this.hasInferredEffect = false;
124029
124479
  if (config.disableMemoizationForDebugging && config.enableChangeDetectionForDebugging != null) {
124030
124480
  CompilerError.throwInvalidConfig({
124031
124481
  reason: `Invalid environment config: the 'disableMemoizationForDebugging' and 'enableChangeDetectionForDebugging' options cannot be used together`,
@@ -124073,6 +124523,21 @@ var Environment = class {
124073
124523
  get nextScopeId() {
124074
124524
  return makeScopeId(__privateWrapper(this, _nextScope)._++);
124075
124525
  }
124526
+ get scope() {
124527
+ return __privateGet(this, _scope);
124528
+ }
124529
+ logErrors(errors) {
124530
+ if (errors.isOk() || this.logger == null) {
124531
+ return;
124532
+ }
124533
+ for (const error of errors.unwrapErr().details) {
124534
+ this.logger.logEvent(this.filename, {
124535
+ kind: "CompileError",
124536
+ detail: error,
124537
+ fnLoc: null
124538
+ });
124539
+ }
124540
+ }
124076
124541
  isContextIdentifier(node) {
124077
124542
  return __privateGet(this, _contextIdentifiers).has(node);
124078
124543
  }
@@ -124611,7 +125076,7 @@ function isMutable2(instr, place) {
124611
125076
  function inRange({ id }, range) {
124612
125077
  return id >= range.start && id < range.end;
124613
125078
  }
124614
- function mayAllocate(_env5, instruction) {
125079
+ function mayAllocate(_env4, instruction) {
124615
125080
  const { value } = instruction;
124616
125081
  switch (value.kind) {
124617
125082
  case "Destructure": {
@@ -124949,260 +125414,14 @@ function pruneUnusedLabelsHIR(fn) {
124949
125414
  }
124950
125415
  }
124951
125416
 
124952
- // src/Entrypoint/Imports.ts
124953
- function validateRestrictedImports(path, { validateBlocklistedImports }) {
124954
- if (validateBlocklistedImports == null || validateBlocklistedImports.length === 0) {
124955
- return null;
124956
- }
124957
- const error = new CompilerError();
124958
- const restrictedImports = new Set(validateBlocklistedImports);
124959
- path.traverse({
124960
- ImportDeclaration(importDeclPath) {
124961
- var _a;
124962
- if (restrictedImports.has(importDeclPath.node.source.value)) {
124963
- error.push({
124964
- severity: "Todo" /* Todo */,
124965
- reason: "Bailing out due to blocklisted import",
124966
- description: `Import from module ${importDeclPath.node.source.value}`,
124967
- loc: (_a = importDeclPath.node.loc) != null ? _a : null
124968
- });
124969
- }
124970
- }
124971
- });
124972
- if (error.hasErrors()) {
124973
- return error;
124974
- } else {
124975
- return null;
124976
- }
124977
- }
124978
- function addImportsToProgram(path, importList) {
124979
- const identifiers = /* @__PURE__ */ new Set();
124980
- const sortedImports = /* @__PURE__ */ new Map();
124981
- for (const { importSpecifierName, source: source2 } of importList) {
124982
- CompilerError.invariant(identifiers.has(importSpecifierName) === false, {
124983
- reason: `Encountered conflicting import specifier for ${importSpecifierName} in Forget config.`,
124984
- description: null,
124985
- loc: GeneratedSource,
124986
- suggestions: null
124987
- });
124988
- CompilerError.invariant(
124989
- path.scope.hasBinding(importSpecifierName) === false,
124990
- {
124991
- reason: `Encountered conflicting import specifiers for ${importSpecifierName} in generated program.`,
124992
- description: null,
124993
- loc: GeneratedSource,
124994
- suggestions: null
124995
- }
124996
- );
124997
- identifiers.add(importSpecifierName);
124998
- const importSpecifierNameList = getOrInsertDefault(
124999
- sortedImports,
125000
- source2,
125001
- []
125002
- );
125003
- importSpecifierNameList.push(importSpecifierName);
125004
- }
125005
- const stmts = [];
125006
- for (const [source2, importSpecifierNameList] of sortedImports) {
125007
- const importSpecifiers = importSpecifierNameList.map((name) => {
125008
- const id = t3.identifier(name);
125009
- return t3.importSpecifier(id, id);
125010
- });
125011
- stmts.push(t3.importDeclaration(importSpecifiers, t3.stringLiteral(source2)));
125012
- }
125013
- path.unshiftContainer("body", stmts);
125014
- }
125015
- function isNonNamespacedImport(importDeclPath, moduleName) {
125016
- return importDeclPath.get("source").node.value === moduleName && importDeclPath.get("specifiers").every((specifier) => specifier.isImportSpecifier()) && importDeclPath.node.importKind !== "type" && importDeclPath.node.importKind !== "typeof";
125017
- }
125018
- function hasExistingNonNamespacedImportOfModule(program, moduleName) {
125019
- let hasExistingImport = false;
125020
- program.traverse({
125021
- ImportDeclaration(importDeclPath) {
125022
- if (isNonNamespacedImport(importDeclPath, moduleName)) {
125023
- hasExistingImport = true;
125024
- }
125025
- }
125026
- });
125027
- return hasExistingImport;
125028
- }
125029
- function addMemoCacheFunctionSpecifierToExistingImport(program, moduleName, identifierName) {
125030
- let didInsertUseMemoCache = false;
125031
- program.traverse({
125032
- ImportDeclaration(importDeclPath) {
125033
- if (!didInsertUseMemoCache && isNonNamespacedImport(importDeclPath, moduleName)) {
125034
- importDeclPath.pushContainer(
125035
- "specifiers",
125036
- t3.importSpecifier(t3.identifier(identifierName), t3.identifier("c"))
125037
- );
125038
- didInsertUseMemoCache = true;
125039
- }
125040
- }
125041
- });
125042
- return didInsertUseMemoCache;
125043
- }
125044
- function updateMemoCacheFunctionImport(program, moduleName, useMemoCacheIdentifier) {
125045
- const hasExistingImport = hasExistingNonNamespacedImportOfModule(
125046
- program,
125047
- moduleName
125048
- );
125049
- if (hasExistingImport) {
125050
- const didUpdateImport = addMemoCacheFunctionSpecifierToExistingImport(
125051
- program,
125052
- moduleName,
125053
- useMemoCacheIdentifier
125054
- );
125055
- if (!didUpdateImport) {
125056
- throw new Error(
125057
- `Expected an ImportDeclaration of \`${moduleName}\` in order to update ImportSpecifiers with useMemoCache`
125058
- );
125059
- }
125060
- } else {
125061
- addMemoCacheFunctionImportDeclaration(
125062
- program,
125063
- moduleName,
125064
- useMemoCacheIdentifier
125065
- );
125066
- }
125067
- }
125068
- function addMemoCacheFunctionImportDeclaration(program, moduleName, localName) {
125069
- program.unshiftContainer(
125070
- "body",
125071
- t3.importDeclaration(
125072
- [t3.importSpecifier(t3.identifier(localName), t3.identifier("c"))],
125073
- t3.stringLiteral(moduleName)
125074
- )
125075
- );
125417
+ // src/Utils/ComponentDeclaration.ts
125418
+ function isComponentDeclaration(node) {
125419
+ return Object.prototype.hasOwnProperty.call(node, "__componentDeclaration");
125076
125420
  }
125077
125421
 
125078
- // src/Entrypoint/Options.ts
125079
- var PanicThresholdOptionsSchema = z.enum([
125080
- /*
125081
- * Any errors will panic the compiler by throwing an exception, which will
125082
- * bubble up to the nearest exception handler above the Forget transform.
125083
- * If Forget is invoked through `BabelPluginReactCompiler`, this will at the least
125084
- * skip Forget compilation for the rest of current file.
125085
- */
125086
- "all_errors",
125087
- /*
125088
- * Panic by throwing an exception only on critical or unrecognized errors.
125089
- * For all other errors, skip the erroring function without inserting
125090
- * a Forget-compiled version (i.e. same behavior as noEmit).
125091
- */
125092
- "critical_errors",
125093
- // Never panic by throwing an exception.
125094
- "none"
125095
- ]);
125096
- var CompilerReactTargetSchema = z.union([
125097
- z.literal("17"),
125098
- z.literal("18"),
125099
- z.literal("19"),
125100
- /**
125101
- * Used exclusively for Meta apps which are guaranteed to have compatible
125102
- * react runtime and compiler versions. Note that only the FB-internal bundles
125103
- * re-export useMemoCache (see
125104
- * https://github.com/facebook/react/blob/5b0ef217ef32333a8e56f39be04327c89efa346f/packages/react/index.fb.js#L68-L70),
125105
- * so this option is invalid / creates runtime errors for open-source users.
125106
- */
125107
- z.object({
125108
- kind: z.literal("donotuse_meta_internal"),
125109
- runtimeModule: z.string().default("react")
125110
- })
125111
- ]);
125112
- var CompilationModeSchema = z.enum([
125113
- /*
125114
- * Compiles functions annotated with "use forget" or component/hook-like functions.
125115
- * This latter includes:
125116
- * * Components declared with component syntax.
125117
- * * Functions which can be inferred to be a component or hook:
125118
- * - Be named like a hook or component. This logic matches the ESLint rule.
125119
- * - *and* create JSX and/or call a hook. This is an additional check to help prevent
125120
- * false positives, since compilation has a greater impact than linting.
125121
- * This is the default mode
125122
- */
125123
- "infer",
125124
- // Compile only components using Flow component syntax and hooks using hook syntax.
125125
- "syntax",
125126
- // Compile only functions which are explicitly annotated with "use forget"
125127
- "annotation",
125128
- // Compile all top-level functions
125129
- "all"
125130
- ]);
125131
- var defaultOptions = {
125132
- compilationMode: "infer",
125133
- panicThreshold: "none",
125134
- environment: parseEnvironmentConfig({}).unwrap(),
125135
- logger: null,
125136
- gating: null,
125137
- noEmit: false,
125138
- eslintSuppressionRules: null,
125139
- flowSuppressions: true,
125140
- ignoreUseNoForget: false,
125141
- sources: (filename) => {
125142
- return filename.indexOf("node_modules") === -1;
125143
- },
125144
- enableReanimatedCheck: true,
125145
- target: "19"
125146
- };
125147
- function parsePluginOptions(obj) {
125148
- if (obj == null || typeof obj !== "object") {
125149
- return defaultOptions;
125150
- }
125151
- const parsedOptions = /* @__PURE__ */ Object.create(null);
125152
- for (let [key2, value] of Object.entries(obj)) {
125153
- if (typeof value === "string") {
125154
- value = value.toLowerCase();
125155
- }
125156
- if (isCompilerFlag(key2)) {
125157
- switch (key2) {
125158
- case "environment": {
125159
- const environmentResult = parseEnvironmentConfig(value);
125160
- if (environmentResult.isErr()) {
125161
- CompilerError.throwInvalidConfig({
125162
- reason: "Error in validating environment config. This is an advanced setting and not meant to be used directly",
125163
- description: environmentResult.unwrapErr().toString(),
125164
- suggestions: null,
125165
- loc: null
125166
- });
125167
- }
125168
- parsedOptions[key2] = environmentResult.unwrap();
125169
- break;
125170
- }
125171
- case "target": {
125172
- parsedOptions[key2] = parseTargetConfig(value);
125173
- break;
125174
- }
125175
- case "gating": {
125176
- if (value == null) {
125177
- parsedOptions[key2] = null;
125178
- } else {
125179
- parsedOptions[key2] = tryParseExternalFunction(value);
125180
- }
125181
- break;
125182
- }
125183
- default: {
125184
- parsedOptions[key2] = value;
125185
- }
125186
- }
125187
- }
125188
- }
125189
- return __spreadValues(__spreadValues({}, defaultOptions), parsedOptions);
125190
- }
125191
- function parseTargetConfig(value) {
125192
- const parsed = CompilerReactTargetSchema.safeParse(value);
125193
- if (parsed.success) {
125194
- return parsed.data;
125195
- } else {
125196
- CompilerError.throwInvalidConfig({
125197
- reason: "Not a valid target",
125198
- description: `${fromZodError(parsed.error)}`,
125199
- suggestions: null,
125200
- loc: null
125201
- });
125202
- }
125203
- }
125204
- function isCompilerFlag(s) {
125205
- return hasOwnProperty2(defaultOptions, s);
125422
+ // src/Utils/HookDeclaration.ts
125423
+ function isHookDeclaration(node) {
125424
+ return Object.prototype.hasOwnProperty.call(node, "__hookDeclaration");
125206
125425
  }
125207
125426
 
125208
125427
  // src/Entrypoint/Pipeline.ts
@@ -129011,7 +129230,7 @@ _catchHandlers = new WeakMap();
129011
129230
  _controlFlowStack = new WeakMap();
129012
129231
 
129013
129232
  // src/ReactiveScopes/CodegenReactiveFunction.ts
129014
- var t4 = __toESM(require("@babel/types"));
129233
+ var t3 = __toESM(require("@babel/types"));
129015
129234
  var import_crypto = require("crypto");
129016
129235
 
129017
129236
  // src/ReactiveScopes/MemoizeFbtAndMacroOperandsInSameScope.ts
@@ -129176,10 +129395,11 @@ function codegenFunction(fn, {
129176
129395
  }
129177
129396
  const compiled = compileResult.unwrap();
129178
129397
  const hookGuard = fn.env.config.enableEmitHookGuards;
129179
- if (hookGuard != null) {
129180
- compiled.body = t4.blockStatement([
129398
+ if (hookGuard != null && fn.env.isInferredMemoEnabled) {
129399
+ compiled.body = t3.blockStatement([
129181
129400
  createHookGuard(
129182
129401
  hookGuard,
129402
+ fn.env.programContext,
129183
129403
  compiled.body.body,
129184
129404
  0 /* PushHookGuard */,
129185
129405
  1 /* PopHookGuard */
@@ -129189,12 +129409,13 @@ function codegenFunction(fn, {
129189
129409
  const cacheCount = compiled.memoSlotsUsed;
129190
129410
  if (cacheCount !== 0) {
129191
129411
  const preface = [];
129412
+ const useMemoCacheIdentifier = fn.env.programContext.addMemoCacheImport().name;
129192
129413
  preface.push(
129193
- t4.variableDeclaration("const", [
129194
- t4.variableDeclarator(
129195
- t4.identifier(cx.synthesizeName("$")),
129196
- t4.callExpression(t4.identifier(fn.env.useMemoCacheIdentifier), [
129197
- 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)
129198
129419
  ])
129199
129420
  )
129200
129421
  ])
@@ -129202,60 +129423,60 @@ function codegenFunction(fn, {
129202
129423
  if (fastRefreshState !== null) {
129203
129424
  const index = cx.synthesizeName("$i");
129204
129425
  preface.push(
129205
- t4.ifStatement(
129206
- t4.binaryExpression(
129426
+ t3.ifStatement(
129427
+ t3.binaryExpression(
129207
129428
  "!==",
129208
- t4.memberExpression(
129209
- t4.identifier(cx.synthesizeName("$")),
129210
- t4.numericLiteral(fastRefreshState.cacheIndex),
129429
+ t3.memberExpression(
129430
+ t3.identifier(cx.synthesizeName("$")),
129431
+ t3.numericLiteral(fastRefreshState.cacheIndex),
129211
129432
  true
129212
129433
  ),
129213
- t4.stringLiteral(fastRefreshState.hash)
129434
+ t3.stringLiteral(fastRefreshState.hash)
129214
129435
  ),
129215
- t4.blockStatement([
129216
- t4.forStatement(
129217
- t4.variableDeclaration("let", [
129218
- 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))
129219
129440
  ]),
129220
- t4.binaryExpression(
129441
+ t3.binaryExpression(
129221
129442
  "<",
129222
- t4.identifier(index),
129223
- t4.numericLiteral(cacheCount)
129443
+ t3.identifier(index),
129444
+ t3.numericLiteral(cacheCount)
129224
129445
  ),
129225
- t4.assignmentExpression(
129446
+ t3.assignmentExpression(
129226
129447
  "+=",
129227
- t4.identifier(index),
129228
- t4.numericLiteral(1)
129448
+ t3.identifier(index),
129449
+ t3.numericLiteral(1)
129229
129450
  ),
129230
- t4.blockStatement([
129231
- t4.expressionStatement(
129232
- t4.assignmentExpression(
129451
+ t3.blockStatement([
129452
+ t3.expressionStatement(
129453
+ t3.assignmentExpression(
129233
129454
  "=",
129234
- t4.memberExpression(
129235
- t4.identifier(cx.synthesizeName("$")),
129236
- t4.identifier(index),
129455
+ t3.memberExpression(
129456
+ t3.identifier(cx.synthesizeName("$")),
129457
+ t3.identifier(index),
129237
129458
  true
129238
129459
  ),
129239
- t4.callExpression(
129240
- t4.memberExpression(
129241
- t4.identifier("Symbol"),
129242
- t4.identifier("for")
129460
+ t3.callExpression(
129461
+ t3.memberExpression(
129462
+ t3.identifier("Symbol"),
129463
+ t3.identifier("for")
129243
129464
  ),
129244
- [t4.stringLiteral(MEMO_CACHE_SENTINEL)]
129465
+ [t3.stringLiteral(MEMO_CACHE_SENTINEL)]
129245
129466
  )
129246
129467
  )
129247
129468
  )
129248
129469
  ])
129249
129470
  ),
129250
- t4.expressionStatement(
129251
- t4.assignmentExpression(
129471
+ t3.expressionStatement(
129472
+ t3.assignmentExpression(
129252
129473
  "=",
129253
- t4.memberExpression(
129254
- t4.identifier(cx.synthesizeName("$")),
129255
- t4.numericLiteral(fastRefreshState.cacheIndex),
129474
+ t3.memberExpression(
129475
+ t3.identifier(cx.synthesizeName("$")),
129476
+ t3.numericLiteral(fastRefreshState.cacheIndex),
129256
129477
  true
129257
129478
  ),
129258
- t4.stringLiteral(fastRefreshState.hash)
129479
+ t3.stringLiteral(fastRefreshState.hash)
129259
129480
  )
129260
129481
  )
129261
129482
  ])
@@ -129265,31 +129486,44 @@ function codegenFunction(fn, {
129265
129486
  compiled.body.body.unshift(...preface);
129266
129487
  }
129267
129488
  const emitInstrumentForget = fn.env.config.enableEmitInstrumentForget;
129268
- if (emitInstrumentForget != null && fn.id != null) {
129269
- let gating;
129270
- if (emitInstrumentForget.gating != null && emitInstrumentForget.globalGating != null) {
129271
- gating = t4.logicalExpression(
129272
- "&&",
129273
- t4.identifier(emitInstrumentForget.globalGating),
129274
- t4.identifier(emitInstrumentForget.gating.importSpecifierName)
129489
+ if (emitInstrumentForget != null && fn.id != null && fn.env.isInferredMemoEnabled) {
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
129275
129499
  );
129276
- } else if (emitInstrumentForget.gating != null) {
129277
- 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;
129278
129509
  } else {
129279
- CompilerError.invariant(emitInstrumentForget.globalGating != null, {
129510
+ CompilerError.invariant(globalGating != null, {
129280
129511
  reason: "Bad config not caught! Expected at least one of gating or globalGating",
129281
129512
  loc: null,
129282
129513
  suggestions: null
129283
129514
  });
129284
- gating = t4.identifier(emitInstrumentForget.globalGating);
129285
- }
129286
- const test = t4.ifStatement(
129287
- gating,
129288
- t4.expressionStatement(
129289
- t4.callExpression(
129290
- t4.identifier(emitInstrumentForget.fn.importSpecifierName),
129291
- [t4.stringLiteral(fn.id), t4.stringLiteral((_b = fn.env.filename) != null ? _b : "")]
129292
- )
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
+ ])
129293
129527
  )
129294
129528
  );
129295
129529
  compiled.body.body.unshift(test);
@@ -129328,7 +129562,7 @@ function codegenReactiveFunction(cx, fn) {
129328
129562
  }
129329
129563
  const params = fn.params.map((param) => convertParameter(param));
129330
129564
  const body = codegenBlock(cx, fn.body);
129331
- body.directives = fn.directives.map((d) => t4.directive(t4.directiveLiteral(d)));
129565
+ body.directives = fn.directives.map((d) => t3.directive(t3.directiveLiteral(d)));
129332
129566
  const statements = body.body;
129333
129567
  if (statements.length !== 0) {
129334
129568
  const last = statements[statements.length - 1];
@@ -129344,7 +129578,7 @@ function codegenReactiveFunction(cx, fn) {
129344
129578
  return Ok({
129345
129579
  type: "CodegenFunction",
129346
129580
  loc: fn.loc,
129347
- id: fn.id !== null ? t4.identifier(fn.id) : null,
129581
+ id: fn.id !== null ? t3.identifier(fn.id) : null,
129348
129582
  params,
129349
129583
  body,
129350
129584
  generator: fn.generator,
@@ -129355,8 +129589,8 @@ function codegenReactiveFunction(cx, fn) {
129355
129589
  prunedMemoBlocks: countMemoBlockVisitor.prunedMemoBlocks,
129356
129590
  prunedMemoValues: countMemoBlockVisitor.prunedMemoValues,
129357
129591
  outlined: [],
129358
- hasLoweredContextAccess: fn.env.hasLoweredContextAccess,
129359
- hasFireRewrite: fn.env.hasFireRewrite
129592
+ hasFireRewrite: fn.env.hasFireRewrite,
129593
+ hasInferredEffect: fn.env.hasInferredEffect
129360
129594
  });
129361
129595
  }
129362
129596
  var CountMemoBlockVisitor = class extends ReactiveFunctionVisitor {
@@ -129383,7 +129617,7 @@ function convertParameter(param) {
129383
129617
  if (param.kind === "Identifier") {
129384
129618
  return convertIdentifier(param.identifier);
129385
129619
  } else {
129386
- return t4.restElement(convertIdentifier(param.place.identifier));
129620
+ return t3.restElement(convertIdentifier(param.place.identifier));
129387
129621
  }
129388
129622
  }
129389
129623
  var _nextCacheIndex, _declarations;
@@ -129477,8 +129711,8 @@ function codegenBlockNoReset(cx, block) {
129477
129711
  if (item.label !== null && !item.label.implicit) {
129478
129712
  const block2 = statement.type === "BlockStatement" && statement.body.length === 1 ? statement.body[0] : statement;
129479
129713
  statements.push(
129480
- t4.labeledStatement(
129481
- t4.identifier(codegenLabel(item.label.id)),
129714
+ t3.labeledStatement(
129715
+ t3.identifier(codegenLabel(item.label.id)),
129482
129716
  block2
129483
129717
  )
129484
129718
  );
@@ -129497,16 +129731,20 @@ function codegenBlockNoReset(cx, block) {
129497
129731
  }
129498
129732
  }
129499
129733
  }
129500
- return t4.blockStatement(statements);
129734
+ return t3.blockStatement(statements);
129501
129735
  }
129502
129736
  function wrapCacheDep(cx, value) {
129503
- if (cx.env.config.enableEmitFreeze != null) {
129504
- return t4.conditionalExpression(
129505
- t4.identifier("__DEV__"),
129506
- t4.callExpression(
129507
- t4.identifier(cx.env.config.enableEmitFreeze.importSpecifierName),
129508
- [value, t4.stringLiteral(cx.fnName)]
129509
- ),
129737
+ if (cx.env.config.enableEmitFreeze != null && cx.env.isInferredMemoEnabled) {
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
+ ]),
129510
129748
  value
129511
129749
  );
129512
129750
  } else {
@@ -129523,20 +129761,20 @@ function codegenReactiveScope(cx, statements, scope, block) {
129523
129761
  for (const dep of [...scope.dependencies].sort(compareScopeDependency)) {
129524
129762
  const index = cx.nextCacheIndex;
129525
129763
  changeExpressionComments.push(printDependencyComment(dep));
129526
- const comparison = t4.binaryExpression(
129764
+ const comparison = t3.binaryExpression(
129527
129765
  "!==",
129528
- t4.memberExpression(
129529
- t4.identifier(cx.synthesizeName("$")),
129530
- t4.numericLiteral(index),
129766
+ t3.memberExpression(
129767
+ t3.identifier(cx.synthesizeName("$")),
129768
+ t3.numericLiteral(index),
129531
129769
  true
129532
129770
  ),
129533
129771
  codegenDependency(cx, dep)
129534
129772
  );
129535
129773
  if (cx.env.config.enableChangeVariableCodegen) {
129536
- const changeIdentifier = t4.identifier(cx.synthesizeName(`c_${index}`));
129774
+ const changeIdentifier = t3.identifier(cx.synthesizeName(`c_${index}`));
129537
129775
  statements.push(
129538
- t4.variableDeclaration("const", [
129539
- t4.variableDeclarator(changeIdentifier, comparison)
129776
+ t3.variableDeclaration("const", [
129777
+ t3.variableDeclarator(changeIdentifier, comparison)
129540
129778
  ])
129541
129779
  );
129542
129780
  changeExpressions.push(changeIdentifier);
@@ -129544,12 +129782,12 @@ function codegenReactiveScope(cx, statements, scope, block) {
129544
129782
  changeExpressions.push(comparison);
129545
129783
  }
129546
129784
  cacheStoreStatements.push(
129547
- t4.expressionStatement(
129548
- t4.assignmentExpression(
129785
+ t3.expressionStatement(
129786
+ t3.assignmentExpression(
129549
129787
  "=",
129550
- t4.memberExpression(
129551
- t4.identifier(cx.synthesizeName("$")),
129552
- t4.numericLiteral(index),
129788
+ t3.memberExpression(
129789
+ t3.identifier(cx.synthesizeName("$")),
129790
+ t3.numericLiteral(index),
129553
129791
  true
129554
129792
  ),
129555
129793
  codegenDependency(cx, dep)
@@ -129577,7 +129815,7 @@ function codegenReactiveScope(cx, statements, scope, block) {
129577
129815
  outputComments.push(name.name);
129578
129816
  if (!cx.hasDeclared(identifier4)) {
129579
129817
  statements.push(
129580
- t4.variableDeclaration("let", [t4.variableDeclarator(name)])
129818
+ t3.variableDeclaration("let", [t3.variableDeclarator(name)])
129581
129819
  );
129582
129820
  }
129583
129821
  cacheLoads.push({ name, index, value: wrapCacheDep(cx, name) });
@@ -129597,7 +129835,7 @@ function codegenReactiveScope(cx, statements, scope, block) {
129597
129835
  if (acc == null) {
129598
129836
  return ident;
129599
129837
  }
129600
- return t4.logicalExpression("||", acc, ident);
129838
+ return t3.logicalExpression("||", acc, ident);
129601
129839
  },
129602
129840
  null
129603
129841
  );
@@ -129608,16 +129846,16 @@ function codegenReactiveScope(cx, statements, scope, block) {
129608
129846
  loc: null,
129609
129847
  suggestions: null
129610
129848
  });
129611
- testCondition = t4.binaryExpression(
129849
+ testCondition = t3.binaryExpression(
129612
129850
  "===",
129613
- t4.memberExpression(
129614
- t4.identifier(cx.synthesizeName("$")),
129615
- t4.numericLiteral(firstOutputIndex),
129851
+ t3.memberExpression(
129852
+ t3.identifier(cx.synthesizeName("$")),
129853
+ t3.numericLiteral(firstOutputIndex),
129616
129854
  true
129617
129855
  ),
129618
- t4.callExpression(
129619
- t4.memberExpression(t4.identifier("Symbol"), t4.identifier("for")),
129620
- [t4.stringLiteral(MEMO_CACHE_SENTINEL)]
129856
+ t3.callExpression(
129857
+ t3.memberExpression(t3.identifier("Symbol"), t3.identifier("for")),
129858
+ [t3.stringLiteral(MEMO_CACHE_SENTINEL)]
129621
129859
  )
129622
129860
  );
129623
129861
  }
@@ -129630,81 +129868,82 @@ function codegenReactiveScope(cx, statements, scope, block) {
129630
129868
  loc: null
129631
129869
  }
129632
129870
  );
129633
- testCondition = t4.logicalExpression(
129871
+ testCondition = t3.logicalExpression(
129634
129872
  "||",
129635
129873
  testCondition,
129636
- t4.booleanLiteral(true)
129874
+ t3.booleanLiteral(true)
129637
129875
  );
129638
129876
  }
129639
129877
  let computationBlock = codegenBlock(cx, block);
129640
129878
  let memoStatement;
129641
- if (cx.env.config.enableChangeDetectionForDebugging != null && changeExpressions.length > 0) {
129879
+ const detectionFunction = cx.env.config.enableChangeDetectionForDebugging;
129880
+ if (detectionFunction != null && changeExpressions.length > 0) {
129642
129881
  const loc = typeof scope.loc === "symbol" ? "unknown location" : `(${scope.loc.start.line}:${scope.loc.end.line})`;
129643
- const detectionFunction = cx.env.config.enableChangeDetectionForDebugging.importSpecifierName;
129882
+ const importedDetectionFunctionIdentifier = cx.env.programContext.addImportSpecifier(detectionFunction).name;
129644
129883
  const cacheLoadOldValueStatements = [];
129645
129884
  const changeDetectionStatements = [];
129646
129885
  const idempotenceDetectionStatements = [];
129647
129886
  for (const { name, index, value } of cacheLoads) {
129648
129887
  const loadName = cx.synthesizeName(`old$${name.name}`);
129649
- const slot = t4.memberExpression(
129650
- t4.identifier(cx.synthesizeName("$")),
129651
- t4.numericLiteral(index),
129888
+ const slot = t3.memberExpression(
129889
+ t3.identifier(cx.synthesizeName("$")),
129890
+ t3.numericLiteral(index),
129652
129891
  true
129653
129892
  );
129654
129893
  cacheStoreStatements.push(
129655
- t4.expressionStatement(t4.assignmentExpression("=", slot, value))
129894
+ t3.expressionStatement(t3.assignmentExpression("=", slot, value))
129656
129895
  );
129657
129896
  cacheLoadOldValueStatements.push(
129658
- t4.variableDeclaration("let", [
129659
- t4.variableDeclarator(t4.identifier(loadName), slot)
129897
+ t3.variableDeclaration("let", [
129898
+ t3.variableDeclarator(t3.identifier(loadName), slot)
129660
129899
  ])
129661
129900
  );
129662
129901
  changeDetectionStatements.push(
129663
- t4.expressionStatement(
129664
- t4.callExpression(t4.identifier(detectionFunction), [
129665
- t4.identifier(loadName),
129666
- t4.cloneNode(name, true),
129667
- t4.stringLiteral(name.name),
129668
- t4.stringLiteral(cx.fnName),
129669
- t4.stringLiteral("cached"),
129670
- 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)
129671
129910
  ])
129672
129911
  )
129673
129912
  );
129674
129913
  idempotenceDetectionStatements.push(
129675
- t4.expressionStatement(
129676
- t4.callExpression(t4.identifier(detectionFunction), [
129677
- t4.cloneNode(slot, true),
129678
- t4.cloneNode(name, true),
129679
- t4.stringLiteral(name.name),
129680
- t4.stringLiteral(cx.fnName),
129681
- t4.stringLiteral("recomputed"),
129682
- 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)
129683
129922
  ])
129684
129923
  )
129685
129924
  );
129686
129925
  idempotenceDetectionStatements.push(
129687
- t4.expressionStatement(t4.assignmentExpression("=", name, slot))
129926
+ t3.expressionStatement(t3.assignmentExpression("=", name, slot))
129688
129927
  );
129689
129928
  }
129690
129929
  const condition = cx.synthesizeName("condition");
129691
- const recomputationBlock = t4.cloneNode(computationBlock, true);
129692
- memoStatement = t4.blockStatement([
129930
+ const recomputationBlock = t3.cloneNode(computationBlock, true);
129931
+ memoStatement = t3.blockStatement([
129693
129932
  ...computationBlock.body,
129694
- t4.variableDeclaration("let", [
129695
- t4.variableDeclarator(t4.identifier(condition), testCondition)
129933
+ t3.variableDeclaration("let", [
129934
+ t3.variableDeclarator(t3.identifier(condition), testCondition)
129696
129935
  ]),
129697
- t4.ifStatement(
129698
- t4.unaryExpression("!", t4.identifier(condition)),
129699
- t4.blockStatement([
129936
+ t3.ifStatement(
129937
+ t3.unaryExpression("!", t3.identifier(condition)),
129938
+ t3.blockStatement([
129700
129939
  ...cacheLoadOldValueStatements,
129701
129940
  ...changeDetectionStatements
129702
129941
  ])
129703
129942
  ),
129704
129943
  ...cacheStoreStatements,
129705
- t4.ifStatement(
129706
- t4.identifier(condition),
129707
- t4.blockStatement([
129944
+ t3.ifStatement(
129945
+ t3.identifier(condition),
129946
+ t3.blockStatement([
129708
129947
  ...recomputationBlock.body,
129709
129948
  ...idempotenceDetectionStatements
129710
129949
  ])
@@ -129713,12 +129952,12 @@ function codegenReactiveScope(cx, statements, scope, block) {
129713
129952
  } else {
129714
129953
  for (const { name, index, value } of cacheLoads) {
129715
129954
  cacheStoreStatements.push(
129716
- t4.expressionStatement(
129717
- t4.assignmentExpression(
129955
+ t3.expressionStatement(
129956
+ t3.assignmentExpression(
129718
129957
  "=",
129719
- t4.memberExpression(
129720
- t4.identifier(cx.synthesizeName("$")),
129721
- t4.numericLiteral(index),
129958
+ t3.memberExpression(
129959
+ t3.identifier(cx.synthesizeName("$")),
129960
+ t3.numericLiteral(index),
129722
129961
  true
129723
129962
  ),
129724
129963
  value
@@ -129726,13 +129965,13 @@ function codegenReactiveScope(cx, statements, scope, block) {
129726
129965
  )
129727
129966
  );
129728
129967
  cacheLoadStatements.push(
129729
- t4.expressionStatement(
129730
- t4.assignmentExpression(
129968
+ t3.expressionStatement(
129969
+ t3.assignmentExpression(
129731
129970
  "=",
129732
129971
  name,
129733
- t4.memberExpression(
129734
- t4.identifier(cx.synthesizeName("$")),
129735
- t4.numericLiteral(index),
129972
+ t3.memberExpression(
129973
+ t3.identifier(cx.synthesizeName("$")),
129974
+ t3.numericLiteral(index),
129736
129975
  true
129737
129976
  )
129738
129977
  )
@@ -129740,15 +129979,15 @@ function codegenReactiveScope(cx, statements, scope, block) {
129740
129979
  );
129741
129980
  }
129742
129981
  computationBlock.body.push(...cacheStoreStatements);
129743
- memoStatement = t4.ifStatement(
129982
+ memoStatement = t3.ifStatement(
129744
129983
  testCondition,
129745
129984
  computationBlock,
129746
- t4.blockStatement(cacheLoadStatements)
129985
+ t3.blockStatement(cacheLoadStatements)
129747
129986
  );
129748
129987
  }
129749
129988
  if (cx.env.config.enableMemoizationComments) {
129750
129989
  if (changeExpressionComments.length) {
129751
- t4.addComment(
129990
+ t3.addComment(
129752
129991
  memoStatement,
129753
129992
  "leading",
129754
129993
  ` check if ${printDelimitedCommentList(
@@ -129757,20 +129996,20 @@ function codegenReactiveScope(cx, statements, scope, block) {
129757
129996
  )} changed`,
129758
129997
  true
129759
129998
  );
129760
- t4.addComment(
129999
+ t3.addComment(
129761
130000
  memoStatement,
129762
130001
  "leading",
129763
130002
  ` "useMemo" for ${printDelimitedCommentList(outputComments, "and")}:`,
129764
130003
  true
129765
130004
  );
129766
130005
  } else {
129767
- t4.addComment(
130006
+ t3.addComment(
129768
130007
  memoStatement,
129769
130008
  "leading",
129770
130009
  " cache value with no dependencies",
129771
130010
  true
129772
130011
  );
129773
- t4.addComment(
130012
+ t3.addComment(
129774
130013
  memoStatement,
129775
130014
  "leading",
129776
130015
  ` "useMemo" for ${printDelimitedCommentList(outputComments, "and")}:`,
@@ -129778,7 +130017,7 @@ function codegenReactiveScope(cx, statements, scope, block) {
129778
130017
  );
129779
130018
  }
129780
130019
  if (computationBlock.body.length > 0) {
129781
- t4.addComment(
130020
+ t3.addComment(
129782
130021
  computationBlock.body[0],
129783
130022
  "leading",
129784
130023
  ` Inputs changed, recompute`,
@@ -129786,7 +130025,7 @@ function codegenReactiveScope(cx, statements, scope, block) {
129786
130025
  );
129787
130026
  }
129788
130027
  if (cacheLoadStatements.length > 0) {
129789
- t4.addComment(
130028
+ t3.addComment(
129790
130029
  cacheLoadStatements[0],
129791
130030
  "leading",
129792
130031
  ` Inputs did not change, use cached value`,
@@ -129808,16 +130047,16 @@ function codegenReactiveScope(cx, statements, scope, block) {
129808
130047
  );
129809
130048
  const name = earlyReturnValue.value.name.value;
129810
130049
  statements.push(
129811
- t4.ifStatement(
129812
- t4.binaryExpression(
130050
+ t3.ifStatement(
130051
+ t3.binaryExpression(
129813
130052
  "!==",
129814
- t4.identifier(name),
129815
- t4.callExpression(
129816
- t4.memberExpression(t4.identifier("Symbol"), t4.identifier("for")),
129817
- [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)]
129818
130057
  )
129819
130058
  ),
129820
- t4.blockStatement([t4.returnStatement(t4.identifier(name))])
130059
+ t3.blockStatement([t3.returnStatement(t3.identifier(name))])
129821
130060
  )
129822
130061
  );
129823
130062
  }
@@ -129828,20 +130067,20 @@ function codegenTerminal(cx, terminal) {
129828
130067
  if (terminal.targetKind === "implicit") {
129829
130068
  return null;
129830
130069
  }
129831
- return t4.breakStatement(
129832
- terminal.targetKind === "labeled" ? t4.identifier(codegenLabel(terminal.target)) : null
130070
+ return t3.breakStatement(
130071
+ terminal.targetKind === "labeled" ? t3.identifier(codegenLabel(terminal.target)) : null
129833
130072
  );
129834
130073
  }
129835
130074
  case "continue": {
129836
130075
  if (terminal.targetKind === "implicit") {
129837
130076
  return null;
129838
130077
  }
129839
- return t4.continueStatement(
129840
- terminal.targetKind === "labeled" ? t4.identifier(codegenLabel(terminal.target)) : null
130078
+ return t3.continueStatement(
130079
+ terminal.targetKind === "labeled" ? t3.identifier(codegenLabel(terminal.target)) : null
129841
130080
  );
129842
130081
  }
129843
130082
  case "for": {
129844
- return t4.forStatement(
130083
+ return t3.forStatement(
129845
130084
  codegenForInit(cx, terminal.init),
129846
130085
  codegenInstructionValueToExpression(cx, terminal.test),
129847
130086
  terminal.update !== null ? codegenInstructionValueToExpression(cx, terminal.update) : null,
@@ -129915,13 +130154,13 @@ function codegenTerminal(cx, terminal) {
129915
130154
  `Unhandled lvalue kind: ${iterableItem.value.lvalue.kind}`
129916
130155
  );
129917
130156
  }
129918
- return t4.forInStatement(
130157
+ return t3.forInStatement(
129919
130158
  /*
129920
130159
  * Special handling here since we only want the VariableDeclarators without any inits
129921
130160
  * This needs to be updated when we handle non-trivial ForOf inits
129922
130161
  */
129923
130162
  createVariableDeclaration(iterableItem.value.loc, varDeclKind, [
129924
- t4.variableDeclarator(lval, null)
130163
+ t3.variableDeclarator(lval, null)
129925
130164
  ]),
129926
130165
  codegenInstructionValueToExpression(cx, iterableCollection.value),
129927
130166
  codegenBlock(cx, terminal.loop)
@@ -129997,13 +130236,13 @@ function codegenTerminal(cx, terminal) {
129997
130236
  `Unhandled lvalue kind: ${iterableItem.value.lvalue.kind}`
129998
130237
  );
129999
130238
  }
130000
- return t4.forOfStatement(
130239
+ return t3.forOfStatement(
130001
130240
  /*
130002
130241
  * Special handling here since we only want the VariableDeclarators without any inits
130003
130242
  * This needs to be updated when we handle non-trivial ForOf inits
130004
130243
  */
130005
130244
  createVariableDeclaration(iterableItem.value.loc, varDeclKind, [
130006
- t4.variableDeclarator(lval, null)
130245
+ t3.variableDeclarator(lval, null)
130007
130246
  ]),
130008
130247
  codegenInstructionValueToExpression(cx, iterableCollection),
130009
130248
  codegenBlock(cx, terminal.loop)
@@ -130019,35 +130258,35 @@ function codegenTerminal(cx, terminal) {
130019
130258
  alternate = block;
130020
130259
  }
130021
130260
  }
130022
- return t4.ifStatement(test, consequent, alternate);
130261
+ return t3.ifStatement(test, consequent, alternate);
130023
130262
  }
130024
130263
  case "return": {
130025
130264
  const value = codegenPlaceToExpression(cx, terminal.value);
130026
130265
  if (value.type === "Identifier" && value.name === "undefined") {
130027
- return t4.returnStatement();
130266
+ return t3.returnStatement();
130028
130267
  }
130029
- return t4.returnStatement(value);
130268
+ return t3.returnStatement(value);
130030
130269
  }
130031
130270
  case "switch": {
130032
- return t4.switchStatement(
130271
+ return t3.switchStatement(
130033
130272
  codegenPlaceToExpression(cx, terminal.test),
130034
130273
  terminal.cases.map((case_) => {
130035
130274
  const test = case_.test !== null ? codegenPlaceToExpression(cx, case_.test) : null;
130036
130275
  const block = codegenBlock(cx, case_.block);
130037
- return t4.switchCase(test, [block]);
130276
+ return t3.switchCase(test, [block]);
130038
130277
  })
130039
130278
  );
130040
130279
  }
130041
130280
  case "throw": {
130042
- return t4.throwStatement(codegenPlaceToExpression(cx, terminal.value));
130281
+ return t3.throwStatement(codegenPlaceToExpression(cx, terminal.value));
130043
130282
  }
130044
130283
  case "do-while": {
130045
130284
  const test = codegenInstructionValueToExpression(cx, terminal.test);
130046
- return t4.doWhileStatement(test, codegenBlock(cx, terminal.loop));
130285
+ return t3.doWhileStatement(test, codegenBlock(cx, terminal.loop));
130047
130286
  }
130048
130287
  case "while": {
130049
130288
  const test = codegenInstructionValueToExpression(cx, terminal.test);
130050
- return t4.whileStatement(test, codegenBlock(cx, terminal.loop));
130289
+ return t3.whileStatement(test, codegenBlock(cx, terminal.loop));
130051
130290
  }
130052
130291
  case "label": {
130053
130292
  return codegenBlock(cx, terminal.block);
@@ -130058,9 +130297,9 @@ function codegenTerminal(cx, terminal) {
130058
130297
  catchParam = convertIdentifier(terminal.handlerBinding.identifier);
130059
130298
  cx.temp.set(terminal.handlerBinding.identifier.declarationId, null);
130060
130299
  }
130061
- return t4.tryStatement(
130300
+ return t3.tryStatement(
130062
130301
  codegenBlock(cx, terminal.block),
130063
- t4.catchClause(catchParam, codegenBlock(cx, terminal.handler))
130302
+ t3.catchClause(catchParam, codegenBlock(cx, terminal.handler))
130064
130303
  );
130065
130304
  }
130066
130305
  default: {
@@ -130123,7 +130362,7 @@ function codegenInstructionNullable(cx, instr) {
130123
130362
  suggestions: null
130124
130363
  });
130125
130364
  return createVariableDeclaration(instr.loc, "const", [
130126
- t4.variableDeclarator(codegenLValue(cx, lvalue), value)
130365
+ t3.variableDeclarator(codegenLValue(cx, lvalue), value)
130127
130366
  ]);
130128
130367
  }
130129
130368
  case "Function" /* Function */: {
@@ -130163,7 +130402,7 @@ function codegenInstructionNullable(cx, instr) {
130163
130402
  suggestions: null
130164
130403
  });
130165
130404
  return createVariableDeclaration(instr.loc, "let", [
130166
- t4.variableDeclarator(codegenLValue(cx, lvalue), value)
130405
+ t3.variableDeclarator(codegenLValue(cx, lvalue), value)
130167
130406
  ]);
130168
130407
  }
130169
130408
  case "Reassign" /* Reassign */: {
@@ -130173,7 +130412,7 @@ function codegenInstructionNullable(cx, instr) {
130173
130412
  loc: instr.value.loc,
130174
130413
  suggestions: null
130175
130414
  });
130176
- const expr = t4.assignmentExpression(
130415
+ const expr = t3.assignmentExpression(
130177
130416
  "=",
130178
130417
  codegenLValue(cx, lvalue),
130179
130418
  value
@@ -130194,7 +130433,7 @@ function codegenInstructionNullable(cx, instr) {
130194
130433
  }
130195
130434
  }
130196
130435
  case "Catch" /* Catch */: {
130197
- return t4.emptyStatement();
130436
+ return t3.emptyStatement();
130198
130437
  }
130199
130438
  case "HoistedLet" /* HoistedLet */:
130200
130439
  case "HoistedConst" /* HoistedConst */:
@@ -130213,7 +130452,7 @@ function codegenInstructionNullable(cx, instr) {
130213
130452
  } else if (instr.value.kind === "StartMemoize" || instr.value.kind === "FinishMemoize") {
130214
130453
  return null;
130215
130454
  } else if (instr.value.kind === "Debugger") {
130216
- return t4.debuggerStatement();
130455
+ return t3.debuggerStatement();
130217
130456
  } else if (instr.value.kind === "ObjectMethod") {
130218
130457
  CompilerError.invariant(instr.lvalue, {
130219
130458
  reason: "Expected object methods to have a temp lvalue",
@@ -130269,7 +130508,7 @@ function codegenForInit(cx, init) {
130269
130508
  description: null,
130270
130509
  suggestions: null
130271
130510
  });
130272
- return t4.variableDeclaration(kind, declarators);
130511
+ return t3.variableDeclaration(kind, declarators);
130273
130512
  } else {
130274
130513
  return codegenInstructionValueToExpression(cx, init);
130275
130514
  }
@@ -130308,17 +130547,17 @@ function codegenDependency(cx, dependency) {
130308
130547
  if (dependency.path.length !== 0) {
130309
130548
  const hasOptional = dependency.path.some((path) => path.optional);
130310
130549
  for (const path of dependency.path) {
130311
- 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);
130312
130551
  const isComputed = typeof path.property !== "string";
130313
130552
  if (hasOptional) {
130314
- object = t4.optionalMemberExpression(
130553
+ object = t3.optionalMemberExpression(
130315
130554
  object,
130316
130555
  property,
130317
130556
  isComputed,
130318
130557
  path.optional
130319
130558
  );
130320
130559
  } else {
130321
- object = t4.memberExpression(object, property, isComputed);
130560
+ object = t3.memberExpression(object, property, isComputed);
130322
130561
  }
130323
130562
  }
130324
130563
  }
@@ -130333,60 +130572,60 @@ function withLoc(fn) {
130333
130572
  return node;
130334
130573
  };
130335
130574
  }
130336
- var createBinaryExpression = withLoc(t4.binaryExpression);
130337
- var createExpressionStatement = withLoc(t4.expressionStatement);
130338
- var _createLabelledStatement = withLoc(t4.labeledStatement);
130339
- var createVariableDeclaration = withLoc(t4.variableDeclaration);
130340
- var createFunctionDeclaration = withLoc(t4.functionDeclaration);
130341
- var _createWhileStatement = withLoc(t4.whileStatement);
130342
- var createTaggedTemplateExpression = withLoc(t4.taggedTemplateExpression);
130343
- var createLogicalExpression = withLoc(t4.logicalExpression);
130344
- var createSequenceExpression = withLoc(t4.sequenceExpression);
130345
- var createConditionalExpression = withLoc(t4.conditionalExpression);
130346
- var createTemplateLiteral = withLoc(t4.templateLiteral);
130347
- var createJsxNamespacedName = withLoc(t4.jsxNamespacedName);
130348
- var createJsxElement = withLoc(t4.jsxElement);
130349
- var createJsxAttribute = withLoc(t4.jsxAttribute);
130350
- var createJsxIdentifier = withLoc(t4.jsxIdentifier);
130351
- var createJsxExpressionContainer = withLoc(t4.jsxExpressionContainer);
130352
- var createJsxText = withLoc(t4.jsxText);
130353
- var createJsxClosingElement = withLoc(t4.jsxClosingElement);
130354
- var createJsxOpeningElement = withLoc(t4.jsxOpeningElement);
130355
- var createStringLiteral = withLoc(t4.stringLiteral);
130356
- 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;
130357
130597
  function createHookGuardImpl(kind) {
130358
- return t4.expressionStatement(
130359
- t4.callExpression(t4.identifier(guard.importSpecifierName), [
130360
- t4.numericLiteral(kind)
130361
- ])
130598
+ return t3.expressionStatement(
130599
+ t3.callExpression(t3.identifier(guardFnName), [t3.numericLiteral(kind)])
130362
130600
  );
130363
130601
  }
130364
- return t4.tryStatement(
130365
- t4.blockStatement([createHookGuardImpl(before), ...stmts]),
130602
+ return t3.tryStatement(
130603
+ t3.blockStatement([createHookGuardImpl(before), ...stmts]),
130366
130604
  null,
130367
- t4.blockStatement([createHookGuardImpl(after)])
130605
+ t3.blockStatement([createHookGuardImpl(after)])
130368
130606
  );
130369
130607
  }
130370
- function createCallExpression(config, callee, args, loc, isHook2) {
130371
- const callExpr = t4.callExpression(callee, args);
130608
+ function createCallExpression(env, callee, args, loc, isHook2) {
130609
+ const callExpr = t3.callExpression(callee, args);
130372
130610
  if (loc != null && loc != GeneratedSource) {
130373
130611
  callExpr.loc = loc;
130374
130612
  }
130375
- const hookGuard = config.enableEmitHookGuards;
130376
- if (hookGuard != null && isHook2) {
130377
- const iife = t4.functionExpression(
130613
+ const hookGuard = env.config.enableEmitHookGuards;
130614
+ if (hookGuard != null && isHook2 && env.isInferredMemoEnabled) {
130615
+ const iife = t3.functionExpression(
130378
130616
  null,
130379
130617
  [],
130380
- t4.blockStatement([
130618
+ t3.blockStatement([
130381
130619
  createHookGuard(
130382
130620
  hookGuard,
130383
- [t4.returnStatement(callExpr)],
130621
+ env.programContext,
130622
+ [t3.returnStatement(callExpr)],
130384
130623
  2 /* AllowHook */,
130385
130624
  3 /* DisallowHook */
130386
130625
  )
130387
130626
  ])
130388
130627
  );
130389
- return t4.callExpression(iife, []);
130628
+ return t3.callExpression(iife, []);
130390
130629
  } else {
130391
130630
  return callExpr;
130392
130631
  }
@@ -130395,21 +130634,21 @@ function codegenLabel(id) {
130395
130634
  return `bb${id}`;
130396
130635
  }
130397
130636
  function codegenInstruction(cx, instr, value) {
130398
- if (t4.isStatement(value)) {
130637
+ if (t3.isStatement(value)) {
130399
130638
  return value;
130400
130639
  }
130401
130640
  if (instr.lvalue === null) {
130402
- return t4.expressionStatement(convertValueToExpression(value));
130641
+ return t3.expressionStatement(convertValueToExpression(value));
130403
130642
  }
130404
130643
  if (instr.lvalue.identifier.name === null) {
130405
130644
  cx.temp.set(instr.lvalue.identifier.declarationId, value);
130406
- return t4.emptyStatement();
130645
+ return t3.emptyStatement();
130407
130646
  } else {
130408
130647
  const expressionValue = convertValueToExpression(value);
130409
130648
  if (cx.hasDeclared(instr.lvalue.identifier)) {
130410
130649
  return createExpressionStatement(
130411
130650
  instr.loc,
130412
- t4.assignmentExpression(
130651
+ t3.assignmentExpression(
130413
130652
  "=",
130414
130653
  convertIdentifier(instr.lvalue.identifier),
130415
130654
  expressionValue
@@ -130417,7 +130656,7 @@ function codegenInstruction(cx, instr, value) {
130417
130656
  );
130418
130657
  } else {
130419
130658
  return createVariableDeclaration(instr.loc, "const", [
130420
- t4.variableDeclarator(
130659
+ t3.variableDeclarator(
130421
130660
  convertIdentifier(instr.lvalue.identifier),
130422
130661
  expressionValue
130423
130662
  )
@@ -130444,12 +130683,12 @@ function codegenInstructionValue(cx, instrValue) {
130444
130683
  if (element.kind === "Identifier") {
130445
130684
  return codegenPlaceToExpression(cx, element);
130446
130685
  } else if (element.kind === "Spread") {
130447
- return t4.spreadElement(codegenPlaceToExpression(cx, element.place));
130686
+ return t3.spreadElement(codegenPlaceToExpression(cx, element.place));
130448
130687
  } else {
130449
130688
  return null;
130450
130689
  }
130451
130690
  });
130452
- value = t4.arrayExpression(elements);
130691
+ value = t3.arrayExpression(elements);
130453
130692
  break;
130454
130693
  }
130455
130694
  case "BinaryExpression": {
@@ -130464,7 +130703,7 @@ function codegenInstructionValue(cx, instrValue) {
130464
130703
  break;
130465
130704
  }
130466
130705
  case "UnaryExpression": {
130467
- value = t4.unaryExpression(
130706
+ value = t3.unaryExpression(
130468
130707
  instrValue.operator,
130469
130708
  // todo
130470
130709
  codegenPlaceToExpression(cx, instrValue.value)
@@ -130479,9 +130718,9 @@ function codegenInstructionValue(cx, instrValue) {
130479
130718
  if (cx.env.config.enableForest) {
130480
130719
  const callee2 = codegenPlaceToExpression(cx, instrValue.callee);
130481
130720
  const args2 = instrValue.args.map((arg) => codegenArgument(cx, arg));
130482
- value = t4.callExpression(callee2, args2);
130721
+ value = t3.callExpression(callee2, args2);
130483
130722
  if (instrValue.typeArguments != null) {
130484
- value.typeArguments = t4.typeParameterInstantiation(
130723
+ value.typeArguments = t3.typeParameterInstantiation(
130485
130724
  instrValue.typeArguments
130486
130725
  );
130487
130726
  }
@@ -130491,7 +130730,7 @@ function codegenInstructionValue(cx, instrValue) {
130491
130730
  const callee = codegenPlaceToExpression(cx, instrValue.callee);
130492
130731
  const args = instrValue.args.map((arg) => codegenArgument(cx, arg));
130493
130732
  value = createCallExpression(
130494
- cx.env.config,
130733
+ cx.env,
130495
130734
  callee,
130496
130735
  args,
130497
130736
  instrValue.loc,
@@ -130507,13 +130746,13 @@ function codegenInstructionValue(cx, instrValue) {
130507
130746
  switch (optionalValue.type) {
130508
130747
  case "OptionalCallExpression":
130509
130748
  case "CallExpression": {
130510
- CompilerError.invariant(t4.isExpression(optionalValue.callee), {
130749
+ CompilerError.invariant(t3.isExpression(optionalValue.callee), {
130511
130750
  reason: "v8 intrinsics are validated during lowering",
130512
130751
  description: null,
130513
130752
  loc: (_a = optionalValue.callee.loc) != null ? _a : null,
130514
130753
  suggestions: null
130515
130754
  });
130516
- value = t4.optionalCallExpression(
130755
+ value = t3.optionalCallExpression(
130517
130756
  optionalValue.callee,
130518
130757
  optionalValue.arguments,
130519
130758
  instrValue.optional
@@ -130523,13 +130762,13 @@ function codegenInstructionValue(cx, instrValue) {
130523
130762
  case "OptionalMemberExpression":
130524
130763
  case "MemberExpression": {
130525
130764
  const property = optionalValue.property;
130526
- CompilerError.invariant(t4.isExpression(property), {
130765
+ CompilerError.invariant(t3.isExpression(property), {
130527
130766
  reason: "Private names are validated during lowering",
130528
130767
  description: null,
130529
130768
  loc: (_b = property.loc) != null ? _b : null,
130530
130769
  suggestions: null
130531
130770
  });
130532
- value = t4.optionalMemberExpression(
130771
+ value = t3.optionalMemberExpression(
130533
130772
  optionalValue.object,
130534
130773
  property,
130535
130774
  optionalValue.computed,
@@ -130552,7 +130791,7 @@ function codegenInstructionValue(cx, instrValue) {
130552
130791
  const isHook2 = getHookKind(cx.env, instrValue.property.identifier) != null;
130553
130792
  const memberExpr = codegenPlaceToExpression(cx, instrValue.property);
130554
130793
  CompilerError.invariant(
130555
- t4.isMemberExpression(memberExpr) || t4.isOptionalMemberExpression(memberExpr),
130794
+ t3.isMemberExpression(memberExpr) || t3.isOptionalMemberExpression(memberExpr),
130556
130795
  {
130557
130796
  reason: `[Codegen] Internal error: MethodCall::property must be an unpromoted + unmemoized MemberExpression. Got a \`${memberExpr.type}\``,
130558
130797
  description: null,
@@ -130561,7 +130800,7 @@ function codegenInstructionValue(cx, instrValue) {
130561
130800
  }
130562
130801
  );
130563
130802
  CompilerError.invariant(
130564
- t4.isNodesEquivalent(
130803
+ t3.isNodesEquivalent(
130565
130804
  memberExpr.object,
130566
130805
  codegenPlaceToExpression(cx, instrValue.receiver)
130567
130806
  ),
@@ -130574,7 +130813,7 @@ function codegenInstructionValue(cx, instrValue) {
130574
130813
  );
130575
130814
  const args = instrValue.args.map((arg) => codegenArgument(cx, arg));
130576
130815
  value = createCallExpression(
130577
- cx.env.config,
130816
+ cx.env,
130578
130817
  memberExpr,
130579
130818
  args,
130580
130819
  instrValue.loc,
@@ -130585,7 +130824,7 @@ function codegenInstructionValue(cx, instrValue) {
130585
130824
  case "NewExpression": {
130586
130825
  const callee = codegenPlaceToExpression(cx, instrValue.callee);
130587
130826
  const args = instrValue.args.map((arg) => codegenArgument(cx, arg));
130588
- value = t4.newExpression(callee, args);
130827
+ value = t3.newExpression(callee, args);
130589
130828
  break;
130590
130829
  }
130591
130830
  case "ObjectExpression": {
@@ -130597,7 +130836,7 @@ function codegenInstructionValue(cx, instrValue) {
130597
130836
  case "property": {
130598
130837
  const value2 = codegenPlaceToExpression(cx, property.place);
130599
130838
  properties.push(
130600
- t4.objectProperty(
130839
+ t3.objectProperty(
130601
130840
  key2,
130602
130841
  value2,
130603
130842
  property.key.kind === "computed",
@@ -130627,7 +130866,7 @@ function codegenInstructionValue(cx, instrValue) {
130627
130866
  ),
130628
130867
  reactiveFunction
130629
130868
  ).unwrap();
130630
- const babelNode = t4.objectMethod(
130869
+ const babelNode = t3.objectMethod(
130631
130870
  "method",
130632
130871
  key2,
130633
130872
  fn.params,
@@ -130647,11 +130886,11 @@ function codegenInstructionValue(cx, instrValue) {
130647
130886
  }
130648
130887
  } else {
130649
130888
  properties.push(
130650
- t4.spreadElement(codegenPlaceToExpression(cx, property.place))
130889
+ t3.spreadElement(codegenPlaceToExpression(cx, property.place))
130651
130890
  );
130652
130891
  }
130653
130892
  }
130654
- value = t4.objectExpression(properties);
130893
+ value = t3.objectExpression(properties);
130655
130894
  break;
130656
130895
  }
130657
130896
  case "JSXText": {
@@ -130663,7 +130902,7 @@ function codegenInstructionValue(cx, instrValue) {
130663
130902
  for (const attribute of instrValue.props) {
130664
130903
  attributes.push(codegenJsxAttribute(cx, attribute));
130665
130904
  }
130666
- 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);
130667
130906
  let tag;
130668
130907
  if (tagValue.type === "Identifier") {
130669
130908
  tag = createJsxIdentifier(instrValue.tag.loc, tagValue.name);
@@ -130716,16 +130955,16 @@ function codegenInstructionValue(cx, instrValue) {
130716
130955
  break;
130717
130956
  }
130718
130957
  case "JsxFragment": {
130719
- value = t4.jsxFragment(
130720
- t4.jsxOpeningFragment(),
130721
- t4.jsxClosingFragment(),
130958
+ value = t3.jsxFragment(
130959
+ t3.jsxOpeningFragment(),
130960
+ t3.jsxClosingFragment(),
130722
130961
  instrValue.children.map((child) => codegenJsxElement(cx, child))
130723
130962
  );
130724
130963
  break;
130725
130964
  }
130726
130965
  case "UnsupportedNode": {
130727
130966
  const node = instrValue.node;
130728
- if (!t4.isExpression(node)) {
130967
+ if (!t3.isExpression(node)) {
130729
130968
  return node;
130730
130969
  }
130731
130970
  value = node;
@@ -130736,19 +130975,19 @@ function codegenInstructionValue(cx, instrValue) {
130736
130975
  case "PropertyDelete": {
130737
130976
  let memberExpr;
130738
130977
  if (typeof instrValue.property === "string") {
130739
- memberExpr = t4.memberExpression(
130978
+ memberExpr = t3.memberExpression(
130740
130979
  codegenPlaceToExpression(cx, instrValue.object),
130741
- t4.identifier(instrValue.property)
130980
+ t3.identifier(instrValue.property)
130742
130981
  );
130743
130982
  } else {
130744
- memberExpr = t4.memberExpression(
130983
+ memberExpr = t3.memberExpression(
130745
130984
  codegenPlaceToExpression(cx, instrValue.object),
130746
- t4.numericLiteral(instrValue.property),
130985
+ t3.numericLiteral(instrValue.property),
130747
130986
  true
130748
130987
  );
130749
130988
  }
130750
130989
  if (instrValue.kind === "PropertyStore") {
130751
- value = t4.assignmentExpression(
130990
+ value = t3.assignmentExpression(
130752
130991
  "=",
130753
130992
  memberExpr,
130754
130993
  codegenPlaceToExpression(cx, instrValue.value)
@@ -130756,14 +130995,14 @@ function codegenInstructionValue(cx, instrValue) {
130756
130995
  } else if (instrValue.kind === "PropertyLoad") {
130757
130996
  value = memberExpr;
130758
130997
  } else {
130759
- value = t4.unaryExpression("delete", memberExpr);
130998
+ value = t3.unaryExpression("delete", memberExpr);
130760
130999
  }
130761
131000
  break;
130762
131001
  }
130763
131002
  case "ComputedStore": {
130764
- value = t4.assignmentExpression(
131003
+ value = t3.assignmentExpression(
130765
131004
  "=",
130766
- t4.memberExpression(
131005
+ t3.memberExpression(
130767
131006
  codegenPlaceToExpression(cx, instrValue.object),
130768
131007
  codegenPlaceToExpression(cx, instrValue.property),
130769
131008
  true
@@ -130775,13 +131014,13 @@ function codegenInstructionValue(cx, instrValue) {
130775
131014
  case "ComputedLoad": {
130776
131015
  const object = codegenPlaceToExpression(cx, instrValue.object);
130777
131016
  const property = codegenPlaceToExpression(cx, instrValue.property);
130778
- value = t4.memberExpression(object, property, true);
131017
+ value = t3.memberExpression(object, property, true);
130779
131018
  break;
130780
131019
  }
130781
131020
  case "ComputedDelete": {
130782
- value = t4.unaryExpression(
131021
+ value = t3.unaryExpression(
130783
131022
  "delete",
130784
- t4.memberExpression(
131023
+ t3.memberExpression(
130785
131024
  codegenPlaceToExpression(cx, instrValue.object),
130786
131025
  codegenPlaceToExpression(cx, instrValue.property),
130787
131026
  true
@@ -130818,10 +131057,10 @@ function codegenInstructionValue(cx, instrValue) {
130818
131057
  body = stmt.argument;
130819
131058
  }
130820
131059
  }
130821
- value = t4.arrowFunctionExpression(fn.params, body, fn.async);
131060
+ value = t3.arrowFunctionExpression(fn.params, body, fn.async);
130822
131061
  } else {
130823
- value = t4.functionExpression(
130824
- (_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,
130825
131064
  fn.params,
130826
131065
  fn.body,
130827
131066
  fn.generator,
@@ -130834,20 +131073,20 @@ function codegenInstructionValue(cx, instrValue) {
130834
131073
  value = createTaggedTemplateExpression(
130835
131074
  instrValue.loc,
130836
131075
  codegenPlaceToExpression(cx, instrValue.tag),
130837
- t4.templateLiteral([t4.templateElement(instrValue.value)], [])
131076
+ t3.templateLiteral([t3.templateElement(instrValue.value)], [])
130838
131077
  );
130839
131078
  break;
130840
131079
  }
130841
131080
  case "TypeCastExpression": {
130842
- if (t4.isTSType(instrValue.typeAnnotation)) {
130843
- value = t4.tsAsExpression(
131081
+ if (t3.isTSType(instrValue.typeAnnotation)) {
131082
+ value = t3.tsAsExpression(
130844
131083
  codegenPlaceToExpression(cx, instrValue.value),
130845
131084
  instrValue.typeAnnotation
130846
131085
  );
130847
131086
  } else {
130848
- value = t4.typeCastExpression(
131087
+ value = t3.typeCastExpression(
130849
131088
  codegenPlaceToExpression(cx, instrValue.value),
130850
- t4.typeAnnotation(instrValue.typeAnnotation)
131089
+ t3.typeAnnotation(instrValue.typeAnnotation)
130851
131090
  );
130852
131091
  }
130853
131092
  break;
@@ -130883,7 +131122,7 @@ function codegenInstructionValue(cx, instrValue) {
130883
131122
  if (stmt.type === "ExpressionStatement") {
130884
131123
  return stmt.expression;
130885
131124
  } else {
130886
- if (t4.isVariableDeclaration(stmt)) {
131125
+ if (t3.isVariableDeclaration(stmt)) {
130887
131126
  const declarator = stmt.declarations[0];
130888
131127
  cx.errors.push({
130889
131128
  reason: `(CodegenReactiveFunction::codegenInstructionValue) Cannot declare variables in a value block, tried to declare '${declarator.id.name}'`,
@@ -130891,7 +131130,7 @@ function codegenInstructionValue(cx, instrValue) {
130891
131130
  loc: (_a2 = declarator.loc) != null ? _a2 : null,
130892
131131
  suggestions: null
130893
131132
  });
130894
- return t4.stringLiteral(`TODO handle ${declarator.id}`);
131133
+ return t3.stringLiteral(`TODO handle ${declarator.id}`);
130895
131134
  } else {
130896
131135
  cx.errors.push({
130897
131136
  reason: `(CodegenReactiveFunction::codegenInstructionValue) Handle conversion of ${stmt.type} to expression`,
@@ -130899,7 +131138,7 @@ function codegenInstructionValue(cx, instrValue) {
130899
131138
  loc: (_b2 = stmt.loc) != null ? _b2 : null,
130900
131139
  suggestions: null
130901
131140
  });
130902
- return t4.stringLiteral(`TODO handle ${stmt.type}`);
131141
+ return t3.stringLiteral(`TODO handle ${stmt.type}`);
130903
131142
  }
130904
131143
  }
130905
131144
  });
@@ -130916,28 +131155,28 @@ function codegenInstructionValue(cx, instrValue) {
130916
131155
  case "TemplateLiteral": {
130917
131156
  value = createTemplateLiteral(
130918
131157
  instrValue.loc,
130919
- instrValue.quasis.map((q) => t4.templateElement(q)),
131158
+ instrValue.quasis.map((q) => t3.templateElement(q)),
130920
131159
  instrValue.subexprs.map((p) => codegenPlaceToExpression(cx, p))
130921
131160
  );
130922
131161
  break;
130923
131162
  }
130924
131163
  case "LoadGlobal": {
130925
- value = t4.identifier(instrValue.binding.name);
131164
+ value = t3.identifier(instrValue.binding.name);
130926
131165
  break;
130927
131166
  }
130928
131167
  case "RegExpLiteral": {
130929
- value = t4.regExpLiteral(instrValue.pattern, instrValue.flags);
131168
+ value = t3.regExpLiteral(instrValue.pattern, instrValue.flags);
130930
131169
  break;
130931
131170
  }
130932
131171
  case "MetaProperty": {
130933
- value = t4.metaProperty(
130934
- t4.identifier(instrValue.meta),
130935
- t4.identifier(instrValue.property)
131172
+ value = t3.metaProperty(
131173
+ t3.identifier(instrValue.meta),
131174
+ t3.identifier(instrValue.property)
130936
131175
  );
130937
131176
  break;
130938
131177
  }
130939
131178
  case "Await": {
130940
- value = t4.awaitExpression(codegenPlaceToExpression(cx, instrValue.value));
131179
+ value = t3.awaitExpression(codegenPlaceToExpression(cx, instrValue.value));
130941
131180
  break;
130942
131181
  }
130943
131182
  case "GetIterator": {
@@ -130953,7 +131192,7 @@ function codegenInstructionValue(cx, instrValue) {
130953
131192
  break;
130954
131193
  }
130955
131194
  case "PostfixUpdate": {
130956
- value = t4.updateExpression(
131195
+ value = t3.updateExpression(
130957
131196
  instrValue.operation,
130958
131197
  codegenPlaceToExpression(cx, instrValue.lvalue),
130959
131198
  false
@@ -130961,7 +131200,7 @@ function codegenInstructionValue(cx, instrValue) {
130961
131200
  break;
130962
131201
  }
130963
131202
  case "PrefixUpdate": {
130964
- value = t4.updateExpression(
131203
+ value = t3.updateExpression(
130965
131204
  instrValue.operation,
130966
131205
  codegenPlaceToExpression(cx, instrValue.lvalue),
130967
131206
  true
@@ -130978,7 +131217,7 @@ function codegenInstructionValue(cx, instrValue) {
130978
131217
  suggestions: null
130979
131218
  }
130980
131219
  );
130981
- value = t4.assignmentExpression(
131220
+ value = t3.assignmentExpression(
130982
131221
  "=",
130983
131222
  codegenLValue(cx, instrValue.lvalue.place),
130984
131223
  codegenPlaceToExpression(cx, instrValue.value)
@@ -130986,9 +131225,9 @@ function codegenInstructionValue(cx, instrValue) {
130986
131225
  break;
130987
131226
  }
130988
131227
  case "StoreGlobal": {
130989
- value = t4.assignmentExpression(
131228
+ value = t3.assignmentExpression(
130990
131229
  "=",
130991
- t4.identifier(instrValue.name),
131230
+ t3.identifier(instrValue.name),
130992
131231
  codegenPlaceToExpression(cx, instrValue.value)
130993
131232
  );
130994
131233
  break;
@@ -131050,7 +131289,7 @@ function codegenJsxAttribute(cx, attribute) {
131050
131289
  return createJsxAttribute(attribute.place.loc, propName, value);
131051
131290
  }
131052
131291
  case "JsxSpreadAttribute": {
131053
- return t4.jsxSpreadAttribute(
131292
+ return t3.jsxSpreadAttribute(
131054
131293
  codegenPlaceToExpression(cx, attribute.argument)
131055
131294
  );
131056
131295
  }
@@ -131105,9 +131344,9 @@ function convertMemberExpressionToJsx(expr) {
131105
131344
  loc: (_a = expr.loc) != null ? _a : null,
131106
131345
  suggestions: null
131107
131346
  });
131108
- const property = t4.jsxIdentifier(expr.property.name);
131347
+ const property = t3.jsxIdentifier(expr.property.name);
131109
131348
  if (expr.object.type === "Identifier") {
131110
- return t4.jsxMemberExpression(t4.jsxIdentifier(expr.object.name), property);
131349
+ return t3.jsxMemberExpression(t3.jsxIdentifier(expr.object.name), property);
131111
131350
  } else {
131112
131351
  CompilerError.invariant(expr.object.type === "MemberExpression", {
131113
131352
  reason: "Expected JSX member expression to be an identifier or nested member expression",
@@ -131116,20 +131355,20 @@ function convertMemberExpressionToJsx(expr) {
131116
131355
  suggestions: null
131117
131356
  });
131118
131357
  const object = convertMemberExpressionToJsx(expr.object);
131119
- return t4.jsxMemberExpression(object, property);
131358
+ return t3.jsxMemberExpression(object, property);
131120
131359
  }
131121
131360
  }
131122
131361
  function codegenObjectPropertyKey(cx, key2) {
131123
131362
  switch (key2.kind) {
131124
131363
  case "string": {
131125
- return t4.stringLiteral(key2.name);
131364
+ return t3.stringLiteral(key2.name);
131126
131365
  }
131127
131366
  case "identifier": {
131128
- return t4.identifier(key2.name);
131367
+ return t3.identifier(key2.name);
131129
131368
  }
131130
131369
  case "computed": {
131131
131370
  const expr = codegenPlace(cx, key2.name);
131132
- CompilerError.invariant(t4.isExpression(expr), {
131371
+ CompilerError.invariant(t3.isExpression(expr), {
131133
131372
  reason: "Expected object property key to be an expression",
131134
131373
  description: null,
131135
131374
  loc: key2.name.loc,
@@ -131138,14 +131377,14 @@ function codegenObjectPropertyKey(cx, key2) {
131138
131377
  return expr;
131139
131378
  }
131140
131379
  case "number": {
131141
- return t4.numericLiteral(key2.name);
131380
+ return t3.numericLiteral(key2.name);
131142
131381
  }
131143
131382
  }
131144
131383
  }
131145
131384
  function codegenArrayPattern(cx, pattern) {
131146
131385
  const hasHoles = !pattern.items.every((e) => e.kind !== "Hole");
131147
131386
  if (hasHoles) {
131148
- const result = t4.arrayPattern([]);
131387
+ const result = t3.arrayPattern([]);
131149
131388
  for (const item of pattern.items) {
131150
131389
  if (item.kind === "Hole") {
131151
131390
  result.elements.push(null);
@@ -131155,7 +131394,7 @@ function codegenArrayPattern(cx, pattern) {
131155
131394
  }
131156
131395
  return result;
131157
131396
  } else {
131158
- return t4.arrayPattern(
131397
+ return t3.arrayPattern(
131159
131398
  pattern.items.map((item) => {
131160
131399
  if (item.kind === "Hole") {
131161
131400
  return null;
@@ -131171,25 +131410,25 @@ function codegenLValue(cx, pattern) {
131171
131410
  return codegenArrayPattern(cx, pattern);
131172
131411
  }
131173
131412
  case "ObjectPattern": {
131174
- return t4.objectPattern(
131413
+ return t3.objectPattern(
131175
131414
  pattern.properties.map((property) => {
131176
131415
  if (property.kind === "ObjectProperty") {
131177
131416
  const key2 = codegenObjectPropertyKey(cx, property.key);
131178
131417
  const value = codegenLValue(cx, property.place);
131179
- return t4.objectProperty(
131418
+ return t3.objectProperty(
131180
131419
  key2,
131181
131420
  value,
131182
131421
  property.key.kind === "computed",
131183
131422
  key2.type === "Identifier" && value.type === "Identifier" && value.name === key2.name
131184
131423
  );
131185
131424
  } else {
131186
- return t4.restElement(codegenLValue(cx, property.place));
131425
+ return t3.restElement(codegenLValue(cx, property.place));
131187
131426
  }
131188
131427
  })
131189
131428
  );
131190
131429
  }
131191
131430
  case "Spread": {
131192
- return t4.restElement(codegenLValue(cx, pattern.place));
131431
+ return t3.restElement(codegenLValue(cx, pattern.place));
131193
131432
  }
131194
131433
  case "Identifier": {
131195
131434
  return convertIdentifier(pattern.identifier);
@@ -131204,15 +131443,15 @@ function codegenLValue(cx, pattern) {
131204
131443
  }
131205
131444
  function codegenValue(cx, loc, value) {
131206
131445
  if (typeof value === "number") {
131207
- return t4.numericLiteral(value);
131446
+ return t3.numericLiteral(value);
131208
131447
  } else if (typeof value === "boolean") {
131209
- return t4.booleanLiteral(value);
131448
+ return t3.booleanLiteral(value);
131210
131449
  } else if (typeof value === "string") {
131211
131450
  return createStringLiteral(loc, value);
131212
131451
  } else if (value === null) {
131213
- return t4.nullLiteral();
131452
+ return t3.nullLiteral();
131214
131453
  } else if (value === void 0) {
131215
- return t4.identifier("undefined");
131454
+ return t3.identifier("undefined");
131216
131455
  } else {
131217
131456
  assertExhaustive(value, "Unexpected primitive value kind");
131218
131457
  }
@@ -131221,7 +131460,7 @@ function codegenArgument(cx, arg) {
131221
131460
  if (arg.kind === "Identifier") {
131222
131461
  return codegenPlaceToExpression(cx, arg);
131223
131462
  } else {
131224
- return t4.spreadElement(codegenPlaceToExpression(cx, arg.place));
131463
+ return t3.spreadElement(codegenPlaceToExpression(cx, arg.place));
131225
131464
  }
131226
131465
  }
131227
131466
  function codegenPlaceToExpression(cx, place) {
@@ -131255,7 +131494,7 @@ function convertIdentifier(identifier4) {
131255
131494
  suggestions: null
131256
131495
  }
131257
131496
  );
131258
- return t4.identifier(identifier4.name.value);
131497
+ return t3.identifier(identifier4.name.value);
131259
131498
  }
131260
131499
  function compareScopeDependency(a, b) {
131261
131500
  var _a, _b;
@@ -132599,10 +132838,9 @@ function inferReferenceEffects(fn, options = { isFunctionExpression: false }) {
132599
132838
  return transformFunctionEffectErrors(functionEffects);
132600
132839
  }
132601
132840
  }
132602
- var _env3, _values, _variables;
132841
+ var _values, _variables;
132603
132842
  var _InferenceState = class _InferenceState {
132604
132843
  constructor(env, values, variables) {
132605
- __privateAdd(this, _env3);
132606
132844
  // The kind of each value, based on its allocation site
132607
132845
  __privateAdd(this, _values);
132608
132846
  /*
@@ -132611,7 +132849,7 @@ var _InferenceState = class _InferenceState {
132611
132849
  * values from different control flow paths).
132612
132850
  */
132613
132851
  __privateAdd(this, _variables);
132614
- __privateSet(this, _env3, env);
132852
+ this.env = env;
132615
132853
  __privateSet(this, _values, values);
132616
132854
  __privateSet(this, _variables, variables);
132617
132855
  }
@@ -132723,7 +132961,7 @@ var _InferenceState = class _InferenceState {
132723
132961
  reason,
132724
132962
  context: /* @__PURE__ */ new Set()
132725
132963
  });
132726
- if (value.kind === "FunctionExpression" && (__privateGet(this, _env3).config.enablePreserveExistingMemoizationGuarantees || __privateGet(this, _env3).config.enableTransitivelyFreezeFunctionExpressions)) {
132964
+ if (value.kind === "FunctionExpression" && (this.env.config.enablePreserveExistingMemoizationGuarantees || this.env.config.enableTransitivelyFreezeFunctionExpressions)) {
132727
132965
  for (const operand of value.loweredFunc.func.context) {
132728
132966
  const operandValues = __privateGet(this, _variables).get(operand.identifier.id);
132729
132967
  if (operandValues !== void 0) {
@@ -132768,6 +133006,18 @@ var _InferenceState = class _InferenceState {
132768
133006
  }
132769
133007
  break;
132770
133008
  }
133009
+ case "mutate-iterator?" /* ConditionallyMutateIterator */: {
133010
+ if (valueKind.kind === "mutable" /* Mutable */ || valueKind.kind === "context" /* Context */) {
133011
+ if (isArrayType(place.identifier) || isSetType(place.identifier) || isMapType(place.identifier)) {
133012
+ effect = "capture" /* Capture */;
133013
+ } else {
133014
+ effect = "mutate?" /* ConditionallyMutate */;
133015
+ }
133016
+ } else {
133017
+ effect = "read" /* Read */;
133018
+ }
133019
+ break;
133020
+ }
132771
133021
  case "mutate" /* Mutate */: {
132772
133022
  effect = "mutate" /* Mutate */;
132773
133023
  break;
@@ -132871,7 +133121,7 @@ var _InferenceState = class _InferenceState {
132871
133121
  return null;
132872
133122
  } else {
132873
133123
  return new _InferenceState(
132874
- __privateGet(this, _env3),
133124
+ this.env,
132875
133125
  nextValues != null ? nextValues : new Map(__privateGet(this, _values)),
132876
133126
  nextVariables != null ? nextVariables : new Map(__privateGet(this, _variables))
132877
133127
  );
@@ -132884,7 +133134,7 @@ var _InferenceState = class _InferenceState {
132884
133134
  */
132885
133135
  clone() {
132886
133136
  return new _InferenceState(
132887
- __privateGet(this, _env3),
133137
+ this.env,
132888
133138
  new Map(__privateGet(this, _values)),
132889
133139
  new Map(__privateGet(this, _variables))
132890
133140
  );
@@ -132927,7 +133177,6 @@ var _InferenceState = class _InferenceState {
132927
133177
  }
132928
133178
  }
132929
133179
  };
132930
- _env3 = new WeakMap();
132931
133180
  _values = new WeakMap();
132932
133181
  _variables = new WeakMap();
132933
133182
  var InferenceState = _InferenceState;
@@ -133011,7 +133260,7 @@ function mergeAbstractValues(a, b) {
133011
133260
  return { kind, reason, context };
133012
133261
  }
133013
133262
  function inferBlock(env, state, block, functionEffects) {
133014
- var _a, _b, _c, _d, _e;
133263
+ var _a, _b, _c;
133015
133264
  for (const phi of block.phis) {
133016
133265
  state.inferPhi(phi);
133017
133266
  }
@@ -133052,7 +133301,7 @@ function inferBlock(env, state, block, functionEffects) {
133052
133301
  state.referenceAndRecordEffects(
133053
133302
  freezeActions,
133054
133303
  element.place,
133055
- isArrayType(element.place.identifier) ? "capture" /* Capture */ : "mutate?" /* ConditionallyMutate */,
133304
+ "mutate-iterator?" /* ConditionallyMutateIterator */,
133056
133305
  "other" /* Other */
133057
133306
  );
133058
133307
  } else if (element.kind === "Identifier") {
@@ -133075,28 +133324,12 @@ function inferBlock(env, state, block, functionEffects) {
133075
133324
  break;
133076
133325
  }
133077
133326
  case "NewExpression": {
133078
- const valueKind = {
133079
- kind: "mutable" /* Mutable */,
133080
- reason: /* @__PURE__ */ new Set(["other" /* Other */]),
133081
- context: /* @__PURE__ */ new Set()
133082
- };
133083
- state.referenceAndRecordEffects(
133327
+ inferCallEffects(
133328
+ state,
133329
+ instr,
133084
133330
  freezeActions,
133085
- instrValue.callee,
133086
- "read" /* Read */,
133087
- "other" /* Other */
133331
+ getFunctionCallSignature(env, instrValue.callee.identifier.type)
133088
133332
  );
133089
- for (const operand of eachCallArgument(instrValue.args)) {
133090
- state.referenceAndRecordEffects(
133091
- freezeActions,
133092
- operand,
133093
- "mutate?" /* ConditionallyMutate */,
133094
- "other" /* Other */
133095
- );
133096
- }
133097
- state.initialize(instrValue, valueKind);
133098
- state.define(instr.lvalue, instrValue);
133099
- instr.lvalue.effect = "mutate?" /* ConditionallyMutate */;
133100
133333
  continuation = { kind: "funeffects" };
133101
133334
  break;
133102
133335
  }
@@ -133369,53 +133602,12 @@ function inferBlock(env, state, block, functionEffects) {
133369
133602
  break;
133370
133603
  }
133371
133604
  case "CallExpression": {
133372
- const signature = getFunctionCallSignature(
133373
- env,
133374
- instrValue.callee.identifier.type
133605
+ inferCallEffects(
133606
+ state,
133607
+ instr,
133608
+ freezeActions,
133609
+ getFunctionCallSignature(env, instrValue.callee.identifier.type)
133375
133610
  );
133376
- const effects = signature !== null ? getFunctionEffects(instrValue, signature) : null;
133377
- const returnValueKind = signature !== null ? {
133378
- kind: signature.returnValueKind,
133379
- reason: /* @__PURE__ */ new Set([
133380
- (_c = signature.returnValueReason) != null ? _c : "known-return-signature" /* KnownReturnSignature */
133381
- ]),
133382
- context: /* @__PURE__ */ new Set()
133383
- } : {
133384
- kind: "mutable" /* Mutable */,
133385
- reason: /* @__PURE__ */ new Set(["other" /* Other */]),
133386
- context: /* @__PURE__ */ new Set()
133387
- };
133388
- let hasCaptureArgument = false;
133389
- for (let i = 0; i < instrValue.args.length; i++) {
133390
- const arg = instrValue.args[i];
133391
- const place = arg.kind === "Identifier" ? arg : arg.place;
133392
- state.referenceAndRecordEffects(
133393
- freezeActions,
133394
- place,
133395
- getArgumentEffect(effects != null ? effects[i] : null, arg),
133396
- "other" /* Other */
133397
- );
133398
- hasCaptureArgument || (hasCaptureArgument = place.effect === "capture" /* Capture */);
133399
- }
133400
- if (signature !== null) {
133401
- state.referenceAndRecordEffects(
133402
- freezeActions,
133403
- instrValue.callee,
133404
- signature.calleeEffect,
133405
- "other" /* Other */
133406
- );
133407
- } else {
133408
- state.referenceAndRecordEffects(
133409
- freezeActions,
133410
- instrValue.callee,
133411
- "mutate?" /* ConditionallyMutate */,
133412
- "other" /* Other */
133413
- );
133414
- }
133415
- hasCaptureArgument || (hasCaptureArgument = instrValue.callee.effect === "capture" /* Capture */);
133416
- state.initialize(instrValue, returnValueKind);
133417
- state.define(instr.lvalue, instrValue);
133418
- instr.lvalue.effect = hasCaptureArgument ? "store" /* Store */ : "mutate?" /* ConditionallyMutate */;
133419
133611
  continuation = { kind: "funeffects" };
133420
133612
  break;
133421
133613
  }
@@ -133432,75 +133624,12 @@ function inferBlock(env, state, block, functionEffects) {
133432
133624
  "read" /* Read */,
133433
133625
  "other" /* Other */
133434
133626
  );
133435
- const signature = getFunctionCallSignature(
133436
- env,
133437
- instrValue.property.identifier.type
133627
+ inferCallEffects(
133628
+ state,
133629
+ instr,
133630
+ freezeActions,
133631
+ getFunctionCallSignature(env, instrValue.property.identifier.type)
133438
133632
  );
133439
- const returnValueKind = signature !== null ? {
133440
- kind: signature.returnValueKind,
133441
- reason: /* @__PURE__ */ new Set([
133442
- (_d = signature.returnValueReason) != null ? _d : "known-return-signature" /* KnownReturnSignature */
133443
- ]),
133444
- context: /* @__PURE__ */ new Set()
133445
- } : {
133446
- kind: "mutable" /* Mutable */,
133447
- reason: /* @__PURE__ */ new Set(["other" /* Other */]),
133448
- context: /* @__PURE__ */ new Set()
133449
- };
133450
- if (signature !== null && signature.mutableOnlyIfOperandsAreMutable && areArgumentsImmutableAndNonMutating(state, instrValue.args)) {
133451
- for (const arg of instrValue.args) {
133452
- const place = arg.kind === "Identifier" ? arg : arg.place;
133453
- state.referenceAndRecordEffects(
133454
- freezeActions,
133455
- place,
133456
- "read" /* Read */,
133457
- "other" /* Other */
133458
- );
133459
- }
133460
- state.referenceAndRecordEffects(
133461
- freezeActions,
133462
- instrValue.receiver,
133463
- "capture" /* Capture */,
133464
- "other" /* Other */
133465
- );
133466
- state.initialize(instrValue, returnValueKind);
133467
- state.define(instr.lvalue, instrValue);
133468
- instr.lvalue.effect = instrValue.receiver.effect === "capture" /* Capture */ ? "store" /* Store */ : "mutate?" /* ConditionallyMutate */;
133469
- continuation = { kind: "funeffects" };
133470
- break;
133471
- }
133472
- const effects = signature !== null ? getFunctionEffects(instrValue, signature) : null;
133473
- let hasCaptureArgument = false;
133474
- for (let i = 0; i < instrValue.args.length; i++) {
133475
- const arg = instrValue.args[i];
133476
- const place = arg.kind === "Identifier" ? arg : arg.place;
133477
- state.referenceAndRecordEffects(
133478
- freezeActions,
133479
- place,
133480
- getArgumentEffect(effects != null ? effects[i] : null, arg),
133481
- "other" /* Other */
133482
- );
133483
- hasCaptureArgument || (hasCaptureArgument = place.effect === "capture" /* Capture */);
133484
- }
133485
- if (signature !== null) {
133486
- state.referenceAndRecordEffects(
133487
- freezeActions,
133488
- instrValue.receiver,
133489
- signature.calleeEffect,
133490
- "other" /* Other */
133491
- );
133492
- } else {
133493
- state.referenceAndRecordEffects(
133494
- freezeActions,
133495
- instrValue.receiver,
133496
- "mutate?" /* ConditionallyMutate */,
133497
- "other" /* Other */
133498
- );
133499
- }
133500
- hasCaptureArgument || (hasCaptureArgument = instrValue.receiver.effect === "capture" /* Capture */);
133501
- state.initialize(instrValue, returnValueKind);
133502
- state.define(instr.lvalue, instrValue);
133503
- instr.lvalue.effect = hasCaptureArgument ? "store" /* Store */ : "mutate?" /* ConditionallyMutate */;
133504
133633
  continuation = { kind: "funeffects" };
133505
133634
  break;
133506
133635
  }
@@ -133827,7 +133956,8 @@ function inferBlock(env, state, block, functionEffects) {
133827
133956
  const isMutable3 = kind === "mutable" /* Mutable */ || kind === "context" /* Context */;
133828
133957
  let effect;
133829
133958
  let valueKind;
133830
- if (!isMutable3 || isArrayType(instrValue.collection.identifier)) {
133959
+ const iterator = instrValue.collection.identifier;
133960
+ if (!isMutable3 || isArrayType(iterator) || isMapType(iterator) || isSetType(iterator)) {
133831
133961
  effect = {
133832
133962
  kind: "read" /* Read */,
133833
133963
  reason: "other" /* Other */
@@ -133856,7 +133986,7 @@ function inferBlock(env, state, block, functionEffects) {
133856
133986
  state.referenceAndRecordEffects(
133857
133987
  freezeActions,
133858
133988
  instrValue.iterator,
133859
- "mutate?" /* ConditionallyMutate */,
133989
+ "mutate-iterator?" /* ConditionallyMutateIterator */,
133860
133990
  "other" /* Other */
133861
133991
  );
133862
133992
  state.referenceAndRecordEffects(
@@ -133905,7 +134035,7 @@ function inferBlock(env, state, block, functionEffects) {
133905
134035
  }
133906
134036
  state.initialize(instrValue, continuation.valueKind);
133907
134037
  state.define(instr.lvalue, instrValue);
133908
- instr.lvalue.effect = (_e = continuation.lvalueEffect) != null ? _e : defaultLvalueEffect;
134038
+ instr.lvalue.effect = (_c = continuation.lvalueEffect) != null ? _c : defaultLvalueEffect;
133909
134039
  }
133910
134040
  functionEffects.push(...inferInstructionFunctionEffects(env, state, instr));
133911
134041
  freezeActions.forEach(
@@ -133969,12 +134099,43 @@ function getFunctionEffects(fn, sig) {
133969
134099
  }
133970
134100
  return results;
133971
134101
  }
134102
+ function isKnownMutableEffect(effect) {
134103
+ switch (effect) {
134104
+ case "store" /* Store */:
134105
+ case "mutate?" /* ConditionallyMutate */:
134106
+ case "mutate-iterator?" /* ConditionallyMutateIterator */:
134107
+ case "mutate" /* Mutate */: {
134108
+ return true;
134109
+ }
134110
+ case "<unknown>" /* Unknown */: {
134111
+ CompilerError.invariant(false, {
134112
+ reason: "Unexpected unknown effect",
134113
+ description: null,
134114
+ loc: GeneratedSource,
134115
+ suggestions: null
134116
+ });
134117
+ }
134118
+ case "read" /* Read */:
134119
+ case "capture" /* Capture */:
134120
+ case "freeze" /* Freeze */: {
134121
+ return false;
134122
+ }
134123
+ default: {
134124
+ assertExhaustive(effect, `Unexpected effect \`${effect}\``);
134125
+ }
134126
+ }
134127
+ }
133972
134128
  function areArgumentsImmutableAndNonMutating(state, args) {
133973
134129
  for (const arg of args) {
134130
+ if (arg.kind === "Identifier" && arg.identifier.type.kind === "Function") {
134131
+ const fnShape = state.env.getFunctionSignature(arg.identifier.type);
134132
+ if (fnShape != null) {
134133
+ return !fnShape.positionalParams.some(isKnownMutableEffect) && (fnShape.restParam == null || !isKnownMutableEffect(fnShape.restParam));
134134
+ }
134135
+ }
133974
134136
  const place = arg.kind === "Identifier" ? arg : arg.place;
133975
134137
  const kind = state.kind(place).kind;
133976
134138
  switch (kind) {
133977
- case "global" /* Global */:
133978
134139
  case "primitive" /* Primitive */:
133979
134140
  case "frozen" /* Frozen */: {
133980
134141
  break;
@@ -134009,12 +134170,81 @@ function getArgumentEffect(signatureEffect, arg) {
134009
134170
  loc: arg.place.loc
134010
134171
  });
134011
134172
  }
134012
- return "mutate?" /* ConditionallyMutate */;
134173
+ return "mutate-iterator?" /* ConditionallyMutateIterator */;
134013
134174
  }
134014
134175
  } else {
134015
134176
  return "mutate?" /* ConditionallyMutate */;
134016
134177
  }
134017
134178
  }
134179
+ function inferCallEffects(state, instr, freezeActions, signature) {
134180
+ var _a;
134181
+ const instrValue = instr.value;
134182
+ const returnValueKind = signature !== null ? {
134183
+ kind: signature.returnValueKind,
134184
+ reason: /* @__PURE__ */ new Set([
134185
+ (_a = signature.returnValueReason) != null ? _a : "known-return-signature" /* KnownReturnSignature */
134186
+ ]),
134187
+ context: /* @__PURE__ */ new Set()
134188
+ } : {
134189
+ kind: "mutable" /* Mutable */,
134190
+ reason: /* @__PURE__ */ new Set(["other" /* Other */]),
134191
+ context: /* @__PURE__ */ new Set()
134192
+ };
134193
+ if (instrValue.kind === "MethodCall" && signature !== null && signature.mutableOnlyIfOperandsAreMutable && areArgumentsImmutableAndNonMutating(state, instrValue.args)) {
134194
+ for (const arg of instrValue.args) {
134195
+ const place = arg.kind === "Identifier" ? arg : arg.place;
134196
+ state.referenceAndRecordEffects(
134197
+ freezeActions,
134198
+ place,
134199
+ "read" /* Read */,
134200
+ "other" /* Other */
134201
+ );
134202
+ }
134203
+ state.referenceAndRecordEffects(
134204
+ freezeActions,
134205
+ instrValue.receiver,
134206
+ "capture" /* Capture */,
134207
+ "other" /* Other */
134208
+ );
134209
+ state.initialize(instrValue, returnValueKind);
134210
+ state.define(instr.lvalue, instrValue);
134211
+ instr.lvalue.effect = instrValue.receiver.effect === "capture" /* Capture */ ? "store" /* Store */ : "mutate?" /* ConditionallyMutate */;
134212
+ return;
134213
+ }
134214
+ const effects = signature !== null ? getFunctionEffects(instrValue, signature) : null;
134215
+ let hasCaptureArgument = false;
134216
+ for (let i = 0; i < instrValue.args.length; i++) {
134217
+ const arg = instrValue.args[i];
134218
+ const place = arg.kind === "Identifier" ? arg : arg.place;
134219
+ state.referenceAndRecordEffects(
134220
+ freezeActions,
134221
+ place,
134222
+ getArgumentEffect(effects != null ? effects[i] : null, arg),
134223
+ "other" /* Other */
134224
+ );
134225
+ hasCaptureArgument || (hasCaptureArgument = place.effect === "capture" /* Capture */);
134226
+ }
134227
+ const callee = instrValue.kind === "MethodCall" ? instrValue.receiver : instrValue.callee;
134228
+ if (signature !== null) {
134229
+ state.referenceAndRecordEffects(
134230
+ freezeActions,
134231
+ callee,
134232
+ signature.calleeEffect,
134233
+ "other" /* Other */
134234
+ );
134235
+ } else {
134236
+ state.referenceAndRecordEffects(
134237
+ freezeActions,
134238
+ callee,
134239
+ instrValue.kind === "NewExpression" ? "read" /* Read */ : "mutate?" /* ConditionallyMutate */,
134240
+ "other" /* Other */
134241
+ );
134242
+ }
134243
+ hasCaptureArgument || (hasCaptureArgument = callee.effect === "capture" /* Capture */);
134244
+ state.initialize(instrValue, returnValueKind);
134245
+ state.define(instr.lvalue, instrValue);
134246
+ instr.lvalue.effect = hasCaptureArgument ? "store" /* Store */ : "mutate?" /* ConditionallyMutate */;
134247
+ }
134018
134248
 
134019
134249
  // src/ReactiveScopes/PruneNonEscapingScopes.ts
134020
134250
  function pruneNonEscapingScopes(fn) {
@@ -134910,7 +135140,7 @@ var Visitor7 = class extends ReactiveFunctionVisitor {
134910
135140
  // src/ReactiveScopes/RenameVariables.ts
134911
135141
  function renameVariables(fn) {
134912
135142
  const globals = collectReferencedGlobals(fn);
134913
- const scopes = new Scopes(globals);
135143
+ const scopes = new Scopes(globals, fn.env.programContext);
134914
135144
  renameVariablesImpl(fn, new Visitor8(), scopes);
134915
135145
  return /* @__PURE__ */ new Set([...scopes.names, ...globals]);
134916
135146
  }
@@ -134960,15 +135190,17 @@ var Visitor8 = class extends ReactiveFunctionVisitor {
134960
135190
  renameVariablesImpl(_fn, this, _state);
134961
135191
  }
134962
135192
  };
134963
- var _seen, _stack, _globals3, _Scopes_instances, lookup_fn;
135193
+ var _seen, _stack, _globals3, _programContext, _Scopes_instances, lookup_fn;
134964
135194
  var Scopes = class {
134965
- constructor(globals) {
135195
+ constructor(globals, programContext) {
134966
135196
  __privateAdd(this, _Scopes_instances);
134967
135197
  __privateAdd(this, _seen, /* @__PURE__ */ new Map());
134968
135198
  __privateAdd(this, _stack, [/* @__PURE__ */ new Map()]);
134969
135199
  __privateAdd(this, _globals3);
135200
+ __privateAdd(this, _programContext);
134970
135201
  this.names = /* @__PURE__ */ new Set();
134971
135202
  __privateSet(this, _globals3, globals);
135203
+ __privateSet(this, _programContext, programContext);
134972
135204
  }
134973
135205
  visit(identifier4) {
134974
135206
  const originalName = identifier4.name;
@@ -134996,6 +135228,7 @@ var Scopes = class {
134996
135228
  name = `${originalName.value}$${id++}`;
134997
135229
  }
134998
135230
  }
135231
+ __privateGet(this, _programContext).addNewReference(name);
134999
135232
  const identifierName = makeIdentifierName(name);
135000
135233
  identifier4.name = identifierName;
135001
135234
  __privateGet(this, _seen).set(identifier4.declarationId, identifierName);
@@ -135018,6 +135251,7 @@ var Scopes = class {
135018
135251
  _seen = new WeakMap();
135019
135252
  _stack = new WeakMap();
135020
135253
  _globals3 = new WeakMap();
135254
+ _programContext = new WeakMap();
135021
135255
  _Scopes_instances = new WeakSet();
135022
135256
  lookup_fn = function(name) {
135023
135257
  for (let i = __privateGet(this, _stack).length - 1; i >= 0; i--) {
@@ -135201,6 +135435,13 @@ function inferPlace(place, instrId, inferMutableRangeForStores) {
135201
135435
  infer(place, instrId);
135202
135436
  }
135203
135437
  return;
135438
+ case "mutate-iterator?" /* ConditionallyMutateIterator */: {
135439
+ const identifier4 = place.identifier;
135440
+ if (!isArrayType(identifier4) && !isSetType(identifier4) && !isMapType(identifier4)) {
135441
+ infer(place, instrId);
135442
+ }
135443
+ return;
135444
+ }
135204
135445
  case "mutate?" /* ConditionallyMutate */:
135205
135446
  case "mutate" /* Mutate */: {
135206
135447
  infer(place, instrId);
@@ -135836,6 +136077,7 @@ function inferReactivePlaces(fn) {
135836
136077
  case "capture" /* Capture */:
135837
136078
  case "store" /* Store */:
135838
136079
  case "mutate?" /* ConditionallyMutate */:
136080
+ case "mutate-iterator?" /* ConditionallyMutateIterator */:
135839
136081
  case "mutate" /* Mutate */: {
135840
136082
  if (isMutable2(instruction, operand)) {
135841
136083
  reactiveIdentifiers.markReactive(operand);
@@ -136203,6 +136445,7 @@ function inferEffectDependencies(fn) {
136203
136445
  if (hasRewrite) {
136204
136446
  markInstructionIds(fn.body);
136205
136447
  fixScopeAndIdentifierRanges(fn.body);
136448
+ fn.env.hasInferredEffect = true;
136206
136449
  }
136207
136450
  }
136208
136451
  function writeDependencyToInstructions(dep, reactive, env, loc) {
@@ -137291,7 +137534,8 @@ function* generateInstructionTypes(env, names, instr) {
137291
137534
  yield equation(value.callee.identifier.type, {
137292
137535
  kind: "Function",
137293
137536
  shapeId: null,
137294
- return: returnType
137537
+ return: returnType,
137538
+ isConstructor: false
137295
137539
  });
137296
137540
  yield equation(left, returnType);
137297
137541
  break;
@@ -137301,7 +137545,8 @@ function* generateInstructionTypes(env, names, instr) {
137301
137545
  yield equation(value.tag.identifier.type, {
137302
137546
  kind: "Function",
137303
137547
  shapeId: null,
137304
- return: returnType
137548
+ return: returnType,
137549
+ isConstructor: false
137305
137550
  });
137306
137551
  yield equation(left, returnType);
137307
137552
  break;
@@ -137350,7 +137595,8 @@ function* generateInstructionTypes(env, names, instr) {
137350
137595
  yield equation(value.property.identifier.type, {
137351
137596
  kind: "Function",
137352
137597
  return: returnType,
137353
- shapeId: null
137598
+ shapeId: null,
137599
+ isConstructor: false
137354
137600
  });
137355
137601
  yield equation(left, returnType);
137356
137602
  break;
@@ -137413,7 +137659,8 @@ function* generateInstructionTypes(env, names, instr) {
137413
137659
  yield equation(left, {
137414
137660
  kind: "Function",
137415
137661
  shapeId: BuiltInFunctionId,
137416
- return: value.loweredFunc.func.returnType
137662
+ return: value.loweredFunc.func.returnType,
137663
+ isConstructor: false
137417
137664
  });
137418
137665
  break;
137419
137666
  }
@@ -137431,9 +137678,19 @@ function* generateInstructionTypes(env, names, instr) {
137431
137678
  yield equation(left, { kind: "Object", shapeId: BuiltInJsxId });
137432
137679
  break;
137433
137680
  }
137681
+ case "NewExpression": {
137682
+ const returnType = makeType();
137683
+ yield equation(value.callee.identifier.type, {
137684
+ kind: "Function",
137685
+ return: returnType,
137686
+ shapeId: null,
137687
+ isConstructor: true
137688
+ });
137689
+ yield equation(left, returnType);
137690
+ break;
137691
+ }
137434
137692
  case "PropertyStore":
137435
137693
  case "DeclareLocal":
137436
- case "NewExpression":
137437
137694
  case "RegExpLiteral":
137438
137695
  case "MetaProperty":
137439
137696
  case "ComputedStore":
@@ -137492,7 +137749,7 @@ var Unifier = class {
137492
137749
  this.bindVariableTo(tB, tA);
137493
137750
  return;
137494
137751
  }
137495
- if (tB.kind === "Function" && tA.kind === "Function") {
137752
+ if (tB.kind === "Function" && tA.kind === "Function" && tA.isConstructor === tB.isConstructor) {
137496
137753
  this.unify(tA.return, tB.return);
137497
137754
  return;
137498
137755
  }
@@ -137593,7 +137850,8 @@ var Unifier = class {
137593
137850
  return {
137594
137851
  kind: "Function",
137595
137852
  return: returnType,
137596
- shapeId: type.shapeId
137853
+ shapeId: type.shapeId,
137854
+ isConstructor: type.isConstructor
137597
137855
  };
137598
137856
  }
137599
137857
  case "ObjectMethod":
@@ -138033,9 +138291,7 @@ function validateHooksUsage(fn) {
138033
138291
  for (const [, error] of errorsByPlace) {
138034
138292
  errors.push(error);
138035
138293
  }
138036
- if (errors.hasErrors()) {
138037
- throw errors;
138038
- }
138294
+ return errors.asResult();
138039
138295
  }
138040
138296
  function visitFunctionExpression(errors, fn) {
138041
138297
  for (const [, block] of fn.body.blocks) {
@@ -138072,9 +138328,7 @@ function visitFunctionExpression(errors, fn) {
138072
138328
  function validateMemoizedEffectDependencies(fn) {
138073
138329
  const errors = new CompilerError();
138074
138330
  visitReactiveFunction(fn, new Visitor10(), errors);
138075
- if (errors.hasErrors()) {
138076
- throw errors;
138077
- }
138331
+ return errors.asResult();
138078
138332
  }
138079
138333
  var Visitor10 = class extends ReactiveFunctionVisitor {
138080
138334
  constructor() {
@@ -138136,6 +138390,7 @@ function validateNoCapitalizedCalls(fn) {
138136
138390
  const isAllowed = (name) => {
138137
138391
  return ALLOW_LIST.has(name) || hookPattern != null && hookPattern.test(name);
138138
138392
  };
138393
+ const errors = new CompilerError();
138139
138394
  const capitalLoadGlobals = /* @__PURE__ */ new Map();
138140
138395
  const capitalizedProperties = /* @__PURE__ */ new Map();
138141
138396
  const reason = "Capitalized functions are reserved for components, which must be invoked with JSX. If this is a component, render it with JSX. Otherwise, ensure that it has no hook calls and rename it to begin with a lowercase letter. Alternatively, if you know for a fact that this function is not a component, you can allowlist it via the compiler config";
@@ -138172,7 +138427,8 @@ function validateNoCapitalizedCalls(fn) {
138172
138427
  const propertyIdentifier = value.property.identifier.id;
138173
138428
  const propertyName = capitalizedProperties.get(propertyIdentifier);
138174
138429
  if (propertyName != null) {
138175
- CompilerError.throwInvalidReact({
138430
+ errors.push({
138431
+ severity: "InvalidReact" /* InvalidReact */,
138176
138432
  reason,
138177
138433
  description: `${propertyName} may be a component.`,
138178
138434
  loc: value.loc,
@@ -138184,6 +138440,7 @@ function validateNoCapitalizedCalls(fn) {
138184
138440
  }
138185
138441
  }
138186
138442
  }
138443
+ return errors.asResult();
138187
138444
  }
138188
138445
 
138189
138446
  // src/Validation/ValidateNoRefAccesInRender.ts
@@ -138225,7 +138482,7 @@ var Env = class extends Map {
138225
138482
  _changed = new WeakMap();
138226
138483
  function validateNoRefAccessInRender(fn) {
138227
138484
  const env = new Env();
138228
- validateNoRefAccessInRenderImpl(fn, env).unwrap();
138485
+ return validateNoRefAccessInRenderImpl(fn, env).map((_) => void 0);
138229
138486
  }
138230
138487
  function refTypeOfType(place) {
138231
138488
  if (isRefValueType(place.identifier)) {
@@ -138687,7 +138944,7 @@ function validateNoDirectRefValueAccess(errors, operand, env) {
138687
138944
  // src/Validation/ValidateNoSetStateInRender.ts
138688
138945
  function validateNoSetStateInRender(fn) {
138689
138946
  const unconditionalSetStateFunctions = /* @__PURE__ */ new Set();
138690
- validateNoSetStateInRenderImpl(fn, unconditionalSetStateFunctions).unwrap();
138947
+ return validateNoSetStateInRenderImpl(fn, unconditionalSetStateFunctions);
138691
138948
  }
138692
138949
  function validateNoSetStateInRenderImpl(fn, unconditionalSetStateFunctions) {
138693
138950
  const unconditionalBlocks = computeUnconditionalBlocks(fn);
@@ -138772,11 +139029,7 @@ function validateNoSetStateInRenderImpl(fn, unconditionalSetStateFunctions) {
138772
139029
  }
138773
139030
  }
138774
139031
  }
138775
- if (errors.hasErrors()) {
138776
- return Err(errors);
138777
- } else {
138778
- return Ok(void 0);
138779
- }
139032
+ return errors.asResult();
138780
139033
  }
138781
139034
 
138782
139035
  // src/Validation/ValidatePreservedManualMemoization.ts
@@ -138786,9 +139039,7 @@ function validatePreservedManualMemoization(fn) {
138786
139039
  manualMemoState: null
138787
139040
  };
138788
139041
  visitReactiveFunction(fn, new Visitor11(), state);
138789
- if (state.errors.hasErrors()) {
138790
- throw state.errors;
138791
- }
139042
+ return state.errors.asResult();
138792
139043
  }
138793
139044
  var DEBUG4 = false;
138794
139045
  function prettyPrintScopeDependency(val) {
@@ -139108,6 +139359,7 @@ function isUnmemoized2(operand, scopes) {
139108
139359
 
139109
139360
  // src/Validation/ValidateUseMemo.ts
139110
139361
  function validateUseMemo(fn) {
139362
+ const errors = new CompilerError();
139111
139363
  const useMemos = /* @__PURE__ */ new Set();
139112
139364
  const react = /* @__PURE__ */ new Set();
139113
139365
  const functions = /* @__PURE__ */ new Map();
@@ -139150,7 +139402,8 @@ function validateUseMemo(fn) {
139150
139402
  continue;
139151
139403
  }
139152
139404
  if (body.loweredFunc.func.params.length > 0) {
139153
- CompilerError.throwInvalidReact({
139405
+ errors.push({
139406
+ severity: "InvalidReact" /* InvalidReact */,
139154
139407
  reason: "useMemo callbacks may not accept any arguments",
139155
139408
  description: null,
139156
139409
  loc: body.loc,
@@ -139158,7 +139411,8 @@ function validateUseMemo(fn) {
139158
139411
  });
139159
139412
  }
139160
139413
  if (body.loweredFunc.func.async || body.loweredFunc.func.generator) {
139161
- CompilerError.throwInvalidReact({
139414
+ errors.push({
139415
+ severity: "InvalidReact" /* InvalidReact */,
139162
139416
  reason: "useMemo callbacks may not be async or generator functions",
139163
139417
  description: null,
139164
139418
  loc: body.loc,
@@ -139170,6 +139424,7 @@ function validateUseMemo(fn) {
139170
139424
  }
139171
139425
  }
139172
139426
  }
139427
+ return errors.asResult();
139173
139428
  }
139174
139429
 
139175
139430
  // src/Validation/ValidateLocalsNotReassignedAfterRender.ts
@@ -139398,7 +139653,7 @@ function propagatePhiTypes(fn) {
139398
139653
  }
139399
139654
 
139400
139655
  // src/Optimization/LowerContextAccess.ts
139401
- function lowerContextAccess(fn, loweredContextCallee) {
139656
+ function lowerContextAccess(fn, loweredContextCalleeConfig) {
139402
139657
  const contextAccess = /* @__PURE__ */ new Map();
139403
139658
  const contextKeys = /* @__PURE__ */ new Map();
139404
139659
  for (const [, block] of fn.body.blocks) {
@@ -139426,6 +139681,7 @@ function lowerContextAccess(fn, loweredContextCallee) {
139426
139681
  }
139427
139682
  }
139428
139683
  }
139684
+ let importLoweredContextCallee = null;
139429
139685
  if (contextAccess.size > 0 && contextKeys.size > 0) {
139430
139686
  for (const [, block] of fn.body.blocks) {
139431
139687
  let nextInstructions = null;
@@ -139433,9 +139689,12 @@ function lowerContextAccess(fn, loweredContextCallee) {
139433
139689
  const instr = block.instructions[i];
139434
139690
  const { lvalue, value } = instr;
139435
139691
  if (value.kind === "CallExpression" && isUseContextHookType(value.callee.identifier) && contextKeys.has(lvalue.identifier.id)) {
139692
+ importLoweredContextCallee != null ? importLoweredContextCallee : importLoweredContextCallee = fn.env.programContext.addImportSpecifier(
139693
+ loweredContextCalleeConfig
139694
+ );
139436
139695
  const loweredContextCalleeInstr = emitLoadLoweredContextCallee(
139437
139696
  fn.env,
139438
- loweredContextCallee
139697
+ importLoweredContextCallee
139439
139698
  );
139440
139699
  if (nextInstructions === null) {
139441
139700
  nextInstructions = block.instructions.slice(0, i);
@@ -139459,17 +139718,12 @@ function lowerContextAccess(fn, loweredContextCallee) {
139459
139718
  }
139460
139719
  markInstructionIds(fn.body);
139461
139720
  inferTypes(fn);
139462
- fn.env.hasLoweredContextAccess = true;
139463
139721
  }
139464
139722
  }
139465
- function emitLoadLoweredContextCallee(env, loweredContextCallee) {
139723
+ function emitLoadLoweredContextCallee(env, importedLowerContextCallee) {
139466
139724
  const loadGlobal = {
139467
139725
  kind: "LoadGlobal",
139468
- binding: {
139469
- kind: "ImportNamespace",
139470
- module: loweredContextCallee.source,
139471
- name: loweredContextCallee.importSpecifierName
139472
- },
139726
+ binding: __spreadValues({}, importedLowerContextCallee),
139473
139727
  loc: GeneratedSource
139474
139728
  };
139475
139729
  return {
@@ -139676,9 +139930,7 @@ function validateNoSetStateInPassiveEffects(fn) {
139676
139930
  }
139677
139931
  }
139678
139932
  }
139679
- if (errors.hasErrors()) {
139680
- throw errors;
139681
- }
139933
+ return errors.asResult();
139682
139934
  }
139683
139935
  function getSetStateCall(fn, setStateFunctions) {
139684
139936
  for (const [, block] of fn.body.blocks) {
@@ -139744,9 +139996,7 @@ function validateNoJSXInTryStatement(fn) {
139744
139996
  activeTryBlocks.push(block.terminal.handler);
139745
139997
  }
139746
139998
  }
139747
- if (errors.hasErrors()) {
139748
- throw errors;
139749
- }
139999
+ return errors.asResult();
139750
140000
  }
139751
140001
 
139752
140002
  // src/HIR/CollectHoistablePropertyLoads.ts
@@ -141180,7 +141430,7 @@ function process2(fn, jsx, globals) {
141180
141430
  if (fn.fnType === "Component") {
141181
141431
  return null;
141182
141432
  }
141183
- const props = collectProps(jsx);
141433
+ const props = collectProps(fn.env, jsx);
141184
141434
  if (!props) return null;
141185
141435
  const outlinedTag = fn.env.generateGloballyUniqueIdentifierName(null).value;
141186
141436
  const newInstrs = emitOutlinedJsx(fn.env, jsx, props, outlinedTag);
@@ -141190,7 +141440,7 @@ function process2(fn, jsx, globals) {
141190
141440
  outlinedFn.id = outlinedTag;
141191
141441
  return { instrs: newInstrs, fn: outlinedFn };
141192
141442
  }
141193
- function collectProps(instructions) {
141443
+ function collectProps(env, instructions) {
141194
141444
  let id = 1;
141195
141445
  function generateName(oldName) {
141196
141446
  let newName = oldName;
@@ -141198,6 +141448,7 @@ function collectProps(instructions) {
141198
141448
  newName = `${oldName}${id++}`;
141199
141449
  }
141200
141450
  seen.add(newName);
141451
+ env.programContext.addNewReference(newName);
141201
141452
  return newName;
141202
141453
  }
141203
141454
  const attributes = [];
@@ -141460,6 +141711,7 @@ function transformFire(fn) {
141460
141711
  context.throwIfErrorsFound();
141461
141712
  }
141462
141713
  function replaceFireFunctions(fn, context) {
141714
+ let importedUseFire = null;
141463
141715
  let hasRewrite = false;
141464
141716
  for (const [, block] of fn.body.blocks) {
141465
141717
  const rewriteInstrs = /* @__PURE__ */ new Map();
@@ -141483,7 +141735,14 @@ function replaceFireFunctions(fn, context) {
141483
141735
  ] of capturedCallees.entries()) {
141484
141736
  if (!context.hasCalleeWithInsertedFire(fireCalleePlace)) {
141485
141737
  context.addCalleeWithInsertedFire(fireCalleePlace);
141486
- const loadUseFireInstr = makeLoadUseFireInstruction(fn.env);
141738
+ importedUseFire != null ? importedUseFire : importedUseFire = fn.env.programContext.addImportSpecifier({
141739
+ source: fn.env.programContext.reactRuntimeModule,
141740
+ importSpecifierName: USE_FIRE_FUNCTION_NAME
141741
+ });
141742
+ const loadUseFireInstr = makeLoadUseFireInstruction(
141743
+ fn.env,
141744
+ importedUseFire
141745
+ );
141487
141746
  const loadFireCalleeInstr = makeLoadFireCalleeInstruction(
141488
141747
  fn.env,
141489
141748
  fireCalleeInfo.capturedCalleeIdentifier
@@ -141703,18 +141962,13 @@ function ensureNoMoreFireUses(fn, context) {
141703
141962
  }
141704
141963
  }
141705
141964
  }
141706
- function makeLoadUseFireInstruction(env) {
141965
+ function makeLoadUseFireInstruction(env, importedLoadUseFire) {
141707
141966
  const useFirePlace = createTemporaryPlace(env, GeneratedSource);
141708
141967
  useFirePlace.effect = "read" /* Read */;
141709
141968
  useFirePlace.identifier.type = DefaultNonmutatingHook;
141710
141969
  const instrValue = {
141711
141970
  kind: "LoadGlobal",
141712
- binding: {
141713
- kind: "ImportSpecifier",
141714
- name: "useFire",
141715
- module: "react",
141716
- imported: "useFire"
141717
- },
141971
+ binding: __spreadValues({}, importedLoadUseFire),
141718
141972
  loc: GeneratedSource
141719
141973
  };
141720
141974
  return {
@@ -141782,10 +142036,10 @@ function makeStoreUseFireInstruction(env, useFireCallResultPlace, fireFunctionBi
141782
142036
  loc: GeneratedSource
141783
142037
  };
141784
142038
  }
141785
- var _env4, _errors, _callExpressions, _functionExpressions, _loadLocals, _fireCalleesToFireFunctions, _calleesWithInsertedFire, _capturedCalleeIdentifierIds, _inUseEffectLambda, _loadGlobalInstructionIds, _arrayExpressions;
142039
+ var _env3, _errors, _callExpressions, _functionExpressions, _loadLocals, _fireCalleesToFireFunctions, _calleesWithInsertedFire, _capturedCalleeIdentifierIds, _inUseEffectLambda, _loadGlobalInstructionIds, _arrayExpressions;
141786
142040
  var Context4 = class {
141787
142041
  constructor(env) {
141788
- __privateAdd(this, _env4);
142042
+ __privateAdd(this, _env3);
141789
142043
  __privateAdd(this, _errors, new CompilerError());
141790
142044
  /*
141791
142045
  * Used to look up the call expression passed to a `fire(callExpr())`. Gives back
@@ -141834,7 +142088,7 @@ var Context4 = class {
141834
142088
  * to use the fire functions
141835
142089
  */
141836
142090
  __privateAdd(this, _arrayExpressions, /* @__PURE__ */ new Map());
141837
- __privateSet(this, _env4, env);
142091
+ __privateSet(this, _env3, env);
141838
142092
  }
141839
142093
  pushError(error) {
141840
142094
  __privateGet(this, _errors).push(error);
@@ -141869,7 +142123,7 @@ var Context4 = class {
141869
142123
  const fireFunctionBinding = getOrInsertWith(
141870
142124
  __privateGet(this, _fireCalleesToFireFunctions),
141871
142125
  callee.identifier.id,
141872
- () => createTemporaryPlace(__privateGet(this, _env4), GeneratedSource)
142126
+ () => createTemporaryPlace(__privateGet(this, _env3), GeneratedSource)
141873
142127
  );
141874
142128
  __privateGet(this, _capturedCalleeIdentifierIds).set(callee.identifier.id, {
141875
142129
  fireFunctionBinding,
@@ -141917,7 +142171,7 @@ var Context4 = class {
141917
142171
  if (this.hasErrors()) throw __privateGet(this, _errors);
141918
142172
  }
141919
142173
  };
141920
- _env4 = new WeakMap();
142174
+ _env3 = new WeakMap();
141921
142175
  _errors = new WeakMap();
141922
142176
  _callExpressions = new WeakMap();
141923
142177
  _functionExpressions = new WeakMap();
@@ -141951,7 +142205,7 @@ function rewriteInstructions(rewriteInstrs, instructions) {
141951
142205
  return instructions;
141952
142206
  }
141953
142207
 
141954
- // src/Validation/ValiateNoImpureFunctionsInRender.ts
142208
+ // src/Validation/ValidateNoImpureFunctionsInRender.ts
141955
142209
  function validateNoImpureFunctionsInRender(fn) {
141956
142210
  const errors = new CompilerError();
141957
142211
  for (const [, block] of fn.body.blocks) {
@@ -141975,13 +142229,79 @@ function validateNoImpureFunctionsInRender(fn) {
141975
142229
  }
141976
142230
  }
141977
142231
  }
141978
- if (errors.hasErrors()) {
141979
- throw errors;
142232
+ return errors.asResult();
142233
+ }
142234
+
142235
+ // src/Validation/ValidateStaticComponents.ts
142236
+ function validateStaticComponents(fn) {
142237
+ const error = new CompilerError();
142238
+ const knownDynamicComponents = /* @__PURE__ */ new Map();
142239
+ for (const block of fn.body.blocks.values()) {
142240
+ phis: for (const phi of block.phis) {
142241
+ for (const operand of phi.operands.values()) {
142242
+ const loc = knownDynamicComponents.get(operand.identifier.id);
142243
+ if (loc != null) {
142244
+ knownDynamicComponents.set(phi.place.identifier.id, loc);
142245
+ continue phis;
142246
+ }
142247
+ }
142248
+ }
142249
+ for (const instr of block.instructions) {
142250
+ const { lvalue, value } = instr;
142251
+ switch (value.kind) {
142252
+ case "FunctionExpression":
142253
+ case "NewExpression":
142254
+ case "MethodCall":
142255
+ case "CallExpression": {
142256
+ knownDynamicComponents.set(lvalue.identifier.id, value.loc);
142257
+ break;
142258
+ }
142259
+ case "LoadLocal": {
142260
+ const loc = knownDynamicComponents.get(value.place.identifier.id);
142261
+ if (loc != null) {
142262
+ knownDynamicComponents.set(lvalue.identifier.id, loc);
142263
+ }
142264
+ break;
142265
+ }
142266
+ case "StoreLocal": {
142267
+ const loc = knownDynamicComponents.get(value.value.identifier.id);
142268
+ if (loc != null) {
142269
+ knownDynamicComponents.set(lvalue.identifier.id, loc);
142270
+ knownDynamicComponents.set(value.lvalue.place.identifier.id, loc);
142271
+ }
142272
+ break;
142273
+ }
142274
+ case "JsxExpression": {
142275
+ if (value.tag.kind === "Identifier") {
142276
+ const location = knownDynamicComponents.get(
142277
+ value.tag.identifier.id
142278
+ );
142279
+ if (location != null) {
142280
+ error.push({
142281
+ reason: `Components created during render will reset their state each time they are created. Declare components outside of render. `,
142282
+ severity: "InvalidReact" /* InvalidReact */,
142283
+ loc: value.tag.loc,
142284
+ description: null,
142285
+ suggestions: null
142286
+ });
142287
+ error.push({
142288
+ reason: `The component may be created during render`,
142289
+ severity: "InvalidReact" /* InvalidReact */,
142290
+ loc: location,
142291
+ description: null,
142292
+ suggestions: null
142293
+ });
142294
+ }
142295
+ }
142296
+ }
142297
+ }
142298
+ }
141980
142299
  }
142300
+ return error.asResult();
141981
142301
  }
141982
142302
 
141983
142303
  // src/Entrypoint/Pipeline.ts
141984
- function run(func, config, fnType, mode, useMemoCacheIdentifier, logger, filename, code) {
142304
+ function run(func, config, fnType, mode, programContext, logger, filename, code) {
141985
142305
  var _a, _b;
141986
142306
  const contextIdentifiers = findContextIdentifiers(func);
141987
142307
  const env = new Environment(
@@ -141993,7 +142313,7 @@ function run(func, config, fnType, mode, useMemoCacheIdentifier, logger, filenam
141993
142313
  logger,
141994
142314
  filename,
141995
142315
  code,
141996
- useMemoCacheIdentifier
142316
+ programContext
141997
142317
  );
141998
142318
  (_b = (_a = env.logger) == null ? void 0 : _a.debugLogIRs) == null ? void 0 : _b.call(_a, {
141999
142319
  kind: "debug",
@@ -142012,7 +142332,7 @@ function runWithEnvironment(func, env) {
142012
142332
  pruneMaybeThrows(hir);
142013
142333
  log2({ kind: "hir", name: "PruneMaybeThrows", value: hir });
142014
142334
  validateContextVariableLValues(hir);
142015
- validateUseMemo(hir);
142335
+ validateUseMemo(hir).unwrap();
142016
142336
  if (env.isInferredMemoEnabled && !env.config.enablePreserveExistingManualUseMemo && !env.config.disableMemoizationForDebugging && !env.config.enableChangeDetectionForDebugging) {
142017
142337
  dropManualMemoization(hir);
142018
142338
  log2({ kind: "hir", name: "DropManualMemoization", value: hir });
@@ -142038,10 +142358,10 @@ function runWithEnvironment(func, env) {
142038
142358
  log2({ kind: "hir", name: "InferTypes", value: hir });
142039
142359
  if (env.isInferredMemoEnabled) {
142040
142360
  if (env.config.validateHooksUsage) {
142041
- validateHooksUsage(hir);
142361
+ validateHooksUsage(hir).unwrap();
142042
142362
  }
142043
142363
  if (env.config.validateNoCapitalizedCalls) {
142044
- validateNoCapitalizedCalls(hir);
142364
+ validateNoCapitalizedCalls(hir).unwrap();
142045
142365
  }
142046
142366
  }
142047
142367
  if (env.config.enableFire) {
@@ -142078,19 +142398,19 @@ function runWithEnvironment(func, env) {
142078
142398
  assertValidMutableRanges(hir);
142079
142399
  }
142080
142400
  if (env.config.validateRefAccessDuringRender) {
142081
- validateNoRefAccessInRender(hir);
142401
+ validateNoRefAccessInRender(hir).unwrap();
142082
142402
  }
142083
142403
  if (env.config.validateNoSetStateInRender) {
142084
- validateNoSetStateInRender(hir);
142404
+ validateNoSetStateInRender(hir).unwrap();
142085
142405
  }
142086
142406
  if (env.config.validateNoSetStateInPassiveEffects) {
142087
- validateNoSetStateInPassiveEffects(hir);
142407
+ env.logErrors(validateNoSetStateInPassiveEffects(hir));
142088
142408
  }
142089
142409
  if (env.config.validateNoJSXInTryStatements) {
142090
- validateNoJSXInTryStatement(hir);
142410
+ env.logErrors(validateNoJSXInTryStatement(hir));
142091
142411
  }
142092
142412
  if (env.config.validateNoImpureFunctionsInRender) {
142093
- validateNoImpureFunctionsInRender(hir);
142413
+ validateNoImpureFunctionsInRender(hir).unwrap();
142094
142414
  }
142095
142415
  }
142096
142416
  inferReactivePlaces(hir);
@@ -142108,6 +142428,9 @@ function runWithEnvironment(func, env) {
142108
142428
  value: hir
142109
142429
  });
142110
142430
  if (env.isInferredMemoEnabled) {
142431
+ if (env.config.validateStaticComponents) {
142432
+ env.logErrors(validateStaticComponents(hir));
142433
+ }
142111
142434
  inferReactiveScopeVariables(hir);
142112
142435
  log2({ kind: "hir", name: "InferReactiveScopeVariables", value: hir });
142113
142436
  }
@@ -142288,10 +142611,10 @@ function runWithEnvironment(func, env) {
142288
142611
  value: reactiveFunction
142289
142612
  });
142290
142613
  if (env.config.validateMemoizedEffectDependencies) {
142291
- validateMemoizedEffectDependencies(reactiveFunction);
142614
+ validateMemoizedEffectDependencies(reactiveFunction).unwrap();
142292
142615
  }
142293
142616
  if (env.config.enablePreserveExistingMemoizationGuarantees || env.config.validatePreserveExistingMemoizationGuarantees) {
142294
- validatePreservedManualMemoization(reactiveFunction);
142617
+ validatePreservedManualMemoization(reactiveFunction).unwrap();
142295
142618
  }
142296
142619
  const ast = codegenFunction(reactiveFunction, {
142297
142620
  uniqueIdentifiers,
@@ -142306,29 +142629,19 @@ function runWithEnvironment(func, env) {
142306
142629
  }
142307
142630
  return ast;
142308
142631
  }
142309
- function compileFn(func, config, fnType, mode, useMemoCacheIdentifier, logger, filename, code) {
142632
+ function compileFn(func, config, fnType, mode, programContext, logger, filename, code) {
142310
142633
  return run(
142311
142634
  func,
142312
142635
  config,
142313
142636
  fnType,
142314
142637
  mode,
142315
- useMemoCacheIdentifier,
142638
+ programContext,
142316
142639
  logger,
142317
142640
  filename,
142318
142641
  code
142319
142642
  );
142320
142643
  }
142321
142644
 
142322
- // src/Utils/ComponentDeclaration.ts
142323
- function isComponentDeclaration(node) {
142324
- return Object.prototype.hasOwnProperty.call(node, "__componentDeclaration");
142325
- }
142326
-
142327
- // src/Utils/HookDeclaration.ts
142328
- function isHookDeclaration(node) {
142329
- return Object.prototype.hasOwnProperty.call(node, "__hookDeclaration");
142330
- }
142331
-
142332
142645
  // src/Entrypoint/Suppression.ts
142333
142646
  function filterSuppressionsThatAffectFunction(suppressionRanges, fn) {
142334
142647
  const suppressionsInScope = [];
@@ -142631,7 +142944,11 @@ function compileProgram(program, pass) {
142631
142944
  handleError(restrictedImportsErr, pass, null);
142632
142945
  return null;
142633
142946
  }
142634
- const useMemoCacheIdentifier = program.scope.generateUidIdentifier("c");
142947
+ const programContext = new ProgramContext2(
142948
+ program,
142949
+ pass.opts.target,
142950
+ environment.hookPattern
142951
+ );
142635
142952
  const suppressions = findProgramSuppressions(
142636
142953
  pass.comments,
142637
142954
  (_a = pass.opts.eslintSuppressionRules) != null ? _a : DEFAULT_ESLINT_SUPPRESSIONS,
@@ -142699,7 +143016,7 @@ function compileProgram(program, pass) {
142699
143016
  environment,
142700
143017
  fnType,
142701
143018
  "all_features",
142702
- useMemoCacheIdentifier.name,
143019
+ programContext,
142703
143020
  pass.opts.logger,
142704
143021
  pass.filename,
142705
143022
  pass.code
@@ -142726,12 +143043,15 @@ function compileProgram(program, pass) {
142726
143043
  environment,
142727
143044
  fnType,
142728
143045
  "no_inferred_memo",
142729
- useMemoCacheIdentifier.name,
143046
+ programContext,
142730
143047
  pass.opts.logger,
142731
143048
  pass.filename,
142732
143049
  pass.code
142733
143050
  )
142734
143051
  };
143052
+ if (!compileResult.compiledFn.hasFireRewrite && !compileResult.compiledFn.hasInferredEffect) {
143053
+ return null;
143054
+ }
142735
143055
  } catch (err) {
142736
143056
  if (err instanceof CompilerError) {
142737
143057
  retryErrors.push({ fn, error: err });
@@ -142808,82 +143128,28 @@ function compileProgram(program, pass) {
142808
143128
  if (moduleScopeOptOutDirectives.length > 0) {
142809
143129
  return null;
142810
143130
  }
142811
- let gating = null;
142812
- if (pass.opts.gating != null) {
142813
- gating = {
142814
- gatingFn: pass.opts.gating,
142815
- referencedBeforeDeclared: getFunctionReferencedBeforeDeclarationAtTopLevel(program, compiledFns)
142816
- };
142817
- }
142818
- const hasLoweredContextAccess = compiledFns.some(
142819
- (c2) => c2.compiledFn.hasLoweredContextAccess
142820
- );
142821
- const externalFunctions = [];
142822
- try {
142823
- if (gating != null) {
142824
- externalFunctions.push(gating.gatingFn);
142825
- }
142826
- const lowerContextAccess2 = environment.lowerContextAccess;
142827
- if (lowerContextAccess2 && hasLoweredContextAccess) {
142828
- externalFunctions.push(lowerContextAccess2);
142829
- }
142830
- const enableEmitInstrumentForget = environment.enableEmitInstrumentForget;
142831
- if (enableEmitInstrumentForget != null) {
142832
- externalFunctions.push(enableEmitInstrumentForget.fn);
142833
- if (enableEmitInstrumentForget.gating != null) {
142834
- externalFunctions.push(enableEmitInstrumentForget.gating);
142835
- }
142836
- }
142837
- if (environment.enableEmitFreeze != null) {
142838
- externalFunctions.push(environment.enableEmitFreeze);
142839
- }
142840
- if (environment.enableEmitHookGuards != null) {
142841
- externalFunctions.push(environment.enableEmitHookGuards);
142842
- }
142843
- if (environment.enableChangeDetectionForDebugging != null) {
142844
- externalFunctions.push(environment.enableChangeDetectionForDebugging);
142845
- }
142846
- const hasFireRewrite = compiledFns.some((c2) => c2.compiledFn.hasFireRewrite);
142847
- if (environment.enableFire && hasFireRewrite) {
142848
- externalFunctions.push({
142849
- source: getReactCompilerRuntimeModule(pass.opts),
142850
- importSpecifierName: "useFire"
142851
- });
142852
- }
142853
- } catch (err) {
142854
- handleError(err, pass, null);
142855
- return null;
142856
- }
143131
+ const referencedBeforeDeclared = pass.opts.gating != null ? getFunctionReferencedBeforeDeclarationAtTopLevel(program, compiledFns) : null;
142857
143132
  for (const result of compiledFns) {
142858
143133
  const { kind, originalFn, compiledFn } = result;
142859
143134
  const transformedFn = createNewFunctionNode(originalFn, compiledFn);
142860
- if (gating != null && kind === "original") {
143135
+ if (referencedBeforeDeclared != null && kind === "original") {
143136
+ CompilerError.invariant(pass.opts.gating != null, {
143137
+ reason: "Expected 'gating' import to be present",
143138
+ loc: null
143139
+ });
142861
143140
  insertGatedFunctionDeclaration(
142862
143141
  originalFn,
142863
143142
  transformedFn,
142864
- gating.gatingFn,
142865
- gating.referencedBeforeDeclared.has(result)
143143
+ programContext,
143144
+ pass.opts.gating,
143145
+ referencedBeforeDeclared.has(result)
142866
143146
  );
142867
143147
  } else {
142868
143148
  originalFn.replaceWith(transformedFn);
142869
143149
  }
142870
143150
  }
142871
143151
  if (compiledFns.length > 0) {
142872
- let needsMemoCacheFunctionImport = false;
142873
- for (const fn of compiledFns) {
142874
- if (fn.compiledFn.memoSlotsUsed > 0) {
142875
- needsMemoCacheFunctionImport = true;
142876
- break;
142877
- }
142878
- }
142879
- if (needsMemoCacheFunctionImport) {
142880
- updateMemoCacheFunctionImport(
142881
- program,
142882
- getReactCompilerRuntimeModule(pass.opts),
142883
- useMemoCacheIdentifier.name
142884
- );
142885
- }
142886
- addImportsToProgram(program, externalFunctions);
143152
+ addImportsToProgram(program, programContext);
142887
143153
  }
142888
143154
  return { retryErrors };
142889
143155
  }
@@ -142908,7 +143174,7 @@ function shouldSkipCompilation(program, pass) {
142908
143174
  }
142909
143175
  if (hasMemoCacheFunctionImport(
142910
143176
  program,
142911
- getReactCompilerRuntimeModule(pass.opts)
143177
+ getReactCompilerRuntimeModule(pass.opts.target)
142912
143178
  )) {
142913
143179
  return true;
142914
143180
  }
@@ -143102,26 +143368,32 @@ function callsHooksOrCreatesJsx(node, hookPattern) {
143102
143368
  });
143103
143369
  return invokesHooks || createsJsx;
143104
143370
  }
143371
+ function isNonNode(node) {
143372
+ if (!node) {
143373
+ return true;
143374
+ }
143375
+ switch (node.type) {
143376
+ case "ObjectExpression":
143377
+ case "ArrowFunctionExpression":
143378
+ case "FunctionExpression":
143379
+ case "BigIntLiteral":
143380
+ case "ClassExpression":
143381
+ case "NewExpression":
143382
+ return true;
143383
+ }
143384
+ return false;
143385
+ }
143105
143386
  function returnsNonNode(node) {
143106
- let hasReturn = false;
143107
143387
  let returnsNonNode2 = false;
143388
+ if (
143389
+ // node.traverse#ArrowFunctionExpression isn't called for the root node
143390
+ node.type === "ArrowFunctionExpression" && node.node.body.type !== "BlockStatement"
143391
+ ) {
143392
+ returnsNonNode2 = isNonNode(node.node.body);
143393
+ }
143108
143394
  node.traverse({
143109
143395
  ReturnStatement(ret) {
143110
- hasReturn = true;
143111
- const argument = ret.node.argument;
143112
- if (argument == null) {
143113
- returnsNonNode2 = true;
143114
- } else {
143115
- switch (argument.type) {
143116
- case "ObjectExpression":
143117
- case "ArrowFunctionExpression":
143118
- case "FunctionExpression":
143119
- case "BigIntLiteral":
143120
- case "ClassExpression":
143121
- case "NewExpression":
143122
- returnsNonNode2 = true;
143123
- }
143124
- }
143396
+ returnsNonNode2 = isNonNode(ret.node.argument);
143125
143397
  },
143126
143398
  // Skip traversing all nested functions and their return statements
143127
143399
  ArrowFunctionExpression: skipNestedFunctions(node),
@@ -143129,7 +143401,7 @@ function returnsNonNode(node) {
143129
143401
  FunctionDeclaration: skipNestedFunctions(node),
143130
143402
  ObjectMethod: (node2) => node2.skip()
143131
143403
  });
143132
- return !hasReturn || returnsNonNode2;
143404
+ return returnsNonNode2;
143133
143405
  }
143134
143406
  function getFunctionName2(path) {
143135
143407
  if (path.isFunctionDeclaration()) {
@@ -143196,14 +143468,14 @@ function getFunctionReferencedBeforeDeclarationAtTopLevel(program, fns) {
143196
143468
  });
143197
143469
  return referencedBeforeDeclaration;
143198
143470
  }
143199
- function getReactCompilerRuntimeModule(opts) {
143200
- if (opts.target === "19") {
143471
+ function getReactCompilerRuntimeModule(target) {
143472
+ if (target === "19") {
143201
143473
  return "react/compiler-runtime";
143202
- } else if (opts.target === "17" || opts.target === "18") {
143474
+ } else if (target === "17" || target === "18") {
143203
143475
  return "react-compiler-runtime";
143204
143476
  } else {
143205
143477
  CompilerError.invariant(
143206
- opts.target != null && opts.target.kind === "donotuse_meta_internal" && typeof opts.target.runtimeModule === "string",
143478
+ target != null && target.kind === "donotuse_meta_internal" && typeof target.runtimeModule === "string",
143207
143479
  {
143208
143480
  reason: "Expected target to already be validated",
143209
143481
  description: null,
@@ -143211,8 +143483,313 @@ function getReactCompilerRuntimeModule(opts) {
143211
143483
  suggestions: null
143212
143484
  }
143213
143485
  );
143214
- return opts.target.runtimeModule;
143486
+ return target.runtimeModule;
143487
+ }
143488
+ }
143489
+
143490
+ // src/Entrypoint/Imports.ts
143491
+ function validateRestrictedImports(path, { validateBlocklistedImports }) {
143492
+ if (validateBlocklistedImports == null || validateBlocklistedImports.length === 0) {
143493
+ return null;
143215
143494
  }
143495
+ const error = new CompilerError();
143496
+ const restrictedImports = new Set(validateBlocklistedImports);
143497
+ path.traverse({
143498
+ ImportDeclaration(importDeclPath) {
143499
+ var _a;
143500
+ if (restrictedImports.has(importDeclPath.node.source.value)) {
143501
+ error.push({
143502
+ severity: "Todo" /* Todo */,
143503
+ reason: "Bailing out due to blocklisted import",
143504
+ description: `Import from module ${importDeclPath.node.source.value}`,
143505
+ loc: (_a = importDeclPath.node.loc) != null ? _a : null
143506
+ });
143507
+ }
143508
+ }
143509
+ });
143510
+ if (error.hasErrors()) {
143511
+ return error;
143512
+ } else {
143513
+ return null;
143514
+ }
143515
+ }
143516
+ var ProgramContext2 = class {
143517
+ constructor(program, reactRuntimeModule, hookPattern) {
143518
+ // known generated or referenced identifiers in the program
143519
+ this.knownReferencedNames = /* @__PURE__ */ new Set();
143520
+ // generated imports
143521
+ this.imports = /* @__PURE__ */ new Map();
143522
+ this.hookPattern = hookPattern;
143523
+ this.scope = program.scope;
143524
+ this.reactRuntimeModule = getReactCompilerRuntimeModule(reactRuntimeModule);
143525
+ }
143526
+ isHookName(name) {
143527
+ if (this.hookPattern == null) {
143528
+ return isHookName(name);
143529
+ } else {
143530
+ const match = new RegExp(this.hookPattern).exec(name);
143531
+ return match != null && typeof match[1] === "string" && isHookName(match[1]);
143532
+ }
143533
+ }
143534
+ hasReference(name) {
143535
+ return this.knownReferencedNames.has(name) || this.scope.hasBinding(name) || this.scope.hasGlobal(name) || this.scope.hasReference(name);
143536
+ }
143537
+ newUid(name) {
143538
+ let uid;
143539
+ if (this.isHookName(name)) {
143540
+ uid = name;
143541
+ let i = 0;
143542
+ while (this.hasReference(uid)) {
143543
+ this.knownReferencedNames.add(uid);
143544
+ uid = `${name}_${i++}`;
143545
+ }
143546
+ } else if (!this.hasReference(name)) {
143547
+ uid = name;
143548
+ } else {
143549
+ uid = this.scope.generateUid(name);
143550
+ }
143551
+ this.knownReferencedNames.add(uid);
143552
+ return uid;
143553
+ }
143554
+ addMemoCacheImport() {
143555
+ return this.addImportSpecifier(
143556
+ {
143557
+ source: this.reactRuntimeModule,
143558
+ importSpecifierName: "c"
143559
+ },
143560
+ "_c"
143561
+ );
143562
+ }
143563
+ /**
143564
+ *
143565
+ * @param externalFunction
143566
+ * @param nameHint if defined, will be used as the name of the import specifier
143567
+ * @returns
143568
+ */
143569
+ addImportSpecifier({ source: module2, importSpecifierName: specifier }, nameHint) {
143570
+ var _a;
143571
+ const maybeBinding = (_a = this.imports.get(module2)) == null ? void 0 : _a.get(specifier);
143572
+ if (maybeBinding != null) {
143573
+ return __spreadValues({}, maybeBinding);
143574
+ }
143575
+ const binding = {
143576
+ kind: "ImportSpecifier",
143577
+ name: this.newUid(nameHint != null ? nameHint : specifier),
143578
+ module: module2,
143579
+ imported: specifier
143580
+ };
143581
+ getOrInsertWith(this.imports, module2, () => /* @__PURE__ */ new Map()).set(specifier, __spreadValues({}, binding));
143582
+ return binding;
143583
+ }
143584
+ addNewReference(name) {
143585
+ this.knownReferencedNames.add(name);
143586
+ }
143587
+ assertGlobalBinding(name, localScope) {
143588
+ var _a, _b;
143589
+ const scope = localScope != null ? localScope : this.scope;
143590
+ if (!scope.hasReference(name) && !scope.hasBinding(name)) {
143591
+ return Ok(void 0);
143592
+ }
143593
+ const error = new CompilerError();
143594
+ error.push({
143595
+ severity: "Todo" /* Todo */,
143596
+ reason: "Encountered conflicting global in generated program",
143597
+ description: `Conflict from local binding ${name}`,
143598
+ loc: (_b = (_a = scope.getBinding(name)) == null ? void 0 : _a.path.node.loc) != null ? _b : null,
143599
+ suggestions: null
143600
+ });
143601
+ return Err(error);
143602
+ }
143603
+ };
143604
+ function getExistingImports(program) {
143605
+ const existingImports = /* @__PURE__ */ new Map();
143606
+ program.traverse({
143607
+ ImportDeclaration(path) {
143608
+ if (isNonNamespacedImport(path)) {
143609
+ existingImports.set(path.node.source.value, path);
143610
+ }
143611
+ }
143612
+ });
143613
+ return existingImports;
143614
+ }
143615
+ function addImportsToProgram(path, programContext) {
143616
+ const existingImports = getExistingImports(path);
143617
+ const stmts = [];
143618
+ const sortedModules = [...programContext.imports.entries()].sort(
143619
+ ([a], [b]) => a.localeCompare(b)
143620
+ );
143621
+ for (const [moduleName, importsMap] of sortedModules) {
143622
+ for (const [specifierName, loweredImport] of importsMap) {
143623
+ CompilerError.invariant(
143624
+ path.scope.getBinding(loweredImport.name) == null,
143625
+ {
143626
+ reason: "Encountered conflicting import specifiers in generated program",
143627
+ description: `Conflict from import ${loweredImport.module}:(${loweredImport.imported} as ${loweredImport.name}).`,
143628
+ loc: GeneratedSource,
143629
+ suggestions: null
143630
+ }
143631
+ );
143632
+ CompilerError.invariant(
143633
+ loweredImport.module === moduleName && loweredImport.imported === specifierName,
143634
+ {
143635
+ reason: "Found inconsistent import specifier. This is an internal bug.",
143636
+ description: `Expected import ${moduleName}:${specifierName} but found ${loweredImport.module}:${loweredImport.imported}`,
143637
+ loc: GeneratedSource
143638
+ }
143639
+ );
143640
+ }
143641
+ const sortedImport = [
143642
+ ...importsMap.values()
143643
+ ].sort(({ imported: a }, { imported: b }) => a.localeCompare(b));
143644
+ const importSpecifiers = sortedImport.map((specifier) => {
143645
+ return t4.importSpecifier(
143646
+ t4.identifier(specifier.name),
143647
+ t4.identifier(specifier.imported)
143648
+ );
143649
+ });
143650
+ const maybeExistingImports = existingImports.get(moduleName);
143651
+ if (maybeExistingImports != null) {
143652
+ maybeExistingImports.pushContainer("specifiers", importSpecifiers);
143653
+ } else {
143654
+ stmts.push(
143655
+ t4.importDeclaration(importSpecifiers, t4.stringLiteral(moduleName))
143656
+ );
143657
+ }
143658
+ }
143659
+ path.unshiftContainer("body", stmts);
143660
+ }
143661
+ function isNonNamespacedImport(importDeclPath) {
143662
+ return importDeclPath.get("specifiers").every((specifier) => specifier.isImportSpecifier()) && importDeclPath.node.importKind !== "type" && importDeclPath.node.importKind !== "typeof";
143663
+ }
143664
+
143665
+ // src/Entrypoint/Options.ts
143666
+ var PanicThresholdOptionsSchema = z.enum([
143667
+ /*
143668
+ * Any errors will panic the compiler by throwing an exception, which will
143669
+ * bubble up to the nearest exception handler above the Forget transform.
143670
+ * If Forget is invoked through `BabelPluginReactCompiler`, this will at the least
143671
+ * skip Forget compilation for the rest of current file.
143672
+ */
143673
+ "all_errors",
143674
+ /*
143675
+ * Panic by throwing an exception only on critical or unrecognized errors.
143676
+ * For all other errors, skip the erroring function without inserting
143677
+ * a Forget-compiled version (i.e. same behavior as noEmit).
143678
+ */
143679
+ "critical_errors",
143680
+ // Never panic by throwing an exception.
143681
+ "none"
143682
+ ]);
143683
+ var CompilerReactTargetSchema = z.union([
143684
+ z.literal("17"),
143685
+ z.literal("18"),
143686
+ z.literal("19"),
143687
+ /**
143688
+ * Used exclusively for Meta apps which are guaranteed to have compatible
143689
+ * react runtime and compiler versions. Note that only the FB-internal bundles
143690
+ * re-export useMemoCache (see
143691
+ * https://github.com/facebook/react/blob/5b0ef217ef32333a8e56f39be04327c89efa346f/packages/react/index.fb.js#L68-L70),
143692
+ * so this option is invalid / creates runtime errors for open-source users.
143693
+ */
143694
+ z.object({
143695
+ kind: z.literal("donotuse_meta_internal"),
143696
+ runtimeModule: z.string().default("react")
143697
+ })
143698
+ ]);
143699
+ var CompilationModeSchema = z.enum([
143700
+ /*
143701
+ * Compiles functions annotated with "use forget" or component/hook-like functions.
143702
+ * This latter includes:
143703
+ * * Components declared with component syntax.
143704
+ * * Functions which can be inferred to be a component or hook:
143705
+ * - Be named like a hook or component. This logic matches the ESLint rule.
143706
+ * - *and* create JSX and/or call a hook. This is an additional check to help prevent
143707
+ * false positives, since compilation has a greater impact than linting.
143708
+ * This is the default mode
143709
+ */
143710
+ "infer",
143711
+ // Compile only components using Flow component syntax and hooks using hook syntax.
143712
+ "syntax",
143713
+ // Compile only functions which are explicitly annotated with "use forget"
143714
+ "annotation",
143715
+ // Compile all top-level functions
143716
+ "all"
143717
+ ]);
143718
+ var defaultOptions = {
143719
+ compilationMode: "infer",
143720
+ panicThreshold: "none",
143721
+ environment: parseEnvironmentConfig({}).unwrap(),
143722
+ logger: null,
143723
+ gating: null,
143724
+ noEmit: false,
143725
+ eslintSuppressionRules: null,
143726
+ flowSuppressions: true,
143727
+ ignoreUseNoForget: false,
143728
+ sources: (filename) => {
143729
+ return filename.indexOf("node_modules") === -1;
143730
+ },
143731
+ enableReanimatedCheck: true,
143732
+ target: "19"
143733
+ };
143734
+ function parsePluginOptions(obj) {
143735
+ if (obj == null || typeof obj !== "object") {
143736
+ return defaultOptions;
143737
+ }
143738
+ const parsedOptions = /* @__PURE__ */ Object.create(null);
143739
+ for (let [key2, value] of Object.entries(obj)) {
143740
+ if (typeof value === "string") {
143741
+ value = value.toLowerCase();
143742
+ }
143743
+ if (isCompilerFlag(key2)) {
143744
+ switch (key2) {
143745
+ case "environment": {
143746
+ const environmentResult = parseEnvironmentConfig(value);
143747
+ if (environmentResult.isErr()) {
143748
+ CompilerError.throwInvalidConfig({
143749
+ reason: "Error in validating environment config. This is an advanced setting and not meant to be used directly",
143750
+ description: environmentResult.unwrapErr().toString(),
143751
+ suggestions: null,
143752
+ loc: null
143753
+ });
143754
+ }
143755
+ parsedOptions[key2] = environmentResult.unwrap();
143756
+ break;
143757
+ }
143758
+ case "target": {
143759
+ parsedOptions[key2] = parseTargetConfig(value);
143760
+ break;
143761
+ }
143762
+ case "gating": {
143763
+ if (value == null) {
143764
+ parsedOptions[key2] = null;
143765
+ } else {
143766
+ parsedOptions[key2] = tryParseExternalFunction(value);
143767
+ }
143768
+ break;
143769
+ }
143770
+ default: {
143771
+ parsedOptions[key2] = value;
143772
+ }
143773
+ }
143774
+ }
143775
+ }
143776
+ return __spreadValues(__spreadValues({}, defaultOptions), parsedOptions);
143777
+ }
143778
+ function parseTargetConfig(value) {
143779
+ const parsed = CompilerReactTargetSchema.safeParse(value);
143780
+ if (parsed.success) {
143781
+ return parsed.data;
143782
+ } else {
143783
+ CompilerError.throwInvalidConfig({
143784
+ reason: "Not a valid target",
143785
+ description: `${fromZodError(parsed.error)}`,
143786
+ suggestions: null,
143787
+ loc: null
143788
+ });
143789
+ }
143790
+ }
143791
+ function isCompilerFlag(s) {
143792
+ return hasOwnProperty2(defaultOptions, s);
143216
143793
  }
143217
143794
 
143218
143795
  // src/Entrypoint/Reanimated.ts
@@ -143538,6 +144115,7 @@ var index_default = BabelPluginReactCompiler;
143538
144115
  ErrorSeverity,
143539
144116
  OPT_IN_DIRECTIVES,
143540
144117
  OPT_OUT_DIRECTIVES,
144118
+ ProgramContext,
143541
144119
  ValueKind,
143542
144120
  compile,
143543
144121
  compileProgram,