babel-plugin-react-compiler 0.0.0-experimental-487cb0e-20240529 → 0.0.0-experimental-938cd9a-20240601

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -136266,6 +136266,9 @@ function isRefValueType(id) {
136266
136266
  function isUseRefType(id) {
136267
136267
  return id.type.kind === "Object" && id.type.shapeId === "BuiltInUseRefId";
136268
136268
  }
136269
+ function isUseStateType(id) {
136270
+ return id.type.kind === "Object" && id.type.shapeId === "BuiltInUseState";
136271
+ }
136269
136272
  function isSetStateType(id) {
136270
136273
  return id.type.kind === "Function" && id.type.shapeId === "BuiltInSetState";
136271
136274
  }
@@ -138896,7 +138899,7 @@ class HIRBuilder {
138896
138899
  ).at(-1);
138897
138900
  return handler !== null && handler !== void 0 ? handler : null;
138898
138901
  }
138899
- makeTemporary() {
138902
+ makeTemporary(loc) {
138900
138903
  const id = this.nextIdentifierId;
138901
138904
  return {
138902
138905
  id: id,
@@ -138904,6 +138907,7 @@ class HIRBuilder {
138904
138907
  mutableRange: { start: makeInstructionId(0), end: makeInstructionId(0) },
138905
138908
  scope: null,
138906
138909
  type: makeType(),
138910
+ loc: loc,
138907
138911
  };
138908
138912
  }
138909
138913
  resolveIdentifier(path) {
@@ -138984,6 +138988,7 @@ class HIRBuilder {
138984
138988
  }
138985
138989
  }
138986
138990
  resolveBinding(node) {
138991
+ var _a;
138987
138992
  const originalName = node.name;
138988
138993
  let name = originalName;
138989
138994
  let index = 0;
@@ -139004,6 +139009,7 @@ class HIRBuilder {
139004
139009
  },
139005
139010
  scope: null,
139006
139011
  type: makeType(),
139012
+ loc: (_a = node.loc) !== null && _a !== void 0 ? _a : GeneratedSource,
139007
139013
  };
139008
139014
  __classPrivateFieldGet(this, _HIRBuilder_bindings, "f").set(name, {
139009
139015
  node: node,
@@ -139436,7 +139442,7 @@ function removeUnnecessaryTryCatch(fn) {
139436
139442
  }
139437
139443
  }
139438
139444
  }
139439
- function createTemporaryPlace(env) {
139445
+ function createTemporaryPlace(env, loc) {
139440
139446
  return {
139441
139447
  kind: "Identifier",
139442
139448
  identifier: {
@@ -139445,6 +139451,7 @@ function createTemporaryPlace(env) {
139445
139451
  name: null,
139446
139452
  scope: null,
139447
139453
  type: makeType(),
139454
+ loc: loc,
139448
139455
  },
139449
139456
  reactive: false,
139450
139457
  effect: exports.Effect.Unknown,
@@ -139742,7 +139749,7 @@ function lower$1(func, env, bindings = null, capturedRefs = [], parent = null) {
139742
139749
  }
139743
139750
  const params = [];
139744
139751
  func.get("params").forEach((param) => {
139745
- var _a, _b, _c, _d, _e, _f, _g;
139752
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
139746
139753
  if (param.isIdentifier()) {
139747
139754
  const binding = builder.resolveIdentifier(param);
139748
139755
  if (binding.kind !== "Identifier") {
@@ -139772,18 +139779,20 @@ function lower$1(func, env, bindings = null, capturedRefs = [], parent = null) {
139772
139779
  ) {
139773
139780
  const place = {
139774
139781
  kind: "Identifier",
139775
- identifier: builder.makeTemporary(),
139782
+ identifier: builder.makeTemporary(
139783
+ (_c = param.node.loc) !== null && _c !== void 0 ? _c : GeneratedSource
139784
+ ),
139776
139785
  effect: exports.Effect.Unknown,
139777
139786
  reactive: false,
139778
139787
  loc:
139779
- (_c = param.node.loc) !== null && _c !== void 0
139780
- ? _c
139788
+ (_d = param.node.loc) !== null && _d !== void 0
139789
+ ? _d
139781
139790
  : GeneratedSource,
139782
139791
  };
139783
139792
  params.push(place);
139784
139793
  lowerAssignment(
139785
139794
  builder,
139786
- (_d = param.node.loc) !== null && _d !== void 0 ? _d : GeneratedSource,
139795
+ (_e = param.node.loc) !== null && _e !== void 0 ? _e : GeneratedSource,
139787
139796
  InstructionKind.Let,
139788
139797
  param,
139789
139798
  place,
@@ -139792,18 +139801,20 @@ function lower$1(func, env, bindings = null, capturedRefs = [], parent = null) {
139792
139801
  } else if (param.isRestElement()) {
139793
139802
  const place = {
139794
139803
  kind: "Identifier",
139795
- identifier: builder.makeTemporary(),
139804
+ identifier: builder.makeTemporary(
139805
+ (_f = param.node.loc) !== null && _f !== void 0 ? _f : GeneratedSource
139806
+ ),
139796
139807
  effect: exports.Effect.Unknown,
139797
139808
  reactive: false,
139798
139809
  loc:
139799
- (_e = param.node.loc) !== null && _e !== void 0
139800
- ? _e
139810
+ (_g = param.node.loc) !== null && _g !== void 0
139811
+ ? _g
139801
139812
  : GeneratedSource,
139802
139813
  };
139803
139814
  params.push({ kind: "Spread", place: place });
139804
139815
  lowerAssignment(
139805
139816
  builder,
139806
- (_f = param.node.loc) !== null && _f !== void 0 ? _f : GeneratedSource,
139817
+ (_h = param.node.loc) !== null && _h !== void 0 ? _h : GeneratedSource,
139807
139818
  InstructionKind.Let,
139808
139819
  param.get("argument"),
139809
139820
  place,
@@ -139813,7 +139824,7 @@ function lower$1(func, env, bindings = null, capturedRefs = [], parent = null) {
139813
139824
  builder.errors.push({
139814
139825
  reason: `(BuildHIR::lower) Handle ${param.node.type} params`,
139815
139826
  severity: exports.ErrorSeverity.Todo,
139816
- loc: (_g = param.node.loc) !== null && _g !== void 0 ? _g : null,
139827
+ loc: (_j = param.node.loc) !== null && _j !== void 0 ? _j : null,
139817
139828
  suggestions: null,
139818
139829
  });
139819
139830
  }
@@ -139928,7 +139939,8 @@ function lowerStatement(builder, stmtPath, label = null) {
139928
139939
  _28,
139929
139940
  _29,
139930
139941
  _30,
139931
- _31;
139942
+ _31,
139943
+ _32;
139932
139944
  const stmtNode = stmtPath.node;
139933
139945
  switch (stmtNode.type) {
139934
139946
  case "ThrowStatement": {
@@ -140955,12 +140967,16 @@ function lowerStatement(builder, stmtPath, label = null) {
140955
140967
  if (hasNode(handlerBindingPath)) {
140956
140968
  const place = {
140957
140969
  kind: "Identifier",
140958
- identifier: builder.makeTemporary(),
140970
+ identifier: builder.makeTemporary(
140971
+ (_27 = handlerBindingPath.node.loc) !== null && _27 !== void 0
140972
+ ? _27
140973
+ : GeneratedSource
140974
+ ),
140959
140975
  effect: exports.Effect.Unknown,
140960
140976
  reactive: false,
140961
140977
  loc:
140962
- (_27 = handlerBindingPath.node.loc) !== null && _27 !== void 0
140963
- ? _27
140978
+ (_28 = handlerBindingPath.node.loc) !== null && _28 !== void 0
140979
+ ? _28
140964
140980
  : GeneratedSource,
140965
140981
  };
140966
140982
  promoteTemporary(place.identifier);
@@ -140972,8 +140988,8 @@ function lowerStatement(builder, stmtPath, label = null) {
140972
140988
  },
140973
140989
  type: null,
140974
140990
  loc:
140975
- (_28 = handlerBindingPath.node.loc) !== null && _28 !== void 0
140976
- ? _28
140991
+ (_29 = handlerBindingPath.node.loc) !== null && _29 !== void 0
140992
+ ? _29
140977
140993
  : GeneratedSource,
140978
140994
  });
140979
140995
  handlerBinding = { path: handlerBindingPath, place: place };
@@ -141033,8 +141049,8 @@ function lowerStatement(builder, stmtPath, label = null) {
141033
141049
  fallthrough: continuationBlock.id,
141034
141050
  id: makeInstructionId(0),
141035
141051
  loc:
141036
- (_29 = stmt.node.loc) !== null && _29 !== void 0
141037
- ? _29
141052
+ (_30 = stmt.node.loc) !== null && _30 !== void 0
141053
+ ? _30
141038
141054
  : GeneratedSource,
141039
141055
  },
141040
141056
  continuationBlock
@@ -141074,14 +141090,14 @@ function lowerStatement(builder, stmtPath, label = null) {
141074
141090
  builder.errors.push({
141075
141091
  reason: `(BuildHIR::lowerStatement) Handle ${stmtPath.type} statements`,
141076
141092
  severity: exports.ErrorSeverity.Todo,
141077
- loc: (_30 = stmtPath.node.loc) !== null && _30 !== void 0 ? _30 : null,
141093
+ loc: (_31 = stmtPath.node.loc) !== null && _31 !== void 0 ? _31 : null,
141078
141094
  suggestions: null,
141079
141095
  });
141080
141096
  lowerValueToTemporary(builder, {
141081
141097
  kind: "UnsupportedNode",
141082
141098
  loc:
141083
- (_31 = stmtPath.node.loc) !== null && _31 !== void 0
141084
- ? _31
141099
+ (_32 = stmtPath.node.loc) !== null && _32 !== void 0
141100
+ ? _32
141085
141101
  : GeneratedSource,
141086
141102
  node: stmtPath.node,
141087
141103
  });
@@ -141173,7 +141189,8 @@ function lowerExpression(builder, exprPath) {
141173
141189
  _12,
141174
141190
  _13,
141175
141191
  _14,
141176
- _15;
141192
+ _15,
141193
+ _16;
141177
141194
  const exprNode = exprPath.node;
141178
141195
  const exprLoc =
141179
141196
  (_a = exprNode.loc) !== null && _a !== void 0 ? _a : GeneratedSource;
@@ -141228,6 +141245,18 @@ function lowerExpression(builder, exprPath) {
141228
141245
  );
141229
141246
  properties.push({ kind: "Spread", place: place });
141230
141247
  } else if (propertyPath.isObjectMethod()) {
141248
+ if (propertyPath.node.kind !== "method") {
141249
+ builder.errors.push({
141250
+ reason: `(BuildHIR::lowerExpression) Handle ${propertyPath.node.kind} functions in ObjectExpression`,
141251
+ severity: exports.ErrorSeverity.Todo,
141252
+ loc:
141253
+ (_c = propertyPath.node.loc) !== null && _c !== void 0
141254
+ ? _c
141255
+ : null,
141256
+ suggestions: null,
141257
+ });
141258
+ continue;
141259
+ }
141231
141260
  const method = lowerObjectMethod(builder, propertyPath);
141232
141261
  const place = lowerValueToTemporary(builder, method);
141233
141262
  const loweredKey = lowerObjectPropertyKey(builder, propertyPath);
@@ -141245,8 +141274,8 @@ function lowerExpression(builder, exprPath) {
141245
141274
  reason: `(BuildHIR::lowerExpression) Handle ${propertyPath.type} properties in ObjectExpression`,
141246
141275
  severity: exports.ErrorSeverity.Todo,
141247
141276
  loc:
141248
- (_c = propertyPath.node.loc) !== null && _c !== void 0
141249
- ? _c
141277
+ (_d = propertyPath.node.loc) !== null && _d !== void 0
141278
+ ? _d
141250
141279
  : null,
141251
141280
  suggestions: null,
141252
141281
  });
@@ -141274,7 +141303,7 @@ function lowerExpression(builder, exprPath) {
141274
141303
  builder.errors.push({
141275
141304
  reason: `(BuildHIR::lowerExpression) Handle ${element.type} elements in ArrayExpression`,
141276
141305
  severity: exports.ErrorSeverity.Todo,
141277
- loc: (_d = element.node.loc) !== null && _d !== void 0 ? _d : null,
141306
+ loc: (_e = element.node.loc) !== null && _e !== void 0 ? _e : null,
141278
141307
  suggestions: null,
141279
141308
  });
141280
141309
  continue;
@@ -141290,7 +141319,7 @@ function lowerExpression(builder, exprPath) {
141290
141319
  reason: `Expected an expression as the \`new\` expression receiver (v8 intrinsics are not supported)`,
141291
141320
  description: `Got a \`${calleePath.node.type}\``,
141292
141321
  severity: exports.ErrorSeverity.InvalidJS,
141293
- loc: (_e = calleePath.node.loc) !== null && _e !== void 0 ? _e : null,
141322
+ loc: (_f = calleePath.node.loc) !== null && _f !== void 0 ? _f : null,
141294
141323
  suggestions: null,
141295
141324
  });
141296
141325
  return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
@@ -141315,7 +141344,7 @@ function lowerExpression(builder, exprPath) {
141315
141344
  builder.errors.push({
141316
141345
  reason: `Expected Expression, got ${calleePath.type} in CallExpression (v8 intrinsics not supported). This error is likely caused by a bug in React Compiler. Please file an issue`,
141317
141346
  severity: exports.ErrorSeverity.Todo,
141318
- loc: (_f = calleePath.node.loc) !== null && _f !== void 0 ? _f : null,
141347
+ loc: (_g = calleePath.node.loc) !== null && _g !== void 0 ? _g : null,
141319
141348
  suggestions: null,
141320
141349
  });
141321
141350
  return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
@@ -141349,7 +141378,7 @@ function lowerExpression(builder, exprPath) {
141349
141378
  builder.errors.push({
141350
141379
  reason: `(BuildHIR::lowerExpression) Expected Expression, got ${leftPath.type} lval in BinaryExpression`,
141351
141380
  severity: exports.ErrorSeverity.Todo,
141352
- loc: (_g = leftPath.node.loc) !== null && _g !== void 0 ? _g : null,
141381
+ loc: (_h = leftPath.node.loc) !== null && _h !== void 0 ? _h : null,
141353
141382
  suggestions: null,
141354
141383
  });
141355
141384
  return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
@@ -141368,7 +141397,7 @@ function lowerExpression(builder, exprPath) {
141368
141397
  case "SequenceExpression": {
141369
141398
  const expr = exprPath;
141370
141399
  const exprLoc =
141371
- (_h = expr.node.loc) !== null && _h !== void 0 ? _h : GeneratedSource;
141400
+ (_j = expr.node.loc) !== null && _j !== void 0 ? _j : GeneratedSource;
141372
141401
  const continuationBlock = builder.reserve(builder.currentBlockKind());
141373
141402
  const place = buildTemporaryPlace(builder, exprLoc);
141374
141403
  const sequenceBlock = builder.enter("sequence", (_) => {
@@ -141419,7 +141448,7 @@ function lowerExpression(builder, exprPath) {
141419
141448
  case "ConditionalExpression": {
141420
141449
  const expr = exprPath;
141421
141450
  const exprLoc =
141422
- (_j = expr.node.loc) !== null && _j !== void 0 ? _j : GeneratedSource;
141451
+ (_k = expr.node.loc) !== null && _k !== void 0 ? _k : GeneratedSource;
141423
141452
  const continuationBlock = builder.reserve(builder.currentBlockKind());
141424
141453
  const testBlock = builder.reserve("value");
141425
141454
  const place = buildTemporaryPlace(builder, exprLoc);
@@ -141500,14 +141529,14 @@ function lowerExpression(builder, exprPath) {
141500
141529
  case "LogicalExpression": {
141501
141530
  const expr = exprPath;
141502
141531
  const exprLoc =
141503
- (_k = expr.node.loc) !== null && _k !== void 0 ? _k : GeneratedSource;
141532
+ (_l = expr.node.loc) !== null && _l !== void 0 ? _l : GeneratedSource;
141504
141533
  const continuationBlock = builder.reserve(builder.currentBlockKind());
141505
141534
  const testBlock = builder.reserve("value");
141506
141535
  const place = buildTemporaryPlace(builder, exprLoc);
141507
141536
  const leftPlace = buildTemporaryPlace(
141508
141537
  builder,
141509
- (_l = expr.get("left").node.loc) !== null && _l !== void 0
141510
- ? _l
141538
+ (_m = expr.get("left").node.loc) !== null && _m !== void 0
141539
+ ? _m
141511
141540
  : GeneratedSource
141512
141541
  );
141513
141542
  const consequent = builder.enter("value", () => {
@@ -141587,7 +141616,7 @@ function lowerExpression(builder, exprPath) {
141587
141616
  const left = expr.get("left");
141588
141617
  return lowerAssignment(
141589
141618
  builder,
141590
- (_m = left.node.loc) !== null && _m !== void 0 ? _m : GeneratedSource,
141619
+ (_o = left.node.loc) !== null && _o !== void 0 ? _o : GeneratedSource,
141591
141620
  InstructionKind.Reassign,
141592
141621
  left,
141593
141622
  lowerExpressionToTemporary(builder, expr.get("right")),
@@ -141615,7 +141644,7 @@ function lowerExpression(builder, exprPath) {
141615
141644
  builder.errors.push({
141616
141645
  reason: `(BuildHIR::lowerExpression) Handle ${operator} operators in AssignmentExpression`,
141617
141646
  severity: exports.ErrorSeverity.Todo,
141618
- loc: (_o = expr.node.loc) !== null && _o !== void 0 ? _o : null,
141647
+ loc: (_p = expr.node.loc) !== null && _p !== void 0 ? _p : null,
141619
141648
  suggestions: null,
141620
141649
  });
141621
141650
  return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
@@ -141675,8 +141704,8 @@ function lowerExpression(builder, exprPath) {
141675
141704
  left: Object.assign({}, previousValuePlace),
141676
141705
  right: lowerExpressionToTemporary(builder, expr.get("right")),
141677
141706
  loc:
141678
- (_p = leftExpr.node.loc) !== null && _p !== void 0
141679
- ? _p
141707
+ (_q = leftExpr.node.loc) !== null && _q !== void 0
141708
+ ? _q
141680
141709
  : GeneratedSource,
141681
141710
  });
141682
141711
  if (typeof property === "string") {
@@ -141686,8 +141715,8 @@ function lowerExpression(builder, exprPath) {
141686
141715
  property: property,
141687
141716
  value: Object.assign({}, newValuePlace),
141688
141717
  loc:
141689
- (_q = leftExpr.node.loc) !== null && _q !== void 0
141690
- ? _q
141718
+ (_r = leftExpr.node.loc) !== null && _r !== void 0
141719
+ ? _r
141691
141720
  : GeneratedSource,
141692
141721
  };
141693
141722
  } else {
@@ -141697,8 +141726,8 @@ function lowerExpression(builder, exprPath) {
141697
141726
  property: Object.assign({}, property),
141698
141727
  value: Object.assign({}, newValuePlace),
141699
141728
  loc:
141700
- (_r = leftExpr.node.loc) !== null && _r !== void 0
141701
- ? _r
141729
+ (_s = leftExpr.node.loc) !== null && _s !== void 0
141730
+ ? _s
141702
141731
  : GeneratedSource,
141703
141732
  };
141704
141733
  }
@@ -141707,7 +141736,7 @@ function lowerExpression(builder, exprPath) {
141707
141736
  builder.errors.push({
141708
141737
  reason: `(BuildHIR::lowerExpression) Expected Identifier or MemberExpression, got ${expr.type} lval in AssignmentExpression`,
141709
141738
  severity: exports.ErrorSeverity.Todo,
141710
- loc: (_s = expr.node.loc) !== null && _s !== void 0 ? _s : null,
141739
+ loc: (_t = expr.node.loc) !== null && _t !== void 0 ? _t : null,
141711
141740
  suggestions: null,
141712
141741
  });
141713
141742
  return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
@@ -141733,8 +141762,8 @@ function lowerExpression(builder, exprPath) {
141733
141762
  const expr = exprPath;
141734
141763
  const opening = expr.get("openingElement");
141735
141764
  const openingLoc =
141736
- (_t = opening.node.loc) !== null && _t !== void 0
141737
- ? _t
141765
+ (_u = opening.node.loc) !== null && _u !== void 0
141766
+ ? _u
141738
141767
  : GeneratedSource;
141739
141768
  const tag = lowerJsxElementName(builder, opening.get("name"));
141740
141769
  const props = [];
@@ -141752,7 +141781,7 @@ function lowerExpression(builder, exprPath) {
141752
141781
  reason: `(BuildHIR::lowerExpression) Handle ${attribute.type} attributes in JSXElement`,
141753
141782
  severity: exports.ErrorSeverity.Todo,
141754
141783
  loc:
141755
- (_u = attribute.node.loc) !== null && _u !== void 0 ? _u : null,
141784
+ (_v = attribute.node.loc) !== null && _v !== void 0 ? _v : null,
141756
141785
  suggestions: null,
141757
141786
  });
141758
141787
  continue;
@@ -141766,7 +141795,7 @@ function lowerExpression(builder, exprPath) {
141766
141795
  reason: `(BuildHIR::lowerExpression) Unexpected colon in attribute name \`${name}\``,
141767
141796
  severity: exports.ErrorSeverity.Todo,
141768
141797
  loc:
141769
- (_v = namePath.node.loc) !== null && _v !== void 0 ? _v : null,
141798
+ (_w = namePath.node.loc) !== null && _w !== void 0 ? _w : null,
141770
141799
  suggestions: null,
141771
141800
  });
141772
141801
  }
@@ -141774,7 +141803,7 @@ function lowerExpression(builder, exprPath) {
141774
141803
  CompilerError.invariant(namePath.isJSXNamespacedName(), {
141775
141804
  reason: "Refinement",
141776
141805
  description: null,
141777
- loc: (_w = namePath.node.loc) !== null && _w !== void 0 ? _w : null,
141806
+ loc: (_x = namePath.node.loc) !== null && _x !== void 0 ? _x : null,
141778
141807
  suggestions: null,
141779
141808
  });
141780
141809
  const namespace = namePath.node.namespace.name;
@@ -141790,8 +141819,8 @@ function lowerExpression(builder, exprPath) {
141790
141819
  kind: "Primitive",
141791
141820
  value: true,
141792
141821
  loc:
141793
- (_x = attribute.node.loc) !== null && _x !== void 0
141794
- ? _x
141822
+ (_y = attribute.node.loc) !== null && _y !== void 0
141823
+ ? _y
141795
141824
  : GeneratedSource,
141796
141825
  });
141797
141826
  } else {
@@ -141800,11 +141829,11 @@ function lowerExpression(builder, exprPath) {
141800
141829
  reason: `(BuildHIR::lowerExpression) Handle ${valueExpr.type} attribute values in JSXElement`,
141801
141830
  severity: exports.ErrorSeverity.Todo,
141802
141831
  loc:
141803
- (_z =
141804
- (_y = valueExpr.node) === null || _y === void 0
141832
+ (_0 =
141833
+ (_z = valueExpr.node) === null || _z === void 0
141805
141834
  ? void 0
141806
- : _y.loc) !== null && _z !== void 0
141807
- ? _z
141835
+ : _z.loc) !== null && _0 !== void 0
141836
+ ? _0
141808
141837
  : null,
141809
141838
  suggestions: null,
141810
141839
  });
@@ -141816,7 +141845,7 @@ function lowerExpression(builder, exprPath) {
141816
141845
  reason: `(BuildHIR::lowerExpression) Handle ${expression.type} expressions in JSXExpressionContainer within JSXElement`,
141817
141846
  severity: exports.ErrorSeverity.Todo,
141818
141847
  loc:
141819
- (_0 = valueExpr.node.loc) !== null && _0 !== void 0 ? _0 : null,
141848
+ (_1 = valueExpr.node.loc) !== null && _1 !== void 0 ? _1 : null,
141820
141849
  suggestions: null,
141821
141850
  });
141822
141851
  continue;
@@ -141838,8 +141867,8 @@ function lowerExpression(builder, exprPath) {
141838
141867
  CompilerError.throwTodo({
141839
141868
  reason: `Support <${tagName}> tags where '${tagName}' is a local variable instead of a global`,
141840
141869
  loc:
141841
- (_1 = openingIdentifier.node.loc) !== null && _1 !== void 0
141842
- ? _1
141870
+ (_2 = openingIdentifier.node.loc) !== null && _2 !== void 0
141871
+ ? _2
141843
141872
  : GeneratedSource,
141844
141873
  description: null,
141845
141874
  suggestions: null,
@@ -141865,8 +141894,8 @@ function lowerExpression(builder, exprPath) {
141865
141894
  CompilerError.throwTodo({
141866
141895
  reason: `Support <${tagName}> tags with multiple <${tagName}:enum> values`,
141867
141896
  loc:
141868
- (_2 = fbtEnumLocations.at(-1)) !== null && _2 !== void 0
141869
- ? _2
141897
+ (_3 = fbtEnumLocations.at(-1)) !== null && _3 !== void 0
141898
+ ? _3
141870
141899
  : GeneratedSource,
141871
141900
  description: null,
141872
141901
  suggestions: null,
@@ -141910,11 +141939,11 @@ function lowerExpression(builder, exprPath) {
141910
141939
  loc: exprLoc,
141911
141940
  openingLoc: openingLoc,
141912
141941
  closingLoc:
141913
- (_4 =
141914
- (_3 = expr.get("closingElement").node) === null || _3 === void 0
141942
+ (_5 =
141943
+ (_4 = expr.get("closingElement").node) === null || _4 === void 0
141915
141944
  ? void 0
141916
- : _3.loc) !== null && _4 !== void 0
141917
- ? _4
141945
+ : _4.loc) !== null && _5 !== void 0
141946
+ ? _5
141918
141947
  : GeneratedSource,
141919
141948
  };
141920
141949
  }
@@ -141938,7 +141967,7 @@ function lowerExpression(builder, exprPath) {
141938
141967
  reason:
141939
141968
  "(BuildHIR::lowerExpression) Handle tagged template with interpolations",
141940
141969
  severity: exports.ErrorSeverity.Todo,
141941
- loc: (_5 = exprPath.node.loc) !== null && _5 !== void 0 ? _5 : null,
141970
+ loc: (_6 = exprPath.node.loc) !== null && _6 !== void 0 ? _6 : null,
141942
141971
  suggestions: null,
141943
141972
  });
141944
141973
  return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
@@ -141947,7 +141976,7 @@ function lowerExpression(builder, exprPath) {
141947
141976
  reason:
141948
141977
  "there should be only one quasi as we don't support interpolations yet",
141949
141978
  description: null,
141950
- loc: (_6 = expr.node.loc) !== null && _6 !== void 0 ? _6 : null,
141979
+ loc: (_7 = expr.node.loc) !== null && _7 !== void 0 ? _7 : null,
141951
141980
  suggestions: null,
141952
141981
  });
141953
141982
  const value = expr.get("quasi").get("quasis").at(0).node.value;
@@ -141956,7 +141985,7 @@ function lowerExpression(builder, exprPath) {
141956
141985
  reason:
141957
141986
  "(BuildHIR::lowerExpression) Handle tagged template where cooked value is different from raw value",
141958
141987
  severity: exports.ErrorSeverity.Todo,
141959
- loc: (_7 = exprPath.node.loc) !== null && _7 !== void 0 ? _7 : null,
141988
+ loc: (_8 = exprPath.node.loc) !== null && _8 !== void 0 ? _8 : null,
141960
141989
  suggestions: null,
141961
141990
  });
141962
141991
  return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
@@ -141976,7 +142005,7 @@ function lowerExpression(builder, exprPath) {
141976
142005
  builder.errors.push({
141977
142006
  reason: `Unexpected quasi and subexpression lengths in template literal`,
141978
142007
  severity: exports.ErrorSeverity.InvalidJS,
141979
- loc: (_8 = exprPath.node.loc) !== null && _8 !== void 0 ? _8 : null,
142008
+ loc: (_9 = exprPath.node.loc) !== null && _9 !== void 0 ? _9 : null,
141980
142009
  suggestions: null,
141981
142010
  });
141982
142011
  return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
@@ -141985,7 +142014,8 @@ function lowerExpression(builder, exprPath) {
141985
142014
  builder.errors.push({
141986
142015
  reason: `(BuildHIR::lowerAssignment) Handle TSType in TemplateLiteral.`,
141987
142016
  severity: exports.ErrorSeverity.Todo,
141988
- loc: (_9 = exprPath.node.loc) !== null && _9 !== void 0 ? _9 : null,
142017
+ loc:
142018
+ (_10 = exprPath.node.loc) !== null && _10 !== void 0 ? _10 : null,
141989
142019
  suggestions: null,
141990
142020
  });
141991
142021
  return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
@@ -142028,7 +142058,7 @@ function lowerExpression(builder, exprPath) {
142028
142058
  builder.errors.push({
142029
142059
  reason: `Only object properties can be deleted`,
142030
142060
  severity: exports.ErrorSeverity.InvalidJS,
142031
- loc: (_10 = expr.node.loc) !== null && _10 !== void 0 ? _10 : null,
142061
+ loc: (_11 = expr.node.loc) !== null && _11 !== void 0 ? _11 : null,
142032
142062
  suggestions: [
142033
142063
  {
142034
142064
  description: "Remove this line",
@@ -142086,7 +142116,7 @@ function lowerExpression(builder, exprPath) {
142086
142116
  reason: `(BuildHIR::lowerExpression) Handle UpdateExpression with ${argument.type} argument`,
142087
142117
  severity: exports.ErrorSeverity.Todo,
142088
142118
  loc:
142089
- (_11 = exprPath.node.loc) !== null && _11 !== void 0 ? _11 : null,
142119
+ (_12 = exprPath.node.loc) !== null && _12 !== void 0 ? _12 : null,
142090
142120
  suggestions: null,
142091
142121
  });
142092
142122
  return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
@@ -142095,15 +142125,15 @@ function lowerExpression(builder, exprPath) {
142095
142125
  reason: `(BuildHIR::lowerExpression) Handle UpdateExpression to variables captured within lambdas.`,
142096
142126
  severity: exports.ErrorSeverity.Todo,
142097
142127
  loc:
142098
- (_12 = exprPath.node.loc) !== null && _12 !== void 0 ? _12 : null,
142128
+ (_13 = exprPath.node.loc) !== null && _13 !== void 0 ? _13 : null,
142099
142129
  suggestions: null,
142100
142130
  });
142101
142131
  return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
142102
142132
  }
142103
142133
  const lvalue = lowerIdentifierForAssignment(
142104
142134
  builder,
142105
- (_13 = argument.node.loc) !== null && _13 !== void 0
142106
- ? _13
142135
+ (_14 = argument.node.loc) !== null && _14 !== void 0
142136
+ ? _14
142107
142137
  : GeneratedSource,
142108
142138
  InstructionKind.Reassign,
142109
142139
  argument
@@ -142153,8 +142183,8 @@ function lowerExpression(builder, exprPath) {
142153
142183
  pattern: expr.node.pattern,
142154
142184
  flags: expr.node.flags,
142155
142185
  loc:
142156
- (_14 = expr.node.loc) !== null && _14 !== void 0
142157
- ? _14
142186
+ (_15 = expr.node.loc) !== null && _15 !== void 0
142187
+ ? _15
142158
142188
  : GeneratedSource,
142159
142189
  };
142160
142190
  }
@@ -142166,7 +142196,7 @@ function lowerExpression(builder, exprPath) {
142166
142196
  builder.errors.push({
142167
142197
  reason: `(BuildHIR::lowerExpression) Handle ${exprPath.type} expressions`,
142168
142198
  severity: exports.ErrorSeverity.Todo,
142169
- loc: (_15 = exprPath.node.loc) !== null && _15 !== void 0 ? _15 : null,
142199
+ loc: (_16 = exprPath.node.loc) !== null && _16 !== void 0 ? _16 : null,
142170
142200
  suggestions: null,
142171
142201
  });
142172
142202
  return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
@@ -142872,7 +142902,7 @@ function lowerIdentifier(builder, exprPath) {
142872
142902
  function buildTemporaryPlace(builder, loc) {
142873
142903
  const place = {
142874
142904
  kind: "Identifier",
142875
- identifier: builder.makeTemporary(),
142905
+ identifier: builder.makeTemporary(loc),
142876
142906
  effect: exports.Effect.Unknown,
142877
142907
  reactive: false,
142878
142908
  loc: loc,
@@ -149924,6 +149954,7 @@ const EnvironmentConfigSchema = z.object({
149924
149954
  enableResetCacheOnSourceFileChanges: z.boolean().default(false),
149925
149955
  enablePreserveExistingMemoizationGuarantees: z.boolean().default(false),
149926
149956
  validatePreserveExistingMemoizationGuarantees: z.boolean().default(true),
149957
+ enablePreserveExistingManualUseMemo: z.boolean().default(false),
149927
149958
  enableForest: z.boolean().default(false),
149928
149959
  enableUseTypeAnnotations: z.boolean().default(false),
149929
149960
  enableReactiveScopesInHIR: z.boolean().default(true),
@@ -149943,6 +149974,8 @@ const EnvironmentConfigSchema = z.object({
149943
149974
  throwUnknownException__testonly: z.boolean().default(false),
149944
149975
  enableSharedRuntime__testonly: z.boolean().default(false),
149945
149976
  enableTreatFunctionDepsAsConditional: z.boolean().default(false),
149977
+ disableMemoizationForDebugging: z.boolean().default(false),
149978
+ enableChangeDetectionForDebugging: ExternalFunctionSchema.nullish(),
149946
149979
  enableCustomTypeDefinitionForReanimated: z.boolean().default(false),
149947
149980
  hookPattern: z.string().nullable().default(null),
149948
149981
  });
@@ -150016,6 +150049,17 @@ class Environment {
150016
150049
  new Map(DEFAULT_GLOBALS),
150017
150050
  "f"
150018
150051
  );
150052
+ if (
150053
+ config.disableMemoizationForDebugging &&
150054
+ config.enableChangeDetectionForDebugging != null
150055
+ ) {
150056
+ CompilerError.throwInvalidConfig({
150057
+ reason: `Invalid environment config: the 'disableMemoizationForDebugging' and 'enableChangeDetectionForDebugging' options cannot be used together`,
150058
+ description: null,
150059
+ loc: null,
150060
+ suggestions: null,
150061
+ });
150062
+ }
150019
150063
  for (const [hookName, hook] of this.config.customHooks) {
150020
150064
  CompilerError.invariant(
150021
150065
  !__classPrivateFieldGet(this, _Environment_globals, "f").has(hookName),
@@ -153036,9 +153080,9 @@ function alignObjectMethodScopes(fn) {
153036
153080
  var _Context_blockScopes, _Context_unclosedScopes, _Context_seenScopes;
153037
153081
  function alignReactiveScopesToBlockScopes(fn) {
153038
153082
  const context = new Context$4();
153039
- visitReactiveFunction(fn, new Visitor$c(), context);
153083
+ visitReactiveFunction(fn, new Visitor$d(), context);
153040
153084
  }
153041
- let Visitor$c = class Visitor extends ReactiveFunctionVisitor {
153085
+ let Visitor$d = class Visitor extends ReactiveFunctionVisitor {
153042
153086
  visitID(id, state) {
153043
153087
  state.visitId(id);
153044
153088
  }
@@ -153188,9 +153232,9 @@ class CheckInstructionsAgainstScopesVisitor extends ReactiveFunctionVisitor {
153188
153232
  }
153189
153233
  }
153190
153234
  function assertWellFormedBreakTargets(fn) {
153191
- visitReactiveFunction(fn, new Visitor$b(), new Set());
153235
+ visitReactiveFunction(fn, new Visitor$c(), new Set());
153192
153236
  }
153193
- let Visitor$b = class Visitor extends ReactiveFunctionVisitor {
153237
+ let Visitor$c = class Visitor extends ReactiveFunctionVisitor {
153194
153238
  visitTerminal(stmt, seenLabels) {
153195
153239
  if (stmt.label != null) {
153196
153240
  seenLabels.add(stmt.label.id);
@@ -154591,13 +154635,13 @@ function codegenFunction(fn, uniqueIdentifiers) {
154591
154635
  uniqueIdentifiers,
154592
154636
  null
154593
154637
  );
154594
- let hotModuleReloadState = null;
154638
+ let fastRefreshState = null;
154595
154639
  if (
154596
154640
  fn.env.config.enableResetCacheOnSourceFileChanges &&
154597
154641
  fn.env.code !== null
154598
154642
  ) {
154599
154643
  const hash = crypto$2.createHmac("sha256", fn.env.code).digest("hex");
154600
- hotModuleReloadState = { cacheIndex: cx.nextCacheIndex, hash: hash };
154644
+ fastRefreshState = { cacheIndex: cx.nextCacheIndex, hash: hash };
154601
154645
  }
154602
154646
  const compileResult = codegenReactiveFunction(cx, fn);
154603
154647
  if (compileResult.isErr()) {
@@ -154629,7 +154673,7 @@ function codegenFunction(fn, uniqueIdentifiers) {
154629
154673
  ),
154630
154674
  ])
154631
154675
  );
154632
- if (hotModuleReloadState !== null) {
154676
+ if (fastRefreshState !== null) {
154633
154677
  const index = cx.synthesizeName("$i");
154634
154678
  preface.push(
154635
154679
  t__namespace.ifStatement(
@@ -154637,10 +154681,10 @@ function codegenFunction(fn, uniqueIdentifiers) {
154637
154681
  "!==",
154638
154682
  t__namespace.memberExpression(
154639
154683
  t__namespace.identifier(cx.synthesizeName("$")),
154640
- t__namespace.numericLiteral(hotModuleReloadState.cacheIndex),
154684
+ t__namespace.numericLiteral(fastRefreshState.cacheIndex),
154641
154685
  true
154642
154686
  ),
154643
- t__namespace.stringLiteral(hotModuleReloadState.hash)
154687
+ t__namespace.stringLiteral(fastRefreshState.hash)
154644
154688
  ),
154645
154689
  t__namespace.blockStatement([
154646
154690
  t__namespace.forStatement(
@@ -154685,10 +154729,10 @@ function codegenFunction(fn, uniqueIdentifiers) {
154685
154729
  "=",
154686
154730
  t__namespace.memberExpression(
154687
154731
  t__namespace.identifier(cx.synthesizeName("$")),
154688
- t__namespace.numericLiteral(hotModuleReloadState.cacheIndex),
154732
+ t__namespace.numericLiteral(fastRefreshState.cacheIndex),
154689
154733
  true
154690
154734
  ),
154691
- t__namespace.stringLiteral(hotModuleReloadState.hash)
154735
+ t__namespace.stringLiteral(fastRefreshState.hash)
154692
154736
  )
154693
154737
  ),
154694
154738
  ])
@@ -154930,6 +154974,7 @@ function wrapCacheDep(cx, value) {
154930
154974
  function codegenReactiveScope(cx, statements, scope, block) {
154931
154975
  const cacheStoreStatements = [];
154932
154976
  const cacheLoadStatements = [];
154977
+ const cacheLoads = [];
154933
154978
  const changeExpressions = [];
154934
154979
  const changeExpressionComments = [];
154935
154980
  const outputComments = [];
@@ -154993,32 +155038,11 @@ function codegenReactiveScope(cx, statements, scope, block) {
154993
155038
  ])
154994
155039
  );
154995
155040
  }
154996
- cacheStoreStatements.push(
154997
- t__namespace.expressionStatement(
154998
- t__namespace.assignmentExpression(
154999
- "=",
155000
- t__namespace.memberExpression(
155001
- t__namespace.identifier(cx.synthesizeName("$")),
155002
- t__namespace.numericLiteral(index),
155003
- true
155004
- ),
155005
- wrapCacheDep(cx, name)
155006
- )
155007
- )
155008
- );
155009
- cacheLoadStatements.push(
155010
- t__namespace.expressionStatement(
155011
- t__namespace.assignmentExpression(
155012
- "=",
155013
- name,
155014
- t__namespace.memberExpression(
155015
- t__namespace.identifier(cx.synthesizeName("$")),
155016
- t__namespace.numericLiteral(index),
155017
- true
155018
- )
155019
- )
155020
- )
155021
- );
155041
+ cacheLoads.push({
155042
+ name: name,
155043
+ index: index,
155044
+ value: wrapCacheDep(cx, name),
155045
+ });
155022
155046
  cx.declare(identifier);
155023
155047
  }
155024
155048
  for (const reassignment of scope.reassignments) {
@@ -155028,32 +155052,11 @@ function codegenReactiveScope(cx, statements, scope, block) {
155028
155052
  }
155029
155053
  const name = convertIdentifier(reassignment);
155030
155054
  outputComments.push(name.name);
155031
- cacheStoreStatements.push(
155032
- t__namespace.expressionStatement(
155033
- t__namespace.assignmentExpression(
155034
- "=",
155035
- t__namespace.memberExpression(
155036
- t__namespace.identifier(cx.synthesizeName("$")),
155037
- t__namespace.numericLiteral(index),
155038
- true
155039
- ),
155040
- wrapCacheDep(cx, name)
155041
- )
155042
- )
155043
- );
155044
- cacheLoadStatements.push(
155045
- t__namespace.expressionStatement(
155046
- t__namespace.assignmentExpression(
155047
- "=",
155048
- name,
155049
- t__namespace.memberExpression(
155050
- t__namespace.identifier(cx.synthesizeName("$")),
155051
- t__namespace.numericLiteral(index),
155052
- true
155053
- )
155054
- )
155055
- )
155056
- );
155055
+ cacheLoads.push({
155056
+ name: name,
155057
+ index: index,
155058
+ value: wrapCacheDep(cx, name),
155059
+ });
155057
155060
  }
155058
155061
  let testCondition = changeExpressions.reduce((acc, ident) => {
155059
155062
  if (acc == null) {
@@ -155084,14 +155087,153 @@ function codegenReactiveScope(cx, statements, scope, block) {
155084
155087
  )
155085
155088
  );
155086
155089
  }
155090
+ if (cx.env.config.disableMemoizationForDebugging) {
155091
+ CompilerError.invariant(
155092
+ cx.env.config.enableChangeDetectionForDebugging == null,
155093
+ {
155094
+ reason: `Expected to not have both change detection enabled and memoization disabled`,
155095
+ description: `Incompatible config options`,
155096
+ loc: null,
155097
+ }
155098
+ );
155099
+ testCondition = t__namespace.logicalExpression(
155100
+ "||",
155101
+ testCondition,
155102
+ t__namespace.booleanLiteral(true)
155103
+ );
155104
+ }
155087
155105
  let computationBlock = codegenBlock(cx, block);
155088
- computationBlock.body.push(...cacheStoreStatements);
155089
- const memoBlock = t__namespace.blockStatement(cacheLoadStatements);
155090
- const memoStatement = t__namespace.ifStatement(
155091
- testCondition,
155092
- computationBlock,
155093
- memoBlock
155094
- );
155106
+ let memoStatement;
155107
+ if (
155108
+ cx.env.config.enableChangeDetectionForDebugging != null &&
155109
+ changeExpressions.length > 0
155110
+ ) {
155111
+ const loc =
155112
+ typeof scope.loc === "symbol"
155113
+ ? "unknown location"
155114
+ : `(${scope.loc.start.line}:${scope.loc.end.line})`;
155115
+ const detectionFunction =
155116
+ cx.env.config.enableChangeDetectionForDebugging.importSpecifierName;
155117
+ const cacheLoadOldValueStatements = [];
155118
+ const changeDetectionStatements = [];
155119
+ const idempotenceDetectionStatements = [];
155120
+ for (const { name: name, index: index, value: value } of cacheLoads) {
155121
+ const loadName = cx.synthesizeName(`old$${name.name}`);
155122
+ const slot = t__namespace.memberExpression(
155123
+ t__namespace.identifier(cx.synthesizeName("$")),
155124
+ t__namespace.numericLiteral(index),
155125
+ true
155126
+ );
155127
+ cacheStoreStatements.push(
155128
+ t__namespace.expressionStatement(
155129
+ t__namespace.assignmentExpression("=", slot, value)
155130
+ )
155131
+ );
155132
+ cacheLoadOldValueStatements.push(
155133
+ t__namespace.variableDeclaration("let", [
155134
+ t__namespace.variableDeclarator(
155135
+ t__namespace.identifier(loadName),
155136
+ slot
155137
+ ),
155138
+ ])
155139
+ );
155140
+ changeDetectionStatements.push(
155141
+ t__namespace.expressionStatement(
155142
+ t__namespace.callExpression(
155143
+ t__namespace.identifier(detectionFunction),
155144
+ [
155145
+ t__namespace.identifier(loadName),
155146
+ name,
155147
+ t__namespace.stringLiteral(name.name),
155148
+ t__namespace.stringLiteral(cx.fnName),
155149
+ t__namespace.stringLiteral("cached"),
155150
+ t__namespace.stringLiteral(loc),
155151
+ ]
155152
+ )
155153
+ )
155154
+ );
155155
+ idempotenceDetectionStatements.push(
155156
+ t__namespace.expressionStatement(
155157
+ t__namespace.callExpression(
155158
+ t__namespace.identifier(detectionFunction),
155159
+ [
155160
+ slot,
155161
+ name,
155162
+ t__namespace.stringLiteral(name.name),
155163
+ t__namespace.stringLiteral(cx.fnName),
155164
+ t__namespace.stringLiteral("recomputed"),
155165
+ t__namespace.stringLiteral(loc),
155166
+ ]
155167
+ )
155168
+ )
155169
+ );
155170
+ idempotenceDetectionStatements.push(
155171
+ t__namespace.expressionStatement(
155172
+ t__namespace.assignmentExpression("=", name, slot)
155173
+ )
155174
+ );
155175
+ }
155176
+ const condition = cx.synthesizeName("condition");
155177
+ memoStatement = t__namespace.blockStatement([
155178
+ ...computationBlock.body,
155179
+ t__namespace.variableDeclaration("let", [
155180
+ t__namespace.variableDeclarator(
155181
+ t__namespace.identifier(condition),
155182
+ testCondition
155183
+ ),
155184
+ ]),
155185
+ t__namespace.ifStatement(
155186
+ t__namespace.unaryExpression("!", t__namespace.identifier(condition)),
155187
+ t__namespace.blockStatement([
155188
+ ...cacheLoadOldValueStatements,
155189
+ ...changeDetectionStatements,
155190
+ ])
155191
+ ),
155192
+ ...cacheStoreStatements,
155193
+ t__namespace.ifStatement(
155194
+ t__namespace.identifier(condition),
155195
+ t__namespace.blockStatement([
155196
+ ...computationBlock.body,
155197
+ ...idempotenceDetectionStatements,
155198
+ ])
155199
+ ),
155200
+ ]);
155201
+ } else {
155202
+ for (const { name: name, index: index, value: value } of cacheLoads) {
155203
+ cacheStoreStatements.push(
155204
+ t__namespace.expressionStatement(
155205
+ t__namespace.assignmentExpression(
155206
+ "=",
155207
+ t__namespace.memberExpression(
155208
+ t__namespace.identifier(cx.synthesizeName("$")),
155209
+ t__namespace.numericLiteral(index),
155210
+ true
155211
+ ),
155212
+ value
155213
+ )
155214
+ )
155215
+ );
155216
+ cacheLoadStatements.push(
155217
+ t__namespace.expressionStatement(
155218
+ t__namespace.assignmentExpression(
155219
+ "=",
155220
+ name,
155221
+ t__namespace.memberExpression(
155222
+ t__namespace.identifier(cx.synthesizeName("$")),
155223
+ t__namespace.numericLiteral(index),
155224
+ true
155225
+ )
155226
+ )
155227
+ )
155228
+ );
155229
+ }
155230
+ computationBlock.body.push(...cacheStoreStatements);
155231
+ memoStatement = t__namespace.ifStatement(
155232
+ testCondition,
155233
+ computationBlock,
155234
+ t__namespace.blockStatement(cacheLoadStatements)
155235
+ );
155236
+ }
155095
155237
  if (cx.env.config.enableMemoizationComments) {
155096
155238
  if (changeExpressionComments.length) {
155097
155239
  t__namespace.addComment(
@@ -155128,9 +155270,9 @@ function codegenReactiveScope(cx, statements, scope, block) {
155128
155270
  true
155129
155271
  );
155130
155272
  }
155131
- if (memoBlock.body.length > 0) {
155273
+ if (cacheLoadStatements.length > 0) {
155132
155274
  t__namespace.addComment(
155133
- memoBlock.body[0],
155275
+ cacheLoadStatements[0],
155134
155276
  "leading",
155135
155277
  ` Inputs did not change, use cached value`,
155136
155278
  true
@@ -156651,7 +156793,7 @@ function convertIdentifier(identifier) {
156651
156793
  }
156652
156794
  function extractScopeDeclarationsFromDestructuring(fn) {
156653
156795
  const state = new State$2(fn.env);
156654
- visitReactiveFunction(fn, new Visitor$a(), state);
156796
+ visitReactiveFunction(fn, new Visitor$b(), state);
156655
156797
  }
156656
156798
  let State$2 = class State {
156657
156799
  constructor(env) {
@@ -156659,7 +156801,7 @@ let State$2 = class State {
156659
156801
  this.env = env;
156660
156802
  }
156661
156803
  };
156662
- let Visitor$a = class Visitor extends ReactiveFunctionTransform {
156804
+ let Visitor$b = class Visitor extends ReactiveFunctionTransform {
156663
156805
  visitScope(scope, state) {
156664
156806
  for (const [, declaration] of scope.scope.declarations) {
156665
156807
  state.declared.add(declaration.identifier.id);
@@ -156816,10 +156958,10 @@ let Transform$5 = class Transform extends ReactiveFunctionTransform {
156816
156958
  };
156817
156959
  function mergeOverlappingReactiveScopes(fn) {
156818
156960
  const context = new Context$1();
156819
- visitReactiveFunction(fn, new Visitor$9(), context);
156961
+ visitReactiveFunction(fn, new Visitor$a(), context);
156820
156962
  context.complete();
156821
156963
  }
156822
- let Visitor$9 = class Visitor extends ReactiveFunctionVisitor {
156964
+ let Visitor$a = class Visitor extends ReactiveFunctionVisitor {
156823
156965
  visitID(id, state) {
156824
156966
  state.visitId(id);
156825
156967
  }
@@ -157258,7 +157400,7 @@ function scopeIsEligibleForMerging(scopeBlock) {
157258
157400
  isAlwaysInvalidatingType(decl.identifier.type)
157259
157401
  );
157260
157402
  }
157261
- let Visitor$8 = class Visitor extends ReactiveFunctionVisitor {
157403
+ let Visitor$9 = class Visitor extends ReactiveFunctionVisitor {
157262
157404
  visitScope(block, state) {
157263
157405
  this.traverseScope(block, state);
157264
157406
  for (const dep of block.scope.dependencies) {
@@ -157312,7 +157454,7 @@ function promoteUsedTemporaries(fn) {
157312
157454
  promoteIdentifier(place.identifier, state);
157313
157455
  }
157314
157456
  }
157315
- visitReactiveFunction(fn, new Visitor$8(), state);
157457
+ visitReactiveFunction(fn, new Visitor$9(), state);
157316
157458
  }
157317
157459
  function promoteIdentifier(identifier, state) {
157318
157460
  CompilerError.invariant(identifier.name === null, {
@@ -157355,10 +157497,10 @@ let Transform$3 = class Transform extends ReactiveFunctionTransform {
157355
157497
  });
157356
157498
  const instructions = scopeBlock.instructions;
157357
157499
  const loc = earlyReturnValue.loc;
157358
- const sentinelTemp = createTemporaryPlace(this.env);
157359
- const symbolTemp = createTemporaryPlace(this.env);
157360
- const forTemp = createTemporaryPlace(this.env);
157361
- const argTemp = createTemporaryPlace(this.env);
157500
+ const sentinelTemp = createTemporaryPlace(this.env, loc);
157501
+ const symbolTemp = createTemporaryPlace(this.env, loc);
157502
+ const forTemp = createTemporaryPlace(this.env, loc);
157503
+ const argTemp = createTemporaryPlace(this.env, loc);
157362
157504
  scopeBlock.instructions = [
157363
157505
  {
157364
157506
  kind: "instruction",
@@ -157462,7 +157604,7 @@ let Transform$3 = class Transform extends ReactiveFunctionTransform {
157462
157604
  if (state.earlyReturnValue !== null) {
157463
157605
  earlyReturnValue = state.earlyReturnValue;
157464
157606
  } else {
157465
- const identifier = createTemporaryPlace(this.env).identifier;
157607
+ const identifier = createTemporaryPlace(this.env, loc).identifier;
157466
157608
  promoteTemporary(identifier);
157467
157609
  earlyReturnValue = {
157468
157610
  label: this.env.nextBlockId,
@@ -158888,9 +159030,9 @@ class PropagationVisitor extends ReactiveFunctionVisitor {
158888
159030
  }
158889
159031
  function pruneHoistedContexts(fn) {
158890
159032
  const hoistedIdentifiers = new Set();
158891
- visitReactiveFunction(fn, new Visitor$7(), hoistedIdentifiers);
159033
+ visitReactiveFunction(fn, new Visitor$8(), hoistedIdentifiers);
158892
159034
  }
158893
- let Visitor$7 = class Visitor extends ReactiveFunctionTransform {
159035
+ let Visitor$8 = class Visitor extends ReactiveFunctionTransform {
158894
159036
  transformInstruction(instruction, state) {
158895
159037
  this.visitInstruction(instruction, state);
158896
159038
  if (
@@ -158926,12 +159068,12 @@ let Visitor$7 = class Visitor extends ReactiveFunctionTransform {
158926
159068
  };
158927
159069
  function validateMemoizedEffectDependencies(fn) {
158928
159070
  const errors = new CompilerError();
158929
- visitReactiveFunction(fn, new Visitor$6(), errors);
159071
+ visitReactiveFunction(fn, new Visitor$7(), errors);
158930
159072
  if (errors.hasErrors()) {
158931
159073
  throw errors;
158932
159074
  }
158933
159075
  }
158934
- let Visitor$6 = class Visitor extends ReactiveFunctionVisitor {
159076
+ let Visitor$7 = class Visitor extends ReactiveFunctionVisitor {
158935
159077
  constructor() {
158936
159078
  super(...arguments);
158937
159079
  this.scopes = new Set();
@@ -159857,16 +159999,55 @@ function inferBlock(env, functionEffects, state, block) {
159857
159999
  break;
159858
160000
  }
159859
160001
  case "JsxExpression": {
159860
- valueKind = {
160002
+ if (instrValue.tag.kind === "Identifier") {
160003
+ state.referenceAndRecordEffects(
160004
+ instrValue.tag,
160005
+ exports.Effect.Freeze,
160006
+ ValueReason.JsxCaptured,
160007
+ functionEffects
160008
+ );
160009
+ }
160010
+ if (instrValue.children !== null) {
160011
+ for (const child of instrValue.children) {
160012
+ state.referenceAndRecordEffects(
160013
+ child,
160014
+ exports.Effect.Freeze,
160015
+ ValueReason.JsxCaptured,
160016
+ functionEffects
160017
+ );
160018
+ }
160019
+ }
160020
+ for (const attr of instrValue.props) {
160021
+ if (attr.kind === "JsxSpreadAttribute") {
160022
+ state.referenceAndRecordEffects(
160023
+ attr.argument,
160024
+ exports.Effect.Freeze,
160025
+ ValueReason.JsxCaptured,
160026
+ functionEffects
160027
+ );
160028
+ } else {
160029
+ const propEffects = [];
160030
+ state.referenceAndRecordEffects(
160031
+ attr.place,
160032
+ exports.Effect.Freeze,
160033
+ ValueReason.JsxCaptured,
160034
+ propEffects
160035
+ );
160036
+ functionEffects.push(
160037
+ ...propEffects.filter(
160038
+ (propEffect) => propEffect.kind !== "GlobalMutation"
160039
+ )
160040
+ );
160041
+ }
160042
+ }
160043
+ state.initialize(instrValue, {
159861
160044
  kind: exports.ValueKind.Frozen,
159862
160045
  reason: new Set([ValueReason.Other]),
159863
160046
  context: new Set(),
159864
- };
159865
- effect = {
159866
- kind: exports.Effect.Freeze,
159867
- reason: ValueReason.JsxCaptured,
159868
- };
159869
- break;
160047
+ });
160048
+ state.define(instr.lvalue, instrValue);
160049
+ instr.lvalue.effect = exports.Effect.ConditionallyMutate;
160050
+ continue;
159870
160051
  }
159871
160052
  case "JsxFragment": {
159872
160053
  valueKind = {
@@ -161285,7 +161466,7 @@ class PruneScopesTransform extends ReactiveFunctionTransform {
161285
161466
  return { kind: "keep" };
161286
161467
  }
161287
161468
  }
161288
- let Visitor$5 = class Visitor extends ReactiveFunctionVisitor {
161469
+ let Visitor$6 = class Visitor extends ReactiveFunctionVisitor {
161289
161470
  visitLValue(id, lvalue, state) {
161290
161471
  this.visitPlace(id, lvalue, state);
161291
161472
  }
@@ -161296,16 +161477,16 @@ let Visitor$5 = class Visitor extends ReactiveFunctionVisitor {
161296
161477
  }
161297
161478
  };
161298
161479
  function collectReactiveIdentifiers(fn) {
161299
- const visitor = new Visitor$5();
161480
+ const visitor = new Visitor$6();
161300
161481
  const state = new Set();
161301
161482
  visitReactiveFunction(fn, visitor, state);
161302
161483
  return state;
161303
161484
  }
161304
161485
  function pruneNonReactiveDependencies(fn) {
161305
161486
  const reactiveIdentifiers = collectReactiveIdentifiers(fn);
161306
- visitReactiveFunction(fn, new Visitor$4(), reactiveIdentifiers);
161487
+ visitReactiveFunction(fn, new Visitor$5(), reactiveIdentifiers);
161307
161488
  }
161308
- let Visitor$4 = class Visitor extends ReactiveFunctionVisitor {
161489
+ let Visitor$5 = class Visitor extends ReactiveFunctionVisitor {
161309
161490
  visitInstruction(instruction, state) {
161310
161491
  this.traverseInstruction(instruction, state);
161311
161492
  const { lvalue: lvalue, value: value } = instruction;
@@ -161381,12 +161562,12 @@ let Visitor$4 = class Visitor extends ReactiveFunctionVisitor {
161381
161562
  };
161382
161563
  function pruneTemporaryLValues(fn) {
161383
161564
  const lvalues = new Map();
161384
- visitReactiveFunction(fn, new Visitor$3(), lvalues);
161565
+ visitReactiveFunction(fn, new Visitor$4(), lvalues);
161385
161566
  for (const [, instr] of lvalues) {
161386
161567
  instr.lvalue = null;
161387
161568
  }
161388
161569
  }
161389
- let Visitor$3 = class Visitor extends ReactiveFunctionVisitor {
161570
+ let Visitor$4 = class Visitor extends ReactiveFunctionVisitor {
161390
161571
  visitPlace(id, place, state) {
161391
161572
  state.delete(place.identifier);
161392
161573
  }
@@ -161470,10 +161651,10 @@ function hasOwnDeclaration(block) {
161470
161651
  }
161471
161652
  function collectReferencedGlobals(fn) {
161472
161653
  const identifiers = new Set();
161473
- visitReactiveFunction(fn, new Visitor$2(), identifiers);
161654
+ visitReactiveFunction(fn, new Visitor$3(), identifiers);
161474
161655
  return identifiers;
161475
161656
  }
161476
- let Visitor$2 = class Visitor extends ReactiveFunctionVisitor {
161657
+ let Visitor$3 = class Visitor extends ReactiveFunctionVisitor {
161477
161658
  visitValue(id, value, state) {
161478
161659
  this.traverseValue(id, value, state);
161479
161660
  if (value.kind === "FunctionExpression" || value.kind === "ObjectMethod") {
@@ -161494,7 +161675,7 @@ var _Scopes_instances,
161494
161675
  function renameVariables(fn) {
161495
161676
  const globals = collectReferencedGlobals(fn);
161496
161677
  const scopes = new Scopes(globals);
161497
- renameVariablesImpl(fn, new Visitor$1(), scopes);
161678
+ renameVariablesImpl(fn, new Visitor$2(), scopes);
161498
161679
  return new Set([...scopes.names, ...globals]);
161499
161680
  }
161500
161681
  function renameVariablesImpl(fn, visitor, scopes) {
@@ -161509,7 +161690,7 @@ function renameVariablesImpl(fn, visitor, scopes) {
161509
161690
  visitReactiveFunction(fn, visitor, scopes);
161510
161691
  });
161511
161692
  }
161512
- let Visitor$1 = class Visitor extends ReactiveFunctionVisitor {
161693
+ let Visitor$2 = class Visitor extends ReactiveFunctionVisitor {
161513
161694
  visitParam(place, state) {
161514
161695
  state.visit(place.identifier);
161515
161696
  }
@@ -161699,6 +161880,7 @@ function inferReactiveScopeVariables(fn) {
161699
161880
  reassignments: new Set(),
161700
161881
  earlyReturnValue: null,
161701
161882
  merged: new Set(),
161883
+ loc: identifier.loc,
161702
161884
  };
161703
161885
  scopes.set(groupIdentifier, scope);
161704
161886
  } else {
@@ -161708,6 +161890,7 @@ function inferReactiveScopeVariables(fn) {
161708
161890
  scope.range.end = makeInstructionId(
161709
161891
  Math.max(scope.range.end, identifier.mutableRange.end)
161710
161892
  );
161893
+ scope.loc = mergeLocation(scope.loc, identifier.loc);
161711
161894
  }
161712
161895
  identifier.scope = scope;
161713
161896
  identifier.mutableRange = scope.range;
@@ -161736,6 +161919,24 @@ function inferReactiveScopeVariables(fn) {
161736
161919
  }
161737
161920
  }
161738
161921
  }
161922
+ function mergeLocation(l, r) {
161923
+ if (l === GeneratedSource) {
161924
+ return r;
161925
+ } else if (r === GeneratedSource) {
161926
+ return l;
161927
+ } else {
161928
+ return {
161929
+ start: {
161930
+ line: Math.min(l.start.line, r.start.line),
161931
+ column: Math.min(l.start.column, r.start.column),
161932
+ },
161933
+ end: {
161934
+ line: Math.max(l.end.line, r.end.line),
161935
+ column: Math.max(l.end.column, r.end.column),
161936
+ },
161937
+ };
161938
+ }
161939
+ }
161739
161940
  function isMutable({ id: id }, place) {
161740
161941
  const range = place.identifier.mutableRange;
161741
161942
  return id >= range.start && id < range.end;
@@ -162537,6 +162738,7 @@ class SSABuilder {
162537
162738
  mutableRange: { start: makeInstructionId(0), end: makeInstructionId(0) },
162538
162739
  scope: null,
162539
162740
  type: makeType(),
162741
+ loc: oldId.loc,
162540
162742
  };
162541
162743
  }
162542
162744
  defineContext(oldPlace) {
@@ -163270,6 +163472,25 @@ function evaluateInstruction(env, constants, instr) {
163270
163472
  }
163271
163473
  return null;
163272
163474
  }
163475
+ case "UnaryExpression": {
163476
+ switch (value.operator) {
163477
+ case "!": {
163478
+ const operand = read(constants, value.value);
163479
+ if (operand !== null && operand.kind === "Primitive") {
163480
+ const result = {
163481
+ kind: "Primitive",
163482
+ value: !operand.value,
163483
+ loc: value.loc,
163484
+ };
163485
+ instr.value = result;
163486
+ return result;
163487
+ }
163488
+ return null;
163489
+ }
163490
+ default:
163491
+ return null;
163492
+ }
163493
+ }
163273
163494
  case "BinaryExpression": {
163274
163495
  const lhsValue = read(constants, value.left);
163275
163496
  const rhsValue = read(constants, value.right);
@@ -163309,6 +163530,62 @@ function evaluateInstruction(env, constants, instr) {
163309
163530
  }
163310
163531
  break;
163311
163532
  }
163533
+ case "|": {
163534
+ if (typeof lhs === "number" && typeof rhs === "number") {
163535
+ result = { kind: "Primitive", value: lhs | rhs, loc: value.loc };
163536
+ }
163537
+ break;
163538
+ }
163539
+ case "&": {
163540
+ if (typeof lhs === "number" && typeof rhs === "number") {
163541
+ result = { kind: "Primitive", value: lhs & rhs, loc: value.loc };
163542
+ }
163543
+ break;
163544
+ }
163545
+ case "^": {
163546
+ if (typeof lhs === "number" && typeof rhs === "number") {
163547
+ result = { kind: "Primitive", value: lhs ^ rhs, loc: value.loc };
163548
+ }
163549
+ break;
163550
+ }
163551
+ case "<<": {
163552
+ if (typeof lhs === "number" && typeof rhs === "number") {
163553
+ result = { kind: "Primitive", value: lhs << rhs, loc: value.loc };
163554
+ }
163555
+ break;
163556
+ }
163557
+ case ">>": {
163558
+ if (typeof lhs === "number" && typeof rhs === "number") {
163559
+ result = { kind: "Primitive", value: lhs >> rhs, loc: value.loc };
163560
+ }
163561
+ break;
163562
+ }
163563
+ case ">>>": {
163564
+ if (typeof lhs === "number" && typeof rhs === "number") {
163565
+ result = {
163566
+ kind: "Primitive",
163567
+ value: lhs >>> rhs,
163568
+ loc: value.loc,
163569
+ };
163570
+ }
163571
+ break;
163572
+ }
163573
+ case "%": {
163574
+ if (typeof lhs === "number" && typeof rhs === "number") {
163575
+ result = { kind: "Primitive", value: lhs % rhs, loc: value.loc };
163576
+ }
163577
+ break;
163578
+ }
163579
+ case "**": {
163580
+ if (typeof lhs === "number" && typeof rhs === "number") {
163581
+ result = {
163582
+ kind: "Primitive",
163583
+ value: Math.pow(lhs, rhs),
163584
+ loc: value.loc,
163585
+ };
163586
+ }
163587
+ break;
163588
+ }
163312
163589
  case "<": {
163313
163590
  if (typeof lhs === "number" && typeof rhs === "number") {
163314
163591
  result = { kind: "Primitive", value: lhs < rhs, loc: value.loc };
@@ -164285,7 +164562,7 @@ function makeManualMemoizationMarkers(
164285
164562
  return [
164286
164563
  {
164287
164564
  id: makeInstructionId(0),
164288
- lvalue: createTemporaryPlace(env),
164565
+ lvalue: createTemporaryPlace(env, fnExpr.loc),
164289
164566
  value: {
164290
164567
  kind: "StartMemoize",
164291
164568
  manualMemoId: manualMemoId,
@@ -164296,7 +164573,7 @@ function makeManualMemoizationMarkers(
164296
164573
  },
164297
164574
  {
164298
164575
  id: makeInstructionId(0),
164299
- lvalue: createTemporaryPlace(env),
164576
+ lvalue: createTemporaryPlace(env, fnExpr.loc),
164300
164577
  value: {
164301
164578
  kind: "FinishMemoize",
164302
164579
  manualMemoId: manualMemoId,
@@ -164819,6 +165096,7 @@ function rewriteBlock(env, block, returnTarget, returnValue) {
164819
165096
  name: null,
164820
165097
  scope: null,
164821
165098
  type: makeType(),
165099
+ loc: terminal.loc,
164822
165100
  },
164823
165101
  kind: "Identifier",
164824
165102
  reactive: false,
@@ -164858,6 +165136,7 @@ function declareTemporary(env, block, result) {
164858
165136
  name: null,
164859
165137
  scope: null,
164860
165138
  type: makeType(),
165139
+ loc: result.loc,
164861
165140
  },
164862
165141
  kind: "Identifier",
164863
165142
  reactive: false,
@@ -166064,7 +166343,12 @@ function validateNoRefAccessInRenderImpl(fn, refAccessingFunctions) {
166064
166343
  case "MethodCall": {
166065
166344
  if (!isEffectHook(instr.value.property.identifier)) {
166066
166345
  for (const operand of eachInstructionValueOperand(instr.value)) {
166067
- validateNoRefAccess(errors, refAccessingFunctions, operand);
166346
+ validateNoRefAccess(
166347
+ errors,
166348
+ refAccessingFunctions,
166349
+ operand,
166350
+ operand.loc
166351
+ );
166068
166352
  }
166069
166353
  }
166070
166354
  break;
@@ -166084,7 +166368,12 @@ function validateNoRefAccessInRenderImpl(fn, refAccessingFunctions) {
166084
166368
  });
166085
166369
  }
166086
166370
  for (const operand of eachInstructionValueOperand(instr.value)) {
166087
- validateNoRefAccess(errors, refAccessingFunctions, operand);
166371
+ validateNoRefAccess(
166372
+ errors,
166373
+ refAccessingFunctions,
166374
+ operand,
166375
+ operand.loc
166376
+ );
166088
166377
  }
166089
166378
  }
166090
166379
  break;
@@ -166092,7 +166381,30 @@ function validateNoRefAccessInRenderImpl(fn, refAccessingFunctions) {
166092
166381
  case "ObjectExpression":
166093
166382
  case "ArrayExpression": {
166094
166383
  for (const operand of eachInstructionValueOperand(instr.value)) {
166095
- validateNoRefAccess(errors, refAccessingFunctions, operand);
166384
+ validateNoRefAccess(
166385
+ errors,
166386
+ refAccessingFunctions,
166387
+ operand,
166388
+ operand.loc
166389
+ );
166390
+ }
166391
+ break;
166392
+ }
166393
+ case "PropertyDelete":
166394
+ case "PropertyStore":
166395
+ case "ComputedDelete":
166396
+ case "ComputedStore": {
166397
+ validateNoRefAccess(
166398
+ errors,
166399
+ refAccessingFunctions,
166400
+ instr.value.object,
166401
+ instr.loc
166402
+ );
166403
+ for (const operand of eachInstructionValueOperand(instr.value)) {
166404
+ if (operand === instr.value.object) {
166405
+ continue;
166406
+ }
166407
+ validateNoRefValueAccess(errors, refAccessingFunctions, operand);
166096
166408
  }
166097
166409
  break;
166098
166410
  }
@@ -166114,14 +166426,10 @@ function validateNoRefAccessInRenderImpl(fn, refAccessingFunctions) {
166114
166426
  return Ok(undefined);
166115
166427
  }
166116
166428
  }
166117
- function validateNoRefValueAccess(
166118
- errors,
166119
- unconditionalSetStateFunctions,
166120
- operand
166121
- ) {
166429
+ function validateNoRefValueAccess(errors, refAccessingFunctions, operand) {
166122
166430
  if (
166123
166431
  isRefValueType(operand.identifier) ||
166124
- unconditionalSetStateFunctions.has(operand.identifier.id)
166432
+ refAccessingFunctions.has(operand.identifier.id)
166125
166433
  ) {
166126
166434
  errors.push({
166127
166435
  severity: exports.ErrorSeverity.InvalidReact,
@@ -166133,18 +166441,22 @@ function validateNoRefValueAccess(
166133
166441
  });
166134
166442
  }
166135
166443
  }
166136
- function validateNoRefAccess(errors, unconditionalSetStateFunctions, operand) {
166444
+ function validateNoRefAccess(errors, refAccessingFunctions, operand, loc) {
166137
166445
  if (
166138
166446
  isRefValueType(operand.identifier) ||
166139
166447
  isUseRefType(operand.identifier) ||
166140
- unconditionalSetStateFunctions.has(operand.identifier.id)
166448
+ refAccessingFunctions.has(operand.identifier.id)
166141
166449
  ) {
166142
166450
  errors.push({
166143
166451
  severity: exports.ErrorSeverity.InvalidReact,
166144
166452
  reason:
166145
166453
  "Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)",
166146
- loc: operand.loc,
166147
- description: `Cannot access ref value at ${printPlace(operand)}`,
166454
+ loc: loc,
166455
+ description:
166456
+ operand.identifier.name !== null &&
166457
+ operand.identifier.name.kind === "named"
166458
+ ? `Cannot access ref value \`${operand.identifier.name.value}\``
166459
+ : null,
166148
166460
  suggestions: null,
166149
166461
  });
166150
166462
  }
@@ -166235,7 +166547,7 @@ function validateNonSetState(errors, unconditionalSetStateFunctions, operand) {
166235
166547
  }
166236
166548
  function validatePreservedManualMemoization(fn) {
166237
166549
  const state = { errors: new CompilerError(), manualMemoState: null };
166238
- visitReactiveFunction(fn, new Visitor(), state);
166550
+ visitReactiveFunction(fn, new Visitor$1(), state);
166239
166551
  if (state.errors.hasErrors()) {
166240
166552
  throw state.errors;
166241
166553
  }
@@ -166357,7 +166669,7 @@ function validateInferredDep(
166357
166669
  suggestions: null,
166358
166670
  });
166359
166671
  }
166360
- class Visitor extends ReactiveFunctionVisitor {
166672
+ let Visitor$1 = class Visitor extends ReactiveFunctionVisitor {
166361
166673
  constructor() {
166362
166674
  super(...arguments);
166363
166675
  this.scopes = new Set();
@@ -166526,7 +166838,7 @@ class Visitor extends ReactiveFunctionVisitor {
166526
166838
  }
166527
166839
  }
166528
166840
  }
166529
- }
166841
+ };
166530
166842
  function isUnmemoized(operand, scopes) {
166531
166843
  return operand.scope != null && !scopes.has(operand.scope.id);
166532
166844
  }
@@ -166598,6 +166910,216 @@ function validateUseMemo(fn) {
166598
166910
  }
166599
166911
  }
166600
166912
  }
166913
+ class Visitor extends ReactiveFunctionVisitor {
166914
+ constructor(env, aliases, paths) {
166915
+ super();
166916
+ this.map = new Map();
166917
+ this.aliases = aliases;
166918
+ this.paths = paths;
166919
+ this.env = env;
166920
+ }
166921
+ join(values) {
166922
+ function join2(l, r) {
166923
+ if (l === "Update" || r === "Update") {
166924
+ return "Update";
166925
+ } else if (l === "Create" || r === "Create") {
166926
+ return "Create";
166927
+ } else if (l === "Unknown" || r === "Unknown") {
166928
+ return "Unknown";
166929
+ }
166930
+ assertExhaustive(r, `Unhandled variable kind ${r}`);
166931
+ }
166932
+ return values.reduce(join2, "Unknown");
166933
+ }
166934
+ isCreateOnlyHook(id) {
166935
+ return isUseStateType(id) || isUseRefType(id);
166936
+ }
166937
+ visitPlace(_, place, state) {
166938
+ var _a;
166939
+ this.map.set(
166940
+ place.identifier.id,
166941
+ this.join([
166942
+ state,
166943
+ (_a = this.map.get(place.identifier.id)) !== null && _a !== void 0
166944
+ ? _a
166945
+ : "Unknown",
166946
+ ])
166947
+ );
166948
+ }
166949
+ visitBlock(block, state) {
166950
+ super.visitBlock([...block].reverse(), state);
166951
+ }
166952
+ visitInstruction(instruction) {
166953
+ const state = this.join(
166954
+ [...eachInstructionLValue(instruction)].map((operand) => {
166955
+ var _a;
166956
+ return (_a = this.map.get(operand.identifier.id)) !== null &&
166957
+ _a !== void 0
166958
+ ? _a
166959
+ : "Unknown";
166960
+ })
166961
+ );
166962
+ const visitCallOrMethodNonArgs = () => {
166963
+ switch (instruction.value.kind) {
166964
+ case "CallExpression": {
166965
+ this.visitPlace(instruction.id, instruction.value.callee, state);
166966
+ break;
166967
+ }
166968
+ case "MethodCall": {
166969
+ this.visitPlace(instruction.id, instruction.value.property, state);
166970
+ this.visitPlace(instruction.id, instruction.value.receiver, state);
166971
+ break;
166972
+ }
166973
+ }
166974
+ };
166975
+ const isHook = () => {
166976
+ let callee = null;
166977
+ switch (instruction.value.kind) {
166978
+ case "CallExpression": {
166979
+ callee = instruction.value.callee.identifier;
166980
+ break;
166981
+ }
166982
+ case "MethodCall": {
166983
+ callee = instruction.value.property.identifier;
166984
+ break;
166985
+ }
166986
+ }
166987
+ return callee != null && getHookKind(this.env, callee) != null;
166988
+ };
166989
+ switch (instruction.value.kind) {
166990
+ case "CallExpression":
166991
+ case "MethodCall": {
166992
+ if (
166993
+ instruction.lvalue &&
166994
+ this.isCreateOnlyHook(instruction.lvalue.identifier)
166995
+ ) {
166996
+ [...eachCallArgument(instruction.value.args)].forEach((operand) =>
166997
+ this.visitPlace(instruction.id, operand, "Create")
166998
+ );
166999
+ visitCallOrMethodNonArgs();
167000
+ } else {
167001
+ this.traverseInstruction(instruction, isHook() ? "Update" : state);
167002
+ }
167003
+ break;
167004
+ }
167005
+ default: {
167006
+ this.traverseInstruction(instruction, state);
167007
+ }
167008
+ }
167009
+ }
167010
+ visitScope(scope) {
167011
+ const state = this.join(
167012
+ [
167013
+ ...scope.scope.declarations.keys(),
167014
+ ...[...scope.scope.reassignments.values()].map((ident) => ident.id),
167015
+ ].map((id) => {
167016
+ var _a;
167017
+ return (_a = this.map.get(id)) !== null && _a !== void 0
167018
+ ? _a
167019
+ : "Unknown";
167020
+ })
167021
+ );
167022
+ super.visitScope(scope, state);
167023
+ [...scope.scope.dependencies].forEach((ident) => {
167024
+ var _a;
167025
+ let target =
167026
+ (_a = this.aliases.find(ident.identifier.id)) !== null && _a !== void 0
167027
+ ? _a
167028
+ : ident.identifier.id;
167029
+ ident.path.forEach((key) => {
167030
+ var _a;
167031
+ target &&
167032
+ (target =
167033
+ (_a = this.paths.get(target)) === null || _a === void 0
167034
+ ? void 0
167035
+ : _a.get(key));
167036
+ });
167037
+ if (target && this.map.get(target) === "Create") {
167038
+ scope.scope.dependencies.delete(ident);
167039
+ }
167040
+ });
167041
+ }
167042
+ visitTerminal(stmt, state) {
167043
+ CompilerError.invariant(state !== "Create", {
167044
+ reason: "Visiting a terminal statement with state 'Create'",
167045
+ loc: stmt.terminal.loc,
167046
+ });
167047
+ super.visitTerminal(stmt, state);
167048
+ }
167049
+ visitReactiveFunctionValue(_id, _dependencies, fn, state) {
167050
+ visitReactiveFunction(fn, this, state);
167051
+ }
167052
+ }
167053
+ function pruneInitializationDependencies(fn) {
167054
+ const [aliases, paths] = getAliases(fn);
167055
+ visitReactiveFunction(fn, new Visitor(fn.env, aliases, paths), "Update");
167056
+ }
167057
+ function update(map, key, path, value) {
167058
+ var _a;
167059
+ const inner = (_a = map.get(key)) !== null && _a !== void 0 ? _a : new Map();
167060
+ inner.set(path, value);
167061
+ map.set(key, inner);
167062
+ }
167063
+ class AliasVisitor extends ReactiveFunctionVisitor {
167064
+ constructor() {
167065
+ super(...arguments);
167066
+ this.scopeIdentifiers = new DisjointSet();
167067
+ this.scopePaths = new Map();
167068
+ }
167069
+ visitInstruction(instr) {
167070
+ if (
167071
+ instr.value.kind === "StoreLocal" ||
167072
+ instr.value.kind === "StoreContext"
167073
+ ) {
167074
+ this.scopeIdentifiers.union([
167075
+ instr.value.lvalue.place.identifier.id,
167076
+ instr.value.value.identifier.id,
167077
+ ]);
167078
+ } else if (
167079
+ instr.value.kind === "LoadLocal" ||
167080
+ instr.value.kind === "LoadContext"
167081
+ ) {
167082
+ instr.lvalue &&
167083
+ this.scopeIdentifiers.union([
167084
+ instr.lvalue.identifier.id,
167085
+ instr.value.place.identifier.id,
167086
+ ]);
167087
+ } else if (instr.value.kind === "PropertyLoad") {
167088
+ instr.lvalue &&
167089
+ update(
167090
+ this.scopePaths,
167091
+ instr.value.object.identifier.id,
167092
+ instr.value.property,
167093
+ instr.lvalue.identifier.id
167094
+ );
167095
+ } else if (instr.value.kind === "PropertyStore") {
167096
+ update(
167097
+ this.scopePaths,
167098
+ instr.value.object.identifier.id,
167099
+ instr.value.property,
167100
+ instr.value.value.identifier.id
167101
+ );
167102
+ }
167103
+ }
167104
+ }
167105
+ function getAliases(fn) {
167106
+ var _a, _b;
167107
+ const visitor = new AliasVisitor();
167108
+ visitReactiveFunction(fn, visitor, null);
167109
+ let disjoint = visitor.scopeIdentifiers;
167110
+ let scopePaths = new Map();
167111
+ for (const [key, value] of visitor.scopePaths) {
167112
+ for (const [path, id] of value) {
167113
+ update(
167114
+ scopePaths,
167115
+ (_a = disjoint.find(key)) !== null && _a !== void 0 ? _a : key,
167116
+ path,
167117
+ (_b = disjoint.find(id)) !== null && _b !== void 0 ? _b : id
167118
+ );
167119
+ }
167120
+ }
167121
+ return [disjoint, scopePaths];
167122
+ }
166601
167123
  function* run(
166602
167124
  func,
166603
167125
  config,
@@ -166632,8 +167154,14 @@ function* runWithEnvironment(func, env) {
166632
167154
  yield log({ kind: "hir", name: "PruneMaybeThrows", value: hir });
166633
167155
  validateContextVariableLValues(hir);
166634
167156
  validateUseMemo(hir);
166635
- dropManualMemoization(hir);
166636
- yield log({ kind: "hir", name: "DropManualMemoization", value: hir });
167157
+ if (
167158
+ !env.config.enablePreserveExistingManualUseMemo &&
167159
+ !env.config.disableMemoizationForDebugging &&
167160
+ !env.config.enableChangeDetectionForDebugging
167161
+ ) {
167162
+ dropManualMemoization(hir);
167163
+ yield log({ kind: "hir", name: "DropManualMemoization", value: hir });
167164
+ }
166637
167165
  inlineImmediatelyInvokedFunctionExpressions(hir);
166638
167166
  yield log({
166639
167167
  kind: "hir",
@@ -166796,6 +167324,14 @@ function* runWithEnvironment(func, env) {
166796
167324
  name: "PruneAlwaysInvalidatingScopes",
166797
167325
  value: reactiveFunction,
166798
167326
  });
167327
+ if (env.config.enableChangeDetectionForDebugging != null) {
167328
+ pruneInitializationDependencies(reactiveFunction);
167329
+ yield log({
167330
+ kind: "reactive",
167331
+ name: "PruneInitializationDependencies",
167332
+ value: reactiveFunction,
167333
+ });
167334
+ }
166799
167335
  propagateEarlyReturns(reactiveFunction);
166800
167336
  yield log({
166801
167337
  kind: "reactive",
@@ -167184,7 +167720,7 @@ function isFilePartOfSources(sources, filename) {
167184
167720
  return false;
167185
167721
  }
167186
167722
  function compileProgram(program, pass) {
167187
- var _a, _b, _c, _d, _e, _f, _g;
167723
+ var _a, _b, _c, _d, _e, _f, _g, _h;
167188
167724
  const options = parsePluginOptions(pass.opts);
167189
167725
  if (options.sources) {
167190
167726
  if (pass.filename === null) {
@@ -167371,6 +167907,16 @@ function compileProgram(program, pass) {
167371
167907
  );
167372
167908
  externalFunctions.push(enableEmitHookGuards);
167373
167909
  }
167910
+ if (
167911
+ ((_h = options.environment) === null || _h === void 0
167912
+ ? void 0
167913
+ : _h.enableChangeDetectionForDebugging) != null
167914
+ ) {
167915
+ const enableChangeDetectionForDebugging = tryParseExternalFunction(
167916
+ options.environment.enableChangeDetectionForDebugging
167917
+ );
167918
+ externalFunctions.push(enableChangeDetectionForDebugging);
167919
+ }
167374
167920
  } catch (err) {
167375
167921
  handleError(err, pass, null);
167376
167922
  return;