babel-plugin-react-compiler 0.0.0-experimental-487cb0e-20240529 → 0.0.0-experimental-696af53-20240625

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
@@ -135799,21 +135799,37 @@ function insertGatedFunctionDeclaration(fnPath, compiled, gating) {
135799
135799
  buildFunctionExpression(compiled),
135800
135800
  buildFunctionExpression(fnPath.node)
135801
135801
  );
135802
- let compiledFn;
135803
135802
  if (
135804
135803
  fnPath.parentPath.node.type !== "ExportDefaultDeclaration" &&
135805
135804
  fnPath.node.type === "FunctionDeclaration" &&
135806
135805
  fnPath.node.id != null
135807
135806
  ) {
135808
- compiledFn = fnPath.replaceWith(
135807
+ fnPath.replaceWith(
135809
135808
  t__namespace.variableDeclaration("const", [
135810
135809
  t__namespace.variableDeclarator(fnPath.node.id, gatingExpression),
135811
135810
  ])
135812
- )[0];
135811
+ );
135812
+ } else if (
135813
+ fnPath.parentPath.node.type === "ExportDefaultDeclaration" &&
135814
+ fnPath.node.type !== "ArrowFunctionExpression" &&
135815
+ fnPath.node.id != null
135816
+ ) {
135817
+ fnPath.insertAfter(
135818
+ t__namespace.exportDefaultDeclaration(
135819
+ t__namespace.identifier(fnPath.node.id.name)
135820
+ )
135821
+ );
135822
+ fnPath.parentPath.replaceWith(
135823
+ t__namespace.variableDeclaration("const", [
135824
+ t__namespace.variableDeclarator(
135825
+ t__namespace.identifier(fnPath.node.id.name),
135826
+ gatingExpression
135827
+ ),
135828
+ ])
135829
+ );
135813
135830
  } else {
135814
- compiledFn = fnPath.replaceWith(gatingExpression)[0];
135831
+ fnPath.replaceWith(gatingExpression);
135815
135832
  }
135816
- return compiledFn;
135817
135833
  }
135818
135834
  function buildFunctionExpression(node) {
135819
135835
  var _a, _b;
@@ -135848,6 +135864,15 @@ function retainWhere(array, predicate) {
135848
135864
  }
135849
135865
  array.length = writeIndex;
135850
135866
  }
135867
+ function getOrInsertWith(m, key, makeDefault) {
135868
+ if (m.has(key)) {
135869
+ return m.get(key);
135870
+ } else {
135871
+ const defaultValue = makeDefault();
135872
+ m.set(key, defaultValue);
135873
+ return defaultValue;
135874
+ }
135875
+ }
135851
135876
  function getOrInsertDefault(m, key, defaultValue) {
135852
135877
  if (m.has(key)) {
135853
135878
  return m.get(key);
@@ -136071,10 +136096,12 @@ function objectMethodTypeEquals(tA, tB) {
136071
136096
  }
136072
136097
  function propTypeEquals(tA, tB) {
136073
136098
  if (tA.kind === "Property" && tB.kind === "Property") {
136074
- if (!typeEquals(tA.object, tB.object)) {
136099
+ if (!typeEquals(tA.objectType, tB.objectType)) {
136075
136100
  return false;
136076
136101
  }
136077
- return tA.propertyName === tB.propertyName;
136102
+ return (
136103
+ tA.propertyName === tB.propertyName && tA.objectName === tB.objectName
136104
+ );
136078
136105
  }
136079
136106
  return false;
136080
136107
  }
@@ -136111,6 +136138,12 @@ function phiTypeEquals(tA, tB) {
136111
136138
  return false;
136112
136139
  }
136113
136140
  const GeneratedSource = Symbol();
136141
+ function isStatementBlockKind(kind) {
136142
+ return kind === "block" || kind === "catch";
136143
+ }
136144
+ function isExpressionBlockKind(kind) {
136145
+ return !isStatementBlockKind(kind);
136146
+ }
136114
136147
  var GotoVariant;
136115
136148
  (function (GotoVariant) {
136116
136149
  GotoVariant["Break"] = "Break";
@@ -136165,6 +136198,7 @@ var ValueReason;
136165
136198
  ValueReason["KnownReturnSignature"] = "known-return-signature";
136166
136199
  ValueReason["Context"] = "context";
136167
136200
  ValueReason["State"] = "state";
136201
+ ValueReason["ReducerState"] = "reducer-state";
136168
136202
  ValueReason["ReactiveFunctionArgument"] = "reactive-function-argument";
136169
136203
  ValueReason["Other"] = "other";
136170
136204
  })(ValueReason || (ValueReason = {}));
@@ -136266,9 +136300,23 @@ function isRefValueType(id) {
136266
136300
  function isUseRefType(id) {
136267
136301
  return id.type.kind === "Object" && id.type.shapeId === "BuiltInUseRefId";
136268
136302
  }
136303
+ function isUseStateType(id) {
136304
+ return id.type.kind === "Object" && id.type.shapeId === "BuiltInUseState";
136305
+ }
136269
136306
  function isSetStateType(id) {
136270
136307
  return id.type.kind === "Function" && id.type.shapeId === "BuiltInSetState";
136271
136308
  }
136309
+ function isSetActionStateType(id) {
136310
+ return (
136311
+ id.type.kind === "Function" && id.type.shapeId === "BuiltInSetActionState"
136312
+ );
136313
+ }
136314
+ function isDispatcherType(id) {
136315
+ return id.type.kind === "Function" && id.type.shapeId === "BuiltInDispatch";
136316
+ }
136317
+ function isStableType(id) {
136318
+ return isSetStateType(id) || isSetActionStateType(id) || isDispatcherType(id);
136319
+ }
136272
136320
  function isUseEffectHookType(id) {
136273
136321
  return (
136274
136322
  id.type.kind === "Function" && id.type.shapeId === "BuiltInUseEffectHook"
@@ -136401,6 +136449,11 @@ function writeReactiveBlock(writer, block) {
136401
136449
  writeReactiveInstructions(writer, block.instructions);
136402
136450
  writer.writeLine("}");
136403
136451
  }
136452
+ function writePrunedScope(writer, block) {
136453
+ writer.writeLine(`<pruned> ${printReactiveScopeSummary(block.scope)} {`);
136454
+ writeReactiveInstructions(writer, block.instructions);
136455
+ writer.writeLine("}");
136456
+ }
136404
136457
  function printDependency(dependency) {
136405
136458
  const identifier =
136406
136459
  printIdentifier(dependency.identifier) +
@@ -136434,6 +136487,10 @@ function writeReactiveInstruction(writer, instr) {
136434
136487
  writeReactiveBlock(writer, instr);
136435
136488
  break;
136436
136489
  }
136490
+ case "pruned-scope": {
136491
+ writePrunedScope(writer, instr);
136492
+ break;
136493
+ }
136437
136494
  case "terminal": {
136438
136495
  if (instr.label !== null) {
136439
136496
  writer.write(`bb${instr.label.id}: `);
@@ -136823,7 +136880,8 @@ function printMixedHIR(value) {
136823
136880
  case "do-while":
136824
136881
  case "for-in":
136825
136882
  case "for-of":
136826
- case "scope": {
136883
+ case "scope":
136884
+ case "pruned-scope": {
136827
136885
  const terminal = printTerminal(value);
136828
136886
  if (Array.isArray(terminal)) {
136829
136887
  return terminal.join("; ");
@@ -136953,6 +137011,10 @@ function printTerminal(terminal) {
136953
137011
  value = `Scope ${printReactiveScopeSummary(terminal.scope)} block=bb${terminal.block} fallthrough=bb${terminal.fallthrough}`;
136954
137012
  break;
136955
137013
  }
137014
+ case "pruned-scope": {
137015
+ value = `<pruned> Scope ${printReactiveScopeSummary(terminal.scope)} block=bb${terminal.block} fallthrough=bb${terminal.fallthrough}`;
137016
+ break;
137017
+ }
136956
137018
  case "try": {
136957
137019
  value = `Try block=bb${terminal.block} handler=bb${terminal.handler}${terminal.handlerBinding !== null ? ` handlerBinding=(${printPlace(terminal.handlerBinding)})` : ""} fallthrough=${terminal.fallthrough != null ? `bb${terminal.fallthrough}` : ""}`;
136958
137020
  break;
@@ -137253,6 +137315,10 @@ function printInstructionValue(instrValue) {
137253
137315
  value = `RegExp /${instrValue.pattern}/${instrValue.flags}`;
137254
137316
  break;
137255
137317
  }
137318
+ case "MetaProperty": {
137319
+ value = `MetaProperty ${instrValue.meta}.${instrValue.property}`;
137320
+ break;
137321
+ }
137256
137322
  case "Await": {
137257
137323
  value = `Await ${printPlace(instrValue.value)}`;
137258
137324
  break;
@@ -137651,6 +137717,7 @@ function* eachInstructionValueOperand(instrValue) {
137651
137717
  }
137652
137718
  case "Debugger":
137653
137719
  case "RegExpLiteral":
137720
+ case "MetaProperty":
137654
137721
  case "LoadGlobal":
137655
137722
  case "UnsupportedNode":
137656
137723
  case "Primitive":
@@ -137949,6 +138016,7 @@ function mapInstructionValueOperands(instrValue, fn) {
137949
138016
  }
137950
138017
  case "Debugger":
137951
138018
  case "RegExpLiteral":
138019
+ case "MetaProperty":
137952
138020
  case "LoadGlobal":
137953
138021
  case "UnsupportedNode":
137954
138022
  case "Primitive":
@@ -138213,11 +138281,12 @@ function mapTerminalSuccessors(terminal, fn) {
138213
138281
  loc: terminal.loc,
138214
138282
  };
138215
138283
  }
138216
- case "scope": {
138284
+ case "scope":
138285
+ case "pruned-scope": {
138217
138286
  const block = fn(terminal.block);
138218
138287
  const fallthrough = fn(terminal.fallthrough);
138219
138288
  return {
138220
- kind: "scope",
138289
+ kind: terminal.kind,
138221
138290
  scope: terminal.scope,
138222
138291
  block: block,
138223
138292
  fallthrough: fallthrough,
@@ -138262,7 +138331,8 @@ function terminalHasFallthrough(terminal) {
138262
138331
  case "switch":
138263
138332
  case "ternary":
138264
138333
  case "while":
138265
- case "scope": {
138334
+ case "scope":
138335
+ case "pruned-scope": {
138266
138336
  terminal.fallthrough;
138267
138337
  return true;
138268
138338
  }
@@ -138352,7 +138422,8 @@ function* eachTerminalSuccessor(terminal) {
138352
138422
  yield terminal.block;
138353
138423
  break;
138354
138424
  }
138355
- case "scope": {
138425
+ case "scope":
138426
+ case "pruned-scope": {
138356
138427
  yield terminal.block;
138357
138428
  break;
138358
138429
  }
@@ -138414,7 +138485,8 @@ function mapTerminalOperands(terminal, fn) {
138414
138485
  case "goto":
138415
138486
  case "unreachable":
138416
138487
  case "unsupported":
138417
- case "scope": {
138488
+ case "scope":
138489
+ case "pruned-scope": {
138418
138490
  break;
138419
138491
  }
138420
138492
  default: {
@@ -138470,7 +138542,8 @@ function* eachTerminalOperand(terminal) {
138470
138542
  case "goto":
138471
138543
  case "unreachable":
138472
138544
  case "unsupported":
138473
- case "scope": {
138545
+ case "scope":
138546
+ case "pruned-scope": {
138474
138547
  break;
138475
138548
  }
138476
138549
  default: {
@@ -138896,7 +138969,7 @@ class HIRBuilder {
138896
138969
  ).at(-1);
138897
138970
  return handler !== null && handler !== void 0 ? handler : null;
138898
138971
  }
138899
- makeTemporary() {
138972
+ makeTemporary(loc) {
138900
138973
  const id = this.nextIdentifierId;
138901
138974
  return {
138902
138975
  id: id,
@@ -138904,6 +138977,7 @@ class HIRBuilder {
138904
138977
  mutableRange: { start: makeInstructionId(0), end: makeInstructionId(0) },
138905
138978
  scope: null,
138906
138979
  type: makeType(),
138980
+ loc: loc,
138907
138981
  };
138908
138982
  }
138909
138983
  resolveIdentifier(path) {
@@ -138984,6 +139058,7 @@ class HIRBuilder {
138984
139058
  }
138985
139059
  }
138986
139060
  resolveBinding(node) {
139061
+ var _a;
138987
139062
  const originalName = node.name;
138988
139063
  let name = originalName;
138989
139064
  let index = 0;
@@ -139004,6 +139079,7 @@ class HIRBuilder {
139004
139079
  },
139005
139080
  scope: null,
139006
139081
  type: makeType(),
139082
+ loc: (_a = node.loc) !== null && _a !== void 0 ? _a : GeneratedSource,
139007
139083
  };
139008
139084
  __classPrivateFieldGet(this, _HIRBuilder_bindings, "f").set(name, {
139009
139085
  node: node,
@@ -139436,7 +139512,7 @@ function removeUnnecessaryTryCatch(fn) {
139436
139512
  }
139437
139513
  }
139438
139514
  }
139439
- function createTemporaryPlace(env) {
139515
+ function createTemporaryPlace(env, loc) {
139440
139516
  return {
139441
139517
  kind: "Identifier",
139442
139518
  identifier: {
@@ -139445,6 +139521,7 @@ function createTemporaryPlace(env) {
139445
139521
  name: null,
139446
139522
  scope: null,
139447
139523
  type: makeType(),
139524
+ loc: loc,
139448
139525
  },
139449
139526
  reactive: false,
139450
139527
  effect: exports.Effect.Unknown,
@@ -139487,12 +139564,15 @@ function addShape(registry, id, properties, functionType) {
139487
139564
  registry.set(id, shape);
139488
139565
  return shape;
139489
139566
  }
139567
+ const BuiltInPropsId = "BuiltInProps";
139490
139568
  const BuiltInArrayId = "BuiltInArray";
139491
139569
  const BuiltInFunctionId = "BuiltInFunction";
139492
139570
  const BuiltInJsxId = "BuiltInJsx";
139493
139571
  const BuiltInObjectId = "BuiltInObject";
139494
139572
  const BuiltInUseStateId = "BuiltInUseState";
139495
139573
  const BuiltInSetStateId = "BuiltInSetState";
139574
+ const BuiltInUseActionStateId = "BuiltInUseActionState";
139575
+ const BuiltInSetActionStateId = "BuiltInSetActionState";
139496
139576
  const BuiltInUseRefId = "BuiltInUseRefId";
139497
139577
  const BuiltInRefValueId = "BuiltInRefValue";
139498
139578
  const BuiltInMixedReadonlyId = "BuiltInMixedReadonly";
@@ -139500,7 +139580,12 @@ const BuiltInUseEffectHookId = "BuiltInUseEffectHook";
139500
139580
  const BuiltInUseLayoutEffectHookId = "BuiltInUseLayoutEffectHook";
139501
139581
  const BuiltInUseInsertionEffectHookId = "BuiltInUseInsertionEffectHook";
139502
139582
  const BuiltInUseOperatorId = "BuiltInUseOperator";
139583
+ const BuiltInUseReducerId = "BuiltInUseReducer";
139584
+ const BuiltInDispatchId = "BuiltInDispatch";
139503
139585
  const BUILTIN_SHAPES = new Map();
139586
+ addObject(BUILTIN_SHAPES, BuiltInPropsId, [
139587
+ ["ref", { kind: "Object", shapeId: BuiltInUseRefId }],
139588
+ ]);
139504
139589
  addObject(BUILTIN_SHAPES, BuiltInArrayId, [
139505
139590
  [
139506
139591
  "at",
@@ -139646,6 +139731,42 @@ addObject(BUILTIN_SHAPES, BuiltInUseStateId, [
139646
139731
  ),
139647
139732
  ],
139648
139733
  ]);
139734
+ addObject(BUILTIN_SHAPES, BuiltInUseActionStateId, [
139735
+ ["0", { kind: "Poly" }],
139736
+ [
139737
+ "1",
139738
+ addFunction(
139739
+ BUILTIN_SHAPES,
139740
+ [],
139741
+ {
139742
+ positionalParams: [],
139743
+ restParam: exports.Effect.Freeze,
139744
+ returnType: PRIMITIVE_TYPE,
139745
+ calleeEffect: exports.Effect.Read,
139746
+ returnValueKind: exports.ValueKind.Primitive,
139747
+ },
139748
+ BuiltInSetActionStateId
139749
+ ),
139750
+ ],
139751
+ ]);
139752
+ addObject(BUILTIN_SHAPES, BuiltInUseReducerId, [
139753
+ ["0", { kind: "Poly" }],
139754
+ [
139755
+ "1",
139756
+ addFunction(
139757
+ BUILTIN_SHAPES,
139758
+ [],
139759
+ {
139760
+ positionalParams: [],
139761
+ restParam: exports.Effect.Freeze,
139762
+ returnType: PRIMITIVE_TYPE,
139763
+ calleeEffect: exports.Effect.Read,
139764
+ returnValueKind: exports.ValueKind.Primitive,
139765
+ },
139766
+ BuiltInDispatchId
139767
+ ),
139768
+ ],
139769
+ ]);
139649
139770
  addObject(BUILTIN_SHAPES, BuiltInUseRefId, [
139650
139771
  ["current", { kind: "Object", shapeId: BuiltInRefValueId }],
139651
139772
  ]);
@@ -139742,7 +139863,7 @@ function lower$1(func, env, bindings = null, capturedRefs = [], parent = null) {
139742
139863
  }
139743
139864
  const params = [];
139744
139865
  func.get("params").forEach((param) => {
139745
- var _a, _b, _c, _d, _e, _f, _g;
139866
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
139746
139867
  if (param.isIdentifier()) {
139747
139868
  const binding = builder.resolveIdentifier(param);
139748
139869
  if (binding.kind !== "Identifier") {
@@ -139772,18 +139893,20 @@ function lower$1(func, env, bindings = null, capturedRefs = [], parent = null) {
139772
139893
  ) {
139773
139894
  const place = {
139774
139895
  kind: "Identifier",
139775
- identifier: builder.makeTemporary(),
139896
+ identifier: builder.makeTemporary(
139897
+ (_c = param.node.loc) !== null && _c !== void 0 ? _c : GeneratedSource
139898
+ ),
139776
139899
  effect: exports.Effect.Unknown,
139777
139900
  reactive: false,
139778
139901
  loc:
139779
- (_c = param.node.loc) !== null && _c !== void 0
139780
- ? _c
139902
+ (_d = param.node.loc) !== null && _d !== void 0
139903
+ ? _d
139781
139904
  : GeneratedSource,
139782
139905
  };
139783
139906
  params.push(place);
139784
139907
  lowerAssignment(
139785
139908
  builder,
139786
- (_d = param.node.loc) !== null && _d !== void 0 ? _d : GeneratedSource,
139909
+ (_e = param.node.loc) !== null && _e !== void 0 ? _e : GeneratedSource,
139787
139910
  InstructionKind.Let,
139788
139911
  param,
139789
139912
  place,
@@ -139792,18 +139915,20 @@ function lower$1(func, env, bindings = null, capturedRefs = [], parent = null) {
139792
139915
  } else if (param.isRestElement()) {
139793
139916
  const place = {
139794
139917
  kind: "Identifier",
139795
- identifier: builder.makeTemporary(),
139918
+ identifier: builder.makeTemporary(
139919
+ (_f = param.node.loc) !== null && _f !== void 0 ? _f : GeneratedSource
139920
+ ),
139796
139921
  effect: exports.Effect.Unknown,
139797
139922
  reactive: false,
139798
139923
  loc:
139799
- (_e = param.node.loc) !== null && _e !== void 0
139800
- ? _e
139924
+ (_g = param.node.loc) !== null && _g !== void 0
139925
+ ? _g
139801
139926
  : GeneratedSource,
139802
139927
  };
139803
139928
  params.push({ kind: "Spread", place: place });
139804
139929
  lowerAssignment(
139805
139930
  builder,
139806
- (_f = param.node.loc) !== null && _f !== void 0 ? _f : GeneratedSource,
139931
+ (_h = param.node.loc) !== null && _h !== void 0 ? _h : GeneratedSource,
139807
139932
  InstructionKind.Let,
139808
139933
  param.get("argument"),
139809
139934
  place,
@@ -139813,7 +139938,7 @@ function lower$1(func, env, bindings = null, capturedRefs = [], parent = null) {
139813
139938
  builder.errors.push({
139814
139939
  reason: `(BuildHIR::lower) Handle ${param.node.type} params`,
139815
139940
  severity: exports.ErrorSeverity.Todo,
139816
- loc: (_g = param.node.loc) !== null && _g !== void 0 ? _g : null,
139941
+ loc: (_j = param.node.loc) !== null && _j !== void 0 ? _j : null,
139817
139942
  suggestions: null,
139818
139943
  });
139819
139944
  }
@@ -139928,7 +140053,8 @@ function lowerStatement(builder, stmtPath, label = null) {
139928
140053
  _28,
139929
140054
  _29,
139930
140055
  _30,
139931
- _31;
140056
+ _31,
140057
+ _32;
139932
140058
  const stmtNode = stmtPath.node;
139933
140059
  switch (stmtNode.type) {
139934
140060
  case "ThrowStatement": {
@@ -140955,12 +141081,16 @@ function lowerStatement(builder, stmtPath, label = null) {
140955
141081
  if (hasNode(handlerBindingPath)) {
140956
141082
  const place = {
140957
141083
  kind: "Identifier",
140958
- identifier: builder.makeTemporary(),
141084
+ identifier: builder.makeTemporary(
141085
+ (_27 = handlerBindingPath.node.loc) !== null && _27 !== void 0
141086
+ ? _27
141087
+ : GeneratedSource
141088
+ ),
140959
141089
  effect: exports.Effect.Unknown,
140960
141090
  reactive: false,
140961
141091
  loc:
140962
- (_27 = handlerBindingPath.node.loc) !== null && _27 !== void 0
140963
- ? _27
141092
+ (_28 = handlerBindingPath.node.loc) !== null && _28 !== void 0
141093
+ ? _28
140964
141094
  : GeneratedSource,
140965
141095
  };
140966
141096
  promoteTemporary(place.identifier);
@@ -140972,8 +141102,8 @@ function lowerStatement(builder, stmtPath, label = null) {
140972
141102
  },
140973
141103
  type: null,
140974
141104
  loc:
140975
- (_28 = handlerBindingPath.node.loc) !== null && _28 !== void 0
140976
- ? _28
141105
+ (_29 = handlerBindingPath.node.loc) !== null && _29 !== void 0
141106
+ ? _29
140977
141107
  : GeneratedSource,
140978
141108
  });
140979
141109
  handlerBinding = { path: handlerBindingPath, place: place };
@@ -141033,8 +141163,8 @@ function lowerStatement(builder, stmtPath, label = null) {
141033
141163
  fallthrough: continuationBlock.id,
141034
141164
  id: makeInstructionId(0),
141035
141165
  loc:
141036
- (_29 = stmt.node.loc) !== null && _29 !== void 0
141037
- ? _29
141166
+ (_30 = stmt.node.loc) !== null && _30 !== void 0
141167
+ ? _30
141038
141168
  : GeneratedSource,
141039
141169
  },
141040
141170
  continuationBlock
@@ -141074,14 +141204,14 @@ function lowerStatement(builder, stmtPath, label = null) {
141074
141204
  builder.errors.push({
141075
141205
  reason: `(BuildHIR::lowerStatement) Handle ${stmtPath.type} statements`,
141076
141206
  severity: exports.ErrorSeverity.Todo,
141077
- loc: (_30 = stmtPath.node.loc) !== null && _30 !== void 0 ? _30 : null,
141207
+ loc: (_31 = stmtPath.node.loc) !== null && _31 !== void 0 ? _31 : null,
141078
141208
  suggestions: null,
141079
141209
  });
141080
141210
  lowerValueToTemporary(builder, {
141081
141211
  kind: "UnsupportedNode",
141082
141212
  loc:
141083
- (_31 = stmtPath.node.loc) !== null && _31 !== void 0
141084
- ? _31
141213
+ (_32 = stmtPath.node.loc) !== null && _32 !== void 0
141214
+ ? _32
141085
141215
  : GeneratedSource,
141086
141216
  node: stmtPath.node,
141087
141217
  });
@@ -141173,7 +141303,12 @@ function lowerExpression(builder, exprPath) {
141173
141303
  _12,
141174
141304
  _13,
141175
141305
  _14,
141176
- _15;
141306
+ _15,
141307
+ _16,
141308
+ _17,
141309
+ _18,
141310
+ _19,
141311
+ _20;
141177
141312
  const exprNode = exprPath.node;
141178
141313
  const exprLoc =
141179
141314
  (_a = exprNode.loc) !== null && _a !== void 0 ? _a : GeneratedSource;
@@ -141228,6 +141363,18 @@ function lowerExpression(builder, exprPath) {
141228
141363
  );
141229
141364
  properties.push({ kind: "Spread", place: place });
141230
141365
  } else if (propertyPath.isObjectMethod()) {
141366
+ if (propertyPath.node.kind !== "method") {
141367
+ builder.errors.push({
141368
+ reason: `(BuildHIR::lowerExpression) Handle ${propertyPath.node.kind} functions in ObjectExpression`,
141369
+ severity: exports.ErrorSeverity.Todo,
141370
+ loc:
141371
+ (_c = propertyPath.node.loc) !== null && _c !== void 0
141372
+ ? _c
141373
+ : null,
141374
+ suggestions: null,
141375
+ });
141376
+ continue;
141377
+ }
141231
141378
  const method = lowerObjectMethod(builder, propertyPath);
141232
141379
  const place = lowerValueToTemporary(builder, method);
141233
141380
  const loweredKey = lowerObjectPropertyKey(builder, propertyPath);
@@ -141245,8 +141392,8 @@ function lowerExpression(builder, exprPath) {
141245
141392
  reason: `(BuildHIR::lowerExpression) Handle ${propertyPath.type} properties in ObjectExpression`,
141246
141393
  severity: exports.ErrorSeverity.Todo,
141247
141394
  loc:
141248
- (_c = propertyPath.node.loc) !== null && _c !== void 0
141249
- ? _c
141395
+ (_d = propertyPath.node.loc) !== null && _d !== void 0
141396
+ ? _d
141250
141397
  : null,
141251
141398
  suggestions: null,
141252
141399
  });
@@ -141274,7 +141421,7 @@ function lowerExpression(builder, exprPath) {
141274
141421
  builder.errors.push({
141275
141422
  reason: `(BuildHIR::lowerExpression) Handle ${element.type} elements in ArrayExpression`,
141276
141423
  severity: exports.ErrorSeverity.Todo,
141277
- loc: (_d = element.node.loc) !== null && _d !== void 0 ? _d : null,
141424
+ loc: (_e = element.node.loc) !== null && _e !== void 0 ? _e : null,
141278
141425
  suggestions: null,
141279
141426
  });
141280
141427
  continue;
@@ -141290,7 +141437,7 @@ function lowerExpression(builder, exprPath) {
141290
141437
  reason: `Expected an expression as the \`new\` expression receiver (v8 intrinsics are not supported)`,
141291
141438
  description: `Got a \`${calleePath.node.type}\``,
141292
141439
  severity: exports.ErrorSeverity.InvalidJS,
141293
- loc: (_e = calleePath.node.loc) !== null && _e !== void 0 ? _e : null,
141440
+ loc: (_f = calleePath.node.loc) !== null && _f !== void 0 ? _f : null,
141294
141441
  suggestions: null,
141295
141442
  });
141296
141443
  return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
@@ -141315,7 +141462,7 @@ function lowerExpression(builder, exprPath) {
141315
141462
  builder.errors.push({
141316
141463
  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
141464
  severity: exports.ErrorSeverity.Todo,
141318
- loc: (_f = calleePath.node.loc) !== null && _f !== void 0 ? _f : null,
141465
+ loc: (_g = calleePath.node.loc) !== null && _g !== void 0 ? _g : null,
141319
141466
  suggestions: null,
141320
141467
  });
141321
141468
  return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
@@ -141349,7 +141496,7 @@ function lowerExpression(builder, exprPath) {
141349
141496
  builder.errors.push({
141350
141497
  reason: `(BuildHIR::lowerExpression) Expected Expression, got ${leftPath.type} lval in BinaryExpression`,
141351
141498
  severity: exports.ErrorSeverity.Todo,
141352
- loc: (_g = leftPath.node.loc) !== null && _g !== void 0 ? _g : null,
141499
+ loc: (_h = leftPath.node.loc) !== null && _h !== void 0 ? _h : null,
141353
141500
  suggestions: null,
141354
141501
  });
141355
141502
  return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
@@ -141357,6 +141504,15 @@ function lowerExpression(builder, exprPath) {
141357
141504
  const left = lowerExpressionToTemporary(builder, leftPath);
141358
141505
  const right = lowerExpressionToTemporary(builder, expr.get("right"));
141359
141506
  const operator = expr.node.operator;
141507
+ if (operator === "|>") {
141508
+ builder.errors.push({
141509
+ reason: `(BuildHIR::lowerExpression) Pipe operator not supported`,
141510
+ severity: exports.ErrorSeverity.Todo,
141511
+ loc: (_j = leftPath.node.loc) !== null && _j !== void 0 ? _j : null,
141512
+ suggestions: null,
141513
+ });
141514
+ return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
141515
+ }
141360
141516
  return {
141361
141517
  kind: "BinaryExpression",
141362
141518
  operator: operator,
@@ -141368,7 +141524,7 @@ function lowerExpression(builder, exprPath) {
141368
141524
  case "SequenceExpression": {
141369
141525
  const expr = exprPath;
141370
141526
  const exprLoc =
141371
- (_h = expr.node.loc) !== null && _h !== void 0 ? _h : GeneratedSource;
141527
+ (_k = expr.node.loc) !== null && _k !== void 0 ? _k : GeneratedSource;
141372
141528
  const continuationBlock = builder.reserve(builder.currentBlockKind());
141373
141529
  const place = buildTemporaryPlace(builder, exprLoc);
141374
141530
  const sequenceBlock = builder.enter("sequence", (_) => {
@@ -141419,7 +141575,7 @@ function lowerExpression(builder, exprPath) {
141419
141575
  case "ConditionalExpression": {
141420
141576
  const expr = exprPath;
141421
141577
  const exprLoc =
141422
- (_j = expr.node.loc) !== null && _j !== void 0 ? _j : GeneratedSource;
141578
+ (_l = expr.node.loc) !== null && _l !== void 0 ? _l : GeneratedSource;
141423
141579
  const continuationBlock = builder.reserve(builder.currentBlockKind());
141424
141580
  const testBlock = builder.reserve("value");
141425
141581
  const place = buildTemporaryPlace(builder, exprLoc);
@@ -141500,14 +141656,14 @@ function lowerExpression(builder, exprPath) {
141500
141656
  case "LogicalExpression": {
141501
141657
  const expr = exprPath;
141502
141658
  const exprLoc =
141503
- (_k = expr.node.loc) !== null && _k !== void 0 ? _k : GeneratedSource;
141659
+ (_m = expr.node.loc) !== null && _m !== void 0 ? _m : GeneratedSource;
141504
141660
  const continuationBlock = builder.reserve(builder.currentBlockKind());
141505
141661
  const testBlock = builder.reserve("value");
141506
141662
  const place = buildTemporaryPlace(builder, exprLoc);
141507
141663
  const leftPlace = buildTemporaryPlace(
141508
141664
  builder,
141509
- (_l = expr.get("left").node.loc) !== null && _l !== void 0
141510
- ? _l
141665
+ (_o = expr.get("left").node.loc) !== null && _o !== void 0
141666
+ ? _o
141511
141667
  : GeneratedSource
141512
141668
  );
141513
141669
  const consequent = builder.enter("value", () => {
@@ -141587,7 +141743,7 @@ function lowerExpression(builder, exprPath) {
141587
141743
  const left = expr.get("left");
141588
141744
  return lowerAssignment(
141589
141745
  builder,
141590
- (_m = left.node.loc) !== null && _m !== void 0 ? _m : GeneratedSource,
141746
+ (_p = left.node.loc) !== null && _p !== void 0 ? _p : GeneratedSource,
141591
141747
  InstructionKind.Reassign,
141592
141748
  left,
141593
141749
  lowerExpressionToTemporary(builder, expr.get("right")),
@@ -141615,7 +141771,7 @@ function lowerExpression(builder, exprPath) {
141615
141771
  builder.errors.push({
141616
141772
  reason: `(BuildHIR::lowerExpression) Handle ${operator} operators in AssignmentExpression`,
141617
141773
  severity: exports.ErrorSeverity.Todo,
141618
- loc: (_o = expr.node.loc) !== null && _o !== void 0 ? _o : null,
141774
+ loc: (_q = expr.node.loc) !== null && _q !== void 0 ? _q : null,
141619
141775
  suggestions: null,
141620
141776
  });
141621
141777
  return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
@@ -141675,8 +141831,8 @@ function lowerExpression(builder, exprPath) {
141675
141831
  left: Object.assign({}, previousValuePlace),
141676
141832
  right: lowerExpressionToTemporary(builder, expr.get("right")),
141677
141833
  loc:
141678
- (_p = leftExpr.node.loc) !== null && _p !== void 0
141679
- ? _p
141834
+ (_r = leftExpr.node.loc) !== null && _r !== void 0
141835
+ ? _r
141680
141836
  : GeneratedSource,
141681
141837
  });
141682
141838
  if (typeof property === "string") {
@@ -141686,8 +141842,8 @@ function lowerExpression(builder, exprPath) {
141686
141842
  property: property,
141687
141843
  value: Object.assign({}, newValuePlace),
141688
141844
  loc:
141689
- (_q = leftExpr.node.loc) !== null && _q !== void 0
141690
- ? _q
141845
+ (_s = leftExpr.node.loc) !== null && _s !== void 0
141846
+ ? _s
141691
141847
  : GeneratedSource,
141692
141848
  };
141693
141849
  } else {
@@ -141697,8 +141853,8 @@ function lowerExpression(builder, exprPath) {
141697
141853
  property: Object.assign({}, property),
141698
141854
  value: Object.assign({}, newValuePlace),
141699
141855
  loc:
141700
- (_r = leftExpr.node.loc) !== null && _r !== void 0
141701
- ? _r
141856
+ (_t = leftExpr.node.loc) !== null && _t !== void 0
141857
+ ? _t
141702
141858
  : GeneratedSource,
141703
141859
  };
141704
141860
  }
@@ -141707,7 +141863,7 @@ function lowerExpression(builder, exprPath) {
141707
141863
  builder.errors.push({
141708
141864
  reason: `(BuildHIR::lowerExpression) Expected Identifier or MemberExpression, got ${expr.type} lval in AssignmentExpression`,
141709
141865
  severity: exports.ErrorSeverity.Todo,
141710
- loc: (_s = expr.node.loc) !== null && _s !== void 0 ? _s : null,
141866
+ loc: (_u = expr.node.loc) !== null && _u !== void 0 ? _u : null,
141711
141867
  suggestions: null,
141712
141868
  });
141713
141869
  return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
@@ -141733,8 +141889,8 @@ function lowerExpression(builder, exprPath) {
141733
141889
  const expr = exprPath;
141734
141890
  const opening = expr.get("openingElement");
141735
141891
  const openingLoc =
141736
- (_t = opening.node.loc) !== null && _t !== void 0
141737
- ? _t
141892
+ (_v = opening.node.loc) !== null && _v !== void 0
141893
+ ? _v
141738
141894
  : GeneratedSource;
141739
141895
  const tag = lowerJsxElementName(builder, opening.get("name"));
141740
141896
  const props = [];
@@ -141752,7 +141908,7 @@ function lowerExpression(builder, exprPath) {
141752
141908
  reason: `(BuildHIR::lowerExpression) Handle ${attribute.type} attributes in JSXElement`,
141753
141909
  severity: exports.ErrorSeverity.Todo,
141754
141910
  loc:
141755
- (_u = attribute.node.loc) !== null && _u !== void 0 ? _u : null,
141911
+ (_w = attribute.node.loc) !== null && _w !== void 0 ? _w : null,
141756
141912
  suggestions: null,
141757
141913
  });
141758
141914
  continue;
@@ -141766,7 +141922,7 @@ function lowerExpression(builder, exprPath) {
141766
141922
  reason: `(BuildHIR::lowerExpression) Unexpected colon in attribute name \`${name}\``,
141767
141923
  severity: exports.ErrorSeverity.Todo,
141768
141924
  loc:
141769
- (_v = namePath.node.loc) !== null && _v !== void 0 ? _v : null,
141925
+ (_x = namePath.node.loc) !== null && _x !== void 0 ? _x : null,
141770
141926
  suggestions: null,
141771
141927
  });
141772
141928
  }
@@ -141774,7 +141930,7 @@ function lowerExpression(builder, exprPath) {
141774
141930
  CompilerError.invariant(namePath.isJSXNamespacedName(), {
141775
141931
  reason: "Refinement",
141776
141932
  description: null,
141777
- loc: (_w = namePath.node.loc) !== null && _w !== void 0 ? _w : null,
141933
+ loc: (_y = namePath.node.loc) !== null && _y !== void 0 ? _y : null,
141778
141934
  suggestions: null,
141779
141935
  });
141780
141936
  const namespace = namePath.node.namespace.name;
@@ -141790,8 +141946,8 @@ function lowerExpression(builder, exprPath) {
141790
141946
  kind: "Primitive",
141791
141947
  value: true,
141792
141948
  loc:
141793
- (_x = attribute.node.loc) !== null && _x !== void 0
141794
- ? _x
141949
+ (_z = attribute.node.loc) !== null && _z !== void 0
141950
+ ? _z
141795
141951
  : GeneratedSource,
141796
141952
  });
141797
141953
  } else {
@@ -141800,11 +141956,11 @@ function lowerExpression(builder, exprPath) {
141800
141956
  reason: `(BuildHIR::lowerExpression) Handle ${valueExpr.type} attribute values in JSXElement`,
141801
141957
  severity: exports.ErrorSeverity.Todo,
141802
141958
  loc:
141803
- (_z =
141804
- (_y = valueExpr.node) === null || _y === void 0
141959
+ (_1 =
141960
+ (_0 = valueExpr.node) === null || _0 === void 0
141805
141961
  ? void 0
141806
- : _y.loc) !== null && _z !== void 0
141807
- ? _z
141962
+ : _0.loc) !== null && _1 !== void 0
141963
+ ? _1
141808
141964
  : null,
141809
141965
  suggestions: null,
141810
141966
  });
@@ -141816,7 +141972,7 @@ function lowerExpression(builder, exprPath) {
141816
141972
  reason: `(BuildHIR::lowerExpression) Handle ${expression.type} expressions in JSXExpressionContainer within JSXElement`,
141817
141973
  severity: exports.ErrorSeverity.Todo,
141818
141974
  loc:
141819
- (_0 = valueExpr.node.loc) !== null && _0 !== void 0 ? _0 : null,
141975
+ (_2 = valueExpr.node.loc) !== null && _2 !== void 0 ? _2 : null,
141820
141976
  suggestions: null,
141821
141977
  });
141822
141978
  continue;
@@ -141838,8 +141994,8 @@ function lowerExpression(builder, exprPath) {
141838
141994
  CompilerError.throwTodo({
141839
141995
  reason: `Support <${tagName}> tags where '${tagName}' is a local variable instead of a global`,
141840
141996
  loc:
141841
- (_1 = openingIdentifier.node.loc) !== null && _1 !== void 0
141842
- ? _1
141997
+ (_3 = openingIdentifier.node.loc) !== null && _3 !== void 0
141998
+ ? _3
141843
141999
  : GeneratedSource,
141844
142000
  description: null,
141845
142001
  suggestions: null,
@@ -141865,8 +142021,8 @@ function lowerExpression(builder, exprPath) {
141865
142021
  CompilerError.throwTodo({
141866
142022
  reason: `Support <${tagName}> tags with multiple <${tagName}:enum> values`,
141867
142023
  loc:
141868
- (_2 = fbtEnumLocations.at(-1)) !== null && _2 !== void 0
141869
- ? _2
142024
+ (_4 = fbtEnumLocations.at(-1)) !== null && _4 !== void 0
142025
+ ? _4
141870
142026
  : GeneratedSource,
141871
142027
  description: null,
141872
142028
  suggestions: null,
@@ -141910,11 +142066,11 @@ function lowerExpression(builder, exprPath) {
141910
142066
  loc: exprLoc,
141911
142067
  openingLoc: openingLoc,
141912
142068
  closingLoc:
141913
- (_4 =
141914
- (_3 = expr.get("closingElement").node) === null || _3 === void 0
142069
+ (_6 =
142070
+ (_5 = expr.get("closingElement").node) === null || _5 === void 0
141915
142071
  ? void 0
141916
- : _3.loc) !== null && _4 !== void 0
141917
- ? _4
142072
+ : _5.loc) !== null && _6 !== void 0
142073
+ ? _6
141918
142074
  : GeneratedSource,
141919
142075
  };
141920
142076
  }
@@ -141938,7 +142094,7 @@ function lowerExpression(builder, exprPath) {
141938
142094
  reason:
141939
142095
  "(BuildHIR::lowerExpression) Handle tagged template with interpolations",
141940
142096
  severity: exports.ErrorSeverity.Todo,
141941
- loc: (_5 = exprPath.node.loc) !== null && _5 !== void 0 ? _5 : null,
142097
+ loc: (_7 = exprPath.node.loc) !== null && _7 !== void 0 ? _7 : null,
141942
142098
  suggestions: null,
141943
142099
  });
141944
142100
  return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
@@ -141947,7 +142103,7 @@ function lowerExpression(builder, exprPath) {
141947
142103
  reason:
141948
142104
  "there should be only one quasi as we don't support interpolations yet",
141949
142105
  description: null,
141950
- loc: (_6 = expr.node.loc) !== null && _6 !== void 0 ? _6 : null,
142106
+ loc: (_8 = expr.node.loc) !== null && _8 !== void 0 ? _8 : null,
141951
142107
  suggestions: null,
141952
142108
  });
141953
142109
  const value = expr.get("quasi").get("quasis").at(0).node.value;
@@ -141956,7 +142112,7 @@ function lowerExpression(builder, exprPath) {
141956
142112
  reason:
141957
142113
  "(BuildHIR::lowerExpression) Handle tagged template where cooked value is different from raw value",
141958
142114
  severity: exports.ErrorSeverity.Todo,
141959
- loc: (_7 = exprPath.node.loc) !== null && _7 !== void 0 ? _7 : null,
142115
+ loc: (_9 = exprPath.node.loc) !== null && _9 !== void 0 ? _9 : null,
141960
142116
  suggestions: null,
141961
142117
  });
141962
142118
  return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
@@ -141976,7 +142132,8 @@ function lowerExpression(builder, exprPath) {
141976
142132
  builder.errors.push({
141977
142133
  reason: `Unexpected quasi and subexpression lengths in template literal`,
141978
142134
  severity: exports.ErrorSeverity.InvalidJS,
141979
- loc: (_8 = exprPath.node.loc) !== null && _8 !== void 0 ? _8 : null,
142135
+ loc:
142136
+ (_10 = exprPath.node.loc) !== null && _10 !== void 0 ? _10 : null,
141980
142137
  suggestions: null,
141981
142138
  });
141982
142139
  return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
@@ -141985,7 +142142,8 @@ function lowerExpression(builder, exprPath) {
141985
142142
  builder.errors.push({
141986
142143
  reason: `(BuildHIR::lowerAssignment) Handle TSType in TemplateLiteral.`,
141987
142144
  severity: exports.ErrorSeverity.Todo,
141988
- loc: (_9 = exprPath.node.loc) !== null && _9 !== void 0 ? _9 : null,
142145
+ loc:
142146
+ (_11 = exprPath.node.loc) !== null && _11 !== void 0 ? _11 : null,
141989
142147
  suggestions: null,
141990
142148
  });
141991
142149
  return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
@@ -142028,7 +142186,7 @@ function lowerExpression(builder, exprPath) {
142028
142186
  builder.errors.push({
142029
142187
  reason: `Only object properties can be deleted`,
142030
142188
  severity: exports.ErrorSeverity.InvalidJS,
142031
- loc: (_10 = expr.node.loc) !== null && _10 !== void 0 ? _10 : null,
142189
+ loc: (_12 = expr.node.loc) !== null && _12 !== void 0 ? _12 : null,
142032
142190
  suggestions: [
142033
142191
  {
142034
142192
  description: "Remove this line",
@@ -142039,6 +142197,20 @@ function lowerExpression(builder, exprPath) {
142039
142197
  });
142040
142198
  return { kind: "UnsupportedNode", node: expr.node, loc: exprLoc };
142041
142199
  }
142200
+ } else if (expr.node.operator === "throw") {
142201
+ builder.errors.push({
142202
+ reason: `Throw expressions are not supported`,
142203
+ severity: exports.ErrorSeverity.InvalidJS,
142204
+ loc: (_13 = expr.node.loc) !== null && _13 !== void 0 ? _13 : null,
142205
+ suggestions: [
142206
+ {
142207
+ description: "Remove this line",
142208
+ range: [expr.node.start, expr.node.end],
142209
+ op: exports.CompilerSuggestionOperation.Remove,
142210
+ },
142211
+ ],
142212
+ });
142213
+ return { kind: "UnsupportedNode", node: expr.node, loc: exprLoc };
142042
142214
  } else {
142043
142215
  return {
142044
142216
  kind: "UnaryExpression",
@@ -142086,7 +142258,7 @@ function lowerExpression(builder, exprPath) {
142086
142258
  reason: `(BuildHIR::lowerExpression) Handle UpdateExpression with ${argument.type} argument`,
142087
142259
  severity: exports.ErrorSeverity.Todo,
142088
142260
  loc:
142089
- (_11 = exprPath.node.loc) !== null && _11 !== void 0 ? _11 : null,
142261
+ (_14 = exprPath.node.loc) !== null && _14 !== void 0 ? _14 : null,
142090
142262
  suggestions: null,
142091
142263
  });
142092
142264
  return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
@@ -142095,15 +142267,15 @@ function lowerExpression(builder, exprPath) {
142095
142267
  reason: `(BuildHIR::lowerExpression) Handle UpdateExpression to variables captured within lambdas.`,
142096
142268
  severity: exports.ErrorSeverity.Todo,
142097
142269
  loc:
142098
- (_12 = exprPath.node.loc) !== null && _12 !== void 0 ? _12 : null,
142270
+ (_15 = exprPath.node.loc) !== null && _15 !== void 0 ? _15 : null,
142099
142271
  suggestions: null,
142100
142272
  });
142101
142273
  return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
142102
142274
  }
142103
142275
  const lvalue = lowerIdentifierForAssignment(
142104
142276
  builder,
142105
- (_13 = argument.node.loc) !== null && _13 !== void 0
142106
- ? _13
142277
+ (_16 = argument.node.loc) !== null && _16 !== void 0
142278
+ ? _16
142107
142279
  : GeneratedSource,
142108
142280
  InstructionKind.Reassign,
142109
142281
  argument
@@ -142153,8 +142325,8 @@ function lowerExpression(builder, exprPath) {
142153
142325
  pattern: expr.node.pattern,
142154
142326
  flags: expr.node.flags,
142155
142327
  loc:
142156
- (_14 = expr.node.loc) !== null && _14 !== void 0
142157
- ? _14
142328
+ (_17 = expr.node.loc) !== null && _17 !== void 0
142329
+ ? _17
142158
142330
  : GeneratedSource,
142159
142331
  };
142160
142332
  }
@@ -142162,11 +142334,35 @@ function lowerExpression(builder, exprPath) {
142162
142334
  let expr = exprPath;
142163
142335
  return lowerExpression(builder, expr.get("expression"));
142164
142336
  }
142337
+ case "MetaProperty": {
142338
+ let expr = exprPath;
142339
+ if (
142340
+ expr.node.meta.name === "import" &&
142341
+ expr.node.property.name === "meta"
142342
+ ) {
142343
+ return {
142344
+ kind: "MetaProperty",
142345
+ meta: expr.node.meta.name,
142346
+ property: expr.node.property.name,
142347
+ loc:
142348
+ (_18 = expr.node.loc) !== null && _18 !== void 0
142349
+ ? _18
142350
+ : GeneratedSource,
142351
+ };
142352
+ }
142353
+ builder.errors.push({
142354
+ reason: `(BuildHIR::lowerExpression) Handle MetaProperty expressions other than import.meta`,
142355
+ severity: exports.ErrorSeverity.Todo,
142356
+ loc: (_19 = exprPath.node.loc) !== null && _19 !== void 0 ? _19 : null,
142357
+ suggestions: null,
142358
+ });
142359
+ return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
142360
+ }
142165
142361
  default: {
142166
142362
  builder.errors.push({
142167
142363
  reason: `(BuildHIR::lowerExpression) Handle ${exprPath.type} expressions`,
142168
142364
  severity: exports.ErrorSeverity.Todo,
142169
- loc: (_15 = exprPath.node.loc) !== null && _15 !== void 0 ? _15 : null,
142365
+ loc: (_20 = exprPath.node.loc) !== null && _20 !== void 0 ? _20 : null,
142170
142366
  suggestions: null,
142171
142367
  });
142172
142368
  return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
@@ -142872,7 +143068,7 @@ function lowerIdentifier(builder, exprPath) {
142872
143068
  function buildTemporaryPlace(builder, loc) {
142873
143069
  const place = {
142874
143070
  kind: "Identifier",
142875
- identifier: builder.makeTemporary(),
143071
+ identifier: builder.makeTemporary(loc),
142876
143072
  effect: exports.Effect.Unknown,
142877
143073
  reactive: false,
142878
143074
  loc: loc,
@@ -149675,6 +149871,30 @@ const REACT_APIS = [
149675
149871
  returnValueReason: ValueReason.State,
149676
149872
  }),
149677
149873
  ],
149874
+ [
149875
+ "useActionState",
149876
+ addHook(DEFAULT_SHAPES, {
149877
+ positionalParams: [],
149878
+ restParam: exports.Effect.Freeze,
149879
+ returnType: { kind: "Object", shapeId: BuiltInUseActionStateId },
149880
+ calleeEffect: exports.Effect.Read,
149881
+ hookKind: "useActionState",
149882
+ returnValueKind: exports.ValueKind.Frozen,
149883
+ returnValueReason: ValueReason.State,
149884
+ }),
149885
+ ],
149886
+ [
149887
+ "useReducer",
149888
+ addHook(DEFAULT_SHAPES, {
149889
+ positionalParams: [],
149890
+ restParam: exports.Effect.Freeze,
149891
+ returnType: { kind: "Object", shapeId: BuiltInUseReducerId },
149892
+ calleeEffect: exports.Effect.Read,
149893
+ hookKind: "useReducer",
149894
+ returnValueKind: exports.ValueKind.Frozen,
149895
+ returnValueReason: ValueReason.ReducerState,
149896
+ }),
149897
+ ],
149678
149898
  [
149679
149899
  "useRef",
149680
149900
  addHook(DEFAULT_SHAPES, {
@@ -149921,9 +150141,11 @@ const HookSchema = z.object({
149921
150141
  });
149922
150142
  const EnvironmentConfigSchema = z.object({
149923
150143
  customHooks: z.map(z.string(), HookSchema).optional().default(new Map()),
150144
+ customMacros: z.nullable(z.array(z.string())).default(null),
149924
150145
  enableResetCacheOnSourceFileChanges: z.boolean().default(false),
149925
150146
  enablePreserveExistingMemoizationGuarantees: z.boolean().default(false),
149926
150147
  validatePreserveExistingMemoizationGuarantees: z.boolean().default(true),
150148
+ enablePreserveExistingManualUseMemo: z.boolean().default(false),
149927
150149
  enableForest: z.boolean().default(false),
149928
150150
  enableUseTypeAnnotations: z.boolean().default(false),
149929
150151
  enableReactiveScopesInHIR: z.boolean().default(true),
@@ -149936,6 +150158,7 @@ const EnvironmentConfigSchema = z.object({
149936
150158
  enableTransitivelyFreezeFunctionExpressions: z.boolean().default(true),
149937
150159
  enableEmitFreeze: ExternalFunctionSchema.nullish(),
149938
150160
  enableEmitHookGuards: ExternalFunctionSchema.nullish(),
150161
+ enableInstructionReordering: z.boolean().default(false),
149939
150162
  enableEmitInstrumentForget: InstrumentationSchema.nullish(),
149940
150163
  assertValidMutableRanges: z.boolean().default(false),
149941
150164
  enableChangeVariableCodegen: z.boolean().default(false),
@@ -149943,8 +150166,11 @@ const EnvironmentConfigSchema = z.object({
149943
150166
  throwUnknownException__testonly: z.boolean().default(false),
149944
150167
  enableSharedRuntime__testonly: z.boolean().default(false),
149945
150168
  enableTreatFunctionDepsAsConditional: z.boolean().default(false),
150169
+ disableMemoizationForDebugging: z.boolean().default(false),
150170
+ enableChangeDetectionForDebugging: ExternalFunctionSchema.nullish(),
149946
150171
  enableCustomTypeDefinitionForReanimated: z.boolean().default(false),
149947
150172
  hookPattern: z.string().nullable().default(null),
150173
+ enableTreatRefLikeIdentifiersAsRefs: z.boolean().nullable().default(false),
149948
150174
  });
149949
150175
  function parseConfigPragma(pragma) {
149950
150176
  const maybeConfig = {};
@@ -149959,6 +150185,16 @@ function parseConfigPragma(pragma) {
149959
150185
  maybeConfig[key] = [];
149960
150186
  continue;
149961
150187
  }
150188
+ if (
150189
+ key === "enableChangeDetectionForDebugging" &&
150190
+ (val === undefined || val === "true")
150191
+ ) {
150192
+ maybeConfig[key] = {
150193
+ source: "react-compiler-runtime",
150194
+ importSpecifierName: "$structuralCheck",
150195
+ };
150196
+ continue;
150197
+ }
149962
150198
  if (typeof defaultConfig[key] !== "boolean") {
149963
150199
  continue;
149964
150200
  }
@@ -150016,6 +150252,17 @@ class Environment {
150016
150252
  new Map(DEFAULT_GLOBALS),
150017
150253
  "f"
150018
150254
  );
150255
+ if (
150256
+ config.disableMemoizationForDebugging &&
150257
+ config.enableChangeDetectionForDebugging != null
150258
+ ) {
150259
+ CompilerError.throwInvalidConfig({
150260
+ reason: `Invalid environment config: the 'disableMemoizationForDebugging' and 'enableChangeDetectionForDebugging' options cannot be used together`,
150261
+ description: null,
150262
+ loc: null,
150263
+ suggestions: null,
150264
+ });
150265
+ }
150019
150266
  for (const [hookName, hook] of this.config.customHooks) {
150020
150267
  CompilerError.invariant(
150021
150268
  !__classPrivateFieldGet(this, _Environment_globals, "f").has(hookName),
@@ -150629,6 +150876,12 @@ class ReactiveFunctionVisitor {
150629
150876
  traverseScope(scope, state) {
150630
150877
  this.visitBlock(scope.instructions, state);
150631
150878
  }
150879
+ visitPrunedScope(scopeBlock, state) {
150880
+ this.traversePrunedScope(scopeBlock, state);
150881
+ }
150882
+ traversePrunedScope(scopeBlock, state) {
150883
+ this.visitBlock(scopeBlock.instructions, state);
150884
+ }
150632
150885
  visitBlock(block, state) {
150633
150886
  this.traverseBlock(block, state);
150634
150887
  }
@@ -150643,6 +150896,10 @@ class ReactiveFunctionVisitor {
150643
150896
  this.visitScope(instr, state);
150644
150897
  break;
150645
150898
  }
150899
+ case "pruned-scope": {
150900
+ this.visitPrunedScope(instr, state);
150901
+ break;
150902
+ }
150646
150903
  case "terminal": {
150647
150904
  this.visitTerminal(instr, state);
150648
150905
  break;
@@ -150692,6 +150949,10 @@ class ReactiveFunctionTransform extends ReactiveFunctionVisitor {
150692
150949
  transformed = this.transformScope(instr, state);
150693
150950
  break;
150694
150951
  }
150952
+ case "pruned-scope": {
150953
+ transformed = this.transformPrunedScope(instr, state);
150954
+ break;
150955
+ }
150695
150956
  case "terminal": {
150696
150957
  transformed = this.transformTerminal(instr, state);
150697
150958
  break;
@@ -150749,6 +151010,10 @@ class ReactiveFunctionTransform extends ReactiveFunctionVisitor {
150749
151010
  this.visitScope(scope, state);
150750
151011
  return { kind: "keep" };
150751
151012
  }
151013
+ transformPrunedScope(scope, state) {
151014
+ this.visitPrunedScope(scope, state);
151015
+ return { kind: "keep" };
151016
+ }
150752
151017
  transformValue(id, value, state) {
150753
151018
  this.visitValue(id, value, state);
150754
151019
  return { kind: "keep" };
@@ -151189,6 +151454,7 @@ function visitBlock(context, block) {
151189
151454
  context.append(stmt, stmt.label);
151190
151455
  break;
151191
151456
  }
151457
+ case "pruned-scope":
151192
151458
  case "scope": {
151193
151459
  CompilerError.invariant(false, {
151194
151460
  reason: "Expected the function to not have scopes already assigned",
@@ -153036,9 +153302,9 @@ function alignObjectMethodScopes(fn) {
153036
153302
  var _Context_blockScopes, _Context_unclosedScopes, _Context_seenScopes;
153037
153303
  function alignReactiveScopesToBlockScopes(fn) {
153038
153304
  const context = new Context$4();
153039
- visitReactiveFunction(fn, new Visitor$c(), context);
153305
+ visitReactiveFunction(fn, new Visitor$d(), context);
153040
153306
  }
153041
- let Visitor$c = class Visitor extends ReactiveFunctionVisitor {
153307
+ let Visitor$d = class Visitor extends ReactiveFunctionVisitor {
153042
153308
  visitID(id, state) {
153043
153309
  state.visitId(id);
153044
153310
  }
@@ -153188,9 +153454,9 @@ class CheckInstructionsAgainstScopesVisitor extends ReactiveFunctionVisitor {
153188
153454
  }
153189
153455
  }
153190
153456
  function assertWellFormedBreakTargets(fn) {
153191
- visitReactiveFunction(fn, new Visitor$b(), new Set());
153457
+ visitReactiveFunction(fn, new Visitor$c(), new Set());
153192
153458
  }
153193
- let Visitor$b = class Visitor extends ReactiveFunctionVisitor {
153459
+ let Visitor$c = class Visitor extends ReactiveFunctionVisitor {
153194
153460
  visitTerminal(stmt, seenLabels) {
153195
153461
  if (stmt.label != null) {
153196
153462
  seenLabels.add(stmt.label.id);
@@ -153895,6 +154161,7 @@ class Driver {
153895
154161
  }
153896
154162
  break;
153897
154163
  }
154164
+ case "pruned-scope":
153898
154165
  case "scope": {
153899
154166
  const fallthroughId = !this.cx.isScheduled(terminal.fallthrough)
153900
154167
  ? terminal.fallthrough
@@ -153915,7 +154182,7 @@ class Driver {
153915
154182
  }
153916
154183
  this.cx.unscheduleAll(scheduleIds);
153917
154184
  blockValue.push({
153918
- kind: "scope",
154185
+ kind: terminal.kind,
153919
154186
  instructions: block,
153920
154187
  scope: terminal.scope,
153921
154188
  });
@@ -154003,12 +154270,15 @@ class Driver {
154003
154270
  const instr = defaultBlock.instructions[0];
154004
154271
  let place = instr.lvalue;
154005
154272
  let value = instr.value;
154006
- if (instr.value.kind === "StoreLocal") {
154007
- place = instr.value.lvalue.place;
154273
+ if (
154274
+ value.kind === "StoreLocal" &&
154275
+ value.lvalue.place.identifier.name === null
154276
+ ) {
154277
+ place = value.lvalue.place;
154008
154278
  value = {
154009
154279
  kind: "LoadLocal",
154010
- place: instr.value.value,
154011
- loc: instr.value.value.loc,
154280
+ place: value.value,
154281
+ loc: value.value.loc,
154012
154282
  };
154013
154283
  }
154014
154284
  return {
@@ -154021,12 +154291,15 @@ class Driver {
154021
154291
  const instr = defaultBlock.instructions.at(-1);
154022
154292
  let place = instr.lvalue;
154023
154293
  let value = instr.value;
154024
- if (instr.value.kind === "StoreLocal") {
154025
- place = instr.value.lvalue.place;
154294
+ if (
154295
+ value.kind === "StoreLocal" &&
154296
+ value.lvalue.place.identifier.name === null
154297
+ ) {
154298
+ place = value.lvalue.place;
154026
154299
  value = {
154027
154300
  kind: "LoadLocal",
154028
- place: instr.value.value,
154029
- loc: instr.value.value.loc,
154301
+ place: value.value,
154302
+ loc: value.value.loc,
154030
154303
  };
154031
154304
  }
154032
154305
  const sequence = {
@@ -154494,11 +154767,16 @@ var GuardKind;
154494
154767
  GuardKind[(GuardKind["AllowHook"] = 2)] = "AllowHook";
154495
154768
  GuardKind[(GuardKind["DisallowHook"] = 3)] = "DisallowHook";
154496
154769
  })(GuardKind || (GuardKind = {}));
154497
- function memoizeFbtOperandsInSameScope(fn) {
154770
+ function memoizeFbtAndMacroOperandsInSameScope(fn) {
154771
+ var _a;
154772
+ const fbtMacroTags = new Set([
154773
+ ...FBT_TAGS,
154774
+ ...((_a = fn.env.config.customMacros) !== null && _a !== void 0 ? _a : []),
154775
+ ]);
154498
154776
  const fbtValues = new Set();
154499
154777
  while (true) {
154500
154778
  let size = fbtValues.size;
154501
- visit$1(fn, fbtValues);
154779
+ visit$1(fn, fbtMacroTags, fbtValues);
154502
154780
  if (size === fbtValues.size) {
154503
154781
  break;
154504
154782
  }
@@ -154506,28 +154784,28 @@ function memoizeFbtOperandsInSameScope(fn) {
154506
154784
  }
154507
154785
  const FBT_TAGS = new Set(["fbt", "fbt:param", "fbs", "fbs:param"]);
154508
154786
  const SINGLE_CHILD_FBT_TAGS = new Set(["fbt:param", "fbs:param"]);
154509
- function visit$1(fn, fbtValues) {
154787
+ function visit$1(fn, fbtMacroTags, fbtValues) {
154510
154788
  for (const [, block] of fn.body.blocks) {
154511
154789
  for (const instruction of block.instructions) {
154512
154790
  const { lvalue: lvalue, value: value } = instruction;
154513
154791
  if (lvalue === null) {
154514
- return;
154792
+ continue;
154515
154793
  }
154516
154794
  if (
154517
154795
  value.kind === "Primitive" &&
154518
154796
  typeof value.value === "string" &&
154519
- FBT_TAGS.has(value.value)
154797
+ fbtMacroTags.has(value.value)
154520
154798
  ) {
154521
154799
  fbtValues.add(lvalue.identifier.id);
154522
154800
  } else if (
154523
154801
  value.kind === "LoadGlobal" &&
154524
- FBT_TAGS.has(value.binding.name)
154802
+ fbtMacroTags.has(value.binding.name)
154525
154803
  ) {
154526
154804
  fbtValues.add(lvalue.identifier.id);
154527
154805
  } else if (isFbtCallExpression(fbtValues, value)) {
154528
154806
  const fbtScope = lvalue.identifier.scope;
154529
154807
  if (fbtScope === null) {
154530
- return;
154808
+ continue;
154531
154809
  }
154532
154810
  for (const operand of eachReactiveValueOperand(value)) {
154533
154811
  operand.identifier.scope = fbtScope;
@@ -154537,14 +154815,15 @@ function visit$1(fn, fbtValues) {
154537
154815
  operand.identifier.mutableRange.start
154538
154816
  )
154539
154817
  );
154818
+ fbtValues.add(operand.identifier.id);
154540
154819
  }
154541
154820
  } else if (
154542
- isFbtJsxExpression(fbtValues, value) ||
154821
+ isFbtJsxExpression(fbtMacroTags, fbtValues, value) ||
154543
154822
  isFbtJsxChild(fbtValues, lvalue, value)
154544
154823
  ) {
154545
154824
  const fbtScope = lvalue.identifier.scope;
154546
154825
  if (fbtScope === null) {
154547
- return;
154826
+ continue;
154548
154827
  }
154549
154828
  for (const operand of eachReactiveValueOperand(value)) {
154550
154829
  operand.identifier.scope = fbtScope;
@@ -154556,6 +154835,26 @@ function visit$1(fn, fbtValues) {
154556
154835
  );
154557
154836
  fbtValues.add(operand.identifier.id);
154558
154837
  }
154838
+ } else if (fbtValues.has(lvalue.identifier.id)) {
154839
+ const fbtScope = lvalue.identifier.scope;
154840
+ if (fbtScope === null) {
154841
+ return;
154842
+ }
154843
+ for (const operand of eachReactiveValueOperand(value)) {
154844
+ if (
154845
+ operand.identifier.name !== null &&
154846
+ operand.identifier.name.kind === "named"
154847
+ ) {
154848
+ continue;
154849
+ }
154850
+ operand.identifier.scope = fbtScope;
154851
+ fbtScope.range.start = makeInstructionId(
154852
+ Math.min(
154853
+ fbtScope.range.start,
154854
+ operand.identifier.mutableRange.start
154855
+ )
154856
+ );
154857
+ }
154559
154858
  }
154560
154859
  }
154561
154860
  }
@@ -154565,12 +154864,12 @@ function isFbtCallExpression(fbtValues, value) {
154565
154864
  value.kind === "CallExpression" && fbtValues.has(value.callee.identifier.id)
154566
154865
  );
154567
154866
  }
154568
- function isFbtJsxExpression(fbtValues, value) {
154867
+ function isFbtJsxExpression(fbtMacroTags, fbtValues, value) {
154569
154868
  return (
154570
154869
  value.kind === "JsxExpression" &&
154571
154870
  ((value.tag.kind === "Identifier" &&
154572
154871
  fbtValues.has(value.tag.identifier.id)) ||
154573
- (value.tag.kind === "BuiltinTag" && FBT_TAGS.has(value.tag.name)))
154872
+ (value.tag.kind === "BuiltinTag" && fbtMacroTags.has(value.tag.name)))
154574
154873
  );
154575
154874
  }
154576
154875
  function isFbtJsxChild(fbtValues, lvalue, value) {
@@ -154591,13 +154890,13 @@ function codegenFunction(fn, uniqueIdentifiers) {
154591
154890
  uniqueIdentifiers,
154592
154891
  null
154593
154892
  );
154594
- let hotModuleReloadState = null;
154893
+ let fastRefreshState = null;
154595
154894
  if (
154596
154895
  fn.env.config.enableResetCacheOnSourceFileChanges &&
154597
154896
  fn.env.code !== null
154598
154897
  ) {
154599
154898
  const hash = crypto$2.createHmac("sha256", fn.env.code).digest("hex");
154600
- hotModuleReloadState = { cacheIndex: cx.nextCacheIndex, hash: hash };
154899
+ fastRefreshState = { cacheIndex: cx.nextCacheIndex, hash: hash };
154601
154900
  }
154602
154901
  const compileResult = codegenReactiveFunction(cx, fn);
154603
154902
  if (compileResult.isErr()) {
@@ -154629,7 +154928,7 @@ function codegenFunction(fn, uniqueIdentifiers) {
154629
154928
  ),
154630
154929
  ])
154631
154930
  );
154632
- if (hotModuleReloadState !== null) {
154931
+ if (fastRefreshState !== null) {
154633
154932
  const index = cx.synthesizeName("$i");
154634
154933
  preface.push(
154635
154934
  t__namespace.ifStatement(
@@ -154637,10 +154936,10 @@ function codegenFunction(fn, uniqueIdentifiers) {
154637
154936
  "!==",
154638
154937
  t__namespace.memberExpression(
154639
154938
  t__namespace.identifier(cx.synthesizeName("$")),
154640
- t__namespace.numericLiteral(hotModuleReloadState.cacheIndex),
154939
+ t__namespace.numericLiteral(fastRefreshState.cacheIndex),
154641
154940
  true
154642
154941
  ),
154643
- t__namespace.stringLiteral(hotModuleReloadState.hash)
154942
+ t__namespace.stringLiteral(fastRefreshState.hash)
154644
154943
  ),
154645
154944
  t__namespace.blockStatement([
154646
154945
  t__namespace.forStatement(
@@ -154685,10 +154984,10 @@ function codegenFunction(fn, uniqueIdentifiers) {
154685
154984
  "=",
154686
154985
  t__namespace.memberExpression(
154687
154986
  t__namespace.identifier(cx.synthesizeName("$")),
154688
- t__namespace.numericLiteral(hotModuleReloadState.cacheIndex),
154987
+ t__namespace.numericLiteral(fastRefreshState.cacheIndex),
154689
154988
  true
154690
154989
  ),
154691
- t__namespace.stringLiteral(hotModuleReloadState.hash)
154990
+ t__namespace.stringLiteral(fastRefreshState.hash)
154692
154991
  )
154693
154992
  ),
154694
154993
  ])
@@ -154763,7 +155062,7 @@ function codegenReactiveFunction(cx, fn) {
154763
155062
  if (cx.errors.hasErrors()) {
154764
155063
  return Err(cx.errors);
154765
155064
  }
154766
- const countMemoBlockVisitor = new CountMemoBlockVisitor();
155065
+ const countMemoBlockVisitor = new CountMemoBlockVisitor(fn.env);
154767
155066
  visitReactiveFunction(fn, countMemoBlockVisitor, undefined);
154768
155067
  return Ok({
154769
155068
  type: "CodegenFunction",
@@ -154774,17 +155073,30 @@ function codegenReactiveFunction(cx, fn) {
154774
155073
  generator: fn.generator,
154775
155074
  async: fn.async,
154776
155075
  memoSlotsUsed: cx.nextCacheIndex,
154777
- memoBlocks: countMemoBlockVisitor.count,
155076
+ memoBlocks: countMemoBlockVisitor.memoBlocks,
155077
+ memoValues: countMemoBlockVisitor.memoValues,
155078
+ prunedMemoBlocks: countMemoBlockVisitor.prunedMemoBlocks,
155079
+ prunedMemoValues: countMemoBlockVisitor.prunedMemoValues,
154778
155080
  });
154779
155081
  }
154780
155082
  class CountMemoBlockVisitor extends ReactiveFunctionVisitor {
154781
- constructor() {
154782
- super(...arguments);
154783
- this.count = 0;
155083
+ constructor(env) {
155084
+ super();
155085
+ this.memoBlocks = 0;
155086
+ this.memoValues = 0;
155087
+ this.prunedMemoBlocks = 0;
155088
+ this.prunedMemoValues = 0;
155089
+ this.env = env;
154784
155090
  }
154785
- visitScope(scope, state) {
154786
- this.count += 1;
154787
- this.traverseScope(scope, state);
155091
+ visitScope(scopeBlock, state) {
155092
+ this.memoBlocks += 1;
155093
+ this.memoValues += scopeBlock.scope.declarations.size;
155094
+ this.traverseScope(scopeBlock, state);
155095
+ }
155096
+ visitPrunedScope(scopeBlock, state) {
155097
+ this.prunedMemoBlocks += 1;
155098
+ this.prunedMemoValues += scopeBlock.scope.declarations.size;
155099
+ this.traversePrunedScope(scopeBlock, state);
154788
155100
  }
154789
155101
  }
154790
155102
  function convertParameter(param) {
@@ -154875,6 +155187,11 @@ function codegenBlockNoReset(cx, block) {
154875
155187
  }
154876
155188
  break;
154877
155189
  }
155190
+ case "pruned-scope": {
155191
+ const scopeBlock = codegenBlockNoReset(cx, item.instructions);
155192
+ statements.push(...scopeBlock.body);
155193
+ break;
155194
+ }
154878
155195
  case "scope": {
154879
155196
  const temp = new Map(cx.temp);
154880
155197
  codegenReactiveScope(cx, statements, item.scope, item.instructions);
@@ -154930,6 +155247,7 @@ function wrapCacheDep(cx, value) {
154930
155247
  function codegenReactiveScope(cx, statements, scope, block) {
154931
155248
  const cacheStoreStatements = [];
154932
155249
  const cacheLoadStatements = [];
155250
+ const cacheLoads = [];
154933
155251
  const changeExpressions = [];
154934
155252
  const changeExpressionComments = [];
154935
155253
  const outputComments = [];
@@ -154979,8 +155297,8 @@ function codegenReactiveScope(cx, statements, scope, block) {
154979
155297
  firstOutputIndex = index;
154980
155298
  }
154981
155299
  CompilerError.invariant(identifier.name != null, {
154982
- reason: `Expected identifier '@${identifier.id}' to be named`,
154983
- description: null,
155300
+ reason: `Expected scope declaration identifier to be named`,
155301
+ description: `Declaration \`${printIdentifier(identifier)}\` is unnamed in scope @${scope.id}`,
154984
155302
  loc: null,
154985
155303
  suggestions: null,
154986
155304
  });
@@ -154993,32 +155311,11 @@ function codegenReactiveScope(cx, statements, scope, block) {
154993
155311
  ])
154994
155312
  );
154995
155313
  }
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
- );
155314
+ cacheLoads.push({
155315
+ name: name,
155316
+ index: index,
155317
+ value: wrapCacheDep(cx, name),
155318
+ });
155022
155319
  cx.declare(identifier);
155023
155320
  }
155024
155321
  for (const reassignment of scope.reassignments) {
@@ -155028,32 +155325,11 @@ function codegenReactiveScope(cx, statements, scope, block) {
155028
155325
  }
155029
155326
  const name = convertIdentifier(reassignment);
155030
155327
  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
- );
155328
+ cacheLoads.push({
155329
+ name: name,
155330
+ index: index,
155331
+ value: wrapCacheDep(cx, name),
155332
+ });
155057
155333
  }
155058
155334
  let testCondition = changeExpressions.reduce((acc, ident) => {
155059
155335
  if (acc == null) {
@@ -155084,14 +155360,153 @@ function codegenReactiveScope(cx, statements, scope, block) {
155084
155360
  )
155085
155361
  );
155086
155362
  }
155363
+ if (cx.env.config.disableMemoizationForDebugging) {
155364
+ CompilerError.invariant(
155365
+ cx.env.config.enableChangeDetectionForDebugging == null,
155366
+ {
155367
+ reason: `Expected to not have both change detection enabled and memoization disabled`,
155368
+ description: `Incompatible config options`,
155369
+ loc: null,
155370
+ }
155371
+ );
155372
+ testCondition = t__namespace.logicalExpression(
155373
+ "||",
155374
+ testCondition,
155375
+ t__namespace.booleanLiteral(true)
155376
+ );
155377
+ }
155087
155378
  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
- );
155379
+ let memoStatement;
155380
+ if (
155381
+ cx.env.config.enableChangeDetectionForDebugging != null &&
155382
+ changeExpressions.length > 0
155383
+ ) {
155384
+ const loc =
155385
+ typeof scope.loc === "symbol"
155386
+ ? "unknown location"
155387
+ : `(${scope.loc.start.line}:${scope.loc.end.line})`;
155388
+ const detectionFunction =
155389
+ cx.env.config.enableChangeDetectionForDebugging.importSpecifierName;
155390
+ const cacheLoadOldValueStatements = [];
155391
+ const changeDetectionStatements = [];
155392
+ const idempotenceDetectionStatements = [];
155393
+ for (const { name: name, index: index, value: value } of cacheLoads) {
155394
+ const loadName = cx.synthesizeName(`old$${name.name}`);
155395
+ const slot = t__namespace.memberExpression(
155396
+ t__namespace.identifier(cx.synthesizeName("$")),
155397
+ t__namespace.numericLiteral(index),
155398
+ true
155399
+ );
155400
+ cacheStoreStatements.push(
155401
+ t__namespace.expressionStatement(
155402
+ t__namespace.assignmentExpression("=", slot, value)
155403
+ )
155404
+ );
155405
+ cacheLoadOldValueStatements.push(
155406
+ t__namespace.variableDeclaration("let", [
155407
+ t__namespace.variableDeclarator(
155408
+ t__namespace.identifier(loadName),
155409
+ slot
155410
+ ),
155411
+ ])
155412
+ );
155413
+ changeDetectionStatements.push(
155414
+ t__namespace.expressionStatement(
155415
+ t__namespace.callExpression(
155416
+ t__namespace.identifier(detectionFunction),
155417
+ [
155418
+ t__namespace.identifier(loadName),
155419
+ name,
155420
+ t__namespace.stringLiteral(name.name),
155421
+ t__namespace.stringLiteral(cx.fnName),
155422
+ t__namespace.stringLiteral("cached"),
155423
+ t__namespace.stringLiteral(loc),
155424
+ ]
155425
+ )
155426
+ )
155427
+ );
155428
+ idempotenceDetectionStatements.push(
155429
+ t__namespace.expressionStatement(
155430
+ t__namespace.callExpression(
155431
+ t__namespace.identifier(detectionFunction),
155432
+ [
155433
+ slot,
155434
+ name,
155435
+ t__namespace.stringLiteral(name.name),
155436
+ t__namespace.stringLiteral(cx.fnName),
155437
+ t__namespace.stringLiteral("recomputed"),
155438
+ t__namespace.stringLiteral(loc),
155439
+ ]
155440
+ )
155441
+ )
155442
+ );
155443
+ idempotenceDetectionStatements.push(
155444
+ t__namespace.expressionStatement(
155445
+ t__namespace.assignmentExpression("=", name, slot)
155446
+ )
155447
+ );
155448
+ }
155449
+ const condition = cx.synthesizeName("condition");
155450
+ memoStatement = t__namespace.blockStatement([
155451
+ ...computationBlock.body,
155452
+ t__namespace.variableDeclaration("let", [
155453
+ t__namespace.variableDeclarator(
155454
+ t__namespace.identifier(condition),
155455
+ testCondition
155456
+ ),
155457
+ ]),
155458
+ t__namespace.ifStatement(
155459
+ t__namespace.unaryExpression("!", t__namespace.identifier(condition)),
155460
+ t__namespace.blockStatement([
155461
+ ...cacheLoadOldValueStatements,
155462
+ ...changeDetectionStatements,
155463
+ ])
155464
+ ),
155465
+ ...cacheStoreStatements,
155466
+ t__namespace.ifStatement(
155467
+ t__namespace.identifier(condition),
155468
+ t__namespace.blockStatement([
155469
+ ...computationBlock.body,
155470
+ ...idempotenceDetectionStatements,
155471
+ ])
155472
+ ),
155473
+ ]);
155474
+ } else {
155475
+ for (const { name: name, index: index, value: value } of cacheLoads) {
155476
+ cacheStoreStatements.push(
155477
+ t__namespace.expressionStatement(
155478
+ t__namespace.assignmentExpression(
155479
+ "=",
155480
+ t__namespace.memberExpression(
155481
+ t__namespace.identifier(cx.synthesizeName("$")),
155482
+ t__namespace.numericLiteral(index),
155483
+ true
155484
+ ),
155485
+ value
155486
+ )
155487
+ )
155488
+ );
155489
+ cacheLoadStatements.push(
155490
+ t__namespace.expressionStatement(
155491
+ t__namespace.assignmentExpression(
155492
+ "=",
155493
+ name,
155494
+ t__namespace.memberExpression(
155495
+ t__namespace.identifier(cx.synthesizeName("$")),
155496
+ t__namespace.numericLiteral(index),
155497
+ true
155498
+ )
155499
+ )
155500
+ )
155501
+ );
155502
+ }
155503
+ computationBlock.body.push(...cacheStoreStatements);
155504
+ memoStatement = t__namespace.ifStatement(
155505
+ testCondition,
155506
+ computationBlock,
155507
+ t__namespace.blockStatement(cacheLoadStatements)
155508
+ );
155509
+ }
155095
155510
  if (cx.env.config.enableMemoizationComments) {
155096
155511
  if (changeExpressionComments.length) {
155097
155512
  t__namespace.addComment(
@@ -155128,9 +155543,9 @@ function codegenReactiveScope(cx, statements, scope, block) {
155128
155543
  true
155129
155544
  );
155130
155545
  }
155131
- if (memoBlock.body.length > 0) {
155546
+ if (cacheLoadStatements.length > 0) {
155132
155547
  t__namespace.addComment(
155133
- memoBlock.body[0],
155548
+ cacheLoadStatements[0],
155134
155549
  "leading",
155135
155550
  ` Inputs did not change, use cached value`,
155136
155551
  true
@@ -156328,6 +156743,13 @@ function codegenInstructionValue(cx, instrValue) {
156328
156743
  value = t__namespace.regExpLiteral(instrValue.pattern, instrValue.flags);
156329
156744
  break;
156330
156745
  }
156746
+ case "MetaProperty": {
156747
+ value = t__namespace.metaProperty(
156748
+ t__namespace.identifier(instrValue.meta),
156749
+ t__namespace.identifier(instrValue.property)
156750
+ );
156751
+ break;
156752
+ }
156331
156753
  case "Await": {
156332
156754
  value = t__namespace.awaitExpression(
156333
156755
  codegenPlaceToExpression(cx, instrValue.value)
@@ -156412,7 +156834,8 @@ function codegenInstructionValue(cx, instrValue) {
156412
156834
  }
156413
156835
  return value;
156414
156836
  }
156415
- const STRING_REQUIRES_EXPR_CONTAINER_PATTERN = /[\u{0080}-\u{FFFF}]|"/u;
156837
+ const STRING_REQUIRES_EXPR_CONTAINER_PATTERN =
156838
+ /[\u{0000}-\u{001F}|\u{007F}|\u{0080}-\u{FFFF}]|"/u;
156416
156839
  function codegenJsxAttribute(cx, attribute) {
156417
156840
  switch (attribute.kind) {
156418
156841
  case "JsxAttribute": {
@@ -156651,7 +157074,7 @@ function convertIdentifier(identifier) {
156651
157074
  }
156652
157075
  function extractScopeDeclarationsFromDestructuring(fn) {
156653
157076
  const state = new State$2(fn.env);
156654
- visitReactiveFunction(fn, new Visitor$a(), state);
157077
+ visitReactiveFunction(fn, new Visitor$b(), state);
156655
157078
  }
156656
157079
  let State$2 = class State {
156657
157080
  constructor(env) {
@@ -156659,7 +157082,7 @@ let State$2 = class State {
156659
157082
  this.env = env;
156660
157083
  }
156661
157084
  };
156662
- let Visitor$a = class Visitor extends ReactiveFunctionTransform {
157085
+ let Visitor$b = class Visitor extends ReactiveFunctionTransform {
156663
157086
  visitScope(scope, state) {
156664
157087
  for (const [, declaration] of scope.scope.declarations) {
156665
157088
  state.declared.add(declaration.identifier.id);
@@ -156741,7 +157164,14 @@ let Transform$6 = class Transform extends ReactiveFunctionTransform {
156741
157164
  transformScope(scope, isWithinLoop) {
156742
157165
  this.visitScope(scope, isWithinLoop);
156743
157166
  if (isWithinLoop) {
156744
- return { kind: "replace-many", value: scope.instructions };
157167
+ return {
157168
+ kind: "replace",
157169
+ value: {
157170
+ kind: "pruned-scope",
157171
+ scope: scope.scope,
157172
+ instructions: scope.instructions,
157173
+ },
157174
+ };
156745
157175
  } else {
156746
157176
  return { kind: "keep" };
156747
157177
  }
@@ -156785,7 +157215,17 @@ let Transform$5 = class Transform extends ReactiveFunctionTransform {
156785
157215
  this.visitScope(scope, innerState);
156786
157216
  outerState.hasHook || (outerState.hasHook = innerState.hasHook);
156787
157217
  if (innerState.hasHook) {
156788
- return { kind: "replace-many", value: scope.instructions };
157218
+ if (scope.instructions.length === 1) {
157219
+ return { kind: "replace-many", value: scope.instructions };
157220
+ }
157221
+ return {
157222
+ kind: "replace",
157223
+ value: {
157224
+ kind: "pruned-scope",
157225
+ scope: scope.scope,
157226
+ instructions: scope.instructions,
157227
+ },
157228
+ };
156789
157229
  } else {
156790
157230
  return { kind: "keep" };
156791
157231
  }
@@ -156816,10 +157256,10 @@ let Transform$5 = class Transform extends ReactiveFunctionTransform {
156816
157256
  };
156817
157257
  function mergeOverlappingReactiveScopes(fn) {
156818
157258
  const context = new Context$1();
156819
- visitReactiveFunction(fn, new Visitor$9(), context);
157259
+ visitReactiveFunction(fn, new Visitor$a(), context);
156820
157260
  context.complete();
156821
157261
  }
156822
- let Visitor$9 = class Visitor extends ReactiveFunctionVisitor {
157262
+ let Visitor$a = class Visitor extends ReactiveFunctionVisitor {
156823
157263
  visitID(id, state) {
156824
157264
  state.visitId(id);
156825
157265
  }
@@ -157011,13 +157451,26 @@ let Transform$4 = class Transform extends ReactiveFunctionTransform {
157011
157451
  }
157012
157452
  break;
157013
157453
  }
157454
+ case "pruned-scope": {
157455
+ if (current !== null) {
157456
+ log$1(
157457
+ `Reset scope @${current.block.scope.id} from pruned scope @${instr.scope.id}`
157458
+ );
157459
+ reset();
157460
+ }
157461
+ break;
157462
+ }
157014
157463
  case "instruction": {
157015
157464
  switch (instr.instruction.value.kind) {
157465
+ case "BinaryExpression":
157016
157466
  case "ComputedLoad":
157017
157467
  case "JSXText":
157468
+ case "LoadGlobal":
157018
157469
  case "LoadLocal":
157019
157470
  case "Primitive":
157020
- case "PropertyLoad": {
157471
+ case "PropertyLoad":
157472
+ case "TemplateLiteral":
157473
+ case "UnaryExpression": {
157021
157474
  if (current !== null && instr.instruction.lvalue !== null) {
157022
157475
  current.lvalues.add(instr.instruction.lvalue.identifier.id);
157023
157476
  }
@@ -157258,21 +157711,36 @@ function scopeIsEligibleForMerging(scopeBlock) {
157258
157711
  isAlwaysInvalidatingType(decl.identifier.type)
157259
157712
  );
157260
157713
  }
157261
- let Visitor$8 = class Visitor extends ReactiveFunctionVisitor {
157262
- visitScope(block, state) {
157263
- this.traverseScope(block, state);
157264
- for (const dep of block.scope.dependencies) {
157714
+ let Visitor$9 = class Visitor extends ReactiveFunctionVisitor {
157715
+ visitScope(scopeBlock, state) {
157716
+ this.traverseScope(scopeBlock, state);
157717
+ for (const dep of scopeBlock.scope.dependencies) {
157265
157718
  const { identifier: identifier } = dep;
157266
157719
  if (identifier.name == null) {
157267
157720
  promoteIdentifier(identifier, state);
157268
157721
  }
157269
157722
  }
157270
- for (const [, declaration] of block.scope.declarations) {
157723
+ for (const [, declaration] of scopeBlock.scope.declarations) {
157271
157724
  if (declaration.identifier.name == null) {
157272
157725
  promoteIdentifier(declaration.identifier, state);
157273
157726
  }
157274
157727
  }
157275
157728
  }
157729
+ visitPrunedScope(scopeBlock, state) {
157730
+ var _a;
157731
+ this.traversePrunedScope(scopeBlock, state);
157732
+ for (const [, declaration] of scopeBlock.scope.declarations) {
157733
+ if (
157734
+ declaration.identifier.name == null &&
157735
+ ((_a = state.pruned.get(declaration.identifier.id)) === null ||
157736
+ _a === void 0
157737
+ ? void 0
157738
+ : _a.usedOutsideScope) === true
157739
+ ) {
157740
+ promoteIdentifier(declaration.identifier, state);
157741
+ }
157742
+ }
157743
+ }
157276
157744
  visitParam(place, state) {
157277
157745
  if (place.identifier.name === null) {
157278
157746
  promoteIdentifier(place.identifier, state);
@@ -157294,25 +157762,52 @@ let Visitor$8 = class Visitor extends ReactiveFunctionVisitor {
157294
157762
  visitReactiveFunction(fn, this, state);
157295
157763
  }
157296
157764
  };
157297
- class CollectJsxTagsVisitor extends ReactiveFunctionVisitor {
157765
+ class CollectPromotableTemporaries extends ReactiveFunctionVisitor {
157766
+ constructor() {
157767
+ super(...arguments);
157768
+ this.activeScopes = [];
157769
+ }
157770
+ visitPlace(_id, place, state) {
157771
+ if (
157772
+ this.activeScopes.length !== 0 &&
157773
+ state.pruned.has(place.identifier.id)
157774
+ ) {
157775
+ const prunedPlace = state.pruned.get(place.identifier.id);
157776
+ if (prunedPlace.activeScopes.indexOf(this.activeScopes.at(-1)) === -1) {
157777
+ prunedPlace.usedOutsideScope = true;
157778
+ }
157779
+ }
157780
+ }
157298
157781
  visitValue(id, value, state) {
157299
157782
  this.traverseValue(id, value, state);
157300
157783
  if (value.kind === "JsxExpression" && value.tag.kind === "Identifier") {
157301
- state.add(value.tag.identifier.id);
157784
+ state.tags.add(value.tag.identifier.id);
157785
+ }
157786
+ }
157787
+ visitPrunedScope(scopeBlock, state) {
157788
+ for (const [id] of scopeBlock.scope.declarations) {
157789
+ state.pruned.set(id, {
157790
+ activeScopes: [...this.activeScopes],
157791
+ usedOutsideScope: false,
157792
+ });
157302
157793
  }
157303
157794
  }
157795
+ visitScope(scopeBlock, state) {
157796
+ this.activeScopes.push(scopeBlock.scope.id);
157797
+ this.traverseScope(scopeBlock, state);
157798
+ this.activeScopes.pop();
157799
+ }
157304
157800
  }
157305
157801
  function promoteUsedTemporaries(fn) {
157306
- const tags = new Set();
157307
- visitReactiveFunction(fn, new CollectJsxTagsVisitor(), tags);
157308
- const state = { tags: tags };
157802
+ const state = { tags: new Set(), pruned: new Map() };
157803
+ visitReactiveFunction(fn, new CollectPromotableTemporaries(), state);
157309
157804
  for (const operand of fn.params) {
157310
157805
  const place = operand.kind === "Identifier" ? operand : operand.place;
157311
157806
  if (place.identifier.name === null) {
157312
157807
  promoteIdentifier(place.identifier, state);
157313
157808
  }
157314
157809
  }
157315
- visitReactiveFunction(fn, new Visitor$8(), state);
157810
+ visitReactiveFunction(fn, new Visitor$9(), state);
157316
157811
  }
157317
157812
  function promoteIdentifier(identifier, state) {
157318
157813
  CompilerError.invariant(identifier.name === null, {
@@ -157355,10 +157850,10 @@ let Transform$3 = class Transform extends ReactiveFunctionTransform {
157355
157850
  });
157356
157851
  const instructions = scopeBlock.instructions;
157357
157852
  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);
157853
+ const sentinelTemp = createTemporaryPlace(this.env, loc);
157854
+ const symbolTemp = createTemporaryPlace(this.env, loc);
157855
+ const forTemp = createTemporaryPlace(this.env, loc);
157856
+ const argTemp = createTemporaryPlace(this.env, loc);
157362
157857
  scopeBlock.instructions = [
157363
157858
  {
157364
157859
  kind: "instruction",
@@ -157462,7 +157957,7 @@ let Transform$3 = class Transform extends ReactiveFunctionTransform {
157462
157957
  if (state.earlyReturnValue !== null) {
157463
157958
  earlyReturnValue = state.earlyReturnValue;
157464
157959
  } else {
157465
- const identifier = createTemporaryPlace(this.env).identifier;
157960
+ const identifier = createTemporaryPlace(this.env, loc).identifier;
157466
157961
  promoteTemporary(identifier);
157467
157962
  earlyReturnValue = {
157468
157963
  label: this.env.nextBlockId,
@@ -158592,6 +159087,11 @@ class PropagationVisitor extends ReactiveFunctionVisitor {
158592
159087
  });
158593
159088
  scope.scope.dependencies = scopeDependencies;
158594
159089
  }
159090
+ visitPrunedScope(scopeBlock, context) {
159091
+ context.enter(scopeBlock.scope, () => {
159092
+ this.visitBlock(scopeBlock.instructions, context);
159093
+ });
159094
+ }
158595
159095
  visitInstruction(instruction, context) {
158596
159096
  const { id: id, value: value, lvalue: lvalue } = instruction;
158597
159097
  this.visitInstructionValue(context, id, value, lvalue);
@@ -158888,9 +159388,9 @@ class PropagationVisitor extends ReactiveFunctionVisitor {
158888
159388
  }
158889
159389
  function pruneHoistedContexts(fn) {
158890
159390
  const hoistedIdentifiers = new Set();
158891
- visitReactiveFunction(fn, new Visitor$7(), hoistedIdentifiers);
159391
+ visitReactiveFunction(fn, new Visitor$8(), hoistedIdentifiers);
158892
159392
  }
158893
- let Visitor$7 = class Visitor extends ReactiveFunctionTransform {
159393
+ let Visitor$8 = class Visitor extends ReactiveFunctionTransform {
158894
159394
  transformInstruction(instruction, state) {
158895
159395
  this.visitInstruction(instruction, state);
158896
159396
  if (
@@ -158926,12 +159426,12 @@ let Visitor$7 = class Visitor extends ReactiveFunctionTransform {
158926
159426
  };
158927
159427
  function validateMemoizedEffectDependencies(fn) {
158928
159428
  const errors = new CompilerError();
158929
- visitReactiveFunction(fn, new Visitor$6(), errors);
159429
+ visitReactiveFunction(fn, new Visitor$7(), errors);
158930
159430
  if (errors.hasErrors()) {
158931
159431
  throw errors;
158932
159432
  }
158933
159433
  }
158934
- let Visitor$6 = class Visitor extends ReactiveFunctionVisitor {
159434
+ let Visitor$7 = class Visitor extends ReactiveFunctionVisitor {
158935
159435
  constructor() {
158936
159436
  super(...arguments);
158937
159437
  this.scopes = new Set();
@@ -159067,7 +159567,9 @@ function inferReferenceEffects(fn, options = { isFunctionExpression: false }) {
159067
159567
  let queuedState = queuedStates.get(blockId);
159068
159568
  if (queuedState != null) {
159069
159569
  state =
159070
- (_a = queuedState.merge(state)) !== null && _a !== void 0 ? _a : state;
159570
+ (_a = queuedState.merge(state)) !== null && _a !== void 0
159571
+ ? _a
159572
+ : queuedState;
159071
159573
  queuedStates.set(blockId, state);
159072
159574
  } else {
159073
159575
  const prevState = statesByBlock.get(blockId);
@@ -159352,7 +159854,8 @@ class InferenceState {
159352
159854
  break;
159353
159855
  }
159354
159856
  case exports.Effect.Mutate: {
159355
- if (valueKind.kind === exports.ValueKind.Context) {
159857
+ if (isRefValueType(place.identifier) || isUseRefType(place.identifier));
159858
+ else if (valueKind.kind === exports.ValueKind.Context) {
159356
159859
  functionEffect = {
159357
159860
  kind: "ContextMutation",
159358
159861
  loc: place.loc,
@@ -159390,7 +159893,8 @@ class InferenceState {
159390
159893
  break;
159391
159894
  }
159392
159895
  case exports.Effect.Store: {
159393
- if (valueKind.kind === exports.ValueKind.Context) {
159896
+ if (isRefValueType(place.identifier) || isUseRefType(place.identifier));
159897
+ else if (valueKind.kind === exports.ValueKind.Context) {
159394
159898
  functionEffect = {
159395
159899
  kind: "ContextMutation",
159396
159900
  loc: place.loc,
@@ -159608,7 +160112,7 @@ class InferenceState {
159608
160112
  _InferenceState_variables,
159609
160113
  "f"
159610
160114
  )) {
159611
- result.variables[variable] = [...values].map(identify);
160115
+ result.variables[`$${variable}`] = [...values].map(identify);
159612
160116
  }
159613
160117
  return result;
159614
160118
  }
@@ -159857,16 +160361,55 @@ function inferBlock(env, functionEffects, state, block) {
159857
160361
  break;
159858
160362
  }
159859
160363
  case "JsxExpression": {
159860
- valueKind = {
160364
+ if (instrValue.tag.kind === "Identifier") {
160365
+ state.referenceAndRecordEffects(
160366
+ instrValue.tag,
160367
+ exports.Effect.Freeze,
160368
+ ValueReason.JsxCaptured,
160369
+ functionEffects
160370
+ );
160371
+ }
160372
+ if (instrValue.children !== null) {
160373
+ for (const child of instrValue.children) {
160374
+ state.referenceAndRecordEffects(
160375
+ child,
160376
+ exports.Effect.Freeze,
160377
+ ValueReason.JsxCaptured,
160378
+ functionEffects
160379
+ );
160380
+ }
160381
+ }
160382
+ for (const attr of instrValue.props) {
160383
+ if (attr.kind === "JsxSpreadAttribute") {
160384
+ state.referenceAndRecordEffects(
160385
+ attr.argument,
160386
+ exports.Effect.Freeze,
160387
+ ValueReason.JsxCaptured,
160388
+ functionEffects
160389
+ );
160390
+ } else {
160391
+ const propEffects = [];
160392
+ state.referenceAndRecordEffects(
160393
+ attr.place,
160394
+ exports.Effect.Freeze,
160395
+ ValueReason.JsxCaptured,
160396
+ propEffects
160397
+ );
160398
+ functionEffects.push(
160399
+ ...propEffects.filter(
160400
+ (propEffect) => propEffect.kind !== "GlobalMutation"
160401
+ )
160402
+ );
160403
+ }
160404
+ }
160405
+ state.initialize(instrValue, {
159861
160406
  kind: exports.ValueKind.Frozen,
159862
160407
  reason: new Set([ValueReason.Other]),
159863
160408
  context: new Set(),
159864
- };
159865
- effect = {
159866
- kind: exports.Effect.Freeze,
159867
- reason: ValueReason.JsxCaptured,
159868
- };
159869
- break;
160409
+ });
160410
+ state.define(instr.lvalue, instrValue);
160411
+ instr.lvalue.effect = exports.Effect.ConditionallyMutate;
160412
+ continue;
159870
160413
  }
159871
160414
  case "JsxFragment": {
159872
160415
  valueKind = {
@@ -159910,6 +160453,17 @@ function inferBlock(env, functionEffects, state, block) {
159910
160453
  };
159911
160454
  break;
159912
160455
  }
160456
+ case "MetaProperty": {
160457
+ if (instrValue.meta !== "import" || instrValue.property !== "meta") {
160458
+ continue;
160459
+ }
160460
+ valueKind = {
160461
+ kind: exports.ValueKind.Global,
160462
+ reason: new Set([ValueReason.Global]),
160463
+ context: new Set(),
160464
+ };
160465
+ break;
160466
+ }
159913
160467
  case "LoadGlobal":
159914
160468
  valueKind = {
159915
160469
  kind: exports.ValueKind.Global,
@@ -160662,6 +161216,8 @@ function getWriteErrorReason(abstractValue) {
160662
161216
  return "Mutating component props or hook arguments is not allowed. Consider using a local variable instead";
160663
161217
  } else if (abstractValue.reason.has(ValueReason.State)) {
160664
161218
  return "Mutating a value returned from 'useState()', which should not be mutated. Use the setter function to update instead";
161219
+ } else if (abstractValue.reason.has(ValueReason.ReducerState)) {
161220
+ return "Mutating a value returned from 'useReducer()', which should not be mutated. Use the dispatch function to update instead";
160665
161221
  } else {
160666
161222
  return "This mutates a variable that React considers immutable";
160667
161223
  }
@@ -160880,6 +161436,7 @@ function computeMemoizationInputs(env, value, lvalue, options) {
160880
161436
  case "ComputedDelete":
160881
161437
  case "PropertyDelete":
160882
161438
  case "LoadGlobal":
161439
+ case "MetaProperty":
160883
161440
  case "TemplateLiteral":
160884
161441
  case "Primitive":
160885
161442
  case "JSXText":
@@ -161285,7 +161842,7 @@ class PruneScopesTransform extends ReactiveFunctionTransform {
161285
161842
  return { kind: "keep" };
161286
161843
  }
161287
161844
  }
161288
- let Visitor$5 = class Visitor extends ReactiveFunctionVisitor {
161845
+ let Visitor$6 = class Visitor extends ReactiveFunctionVisitor {
161289
161846
  visitLValue(id, lvalue, state) {
161290
161847
  this.visitPlace(id, lvalue, state);
161291
161848
  }
@@ -161294,18 +161851,26 @@ let Visitor$5 = class Visitor extends ReactiveFunctionVisitor {
161294
161851
  state.add(place.identifier.id);
161295
161852
  }
161296
161853
  }
161854
+ visitPrunedScope(scopeBlock, state) {
161855
+ this.traversePrunedScope(scopeBlock, state);
161856
+ for (const [id, decl] of scopeBlock.scope.declarations) {
161857
+ if (!isPrimitiveType(decl.identifier)) {
161858
+ state.add(id);
161859
+ }
161860
+ }
161861
+ }
161297
161862
  };
161298
161863
  function collectReactiveIdentifiers(fn) {
161299
- const visitor = new Visitor$5();
161864
+ const visitor = new Visitor$6();
161300
161865
  const state = new Set();
161301
161866
  visitReactiveFunction(fn, visitor, state);
161302
161867
  return state;
161303
161868
  }
161304
161869
  function pruneNonReactiveDependencies(fn) {
161305
161870
  const reactiveIdentifiers = collectReactiveIdentifiers(fn);
161306
- visitReactiveFunction(fn, new Visitor$4(), reactiveIdentifiers);
161871
+ visitReactiveFunction(fn, new Visitor$5(), reactiveIdentifiers);
161307
161872
  }
161308
- let Visitor$4 = class Visitor extends ReactiveFunctionVisitor {
161873
+ let Visitor$5 = class Visitor extends ReactiveFunctionVisitor {
161309
161874
  visitInstruction(instruction, state) {
161310
161875
  this.traverseInstruction(instruction, state);
161311
161876
  const { lvalue: lvalue, value: value } = instruction;
@@ -161328,7 +161893,7 @@ let Visitor$4 = class Visitor extends ReactiveFunctionVisitor {
161328
161893
  case "Destructure": {
161329
161894
  if (state.has(value.value.identifier.id)) {
161330
161895
  for (const lvalue of eachPatternOperand(value.lvalue.pattern)) {
161331
- if (isSetStateType(lvalue.identifier)) {
161896
+ if (isStableType(lvalue.identifier)) {
161332
161897
  continue;
161333
161898
  }
161334
161899
  state.add(lvalue.identifier.id);
@@ -161343,7 +161908,7 @@ let Visitor$4 = class Visitor extends ReactiveFunctionVisitor {
161343
161908
  if (
161344
161909
  lvalue !== null &&
161345
161910
  state.has(value.object.identifier.id) &&
161346
- !isSetStateType(lvalue.identifier)
161911
+ !isStableType(lvalue.identifier)
161347
161912
  ) {
161348
161913
  state.add(lvalue.identifier.id);
161349
161914
  }
@@ -161381,12 +161946,12 @@ let Visitor$4 = class Visitor extends ReactiveFunctionVisitor {
161381
161946
  };
161382
161947
  function pruneTemporaryLValues(fn) {
161383
161948
  const lvalues = new Map();
161384
- visitReactiveFunction(fn, new Visitor$3(), lvalues);
161949
+ visitReactiveFunction(fn, new Visitor$4(), lvalues);
161385
161950
  for (const [, instr] of lvalues) {
161386
161951
  instr.lvalue = null;
161387
161952
  }
161388
161953
  }
161389
- let Visitor$3 = class Visitor extends ReactiveFunctionVisitor {
161954
+ let Visitor$4 = class Visitor extends ReactiveFunctionVisitor {
161390
161955
  visitPlace(id, place, state) {
161391
161956
  state.delete(place.identifier);
161392
161957
  }
@@ -161454,7 +162019,14 @@ let Transform$1 = class Transform extends ReactiveFunctionTransform {
161454
162019
  (scopeBlock.scope.declarations.size === 0 ||
161455
162020
  !hasOwnDeclaration(scopeBlock))
161456
162021
  ) {
161457
- return { kind: "replace-many", value: scopeBlock.instructions };
162022
+ return {
162023
+ kind: "replace",
162024
+ value: {
162025
+ kind: "pruned-scope",
162026
+ scope: scopeBlock.scope,
162027
+ instructions: scopeBlock.instructions,
162028
+ },
162029
+ };
161458
162030
  } else {
161459
162031
  return { kind: "keep" };
161460
162032
  }
@@ -161470,10 +162042,10 @@ function hasOwnDeclaration(block) {
161470
162042
  }
161471
162043
  function collectReferencedGlobals(fn) {
161472
162044
  const identifiers = new Set();
161473
- visitReactiveFunction(fn, new Visitor$2(), identifiers);
162045
+ visitReactiveFunction(fn, new Visitor$3(), identifiers);
161474
162046
  return identifiers;
161475
162047
  }
161476
- let Visitor$2 = class Visitor extends ReactiveFunctionVisitor {
162048
+ let Visitor$3 = class Visitor extends ReactiveFunctionVisitor {
161477
162049
  visitValue(id, value, state) {
161478
162050
  this.traverseValue(id, value, state);
161479
162051
  if (value.kind === "FunctionExpression" || value.kind === "ObjectMethod") {
@@ -161494,7 +162066,7 @@ var _Scopes_instances,
161494
162066
  function renameVariables(fn) {
161495
162067
  const globals = collectReferencedGlobals(fn);
161496
162068
  const scopes = new Scopes(globals);
161497
- renameVariablesImpl(fn, new Visitor$1(), scopes);
162069
+ renameVariablesImpl(fn, new Visitor$2(), scopes);
161498
162070
  return new Set([...scopes.names, ...globals]);
161499
162071
  }
161500
162072
  function renameVariablesImpl(fn, visitor, scopes) {
@@ -161509,7 +162081,7 @@ function renameVariablesImpl(fn, visitor, scopes) {
161509
162081
  visitReactiveFunction(fn, visitor, scopes);
161510
162082
  });
161511
162083
  }
161512
- let Visitor$1 = class Visitor extends ReactiveFunctionVisitor {
162084
+ let Visitor$2 = class Visitor extends ReactiveFunctionVisitor {
161513
162085
  visitParam(place, state) {
161514
162086
  state.visit(place.identifier);
161515
162087
  }
@@ -161524,6 +162096,9 @@ let Visitor$1 = class Visitor extends ReactiveFunctionVisitor {
161524
162096
  this.traverseBlock(block, state);
161525
162097
  });
161526
162098
  }
162099
+ visitPrunedScope(scopeBlock, state) {
162100
+ this.traverseBlock(scopeBlock.instructions, state);
162101
+ }
161527
162102
  visitScope(scope, state) {
161528
162103
  for (const [_, declaration] of scope.scope.declarations) {
161529
162104
  state.visit(declaration.identifier);
@@ -161699,6 +162274,7 @@ function inferReactiveScopeVariables(fn) {
161699
162274
  reassignments: new Set(),
161700
162275
  earlyReturnValue: null,
161701
162276
  merged: new Set(),
162277
+ loc: identifier.loc,
161702
162278
  };
161703
162279
  scopes.set(groupIdentifier, scope);
161704
162280
  } else {
@@ -161708,6 +162284,7 @@ function inferReactiveScopeVariables(fn) {
161708
162284
  scope.range.end = makeInstructionId(
161709
162285
  Math.max(scope.range.end, identifier.mutableRange.end)
161710
162286
  );
162287
+ scope.loc = mergeLocation(scope.loc, identifier.loc);
161711
162288
  }
161712
162289
  identifier.scope = scope;
161713
162290
  identifier.mutableRange = scope.range;
@@ -161736,6 +162313,24 @@ function inferReactiveScopeVariables(fn) {
161736
162313
  }
161737
162314
  }
161738
162315
  }
162316
+ function mergeLocation(l, r) {
162317
+ if (l === GeneratedSource) {
162318
+ return r;
162319
+ } else if (r === GeneratedSource) {
162320
+ return l;
162321
+ } else {
162322
+ return {
162323
+ start: {
162324
+ line: Math.min(l.start.line, r.start.line),
162325
+ column: Math.min(l.start.column, r.start.column),
162326
+ },
162327
+ end: {
162328
+ line: Math.max(l.end.line, r.end.line),
162329
+ column: Math.max(l.end.column, r.end.column),
162330
+ },
162331
+ };
162332
+ }
162333
+ }
161739
162334
  function isMutable({ id: id }, place) {
161740
162335
  const range = place.identifier.mutableRange;
161741
162336
  return id >= range.start && id < range.end;
@@ -161753,6 +162348,7 @@ function mayAllocate(env, instruction) {
161753
162348
  case "DeclareContext":
161754
162349
  case "StoreLocal":
161755
162350
  case "LoadGlobal":
162351
+ case "MetaProperty":
161756
162352
  case "TypeCastExpression":
161757
162353
  case "LoadLocal":
161758
162354
  case "LoadContext":
@@ -162205,7 +162801,7 @@ function addMemoCacheFunctionImportDeclaration(program, moduleName, localName) {
162205
162801
  );
162206
162802
  }
162207
162803
  z.enum(["all_errors", "critical_errors", "none"]);
162208
- z.enum(["infer", "annotation", "all"]);
162804
+ z.enum(["infer", "syntax", "annotation", "all"]);
162209
162805
  const defaultOptions = {
162210
162806
  compilationMode: "infer",
162211
162807
  panicThreshold: "none",
@@ -162218,6 +162814,7 @@ const defaultOptions = {
162218
162814
  flowSuppressions: false,
162219
162815
  ignoreUseNoForget: false,
162220
162816
  sources: (filename) => filename.indexOf("node_modules") === -1,
162817
+ enableReanimatedCheck: true,
162221
162818
  };
162222
162819
  function parsePluginOptions(obj) {
162223
162820
  if (obj == null || typeof obj !== "object") {
@@ -162537,6 +163134,7 @@ class SSABuilder {
162537
163134
  mutableRange: { start: makeInstructionId(0), end: makeInstructionId(0) },
162538
163135
  scope: null,
162539
163136
  type: makeType(),
163137
+ loc: oldId.loc,
162540
163138
  };
162541
163139
  }
162542
163140
  defineContext(oldPlace) {
@@ -163270,6 +163868,25 @@ function evaluateInstruction(env, constants, instr) {
163270
163868
  }
163271
163869
  return null;
163272
163870
  }
163871
+ case "UnaryExpression": {
163872
+ switch (value.operator) {
163873
+ case "!": {
163874
+ const operand = read(constants, value.value);
163875
+ if (operand !== null && operand.kind === "Primitive") {
163876
+ const result = {
163877
+ kind: "Primitive",
163878
+ value: !operand.value,
163879
+ loc: value.loc,
163880
+ };
163881
+ instr.value = result;
163882
+ return result;
163883
+ }
163884
+ return null;
163885
+ }
163886
+ default:
163887
+ return null;
163888
+ }
163889
+ }
163273
163890
  case "BinaryExpression": {
163274
163891
  const lhsValue = read(constants, value.left);
163275
163892
  const rhsValue = read(constants, value.right);
@@ -163309,44 +163926,100 @@ function evaluateInstruction(env, constants, instr) {
163309
163926
  }
163310
163927
  break;
163311
163928
  }
163312
- case "<": {
163929
+ case "|": {
163313
163930
  if (typeof lhs === "number" && typeof rhs === "number") {
163314
- result = { kind: "Primitive", value: lhs < rhs, loc: value.loc };
163931
+ result = { kind: "Primitive", value: lhs | rhs, loc: value.loc };
163315
163932
  }
163316
163933
  break;
163317
163934
  }
163318
- case "<=": {
163935
+ case "&": {
163319
163936
  if (typeof lhs === "number" && typeof rhs === "number") {
163320
- result = { kind: "Primitive", value: lhs <= rhs, loc: value.loc };
163937
+ result = { kind: "Primitive", value: lhs & rhs, loc: value.loc };
163321
163938
  }
163322
163939
  break;
163323
163940
  }
163324
- case ">": {
163941
+ case "^": {
163325
163942
  if (typeof lhs === "number" && typeof rhs === "number") {
163326
- result = { kind: "Primitive", value: lhs > rhs, loc: value.loc };
163943
+ result = { kind: "Primitive", value: lhs ^ rhs, loc: value.loc };
163327
163944
  }
163328
163945
  break;
163329
163946
  }
163330
- case ">=": {
163947
+ case "<<": {
163331
163948
  if (typeof lhs === "number" && typeof rhs === "number") {
163332
- result = { kind: "Primitive", value: lhs >= rhs, loc: value.loc };
163949
+ result = { kind: "Primitive", value: lhs << rhs, loc: value.loc };
163333
163950
  }
163334
163951
  break;
163335
163952
  }
163336
- case "==": {
163337
- result = { kind: "Primitive", value: lhs == rhs, loc: value.loc };
163338
- break;
163339
- }
163340
- case "===": {
163341
- result = { kind: "Primitive", value: lhs === rhs, loc: value.loc };
163953
+ case ">>": {
163954
+ if (typeof lhs === "number" && typeof rhs === "number") {
163955
+ result = { kind: "Primitive", value: lhs >> rhs, loc: value.loc };
163956
+ }
163342
163957
  break;
163343
163958
  }
163344
- case "!=": {
163345
- result = { kind: "Primitive", value: lhs != rhs, loc: value.loc };
163959
+ case ">>>": {
163960
+ if (typeof lhs === "number" && typeof rhs === "number") {
163961
+ result = {
163962
+ kind: "Primitive",
163963
+ value: lhs >>> rhs,
163964
+ loc: value.loc,
163965
+ };
163966
+ }
163346
163967
  break;
163347
163968
  }
163348
- case "!==": {
163349
- result = { kind: "Primitive", value: lhs !== rhs, loc: value.loc };
163969
+ case "%": {
163970
+ if (typeof lhs === "number" && typeof rhs === "number") {
163971
+ result = { kind: "Primitive", value: lhs % rhs, loc: value.loc };
163972
+ }
163973
+ break;
163974
+ }
163975
+ case "**": {
163976
+ if (typeof lhs === "number" && typeof rhs === "number") {
163977
+ result = {
163978
+ kind: "Primitive",
163979
+ value: Math.pow(lhs, rhs),
163980
+ loc: value.loc,
163981
+ };
163982
+ }
163983
+ break;
163984
+ }
163985
+ case "<": {
163986
+ if (typeof lhs === "number" && typeof rhs === "number") {
163987
+ result = { kind: "Primitive", value: lhs < rhs, loc: value.loc };
163988
+ }
163989
+ break;
163990
+ }
163991
+ case "<=": {
163992
+ if (typeof lhs === "number" && typeof rhs === "number") {
163993
+ result = { kind: "Primitive", value: lhs <= rhs, loc: value.loc };
163994
+ }
163995
+ break;
163996
+ }
163997
+ case ">": {
163998
+ if (typeof lhs === "number" && typeof rhs === "number") {
163999
+ result = { kind: "Primitive", value: lhs > rhs, loc: value.loc };
164000
+ }
164001
+ break;
164002
+ }
164003
+ case ">=": {
164004
+ if (typeof lhs === "number" && typeof rhs === "number") {
164005
+ result = { kind: "Primitive", value: lhs >= rhs, loc: value.loc };
164006
+ }
164007
+ break;
164008
+ }
164009
+ case "==": {
164010
+ result = { kind: "Primitive", value: lhs == rhs, loc: value.loc };
164011
+ break;
164012
+ }
164013
+ case "===": {
164014
+ result = { kind: "Primitive", value: lhs === rhs, loc: value.loc };
164015
+ break;
164016
+ }
164017
+ case "!=": {
164018
+ result = { kind: "Primitive", value: lhs != rhs, loc: value.loc };
164019
+ break;
164020
+ }
164021
+ case "!==": {
164022
+ result = { kind: "Primitive", value: lhs !== rhs, loc: value.loc };
163350
164023
  break;
163351
164024
  }
163352
164025
  }
@@ -163633,6 +164306,7 @@ function pruneableValue(value, state) {
163633
164306
  return false;
163634
164307
  }
163635
164308
  case "RegExpLiteral":
164309
+ case "MetaProperty":
163636
164310
  case "LoadGlobal":
163637
164311
  case "ArrayExpression":
163638
164312
  case "BinaryExpression":
@@ -164285,7 +164959,7 @@ function makeManualMemoizationMarkers(
164285
164959
  return [
164286
164960
  {
164287
164961
  id: makeInstructionId(0),
164288
- lvalue: createTemporaryPlace(env),
164962
+ lvalue: createTemporaryPlace(env, fnExpr.loc),
164289
164963
  value: {
164290
164964
  kind: "StartMemoize",
164291
164965
  manualMemoId: manualMemoId,
@@ -164296,7 +164970,7 @@ function makeManualMemoizationMarkers(
164296
164970
  },
164297
164971
  {
164298
164972
  id: makeInstructionId(0),
164299
- lvalue: createTemporaryPlace(env),
164973
+ lvalue: createTemporaryPlace(env, fnExpr.loc),
164300
164974
  value: {
164301
164975
  kind: "FinishMemoize",
164302
164976
  manualMemoId: manualMemoId,
@@ -164559,7 +165233,7 @@ function inferReactivePlaces(fn) {
164559
165233
  }
164560
165234
  if (hasReactiveInput) {
164561
165235
  for (const lvalue of eachInstructionLValue(instruction)) {
164562
- if (isSetStateType(lvalue.identifier)) {
165236
+ if (isStableType(lvalue.identifier)) {
164563
165237
  continue;
164564
165238
  }
164565
165239
  reactiveIdentifiers.markReactive(lvalue);
@@ -164819,6 +165493,7 @@ function rewriteBlock(env, block, returnTarget, returnValue) {
164819
165493
  name: null,
164820
165494
  scope: null,
164821
165495
  type: makeType(),
165496
+ loc: terminal.loc,
164822
165497
  },
164823
165498
  kind: "Identifier",
164824
165499
  reactive: false,
@@ -164858,6 +165533,7 @@ function declareTemporary(env, block, result) {
164858
165533
  name: null,
164859
165534
  scope: null,
164860
165535
  type: makeType(),
165536
+ loc: result.loc,
164861
165537
  },
164862
165538
  kind: "Identifier",
164863
165539
  reactive: false,
@@ -164871,6 +165547,268 @@ function declareTemporary(env, block, result) {
164871
165547
  },
164872
165548
  });
164873
165549
  }
165550
+ function instructionReordering(fn) {
165551
+ var _a;
165552
+ const shared = new Map();
165553
+ const references = findReferencedRangeOfTemporaries(fn);
165554
+ for (const [, block] of fn.body.blocks) {
165555
+ reorderBlock(fn.env, block, shared, references);
165556
+ }
165557
+ CompilerError.invariant(shared.size === 0, {
165558
+ reason: `InstructionReordering: expected all reorderable nodes to have been emitted`,
165559
+ loc:
165560
+ (_a = [...shared.values()]
165561
+ .map((node) => {
165562
+ var _a;
165563
+ return (_a = node.instruction) === null || _a === void 0
165564
+ ? void 0
165565
+ : _a.loc;
165566
+ })
165567
+ .filter((loc) => loc != null)[0]) !== null && _a !== void 0
165568
+ ? _a
165569
+ : GeneratedSource,
165570
+ });
165571
+ markInstructionIds(fn.body);
165572
+ }
165573
+ var ReferenceKind;
165574
+ (function (ReferenceKind) {
165575
+ ReferenceKind[(ReferenceKind["Read"] = 0)] = "Read";
165576
+ ReferenceKind[(ReferenceKind["Write"] = 1)] = "Write";
165577
+ })(ReferenceKind || (ReferenceKind = {}));
165578
+ function findReferencedRangeOfTemporaries(fn) {
165579
+ const singleUseIdentifiers = new Map();
165580
+ const lastAssignments = new Map();
165581
+ function reference(instr, place, kind) {
165582
+ var _a;
165583
+ if (
165584
+ place.identifier.name !== null &&
165585
+ place.identifier.name.kind === "named"
165586
+ ) {
165587
+ if (kind === ReferenceKind.Write) {
165588
+ const name = place.identifier.name.value;
165589
+ const previous = lastAssignments.get(name);
165590
+ if (previous === undefined) {
165591
+ lastAssignments.set(name, instr);
165592
+ } else {
165593
+ lastAssignments.set(
165594
+ name,
165595
+ makeInstructionId(Math.max(previous, instr))
165596
+ );
165597
+ }
165598
+ }
165599
+ return;
165600
+ } else if (kind === ReferenceKind.Read) {
165601
+ const previousCount =
165602
+ (_a = singleUseIdentifiers.get(place.identifier.id)) !== null &&
165603
+ _a !== void 0
165604
+ ? _a
165605
+ : 0;
165606
+ singleUseIdentifiers.set(place.identifier.id, previousCount + 1);
165607
+ }
165608
+ }
165609
+ for (const [, block] of fn.body.blocks) {
165610
+ for (const instr of block.instructions) {
165611
+ for (const operand of eachInstructionValueLValue(instr.value)) {
165612
+ reference(instr.id, operand, ReferenceKind.Read);
165613
+ }
165614
+ for (const lvalue of eachInstructionLValue(instr)) {
165615
+ reference(instr.id, lvalue, ReferenceKind.Write);
165616
+ }
165617
+ }
165618
+ for (const operand of eachTerminalOperand(block.terminal)) {
165619
+ reference(block.terminal.id, operand, ReferenceKind.Read);
165620
+ }
165621
+ }
165622
+ return {
165623
+ singleUseIdentifiers: new Set(
165624
+ [...singleUseIdentifiers]
165625
+ .filter(([, count]) => count === 1)
165626
+ .map(([id]) => id)
165627
+ ),
165628
+ lastAssignments: lastAssignments,
165629
+ };
165630
+ }
165631
+ function reorderBlock(env, block, shared, references) {
165632
+ var _a, _b;
165633
+ const locals = new Map();
165634
+ const named = new Map();
165635
+ let previous = null;
165636
+ for (const instr of block.instructions) {
165637
+ const { lvalue: lvalue, value: value } = instr;
165638
+ const reorderability = getReorderability(instr, references);
165639
+ const node = getOrInsertWith(locals, lvalue.identifier.id, () => ({
165640
+ instruction: instr,
165641
+ dependencies: new Set(),
165642
+ reorderability: reorderability,
165643
+ depth: null,
165644
+ }));
165645
+ if (reorderability === Reorderability.Nonreorderable) {
165646
+ if (previous !== null) {
165647
+ node.dependencies.add(previous);
165648
+ }
165649
+ previous = lvalue.identifier.id;
165650
+ }
165651
+ for (const operand of eachInstructionValueOperand(value)) {
165652
+ const { name: name, id: id } = operand.identifier;
165653
+ if (name !== null && name.kind === "named") {
165654
+ const previous = named.get(name.value);
165655
+ if (previous !== undefined) {
165656
+ node.dependencies.add(previous);
165657
+ }
165658
+ named.set(name.value, lvalue.identifier.id);
165659
+ } else if (locals.has(id) || shared.has(id)) {
165660
+ node.dependencies.add(id);
165661
+ }
165662
+ }
165663
+ for (const lvalueOperand of eachInstructionValueLValue(value)) {
165664
+ const lvalueNode = getOrInsertWith(
165665
+ locals,
165666
+ lvalueOperand.identifier.id,
165667
+ () => ({ instruction: null, dependencies: new Set(), depth: null })
165668
+ );
165669
+ lvalueNode.dependencies.add(lvalue.identifier.id);
165670
+ const name = lvalueOperand.identifier.name;
165671
+ if (name !== null && name.kind === "named") {
165672
+ const previous = named.get(name.value);
165673
+ if (previous !== undefined) {
165674
+ node.dependencies.add(previous);
165675
+ }
165676
+ named.set(name.value, lvalue.identifier.id);
165677
+ }
165678
+ }
165679
+ }
165680
+ const nextInstructions = [];
165681
+ if (isExpressionBlockKind(block.kind)) {
165682
+ if (previous !== null) {
165683
+ emit(env, locals, shared, nextInstructions, previous);
165684
+ }
165685
+ if (block.instructions.length !== 0) {
165686
+ emit(
165687
+ env,
165688
+ locals,
165689
+ shared,
165690
+ nextInstructions,
165691
+ block.instructions.at(-1).lvalue.identifier.id
165692
+ );
165693
+ }
165694
+ for (const operand of eachTerminalOperand(block.terminal)) {
165695
+ emit(env, locals, shared, nextInstructions, operand.identifier.id);
165696
+ }
165697
+ for (const [id, node] of locals) {
165698
+ if (node.instruction == null) {
165699
+ continue;
165700
+ }
165701
+ CompilerError.invariant(
165702
+ node.reorderability === Reorderability.Reorderable,
165703
+ {
165704
+ reason: `Expected all remaining instructions to be reorderable`,
165705
+ loc:
165706
+ (_b =
165707
+ (_a = node.instruction) === null || _a === void 0
165708
+ ? void 0
165709
+ : _a.loc) !== null && _b !== void 0
165710
+ ? _b
165711
+ : block.terminal.loc,
165712
+ description:
165713
+ node.instruction != null
165714
+ ? `Instruction [${node.instruction.id}] was not emitted yet but is not reorderable`
165715
+ : `Lvalue $${id} was not emitted yet but is not reorderable`,
165716
+ }
165717
+ );
165718
+ shared.set(id, node);
165719
+ }
165720
+ } else {
165721
+ for (const operand of eachTerminalOperand(block.terminal)) {
165722
+ emit(env, locals, shared, nextInstructions, operand.identifier.id);
165723
+ }
165724
+ for (const id of Array.from(locals.keys()).reverse()) {
165725
+ const node = locals.get(id);
165726
+ if (node === undefined) {
165727
+ continue;
165728
+ }
165729
+ if (node.reorderability === Reorderability.Reorderable) {
165730
+ shared.set(id, node);
165731
+ } else {
165732
+ emit(env, locals, shared, nextInstructions, id);
165733
+ }
165734
+ }
165735
+ }
165736
+ block.instructions = nextInstructions;
165737
+ }
165738
+ function getDepth(env, nodes, id) {
165739
+ const node = nodes.get(id);
165740
+ if (node == null) {
165741
+ return 0;
165742
+ }
165743
+ if (node.depth != null) {
165744
+ return node.depth;
165745
+ }
165746
+ node.depth = 0;
165747
+ let depth = node.reorderability === Reorderability.Reorderable ? 1 : 10;
165748
+ for (const dep of node.dependencies) {
165749
+ depth += getDepth(env, nodes, dep);
165750
+ }
165751
+ node.depth = depth;
165752
+ return depth;
165753
+ }
165754
+ function emit(env, locals, shared, instructions, id) {
165755
+ var _a;
165756
+ const node =
165757
+ (_a = locals.get(id)) !== null && _a !== void 0 ? _a : shared.get(id);
165758
+ if (node == null) {
165759
+ return;
165760
+ }
165761
+ locals.delete(id);
165762
+ shared.delete(id);
165763
+ const deps = [...node.dependencies];
165764
+ deps.sort((a, b) => {
165765
+ const aDepth = getDepth(env, locals, a);
165766
+ const bDepth = getDepth(env, locals, b);
165767
+ return bDepth - aDepth;
165768
+ });
165769
+ for (const dep of deps) {
165770
+ emit(env, locals, shared, instructions, dep);
165771
+ }
165772
+ if (node.instruction !== null) {
165773
+ instructions.push(node.instruction);
165774
+ }
165775
+ }
165776
+ var Reorderability;
165777
+ (function (Reorderability) {
165778
+ Reorderability[(Reorderability["Reorderable"] = 0)] = "Reorderable";
165779
+ Reorderability[(Reorderability["Nonreorderable"] = 1)] = "Nonreorderable";
165780
+ })(Reorderability || (Reorderability = {}));
165781
+ function getReorderability(instr, references) {
165782
+ switch (instr.value.kind) {
165783
+ case "JsxExpression":
165784
+ case "JsxFragment":
165785
+ case "JSXText":
165786
+ case "LoadGlobal":
165787
+ case "Primitive":
165788
+ case "TemplateLiteral":
165789
+ case "BinaryExpression":
165790
+ case "UnaryExpression": {
165791
+ return Reorderability.Reorderable;
165792
+ }
165793
+ case "LoadLocal": {
165794
+ const name = instr.value.place.identifier.name;
165795
+ if (name !== null && name.kind === "named") {
165796
+ const lastAssignment = references.lastAssignments.get(name.value);
165797
+ if (
165798
+ lastAssignment !== undefined &&
165799
+ lastAssignment < instr.id &&
165800
+ references.singleUseIdentifiers.has(instr.lvalue.identifier.id)
165801
+ ) {
165802
+ return Reorderability.Reorderable;
165803
+ }
165804
+ }
165805
+ return Reorderability.Nonreorderable;
165806
+ }
165807
+ default: {
165808
+ return Reorderability.Nonreorderable;
165809
+ }
165810
+ }
165811
+ }
164874
165812
  function alignMethodCallScopes(fn) {
164875
165813
  const scopeMapping = new Map();
164876
165814
  const mergedScopes = new DisjointSet();
@@ -165059,6 +165997,127 @@ function alignReactiveScopesToBlockScopesHIR(fn) {
165059
165997
  });
165060
165998
  }
165061
165999
  }
166000
+ function flattenReactiveLoopsHIR(fn) {
166001
+ const activeLoops = Array();
166002
+ for (const [, block] of fn.body.blocks) {
166003
+ retainWhere(activeLoops, (id) => id !== block.id);
166004
+ const { terminal: terminal } = block;
166005
+ switch (terminal.kind) {
166006
+ case "do-while":
166007
+ case "for":
166008
+ case "for-in":
166009
+ case "for-of":
166010
+ case "while": {
166011
+ activeLoops.push(terminal.fallthrough);
166012
+ break;
166013
+ }
166014
+ case "scope": {
166015
+ if (activeLoops.length !== 0) {
166016
+ block.terminal = {
166017
+ kind: "pruned-scope",
166018
+ block: terminal.block,
166019
+ fallthrough: terminal.fallthrough,
166020
+ id: terminal.id,
166021
+ loc: terminal.loc,
166022
+ scope: terminal.scope,
166023
+ };
166024
+ }
166025
+ break;
166026
+ }
166027
+ case "branch":
166028
+ case "goto":
166029
+ case "if":
166030
+ case "label":
166031
+ case "logical":
166032
+ case "maybe-throw":
166033
+ case "optional":
166034
+ case "pruned-scope":
166035
+ case "return":
166036
+ case "sequence":
166037
+ case "switch":
166038
+ case "ternary":
166039
+ case "throw":
166040
+ case "try":
166041
+ case "unreachable":
166042
+ case "unsupported": {
166043
+ break;
166044
+ }
166045
+ default: {
166046
+ assertExhaustive(
166047
+ terminal,
166048
+ `Unexpected terminal kind \`${terminal.kind}\``
166049
+ );
166050
+ }
166051
+ }
166052
+ }
166053
+ }
166054
+ function flattenScopesWithHooksOrUseHIR(fn) {
166055
+ var _a, _b;
166056
+ const activeScopes = [];
166057
+ const prune = [];
166058
+ for (const [, block] of fn.body.blocks) {
166059
+ const firstId =
166060
+ (_b =
166061
+ (_a = block.instructions[0]) === null || _a === void 0
166062
+ ? void 0
166063
+ : _a.id) !== null && _b !== void 0
166064
+ ? _b
166065
+ : block.terminal.id;
166066
+ retainWhere(activeScopes, (current) => current.scope.range.end > firstId);
166067
+ for (const instr of block.instructions) {
166068
+ const { value: value } = instr;
166069
+ switch (value.kind) {
166070
+ case "MethodCall":
166071
+ case "CallExpression": {
166072
+ const callee =
166073
+ value.kind === "MethodCall" ? value.property : value.callee;
166074
+ if (
166075
+ getHookKind(fn.env, callee.identifier) != null ||
166076
+ isUseOperator(callee.identifier)
166077
+ ) {
166078
+ prune.push(...activeScopes.map((entry) => entry.block));
166079
+ activeScopes.length = 0;
166080
+ }
166081
+ }
166082
+ }
166083
+ }
166084
+ if (block.terminal.kind === "scope") {
166085
+ activeScopes.push({ block: block.id, scope: block.terminal.scope });
166086
+ }
166087
+ }
166088
+ for (const id of prune) {
166089
+ const block = fn.body.blocks.get(id);
166090
+ const terminal = block.terminal;
166091
+ CompilerError.invariant(terminal.kind === "scope", {
166092
+ reason: `Expected block to have a scope terminal`,
166093
+ description: `Expected block bb${block.id} to end in a scope terminal`,
166094
+ loc: terminal.loc,
166095
+ });
166096
+ const body = fn.body.blocks.get(terminal.block);
166097
+ if (
166098
+ body.instructions.length === 1 &&
166099
+ body.terminal.kind === "goto" &&
166100
+ body.terminal.block === terminal.fallthrough
166101
+ ) {
166102
+ block.terminal = {
166103
+ kind: "label",
166104
+ block: terminal.block,
166105
+ fallthrough: terminal.fallthrough,
166106
+ id: terminal.id,
166107
+ loc: terminal.loc,
166108
+ };
166109
+ continue;
166110
+ }
166111
+ block.terminal = {
166112
+ kind: "pruned-scope",
166113
+ block: terminal.block,
166114
+ fallthrough: terminal.fallthrough,
166115
+ id: terminal.id,
166116
+ loc: terminal.loc,
166117
+ scope: terminal.scope,
166118
+ };
166119
+ }
166120
+ }
165062
166121
  function pruneAlwaysInvalidatingScopes(fn) {
165063
166122
  visitReactiveFunction(fn, new Transform(), false);
165064
166123
  }
@@ -165126,12 +166185,229 @@ class Transform extends ReactiveFunctionTransform {
165126
166185
  this.unmemoizedValues.add(identifier);
165127
166186
  }
165128
166187
  }
165129
- return { kind: "replace-many", value: scopeBlock.instructions };
166188
+ return {
166189
+ kind: "replace",
166190
+ value: {
166191
+ kind: "pruned-scope",
166192
+ scope: scopeBlock.scope,
166193
+ instructions: scopeBlock.instructions,
166194
+ },
166195
+ };
165130
166196
  }
165131
166197
  }
165132
166198
  return { kind: "keep" };
165133
166199
  }
165134
166200
  }
166201
+ let Visitor$1 = class Visitor extends ReactiveFunctionVisitor {
166202
+ constructor(env, aliases, paths) {
166203
+ super();
166204
+ this.map = new Map();
166205
+ this.aliases = aliases;
166206
+ this.paths = paths;
166207
+ this.env = env;
166208
+ }
166209
+ join(values) {
166210
+ function join2(l, r) {
166211
+ if (l === "Update" || r === "Update") {
166212
+ return "Update";
166213
+ } else if (l === "Create" || r === "Create") {
166214
+ return "Create";
166215
+ } else if (l === "Unknown" || r === "Unknown") {
166216
+ return "Unknown";
166217
+ }
166218
+ assertExhaustive(r, `Unhandled variable kind ${r}`);
166219
+ }
166220
+ return values.reduce(join2, "Unknown");
166221
+ }
166222
+ isCreateOnlyHook(id) {
166223
+ return isUseStateType(id) || isUseRefType(id);
166224
+ }
166225
+ visitPlace(_, place, state) {
166226
+ var _a;
166227
+ this.map.set(
166228
+ place.identifier.id,
166229
+ this.join([
166230
+ state,
166231
+ (_a = this.map.get(place.identifier.id)) !== null && _a !== void 0
166232
+ ? _a
166233
+ : "Unknown",
166234
+ ])
166235
+ );
166236
+ }
166237
+ visitBlock(block, state) {
166238
+ super.visitBlock([...block].reverse(), state);
166239
+ }
166240
+ visitInstruction(instruction) {
166241
+ const state = this.join(
166242
+ [...eachInstructionLValue(instruction)].map((operand) => {
166243
+ var _a;
166244
+ return (_a = this.map.get(operand.identifier.id)) !== null &&
166245
+ _a !== void 0
166246
+ ? _a
166247
+ : "Unknown";
166248
+ })
166249
+ );
166250
+ const visitCallOrMethodNonArgs = () => {
166251
+ switch (instruction.value.kind) {
166252
+ case "CallExpression": {
166253
+ this.visitPlace(instruction.id, instruction.value.callee, state);
166254
+ break;
166255
+ }
166256
+ case "MethodCall": {
166257
+ this.visitPlace(instruction.id, instruction.value.property, state);
166258
+ this.visitPlace(instruction.id, instruction.value.receiver, state);
166259
+ break;
166260
+ }
166261
+ }
166262
+ };
166263
+ const isHook = () => {
166264
+ let callee = null;
166265
+ switch (instruction.value.kind) {
166266
+ case "CallExpression": {
166267
+ callee = instruction.value.callee.identifier;
166268
+ break;
166269
+ }
166270
+ case "MethodCall": {
166271
+ callee = instruction.value.property.identifier;
166272
+ break;
166273
+ }
166274
+ }
166275
+ return callee != null && getHookKind(this.env, callee) != null;
166276
+ };
166277
+ switch (instruction.value.kind) {
166278
+ case "CallExpression":
166279
+ case "MethodCall": {
166280
+ if (
166281
+ instruction.lvalue &&
166282
+ this.isCreateOnlyHook(instruction.lvalue.identifier)
166283
+ ) {
166284
+ [...eachCallArgument(instruction.value.args)].forEach((operand) =>
166285
+ this.visitPlace(instruction.id, operand, "Create")
166286
+ );
166287
+ visitCallOrMethodNonArgs();
166288
+ } else {
166289
+ this.traverseInstruction(instruction, isHook() ? "Update" : state);
166290
+ }
166291
+ break;
166292
+ }
166293
+ default: {
166294
+ this.traverseInstruction(instruction, state);
166295
+ }
166296
+ }
166297
+ }
166298
+ visitScope(scope) {
166299
+ const state = this.join(
166300
+ [
166301
+ ...scope.scope.declarations.keys(),
166302
+ ...[...scope.scope.reassignments.values()].map((ident) => ident.id),
166303
+ ].map((id) => {
166304
+ var _a;
166305
+ return (_a = this.map.get(id)) !== null && _a !== void 0
166306
+ ? _a
166307
+ : "Unknown";
166308
+ })
166309
+ );
166310
+ super.visitScope(scope, state);
166311
+ [...scope.scope.dependencies].forEach((ident) => {
166312
+ var _a;
166313
+ let target =
166314
+ (_a = this.aliases.find(ident.identifier.id)) !== null && _a !== void 0
166315
+ ? _a
166316
+ : ident.identifier.id;
166317
+ ident.path.forEach((key) => {
166318
+ var _a;
166319
+ target &&
166320
+ (target =
166321
+ (_a = this.paths.get(target)) === null || _a === void 0
166322
+ ? void 0
166323
+ : _a.get(key));
166324
+ });
166325
+ if (target && this.map.get(target) === "Create") {
166326
+ scope.scope.dependencies.delete(ident);
166327
+ }
166328
+ });
166329
+ }
166330
+ visitTerminal(stmt, state) {
166331
+ CompilerError.invariant(state !== "Create", {
166332
+ reason: "Visiting a terminal statement with state 'Create'",
166333
+ loc: stmt.terminal.loc,
166334
+ });
166335
+ super.visitTerminal(stmt, state);
166336
+ }
166337
+ visitReactiveFunctionValue(_id, _dependencies, fn, state) {
166338
+ visitReactiveFunction(fn, this, state);
166339
+ }
166340
+ };
166341
+ function pruneInitializationDependencies(fn) {
166342
+ const [aliases, paths] = getAliases(fn);
166343
+ visitReactiveFunction(fn, new Visitor$1(fn.env, aliases, paths), "Update");
166344
+ }
166345
+ function update(map, key, path, value) {
166346
+ var _a;
166347
+ const inner = (_a = map.get(key)) !== null && _a !== void 0 ? _a : new Map();
166348
+ inner.set(path, value);
166349
+ map.set(key, inner);
166350
+ }
166351
+ class AliasVisitor extends ReactiveFunctionVisitor {
166352
+ constructor() {
166353
+ super(...arguments);
166354
+ this.scopeIdentifiers = new DisjointSet();
166355
+ this.scopePaths = new Map();
166356
+ }
166357
+ visitInstruction(instr) {
166358
+ if (
166359
+ instr.value.kind === "StoreLocal" ||
166360
+ instr.value.kind === "StoreContext"
166361
+ ) {
166362
+ this.scopeIdentifiers.union([
166363
+ instr.value.lvalue.place.identifier.id,
166364
+ instr.value.value.identifier.id,
166365
+ ]);
166366
+ } else if (
166367
+ instr.value.kind === "LoadLocal" ||
166368
+ instr.value.kind === "LoadContext"
166369
+ ) {
166370
+ instr.lvalue &&
166371
+ this.scopeIdentifiers.union([
166372
+ instr.lvalue.identifier.id,
166373
+ instr.value.place.identifier.id,
166374
+ ]);
166375
+ } else if (instr.value.kind === "PropertyLoad") {
166376
+ instr.lvalue &&
166377
+ update(
166378
+ this.scopePaths,
166379
+ instr.value.object.identifier.id,
166380
+ instr.value.property,
166381
+ instr.lvalue.identifier.id
166382
+ );
166383
+ } else if (instr.value.kind === "PropertyStore") {
166384
+ update(
166385
+ this.scopePaths,
166386
+ instr.value.object.identifier.id,
166387
+ instr.value.property,
166388
+ instr.value.value.identifier.id
166389
+ );
166390
+ }
166391
+ }
166392
+ }
166393
+ function getAliases(fn) {
166394
+ var _a, _b;
166395
+ const visitor = new AliasVisitor();
166396
+ visitReactiveFunction(fn, visitor, null);
166397
+ let disjoint = visitor.scopeIdentifiers;
166398
+ let scopePaths = new Map();
166399
+ for (const [key, value] of visitor.scopePaths) {
166400
+ for (const [path, id] of value) {
166401
+ update(
166402
+ scopePaths,
166403
+ (_a = disjoint.find(key)) !== null && _a !== void 0 ? _a : key,
166404
+ path,
166405
+ (_b = disjoint.find(id)) !== null && _b !== void 0 ? _b : id
166406
+ );
166407
+ }
166408
+ }
166409
+ return [disjoint, scopePaths];
166410
+ }
165135
166411
  function isPrimitiveBinaryOp(op) {
165136
166412
  switch (op) {
165137
166413
  case "+":
@@ -165190,7 +166466,13 @@ function equation(left, right) {
165190
166466
  }
165191
166467
  function* generate(func) {
165192
166468
  if (func.env.fnType === "Component") {
165193
- const [_, ref] = func.params;
166469
+ const [props, ref] = func.params;
166470
+ if (props && props.kind === "Identifier") {
166471
+ yield equation(props.identifier.type, {
166472
+ kind: "Object",
166473
+ shapeId: BuiltInPropsId,
166474
+ });
166475
+ }
165194
166476
  if (ref && ref.kind === "Identifier") {
165195
166477
  yield equation(ref.identifier.type, {
165196
166478
  kind: "Object",
@@ -165198,6 +166480,7 @@ function* generate(func) {
165198
166480
  });
165199
166481
  }
165200
166482
  }
166483
+ const names = new Map();
165201
166484
  for (const [_, block] of func.body.blocks) {
165202
166485
  for (const phi of block.phis) {
165203
166486
  yield equation(phi.type, {
@@ -165206,11 +166489,23 @@ function* generate(func) {
165206
166489
  });
165207
166490
  }
165208
166491
  for (const instr of block.instructions) {
165209
- yield* generateInstructionTypes(func.env, instr);
166492
+ yield* generateInstructionTypes(func.env, names, instr);
165210
166493
  }
165211
166494
  }
165212
166495
  }
165213
- function* generateInstructionTypes(env, instr) {
166496
+ function setName(names, id, name) {
166497
+ var _a;
166498
+ if (
166499
+ ((_a = name.name) === null || _a === void 0 ? void 0 : _a.kind) === "named"
166500
+ ) {
166501
+ names.set(id, name.name.value);
166502
+ }
166503
+ }
166504
+ function getName(names, id) {
166505
+ var _a;
166506
+ return (_a = names.get(id)) !== null && _a !== void 0 ? _a : "";
166507
+ }
166508
+ function* generateInstructionTypes(env, names, instr) {
165214
166509
  const { lvalue: lvalue, value: value } = instr;
165215
166510
  const left = lvalue.identifier.type;
165216
166511
  switch (value.kind) {
@@ -165225,6 +166520,7 @@ function* generateInstructionTypes(env, instr) {
165225
166520
  break;
165226
166521
  }
165227
166522
  case "LoadLocal": {
166523
+ setName(names, lvalue.identifier.id, value.place.identifier);
165228
166524
  yield equation(left, value.place.identifier.type);
165229
166525
  break;
165230
166526
  }
@@ -165307,7 +166603,8 @@ function* generateInstructionTypes(env, instr) {
165307
166603
  case "PropertyLoad": {
165308
166604
  yield equation(left, {
165309
166605
  kind: "Property",
165310
- object: value.object.identifier.type,
166606
+ objectType: value.object.identifier.type,
166607
+ objectName: getName(names, value.object.identifier.id),
165311
166608
  propertyName: value.property,
165312
166609
  });
165313
166610
  break;
@@ -165331,7 +166628,8 @@ function* generateInstructionTypes(env, instr) {
165331
166628
  const propertyName = String(i);
165332
166629
  yield equation(item.identifier.type, {
165333
166630
  kind: "Property",
165334
- object: value.value.identifier.type,
166631
+ objectType: value.value.identifier.type,
166632
+ objectName: getName(names, value.value.identifier.id),
165335
166633
  propertyName: propertyName,
165336
166634
  });
165337
166635
  } else {
@@ -165347,7 +166645,8 @@ function* generateInstructionTypes(env, instr) {
165347
166645
  ) {
165348
166646
  yield equation(property.place.identifier.type, {
165349
166647
  kind: "Property",
165350
- object: value.value.identifier.type,
166648
+ objectType: value.value.identifier.type,
166649
+ objectName: getName(names, value.value.identifier.id),
165351
166650
  propertyName: property.key.name,
165352
166651
  });
165353
166652
  }
@@ -165389,10 +166688,11 @@ function* generateInstructionTypes(env, instr) {
165389
166688
  yield equation(left, { kind: "Object", shapeId: BuiltInJsxId });
165390
166689
  break;
165391
166690
  }
166691
+ case "PropertyStore":
165392
166692
  case "DeclareLocal":
165393
166693
  case "NewExpression":
165394
166694
  case "RegExpLiteral":
165395
- case "PropertyStore":
166695
+ case "MetaProperty":
165396
166696
  case "ComputedStore":
165397
166697
  case "ComputedLoad":
165398
166698
  case "TaggedTemplateExpression":
@@ -165416,7 +166716,15 @@ class Unifier {
165416
166716
  }
165417
166717
  unify(tA, tB) {
165418
166718
  if (tB.kind === "Property") {
165419
- const objectType = this.get(tB.object);
166719
+ if (
166720
+ this.env.config.enableTreatRefLikeIdentifiersAsRefs &&
166721
+ isRefLikeName(tB)
166722
+ ) {
166723
+ this.unify(tB.objectType, { kind: "Object", shapeId: BuiltInUseRefId });
166724
+ this.unify(tA, { kind: "Object", shapeId: BuiltInRefValueId });
166725
+ return;
166726
+ }
166727
+ const objectType = this.get(tB.objectType);
165420
166728
  const propertyType = this.env.getPropertyType(
165421
166729
  objectType,
165422
166730
  tB.propertyName
@@ -165498,6 +166806,10 @@ class Unifier {
165498
166806
  return type;
165499
166807
  }
165500
166808
  }
166809
+ const RefLikeNameRE = /^(?:[a-zA-Z$_][a-zA-Z$_0-9]*)Ref$|^ref$/;
166810
+ function isRefLikeName(t) {
166811
+ return RefLikeNameRE.test(t.objectName) && t.propertyName === "current";
166812
+ }
165501
166813
  function validateContextVariableLValues(fn) {
165502
166814
  const identifierKinds = new Map();
165503
166815
  validateContextVariableLValuesImpl(fn, identifierKinds);
@@ -166064,7 +167376,12 @@ function validateNoRefAccessInRenderImpl(fn, refAccessingFunctions) {
166064
167376
  case "MethodCall": {
166065
167377
  if (!isEffectHook(instr.value.property.identifier)) {
166066
167378
  for (const operand of eachInstructionValueOperand(instr.value)) {
166067
- validateNoRefAccess(errors, refAccessingFunctions, operand);
167379
+ validateNoRefAccess(
167380
+ errors,
167381
+ refAccessingFunctions,
167382
+ operand,
167383
+ operand.loc
167384
+ );
166068
167385
  }
166069
167386
  }
166070
167387
  break;
@@ -166084,7 +167401,12 @@ function validateNoRefAccessInRenderImpl(fn, refAccessingFunctions) {
166084
167401
  });
166085
167402
  }
166086
167403
  for (const operand of eachInstructionValueOperand(instr.value)) {
166087
- validateNoRefAccess(errors, refAccessingFunctions, operand);
167404
+ validateNoRefAccess(
167405
+ errors,
167406
+ refAccessingFunctions,
167407
+ operand,
167408
+ operand.loc
167409
+ );
166088
167410
  }
166089
167411
  }
166090
167412
  break;
@@ -166092,7 +167414,30 @@ function validateNoRefAccessInRenderImpl(fn, refAccessingFunctions) {
166092
167414
  case "ObjectExpression":
166093
167415
  case "ArrayExpression": {
166094
167416
  for (const operand of eachInstructionValueOperand(instr.value)) {
166095
- validateNoRefAccess(errors, refAccessingFunctions, operand);
167417
+ validateNoRefAccess(
167418
+ errors,
167419
+ refAccessingFunctions,
167420
+ operand,
167421
+ operand.loc
167422
+ );
167423
+ }
167424
+ break;
167425
+ }
167426
+ case "PropertyDelete":
167427
+ case "PropertyStore":
167428
+ case "ComputedDelete":
167429
+ case "ComputedStore": {
167430
+ validateNoRefAccess(
167431
+ errors,
167432
+ refAccessingFunctions,
167433
+ instr.value.object,
167434
+ instr.loc
167435
+ );
167436
+ for (const operand of eachInstructionValueOperand(instr.value)) {
167437
+ if (operand === instr.value.object) {
167438
+ continue;
167439
+ }
167440
+ validateNoRefValueAccess(errors, refAccessingFunctions, operand);
166096
167441
  }
166097
167442
  break;
166098
167443
  }
@@ -166114,14 +167459,10 @@ function validateNoRefAccessInRenderImpl(fn, refAccessingFunctions) {
166114
167459
  return Ok(undefined);
166115
167460
  }
166116
167461
  }
166117
- function validateNoRefValueAccess(
166118
- errors,
166119
- unconditionalSetStateFunctions,
166120
- operand
166121
- ) {
167462
+ function validateNoRefValueAccess(errors, refAccessingFunctions, operand) {
166122
167463
  if (
166123
167464
  isRefValueType(operand.identifier) ||
166124
- unconditionalSetStateFunctions.has(operand.identifier.id)
167465
+ refAccessingFunctions.has(operand.identifier.id)
166125
167466
  ) {
166126
167467
  errors.push({
166127
167468
  severity: exports.ErrorSeverity.InvalidReact,
@@ -166133,18 +167474,22 @@ function validateNoRefValueAccess(
166133
167474
  });
166134
167475
  }
166135
167476
  }
166136
- function validateNoRefAccess(errors, unconditionalSetStateFunctions, operand) {
167477
+ function validateNoRefAccess(errors, refAccessingFunctions, operand, loc) {
166137
167478
  if (
166138
167479
  isRefValueType(operand.identifier) ||
166139
167480
  isUseRefType(operand.identifier) ||
166140
- unconditionalSetStateFunctions.has(operand.identifier.id)
167481
+ refAccessingFunctions.has(operand.identifier.id)
166141
167482
  ) {
166142
167483
  errors.push({
166143
167484
  severity: exports.ErrorSeverity.InvalidReact,
166144
167485
  reason:
166145
167486
  "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)}`,
167487
+ loc: loc,
167488
+ description:
167489
+ operand.identifier.name !== null &&
167490
+ operand.identifier.name.kind === "named"
167491
+ ? `Cannot access ref value \`${operand.identifier.name.value}\``
167492
+ : null,
166148
167493
  suggestions: null,
166149
167494
  });
166150
167495
  }
@@ -166632,8 +167977,14 @@ function* runWithEnvironment(func, env) {
166632
167977
  yield log({ kind: "hir", name: "PruneMaybeThrows", value: hir });
166633
167978
  validateContextVariableLValues(hir);
166634
167979
  validateUseMemo(hir);
166635
- dropManualMemoization(hir);
166636
- yield log({ kind: "hir", name: "DropManualMemoization", value: hir });
167980
+ if (
167981
+ !env.config.enablePreserveExistingManualUseMemo &&
167982
+ !env.config.disableMemoizationForDebugging &&
167983
+ !env.config.enableChangeDetectionForDebugging
167984
+ ) {
167985
+ dropManualMemoization(hir);
167986
+ yield log({ kind: "hir", name: "DropManualMemoization", value: hir });
167987
+ }
166637
167988
  inlineImmediatelyInvokedFunctionExpressions(hir);
166638
167989
  yield log({
166639
167990
  kind: "hir",
@@ -166665,6 +168016,10 @@ function* runWithEnvironment(func, env) {
166665
168016
  yield log({ kind: "hir", name: "InferReferenceEffects", value: hir });
166666
168017
  deadCodeElimination(hir);
166667
168018
  yield log({ kind: "hir", name: "DeadCodeElimination", value: hir });
168019
+ if (env.config.enableInstructionReordering) {
168020
+ instructionReordering(hir);
168021
+ yield log({ kind: "hir", name: "InstructionReordering", value: hir });
168022
+ }
166668
168023
  pruneMaybeThrows(hir);
166669
168024
  yield log({ kind: "hir", name: "PruneMaybeThrows", value: hir });
166670
168025
  inferMutableRanges(hir);
@@ -166688,8 +168043,12 @@ function* runWithEnvironment(func, env) {
166688
168043
  yield log({ kind: "hir", name: "AlignMethodCallScopes", value: hir });
166689
168044
  alignObjectMethodScopes(hir);
166690
168045
  yield log({ kind: "hir", name: "AlignObjectMethodScopes", value: hir });
166691
- memoizeFbtOperandsInSameScope(hir);
166692
- yield log({ kind: "hir", name: "MemoizeFbtOperandsInSameScope", value: hir });
168046
+ memoizeFbtAndMacroOperandsInSameScope(hir);
168047
+ yield log({
168048
+ kind: "hir",
168049
+ name: "MemoizeFbtAndMacroOperandsInSameScope",
168050
+ value: hir,
168051
+ });
166693
168052
  if (env.config.enableReactiveScopesInHIR) {
166694
168053
  pruneUnusedLabelsHIR(hir);
166695
168054
  yield log({ kind: "hir", name: "PruneUnusedLabelsHIR", value: hir });
@@ -166713,6 +168072,14 @@ function* runWithEnvironment(func, env) {
166713
168072
  value: hir,
166714
168073
  });
166715
168074
  assertValidBlockNesting(hir);
168075
+ flattenReactiveLoopsHIR(hir);
168076
+ yield log({ kind: "hir", name: "FlattenReactiveLoopsHIR", value: hir });
168077
+ flattenScopesWithHooksOrUseHIR(hir);
168078
+ yield log({
168079
+ kind: "hir",
168080
+ name: "FlattenScopesWithHooksOrUseHIR",
168081
+ value: hir,
168082
+ });
166716
168083
  }
166717
168084
  const reactiveFunction = buildReactiveFunction(hir);
166718
168085
  yield log({
@@ -166746,20 +168113,20 @@ function* runWithEnvironment(func, env) {
166746
168113
  name: "BuildReactiveBlocks",
166747
168114
  value: reactiveFunction,
166748
168115
  });
168116
+ flattenReactiveLoops(reactiveFunction);
168117
+ yield log({
168118
+ kind: "reactive",
168119
+ name: "FlattenReactiveLoops",
168120
+ value: reactiveFunction,
168121
+ });
168122
+ flattenScopesWithHooksOrUse(reactiveFunction);
168123
+ yield log({
168124
+ kind: "reactive",
168125
+ name: "FlattenScopesWithHooks",
168126
+ value: reactiveFunction,
168127
+ });
166749
168128
  }
166750
- flattenReactiveLoops(reactiveFunction);
166751
- yield log({
166752
- kind: "reactive",
166753
- name: "FlattenReactiveLoops",
166754
- value: reactiveFunction,
166755
- });
166756
168129
  assertScopeInstructionsWithinScopes(reactiveFunction);
166757
- flattenScopesWithHooksOrUse(reactiveFunction);
166758
- yield log({
166759
- kind: "reactive",
166760
- name: "FlattenScopesWithHooks",
166761
- value: reactiveFunction,
166762
- });
166763
168130
  propagateScopeDependencies(reactiveFunction);
166764
168131
  yield log({
166765
168132
  kind: "reactive",
@@ -166796,6 +168163,14 @@ function* runWithEnvironment(func, env) {
166796
168163
  name: "PruneAlwaysInvalidatingScopes",
166797
168164
  value: reactiveFunction,
166798
168165
  });
168166
+ if (env.config.enableChangeDetectionForDebugging != null) {
168167
+ pruneInitializationDependencies(reactiveFunction);
168168
+ yield log({
168169
+ kind: "reactive",
168170
+ name: "PruneInitializationDependencies",
168171
+ value: reactiveFunction,
168172
+ });
168173
+ }
166799
168174
  propagateEarlyReturns(reactiveFunction);
166800
168175
  yield log({
166801
168176
  kind: "reactive",
@@ -167184,9 +168559,8 @@ function isFilePartOfSources(sources, filename) {
167184
168559
  return false;
167185
168560
  }
167186
168561
  function compileProgram(program, pass) {
167187
- var _a, _b, _c, _d, _e, _f, _g;
167188
- const options = parsePluginOptions(pass.opts);
167189
- if (options.sources) {
168562
+ var _a, _b, _c, _d, _e, _f, _g, _h;
168563
+ if (pass.opts.sources) {
167190
168564
  if (pass.filename === null) {
167191
168565
  const error = new CompilerError();
167192
168566
  error.pushErrorDetail(
@@ -167201,12 +168575,13 @@ function compileProgram(program, pass) {
167201
168575
  handleError(error, pass, null);
167202
168576
  return;
167203
168577
  }
167204
- if (!isFilePartOfSources(options.sources, pass.filename)) {
168578
+ if (!isFilePartOfSources(pass.opts.sources, pass.filename)) {
167205
168579
  return;
167206
168580
  }
167207
168581
  }
167208
168582
  if (
167209
- findDirectiveDisablingMemoization(program.node.directives, options) != null
168583
+ findDirectiveDisablingMemoization(program.node.directives, pass.opts) !=
168584
+ null
167210
168585
  ) {
167211
168586
  return;
167212
168587
  }
@@ -167215,7 +168590,7 @@ function compileProgram(program, pass) {
167215
168590
  );
167216
168591
  const useMemoCacheIdentifier = program.scope.generateUidIdentifier("c");
167217
168592
  const moduleName =
167218
- (_b = options.runtimeModule) !== null && _b !== void 0
168593
+ (_b = pass.opts.runtimeModule) !== null && _b !== void 0
167219
168594
  ? _b
167220
168595
  : "react/compiler-runtime";
167221
168596
  if (hasMemoCacheFunctionImport(program, moduleName)) {
@@ -167223,10 +168598,10 @@ function compileProgram(program, pass) {
167223
168598
  }
167224
168599
  const suppressions = findProgramSuppressions(
167225
168600
  pass.comments,
167226
- (_c = options.eslintSuppressionRules) !== null && _c !== void 0
168601
+ (_c = pass.opts.eslintSuppressionRules) !== null && _c !== void 0
167227
168602
  ? _c
167228
168603
  : DEFAULT_ESLINT_SUPPRESSIONS,
167229
- options.flowSuppressions
168604
+ pass.opts.flowSuppressions
167230
168605
  );
167231
168606
  const lintError = suppressionsToCompilerError(suppressions);
167232
168607
  let hasCriticalError = lintError != null;
@@ -167269,11 +168644,11 @@ function compileProgram(program, pass) {
167269
168644
  config,
167270
168645
  fnType,
167271
168646
  useMemoCacheIdentifier.name,
167272
- options.logger,
168647
+ pass.opts.logger,
167273
168648
  pass.filename,
167274
168649
  pass.code
167275
168650
  );
167276
- (_b = options.logger) === null || _b === void 0
168651
+ (_b = pass.opts.logger) === null || _b === void 0
167277
168652
  ? void 0
167278
168653
  : _b.logEvent(pass.filename, {
167279
168654
  kind: "CompileSuccess",
@@ -167287,6 +168662,9 @@ function compileProgram(program, pass) {
167287
168662
  : null,
167288
168663
  memoSlots: compiledFn.memoSlotsUsed,
167289
168664
  memoBlocks: compiledFn.memoBlocks,
168665
+ memoValues: compiledFn.memoValues,
168666
+ prunedMemoBlocks: compiledFn.prunedMemoBlocks,
168667
+ prunedMemoValues: compiledFn.prunedMemoValues,
167290
168668
  });
167291
168669
  } catch (err) {
167292
168670
  hasCriticalError || (hasCriticalError = isCriticalError(err));
@@ -167316,11 +168694,11 @@ function compileProgram(program, pass) {
167316
168694
  ArrowFunctionExpression: traverseFunction,
167317
168695
  },
167318
168696
  Object.assign(Object.assign({}, pass), {
167319
- opts: Object.assign(Object.assign({}, pass.opts), options),
168697
+ opts: Object.assign(Object.assign({}, pass.opts), pass.opts),
167320
168698
  filename: (_d = pass.filename) !== null && _d !== void 0 ? _d : null,
167321
168699
  })
167322
168700
  );
167323
- if (options.gating != null) {
168701
+ if (pass.opts.gating != null) {
167324
168702
  const error = checkFunctionReferencedBeforeDeclarationAtTopLevel(
167325
168703
  program,
167326
168704
  compiledFns.map(({ originalFn: originalFn }) => originalFn)
@@ -167333,12 +168711,12 @@ function compileProgram(program, pass) {
167333
168711
  const externalFunctions = [];
167334
168712
  let gating = null;
167335
168713
  try {
167336
- if (options.gating != null) {
167337
- gating = tryParseExternalFunction(options.gating);
168714
+ if (pass.opts.gating != null) {
168715
+ gating = tryParseExternalFunction(pass.opts.gating);
167338
168716
  externalFunctions.push(gating);
167339
168717
  }
167340
168718
  const enableEmitInstrumentForget =
167341
- (_e = options.environment) === null || _e === void 0
168719
+ (_e = pass.opts.environment) === null || _e === void 0
167342
168720
  ? void 0
167343
168721
  : _e.enableEmitInstrumentForget;
167344
168722
  if (enableEmitInstrumentForget != null) {
@@ -167352,25 +168730,35 @@ function compileProgram(program, pass) {
167352
168730
  }
167353
168731
  }
167354
168732
  if (
167355
- ((_f = options.environment) === null || _f === void 0
168733
+ ((_f = pass.opts.environment) === null || _f === void 0
167356
168734
  ? void 0
167357
168735
  : _f.enableEmitFreeze) != null
167358
168736
  ) {
167359
168737
  const enableEmitFreeze = tryParseExternalFunction(
167360
- options.environment.enableEmitFreeze
168738
+ pass.opts.environment.enableEmitFreeze
167361
168739
  );
167362
168740
  externalFunctions.push(enableEmitFreeze);
167363
168741
  }
167364
168742
  if (
167365
- ((_g = options.environment) === null || _g === void 0
168743
+ ((_g = pass.opts.environment) === null || _g === void 0
167366
168744
  ? void 0
167367
168745
  : _g.enableEmitHookGuards) != null
167368
168746
  ) {
167369
168747
  const enableEmitHookGuards = tryParseExternalFunction(
167370
- options.environment.enableEmitHookGuards
168748
+ pass.opts.environment.enableEmitHookGuards
167371
168749
  );
167372
168750
  externalFunctions.push(enableEmitHookGuards);
167373
168751
  }
168752
+ if (
168753
+ ((_h = pass.opts.environment) === null || _h === void 0
168754
+ ? void 0
168755
+ : _h.enableChangeDetectionForDebugging) != null
168756
+ ) {
168757
+ const enableChangeDetectionForDebugging = tryParseExternalFunction(
168758
+ pass.opts.environment.enableChangeDetectionForDebugging
168759
+ );
168760
+ externalFunctions.push(enableChangeDetectionForDebugging);
168761
+ }
167374
168762
  } catch (err) {
167375
168763
  handleError(err, pass, null);
167376
168764
  return;
@@ -167441,19 +168829,25 @@ function getReactFunctionType(fn, pass) {
167441
168829
  : "Other";
167442
168830
  }
167443
168831
  }
168832
+ let componentSyntaxType = null;
168833
+ if (fn.isFunctionDeclaration()) {
168834
+ if (isComponentDeclaration(fn.node)) {
168835
+ componentSyntaxType = "Component";
168836
+ } else if (isHookDeclaration(fn.node)) {
168837
+ componentSyntaxType = "Hook";
168838
+ }
168839
+ }
167444
168840
  switch (pass.opts.compilationMode) {
167445
168841
  case "annotation": {
167446
168842
  return null;
167447
168843
  }
167448
168844
  case "infer": {
167449
- if (fn.isFunctionDeclaration()) {
167450
- if (isComponentDeclaration(fn.node)) {
167451
- return "Component";
167452
- } else if (isHookDeclaration(fn.node)) {
167453
- return "Hook";
167454
- }
167455
- }
167456
- return getComponentOrHookLike(fn, hookPattern);
168845
+ return componentSyntaxType !== null && componentSyntaxType !== void 0
168846
+ ? componentSyntaxType
168847
+ : getComponentOrHookLike(fn, hookPattern);
168848
+ }
168849
+ case "syntax": {
168850
+ return componentSyntaxType;
167457
168851
  }
167458
168852
  case "all": {
167459
168853
  if (fn.scope.getProgramParent() !== fn.scope.parent) {
@@ -167543,15 +168937,62 @@ function isMemoCallback(path) {
167543
168937
  isReactAPI(path.parentPath.get("callee"), "memo")
167544
168938
  );
167545
168939
  }
168940
+ function isValidPropsAnnotation(annot) {
168941
+ if (annot == null) {
168942
+ return true;
168943
+ } else if (annot.type === "TSTypeAnnotation") {
168944
+ switch (annot.typeAnnotation.type) {
168945
+ case "TSArrayType":
168946
+ case "TSBigIntKeyword":
168947
+ case "TSBooleanKeyword":
168948
+ case "TSConstructorType":
168949
+ case "TSFunctionType":
168950
+ case "TSLiteralType":
168951
+ case "TSNeverKeyword":
168952
+ case "TSNumberKeyword":
168953
+ case "TSStringKeyword":
168954
+ case "TSSymbolKeyword":
168955
+ case "TSTupleType":
168956
+ return false;
168957
+ }
168958
+ return true;
168959
+ } else if (annot.type === "TypeAnnotation") {
168960
+ switch (annot.typeAnnotation.type) {
168961
+ case "ArrayTypeAnnotation":
168962
+ case "BooleanLiteralTypeAnnotation":
168963
+ case "BooleanTypeAnnotation":
168964
+ case "EmptyTypeAnnotation":
168965
+ case "FunctionTypeAnnotation":
168966
+ case "NumberLiteralTypeAnnotation":
168967
+ case "NumberTypeAnnotation":
168968
+ case "StringLiteralTypeAnnotation":
168969
+ case "StringTypeAnnotation":
168970
+ case "SymbolTypeAnnotation":
168971
+ case "ThisTypeAnnotation":
168972
+ case "TupleTypeAnnotation":
168973
+ return false;
168974
+ }
168975
+ return true;
168976
+ } else if (annot.type === "Noop") {
168977
+ return true;
168978
+ } else {
168979
+ assertExhaustive(annot, `Unexpected annotation node \`${annot}\``);
168980
+ }
168981
+ }
167546
168982
  function isValidComponentParams(params) {
167547
168983
  if (params.length === 0) {
167548
168984
  return true;
167549
- } else if (params.length === 1) {
167550
- return !params[0].isRestElement();
167551
- } else if (params.length === 2) {
167552
- if (params[1].isIdentifier()) {
168985
+ } else if (params.length > 0 && params.length <= 2) {
168986
+ if (!isValidPropsAnnotation(params[0].node.typeAnnotation)) {
168987
+ return false;
168988
+ }
168989
+ if (params.length === 1) {
168990
+ return !params[0].isRestElement();
168991
+ } else if (params[1].isIdentifier()) {
167553
168992
  const { name: name } = params[1].node;
167554
168993
  return name.includes("ref") || name.includes("Ref");
168994
+ } else {
168995
+ return false;
167555
168996
  }
167556
168997
  }
167557
168998
  return false;
@@ -167561,7 +169002,8 @@ function getComponentOrHookLike(node, hookPattern) {
167561
169002
  if (functionName !== null && isComponentName(functionName)) {
167562
169003
  let isComponent =
167563
169004
  callsHooksOrCreatesJsx(node, hookPattern) &&
167564
- isValidComponentParams(node.get("params"));
169005
+ isValidComponentParams(node.get("params")) &&
169006
+ !returnsNonNode(node);
167565
169007
  return isComponent ? "Component" : null;
167566
169008
  } else if (functionName !== null && isHook(functionName, hookPattern)) {
167567
169009
  return callsHooksOrCreatesJsx(node, hookPattern) ? "Hook" : null;
@@ -167573,6 +169015,13 @@ function getComponentOrHookLike(node, hookPattern) {
167573
169015
  }
167574
169016
  return null;
167575
169017
  }
169018
+ function skipNestedFunctions(node) {
169019
+ return (fn) => {
169020
+ if (fn.node !== node.node) {
169021
+ fn.skip();
169022
+ }
169023
+ };
169024
+ }
167576
169025
  function callsHooksOrCreatesJsx(node, hookPattern) {
167577
169026
  let invokesHooks = false;
167578
169027
  let createsJsx = false;
@@ -167586,9 +169035,39 @@ function callsHooksOrCreatesJsx(node, hookPattern) {
167586
169035
  invokesHooks = true;
167587
169036
  }
167588
169037
  },
169038
+ ArrowFunctionExpression: skipNestedFunctions(node),
169039
+ FunctionExpression: skipNestedFunctions(node),
169040
+ FunctionDeclaration: skipNestedFunctions(node),
167589
169041
  });
167590
169042
  return invokesHooks || createsJsx;
167591
169043
  }
169044
+ function returnsNonNode(node) {
169045
+ let hasReturn = false;
169046
+ let returnsNonNode = false;
169047
+ node.traverse({
169048
+ ReturnStatement(ret) {
169049
+ hasReturn = true;
169050
+ const argument = ret.node.argument;
169051
+ if (argument == null) {
169052
+ returnsNonNode = true;
169053
+ } else {
169054
+ switch (argument.type) {
169055
+ case "ObjectExpression":
169056
+ case "ArrowFunctionExpression":
169057
+ case "FunctionExpression":
169058
+ case "BigIntLiteral":
169059
+ case "ClassExpression":
169060
+ case "NewExpression":
169061
+ returnsNonNode = true;
169062
+ }
169063
+ }
169064
+ },
169065
+ ArrowFunctionExpression: skipNestedFunctions(node),
169066
+ FunctionExpression: skipNestedFunctions(node),
169067
+ FunctionDeclaration: skipNestedFunctions(node),
169068
+ });
169069
+ return !hasReturn || returnsNonNode;
169070
+ }
167592
169071
  function getFunctionName(path) {
167593
169072
  if (path.isFunctionDeclaration()) {
167594
169073
  const id = path.get("id");
@@ -167719,10 +169198,16 @@ function BabelPluginReactCompiler(_babel) {
167719
169198
  Program(prog, pass) {
167720
169199
  var _a, _b;
167721
169200
  let opts = parsePluginOptions(pass.opts);
167722
- if (pipelineUsesReanimatedPlugin(pass.file.opts.plugins)) {
169201
+ const isDev =
169202
+ (typeof __DEV__ !== "undefined" && __DEV__ === true) ||
169203
+ process.env["NODE_ENV"] === "development";
169204
+ if (
169205
+ opts.enableReanimatedCheck === true &&
169206
+ pipelineUsesReanimatedPlugin(pass.file.opts.plugins)
169207
+ ) {
167723
169208
  opts = injectReanimatedFlag(opts);
167724
169209
  }
167725
- if (process.env["NODE_ENV"] === "development") {
169210
+ if (isDev) {
167726
169211
  opts = Object.assign(Object.assign({}, opts), {
167727
169212
  environment: Object.assign(Object.assign({}, opts.environment), {
167728
169213
  enableResetCacheOnSourceFileChanges: true,