babel-plugin-react-compiler 0.0.0-experimental-fe484b5-20240912 → 0.0.0-experimental-23b8160-20240916

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
@@ -135625,6 +135625,31 @@ function getOrInsertDefault(m, key, defaultValue) {
135625
135625
  return defaultValue;
135626
135626
  }
135627
135627
  }
135628
+ function Set_union(a, b) {
135629
+ const union = new Set(a);
135630
+ for (const item of b) {
135631
+ union.add(item);
135632
+ }
135633
+ return union;
135634
+ }
135635
+ function Set_intersect(sets) {
135636
+ if (sets.length === 0 || sets.some(s => s.size === 0)) {
135637
+ return new Set();
135638
+ } else if (sets.length === 1) {
135639
+ return new Set(sets[0]);
135640
+ }
135641
+ const result = new Set();
135642
+ const first = sets[0];
135643
+ outer: for (const e of first) {
135644
+ for (let i = 1; i < sets.length; i++) {
135645
+ if (!sets[i].has(e)) {
135646
+ continue outer;
135647
+ }
135648
+ }
135649
+ result.add(e);
135650
+ }
135651
+ return result;
135652
+ }
135628
135653
  function Iterable_some(iter, pred) {
135629
135654
  for (const item of iter) {
135630
135655
  if (pred(item)) {
@@ -140998,6 +141023,7 @@ function getFunctionName$1(instrValue, defaultValue) {
140998
141023
  return defaultValue;
140999
141024
  }
141000
141025
  }
141026
+ var _ScopeBlockTraversal_activeScopes;
141001
141027
  function* eachInstructionLValue(instr) {
141002
141028
  if (instr.lvalue !== null) {
141003
141029
  yield instr.lvalue;
@@ -142052,6 +142078,93 @@ function* eachTerminalOperand(terminal) {
142052
142078
  }
142053
142079
  }
142054
142080
  }
142081
+ class ScopeBlockTraversal {
142082
+ constructor() {
142083
+ _ScopeBlockTraversal_activeScopes.set(this, []);
142084
+ this.blockInfos = new Map();
142085
+ }
142086
+ recordScopes(block) {
142087
+ var _a, _b;
142088
+ const blockInfo = this.blockInfos.get(block.id);
142089
+ if (
142090
+ (blockInfo === null || blockInfo === void 0 ? void 0 : blockInfo.kind) ===
142091
+ 'begin'
142092
+ ) {
142093
+ __classPrivateFieldGet(this, _ScopeBlockTraversal_activeScopes, 'f').push(
142094
+ blockInfo.scope.id
142095
+ );
142096
+ } else if (
142097
+ (blockInfo === null || blockInfo === void 0 ? void 0 : blockInfo.kind) ===
142098
+ 'end'
142099
+ ) {
142100
+ const top = __classPrivateFieldGet(
142101
+ this,
142102
+ _ScopeBlockTraversal_activeScopes,
142103
+ 'f'
142104
+ ).at(-1);
142105
+ CompilerError.invariant(blockInfo.scope.id === top, {
142106
+ reason:
142107
+ 'Expected traversed block fallthrough to match top-most active scope',
142108
+ loc:
142109
+ (_b =
142110
+ (_a = block.instructions[0]) === null || _a === void 0
142111
+ ? void 0
142112
+ : _a.loc) !== null && _b !== void 0
142113
+ ? _b
142114
+ : block.terminal.id,
142115
+ });
142116
+ __classPrivateFieldGet(
142117
+ this,
142118
+ _ScopeBlockTraversal_activeScopes,
142119
+ 'f'
142120
+ ).pop();
142121
+ }
142122
+ if (
142123
+ block.terminal.kind === 'scope' ||
142124
+ block.terminal.kind === 'pruned-scope'
142125
+ ) {
142126
+ CompilerError.invariant(
142127
+ !this.blockInfos.has(block.terminal.block) &&
142128
+ !this.blockInfos.has(block.terminal.fallthrough),
142129
+ {
142130
+ reason: 'Expected unique scope blocks and fallthroughs',
142131
+ loc: block.terminal.loc,
142132
+ }
142133
+ );
142134
+ this.blockInfos.set(block.terminal.block, {
142135
+ kind: 'begin',
142136
+ scope: block.terminal.scope,
142137
+ pruned: block.terminal.kind === 'pruned-scope',
142138
+ fallthrough: block.terminal.fallthrough,
142139
+ });
142140
+ this.blockInfos.set(block.terminal.fallthrough, {
142141
+ kind: 'end',
142142
+ scope: block.terminal.scope,
142143
+ pruned: block.terminal.kind === 'pruned-scope',
142144
+ });
142145
+ }
142146
+ }
142147
+ isScopeActive(scopeId) {
142148
+ return (
142149
+ __classPrivateFieldGet(
142150
+ this,
142151
+ _ScopeBlockTraversal_activeScopes,
142152
+ 'f'
142153
+ ).indexOf(scopeId) !== -1
142154
+ );
142155
+ }
142156
+ get currentScope() {
142157
+ var _a;
142158
+ return (_a = __classPrivateFieldGet(
142159
+ this,
142160
+ _ScopeBlockTraversal_activeScopes,
142161
+ 'f'
142162
+ ).at(-1)) !== null && _a !== void 0
142163
+ ? _a
142164
+ : null;
142165
+ }
142166
+ }
142167
+ _ScopeBlockTraversal_activeScopes = new WeakMap();
142055
142168
  function assertConsistentIdentifiers(fn) {
142056
142169
  const identifiers = new Map();
142057
142170
  const assignments = new Set();
@@ -150485,7 +150598,7 @@ const EnvironmentConfigSchema = z.object({
150485
150598
  enablePreserveExistingManualUseMemo: z.boolean().default(false),
150486
150599
  enableForest: z.boolean().default(false),
150487
150600
  enableUseTypeAnnotations: z.boolean().default(false),
150488
- enablePropagateDepsInHIR: z.boolean().default(true),
150601
+ enablePropagateDepsInHIR: z.boolean().default(false),
150489
150602
  enableOptionalDependencies: z.boolean().default(true),
150490
150603
  validateHooksUsage: z.boolean().default(true),
150491
150604
  validateRefAccessDuringRender: z.boolean().default(true),
@@ -153014,8 +153127,10 @@ function mergeLocation(l, r) {
153014
153127
  };
153015
153128
  }
153016
153129
  }
153017
- function isMutable({id: id}, place) {
153018
- const range = place.identifier.mutableRange;
153130
+ function isMutable(instr, place) {
153131
+ return inRange(instr, place.identifier.mutableRange);
153132
+ }
153133
+ function inRange({id: id}, range) {
153019
153134
  return id >= range.start && id < range.end;
153020
153135
  }
153021
153136
  function mayAllocate(env, instruction) {
@@ -155630,7 +155745,7 @@ var _Context_nextScheduleId,
155630
155745
  _Context_catchHandlers,
155631
155746
  _Context_controlFlowStack;
155632
155747
  function buildReactiveFunction(fn) {
155633
- const cx = new Context$2(fn.body);
155748
+ const cx = new Context$3(fn.body);
155634
155749
  const driver = new Driver(cx);
155635
155750
  const body = driver.traverseBlock(cx.block(fn.body.entry));
155636
155751
  return {
@@ -156678,7 +156793,7 @@ class Driver {
156678
156793
  };
156679
156794
  }
156680
156795
  }
156681
- let Context$2 = class Context {
156796
+ let Context$3 = class Context {
156682
156797
  constructor(ir) {
156683
156798
  _Context_nextScheduleId.set(this, 0);
156684
156799
  this.emitted = new Set();
@@ -157058,7 +157173,7 @@ function expandFbtScopeRange(fbtRange, extendWith) {
157058
157173
  );
157059
157174
  }
157060
157175
  }
157061
- var _Context_nextCacheIndex, _Context_declarations$1;
157176
+ var _Context_nextCacheIndex, _Context_declarations$2;
157062
157177
  const MEMO_CACHE_SENTINEL = 'react.memo_cache_sentinel';
157063
157178
  const EARLY_RETURN_SENTINEL = 'react.early_return_sentinel';
157064
157179
  function codegenFunction(
@@ -157066,7 +157181,7 @@ function codegenFunction(
157066
157181
  {uniqueIdentifiers: uniqueIdentifiers, fbtOperands: fbtOperands}
157067
157182
  ) {
157068
157183
  var _a, _b, _c;
157069
- const cx = new Context$1(
157184
+ const cx = new Context$2(
157070
157185
  fn.env,
157071
157186
  (_a = fn.id) !== null && _a !== void 0 ? _a : '[[ anonymous ]]',
157072
157187
  uniqueIdentifiers,
@@ -157231,7 +157346,7 @@ function codegenFunction(
157231
157346
  pruneHoistedContexts(reactiveFunction);
157232
157347
  const identifiers = renameVariables(reactiveFunction);
157233
157348
  const codegen = codegenReactiveFunction(
157234
- new Context$1(
157349
+ new Context$2(
157235
157350
  cx.env,
157236
157351
  (_c = reactiveFunction.id) !== null && _c !== void 0
157237
157352
  ? _c
@@ -157318,10 +157433,10 @@ function convertParameter(param) {
157318
157433
  return t__namespace.restElement(convertIdentifier(param.place.identifier));
157319
157434
  }
157320
157435
  }
157321
- let Context$1 = class Context {
157436
+ let Context$2 = class Context {
157322
157437
  constructor(env, fnName, uniqueIdentifiers, fbtOperands, temporaries = null) {
157323
157438
  _Context_nextCacheIndex.set(this, 0);
157324
- _Context_declarations$1.set(this, new Set());
157439
+ _Context_declarations$2.set(this, new Set());
157325
157440
  this.errors = new CompilerError();
157326
157441
  this.objectMethods = new Map();
157327
157442
  this.synthesizedNames = new Map();
@@ -157346,12 +157461,12 @@ let Context$1 = class Context {
157346
157461
  );
157347
157462
  }
157348
157463
  declare(identifier) {
157349
- __classPrivateFieldGet(this, _Context_declarations$1, 'f').add(
157464
+ __classPrivateFieldGet(this, _Context_declarations$2, 'f').add(
157350
157465
  identifier.declarationId
157351
157466
  );
157352
157467
  }
157353
157468
  hasDeclared(identifier) {
157354
- return __classPrivateFieldGet(this, _Context_declarations$1, 'f').has(
157469
+ return __classPrivateFieldGet(this, _Context_declarations$2, 'f').has(
157355
157470
  identifier.declarationId
157356
157471
  );
157357
157472
  }
@@ -157371,7 +157486,7 @@ let Context$1 = class Context {
157371
157486
  }
157372
157487
  };
157373
157488
  (_Context_nextCacheIndex = new WeakMap()),
157374
- (_Context_declarations$1 = new WeakMap());
157489
+ (_Context_declarations$2 = new WeakMap());
157375
157490
  function codegenBlock(cx, block) {
157376
157491
  const temp = new Map(cx.temp);
157377
157492
  const result = codegenBlockNoReset(cx, block);
@@ -158648,7 +158763,7 @@ function codegenInstructionValue(cx, instrValue) {
158648
158763
  pruneUnusedLabels(reactiveFunction);
158649
158764
  pruneUnusedLValues(reactiveFunction);
158650
158765
  const fn = codegenReactiveFunction(
158651
- new Context$1(
158766
+ new Context$2(
158652
158767
  cx.env,
158653
158768
  (_e = reactiveFunction.id) !== null && _e !== void 0
158654
158769
  ? _e
@@ -158847,7 +158962,7 @@ function codegenInstructionValue(cx, instrValue) {
158847
158962
  pruneUnusedLValues(reactiveFunction);
158848
158963
  pruneHoistedContexts(reactiveFunction);
158849
158964
  const fn = codegenReactiveFunction(
158850
- new Context$1(
158965
+ new Context$2(
158851
158966
  cx.env,
158852
158967
  (_g = reactiveFunction.id) !== null && _g !== void 0
158853
158968
  ? _g
@@ -160398,21 +160513,21 @@ class ReactiveScopeDependencyTree {
160398
160513
  _ReactiveScopeDependencyTree_getOrCreateRoot
160399
160514
  ).call(this, dep.identifier);
160400
160515
  for (const item of path) {
160401
- let currChild = getOrMakeProperty(currNode, item.property);
160516
+ let currChild = getOrMakeProperty$1(currNode, item.property);
160402
160517
  const accessType = inConditional
160403
- ? PropertyAccessType.ConditionalAccess
160518
+ ? PropertyAccessType$1.ConditionalAccess
160404
160519
  : item.optional
160405
- ? PropertyAccessType.OptionalAccess
160406
- : PropertyAccessType.UnconditionalAccess;
160407
- currChild.accessType = merge(currChild.accessType, accessType);
160520
+ ? PropertyAccessType$1.OptionalAccess
160521
+ : PropertyAccessType$1.UnconditionalAccess;
160522
+ currChild.accessType = merge$1(currChild.accessType, accessType);
160408
160523
  currNode = currChild;
160409
160524
  }
160410
160525
  const depType = inConditional
160411
- ? PropertyAccessType.ConditionalDependency
160526
+ ? PropertyAccessType$1.ConditionalDependency
160412
160527
  : isOptional(currNode.accessType)
160413
- ? PropertyAccessType.OptionalDependency
160414
- : PropertyAccessType.UnconditionalDependency;
160415
- currNode.accessType = merge(currNode.accessType, depType);
160528
+ ? PropertyAccessType$1.OptionalDependency
160529
+ : PropertyAccessType$1.UnconditionalDependency;
160530
+ currNode.accessType = merge$1(currNode.accessType, depType);
160416
160531
  }
160417
160532
  deriveMinimalDependencies() {
160418
160533
  const results = new Set();
@@ -160421,12 +160536,12 @@ class ReactiveScopeDependencyTree {
160421
160536
  _ReactiveScopeDependencyTree_roots,
160422
160537
  'f'
160423
160538
  ).entries()) {
160424
- const deps = deriveMinimalDependenciesInSubtree(rootNode, null);
160539
+ const deps = deriveMinimalDependenciesInSubtree$1(rootNode, null);
160425
160540
  CompilerError.invariant(
160426
160541
  deps.every(
160427
160542
  dep =>
160428
- dep.accessType === PropertyAccessType.UnconditionalDependency ||
160429
- dep.accessType == PropertyAccessType.OptionalDependency
160543
+ dep.accessType === PropertyAccessType$1.UnconditionalDependency ||
160544
+ dep.accessType == PropertyAccessType$1.OptionalDependency
160430
160545
  ),
160431
160546
  {
160432
160547
  reason:
@@ -160463,9 +160578,9 @@ class ReactiveScopeDependencyTree {
160463
160578
  ).call(this, id);
160464
160579
  addSubtree(currRoot, otherRoot, innerScopeInConditionalWithinParent);
160465
160580
  if (!isUnconditional(currRoot.accessType)) {
160466
- currRoot.accessType = isDependency(currRoot.accessType)
160467
- ? PropertyAccessType.UnconditionalDependency
160468
- : PropertyAccessType.UnconditionalAccess;
160581
+ currRoot.accessType = isDependency$1(currRoot.accessType)
160582
+ ? PropertyAccessType$1.UnconditionalDependency
160583
+ : PropertyAccessType$1.UnconditionalAccess;
160469
160584
  }
160470
160585
  }
160471
160586
  }
@@ -160508,7 +160623,7 @@ class ReactiveScopeDependencyTree {
160508
160623
  _ReactiveScopeDependencyTree_roots,
160509
160624
  'f'
160510
160625
  ).entries()) {
160511
- const rootResults = printSubtree(rootNode, includeAccesses).map(
160626
+ const rootResults = printSubtree$1(rootNode, includeAccesses).map(
160512
160627
  result => `${printIdentifier(rootId)}.${result}`
160513
160628
  );
160514
160629
  res.push(rootResults);
@@ -160546,7 +160661,7 @@ class ReactiveScopeDependencyTree {
160546
160661
  if (rootNode === undefined) {
160547
160662
  rootNode = {
160548
160663
  properties: new Map(),
160549
- accessType: PropertyAccessType.UnconditionalAccess,
160664
+ accessType: PropertyAccessType$1.UnconditionalAccess,
160550
160665
  };
160551
160666
  __classPrivateFieldGet(
160552
160667
  this,
@@ -160570,7 +160685,7 @@ class ReactiveScopeDependencyTree {
160570
160685
  ).call(this, buf, childNode, depth + 1);
160571
160686
  }
160572
160687
  });
160573
- var PropertyAccessType;
160688
+ var PropertyAccessType$1;
160574
160689
  (function (PropertyAccessType) {
160575
160690
  PropertyAccessType['ConditionalAccess'] = 'ConditionalAccess';
160576
160691
  PropertyAccessType['OptionalAccess'] = 'OptionalAccess';
@@ -160578,49 +160693,49 @@ var PropertyAccessType;
160578
160693
  PropertyAccessType['ConditionalDependency'] = 'ConditionalDependency';
160579
160694
  PropertyAccessType['OptionalDependency'] = 'OptionalDependency';
160580
160695
  PropertyAccessType['UnconditionalDependency'] = 'UnconditionalDependency';
160581
- })(PropertyAccessType || (PropertyAccessType = {}));
160582
- const MIN_ACCESS_TYPE = PropertyAccessType.ConditionalAccess;
160696
+ })(PropertyAccessType$1 || (PropertyAccessType$1 = {}));
160697
+ const MIN_ACCESS_TYPE$1 = PropertyAccessType$1.ConditionalAccess;
160583
160698
  function isUnconditional(access) {
160584
160699
  return (
160585
- access === PropertyAccessType.UnconditionalAccess ||
160586
- access === PropertyAccessType.UnconditionalDependency
160700
+ access === PropertyAccessType$1.UnconditionalAccess ||
160701
+ access === PropertyAccessType$1.UnconditionalDependency
160587
160702
  );
160588
160703
  }
160589
- function isDependency(access) {
160704
+ function isDependency$1(access) {
160590
160705
  return (
160591
- access === PropertyAccessType.ConditionalDependency ||
160592
- access === PropertyAccessType.OptionalDependency ||
160593
- access === PropertyAccessType.UnconditionalDependency
160706
+ access === PropertyAccessType$1.ConditionalDependency ||
160707
+ access === PropertyAccessType$1.OptionalDependency ||
160708
+ access === PropertyAccessType$1.UnconditionalDependency
160594
160709
  );
160595
160710
  }
160596
160711
  function isOptional(access) {
160597
160712
  return (
160598
- access === PropertyAccessType.OptionalAccess ||
160599
- access === PropertyAccessType.OptionalDependency
160713
+ access === PropertyAccessType$1.OptionalAccess ||
160714
+ access === PropertyAccessType$1.OptionalDependency
160600
160715
  );
160601
160716
  }
160602
- function merge(access1, access2) {
160717
+ function merge$1(access1, access2) {
160603
160718
  const resultIsUnconditional =
160604
160719
  isUnconditional(access1) || isUnconditional(access2);
160605
- const resultIsDependency = isDependency(access1) || isDependency(access2);
160720
+ const resultIsDependency = isDependency$1(access1) || isDependency$1(access2);
160606
160721
  const resultIsOptional = isOptional(access1) || isOptional(access2);
160607
160722
  if (resultIsUnconditional) {
160608
160723
  if (resultIsDependency) {
160609
- return PropertyAccessType.UnconditionalDependency;
160724
+ return PropertyAccessType$1.UnconditionalDependency;
160610
160725
  } else {
160611
- return PropertyAccessType.UnconditionalAccess;
160726
+ return PropertyAccessType$1.UnconditionalAccess;
160612
160727
  }
160613
160728
  } else if (resultIsOptional) {
160614
160729
  if (resultIsDependency) {
160615
- return PropertyAccessType.OptionalDependency;
160730
+ return PropertyAccessType$1.OptionalDependency;
160616
160731
  } else {
160617
- return PropertyAccessType.OptionalAccess;
160732
+ return PropertyAccessType$1.OptionalAccess;
160618
160733
  }
160619
160734
  } else {
160620
160735
  if (resultIsDependency) {
160621
- return PropertyAccessType.ConditionalDependency;
160736
+ return PropertyAccessType$1.ConditionalDependency;
160622
160737
  } else {
160623
- return PropertyAccessType.ConditionalAccess;
160738
+ return PropertyAccessType$1.ConditionalAccess;
160624
160739
  }
160625
160740
  }
160626
160741
  }
@@ -160640,28 +160755,28 @@ function prependPath(results, path) {
160640
160755
  relativePath: [path, ...result.relativePath],
160641
160756
  }));
160642
160757
  }
160643
- function deriveMinimalDependenciesInSubtree(dep, property) {
160758
+ function deriveMinimalDependenciesInSubtree$1(dep, property) {
160644
160759
  const results = [];
160645
160760
  for (const [childName, childNode] of dep.properties) {
160646
- const childResult = deriveMinimalDependenciesInSubtree(
160761
+ const childResult = deriveMinimalDependenciesInSubtree$1(
160647
160762
  childNode,
160648
160763
  childName
160649
160764
  );
160650
160765
  results.push(...childResult);
160651
160766
  }
160652
160767
  switch (dep.accessType) {
160653
- case PropertyAccessType.UnconditionalDependency: {
160768
+ case PropertyAccessType$1.UnconditionalDependency: {
160654
160769
  return promoteResult(
160655
- PropertyAccessType.UnconditionalDependency,
160770
+ PropertyAccessType$1.UnconditionalDependency,
160656
160771
  property !== null ? {property: property, optional: false} : null
160657
160772
  );
160658
160773
  }
160659
- case PropertyAccessType.UnconditionalAccess: {
160774
+ case PropertyAccessType$1.UnconditionalAccess: {
160660
160775
  if (
160661
160776
  results.every(
160662
160777
  ({accessType: accessType}) =>
160663
- accessType === PropertyAccessType.UnconditionalDependency ||
160664
- accessType === PropertyAccessType.OptionalDependency
160778
+ accessType === PropertyAccessType$1.UnconditionalDependency ||
160779
+ accessType === PropertyAccessType$1.OptionalDependency
160665
160780
  )
160666
160781
  ) {
160667
160782
  return prependPath(
@@ -160670,23 +160785,23 @@ function deriveMinimalDependenciesInSubtree(dep, property) {
160670
160785
  );
160671
160786
  } else {
160672
160787
  return promoteResult(
160673
- PropertyAccessType.UnconditionalDependency,
160788
+ PropertyAccessType$1.UnconditionalDependency,
160674
160789
  property !== null ? {property: property, optional: false} : null
160675
160790
  );
160676
160791
  }
160677
160792
  }
160678
- case PropertyAccessType.OptionalDependency: {
160793
+ case PropertyAccessType$1.OptionalDependency: {
160679
160794
  return promoteResult(
160680
- PropertyAccessType.OptionalDependency,
160795
+ PropertyAccessType$1.OptionalDependency,
160681
160796
  property !== null ? {property: property, optional: true} : null
160682
160797
  );
160683
160798
  }
160684
- case PropertyAccessType.OptionalAccess: {
160799
+ case PropertyAccessType$1.OptionalAccess: {
160685
160800
  if (
160686
160801
  results.every(
160687
160802
  ({accessType: accessType}) =>
160688
- accessType === PropertyAccessType.UnconditionalDependency ||
160689
- accessType === PropertyAccessType.OptionalDependency
160803
+ accessType === PropertyAccessType$1.UnconditionalDependency ||
160804
+ accessType === PropertyAccessType$1.OptionalDependency
160690
160805
  )
160691
160806
  ) {
160692
160807
  return prependPath(
@@ -160695,26 +160810,26 @@ function deriveMinimalDependenciesInSubtree(dep, property) {
160695
160810
  );
160696
160811
  } else {
160697
160812
  return promoteResult(
160698
- PropertyAccessType.OptionalDependency,
160813
+ PropertyAccessType$1.OptionalDependency,
160699
160814
  property !== null ? {property: property, optional: true} : null
160700
160815
  );
160701
160816
  }
160702
160817
  }
160703
- case PropertyAccessType.ConditionalAccess:
160704
- case PropertyAccessType.ConditionalDependency: {
160818
+ case PropertyAccessType$1.ConditionalAccess:
160819
+ case PropertyAccessType$1.ConditionalDependency: {
160705
160820
  if (
160706
160821
  results.every(
160707
160822
  ({accessType: accessType}) =>
160708
- accessType === PropertyAccessType.ConditionalDependency
160823
+ accessType === PropertyAccessType$1.ConditionalDependency
160709
160824
  )
160710
160825
  ) {
160711
160826
  return promoteResult(
160712
- PropertyAccessType.ConditionalDependency,
160827
+ PropertyAccessType$1.ConditionalDependency,
160713
160828
  property !== null ? {property: property, optional: true} : null
160714
160829
  );
160715
160830
  } else {
160716
160831
  return promoteResult(
160717
- PropertyAccessType.UnconditionalDependency,
160832
+ PropertyAccessType$1.UnconditionalDependency,
160718
160833
  property !== null ? {property: property, optional: true} : null
160719
160834
  );
160720
160835
  }
@@ -160735,9 +160850,9 @@ function demoteSubtreeToConditional(subtree) {
160735
160850
  if (!isUnconditional(accessType)) {
160736
160851
  continue;
160737
160852
  }
160738
- node.accessType = isDependency(accessType)
160739
- ? PropertyAccessType.ConditionalDependency
160740
- : PropertyAccessType.ConditionalAccess;
160853
+ node.accessType = isDependency$1(accessType)
160854
+ ? PropertyAccessType$1.ConditionalDependency
160855
+ : PropertyAccessType$1.ConditionalAccess;
160741
160856
  for (const childNode of properties.values()) {
160742
160857
  if (isUnconditional(accessType)) {
160743
160858
  stack.push(childNode);
@@ -160748,11 +160863,11 @@ function demoteSubtreeToConditional(subtree) {
160748
160863
  function addSubtree(currNode, otherNode, demoteOtherNode) {
160749
160864
  let otherType = otherNode.accessType;
160750
160865
  if (demoteOtherNode) {
160751
- otherType = isDependency(otherType)
160752
- ? PropertyAccessType.ConditionalDependency
160753
- : PropertyAccessType.ConditionalAccess;
160866
+ otherType = isDependency$1(otherType)
160867
+ ? PropertyAccessType$1.ConditionalDependency
160868
+ : PropertyAccessType$1.ConditionalAccess;
160754
160869
  }
160755
- currNode.accessType = merge(currNode.accessType, otherType);
160870
+ currNode.accessType = merge$1(currNode.accessType, otherType);
160756
160871
  for (const [propertyName, otherChild] of otherNode.properties) {
160757
160872
  const currChild = currNode.properties.get(propertyName);
160758
160873
  if (currChild) {
@@ -160787,29 +160902,29 @@ function addSubtreeIntersection(currProperties, otherProperties) {
160787
160902
  currNode.properties,
160788
160903
  otherNodes.map(node => node.properties)
160789
160904
  );
160790
- const isDep = otherNodes.some(tree => isDependency(tree.accessType));
160905
+ const isDep = otherNodes.some(tree => isDependency$1(tree.accessType));
160791
160906
  const externalAccessType = isDep
160792
- ? PropertyAccessType.UnconditionalDependency
160793
- : PropertyAccessType.UnconditionalAccess;
160794
- currNode.accessType = merge(externalAccessType, currNode.accessType);
160907
+ ? PropertyAccessType$1.UnconditionalDependency
160908
+ : PropertyAccessType$1.UnconditionalAccess;
160909
+ currNode.accessType = merge$1(externalAccessType, currNode.accessType);
160795
160910
  }
160796
160911
  }
160797
160912
  }
160798
- function printSubtree(node, includeAccesses) {
160913
+ function printSubtree$1(node, includeAccesses) {
160799
160914
  const results = [];
160800
160915
  for (const [propertyName, propertyNode] of node.properties) {
160801
- if (includeAccesses || isDependency(propertyNode.accessType)) {
160916
+ if (includeAccesses || isDependency$1(propertyNode.accessType)) {
160802
160917
  results.push(`${propertyName} (${propertyNode.accessType})`);
160803
160918
  }
160804
- const propertyResults = printSubtree(propertyNode, includeAccesses);
160919
+ const propertyResults = printSubtree$1(propertyNode, includeAccesses);
160805
160920
  results.push(...propertyResults.map(result => `${propertyName}.${result}`));
160806
160921
  }
160807
160922
  return results;
160808
160923
  }
160809
- function getOrMakeProperty(node, property) {
160924
+ function getOrMakeProperty$1(node, property) {
160810
160925
  let child = node.properties.get(property);
160811
160926
  if (child == null) {
160812
- child = {properties: new Map(), accessType: MIN_ACCESS_TYPE};
160927
+ child = {properties: new Map(), accessType: MIN_ACCESS_TYPE$1};
160813
160928
  node.properties.set(property, child);
160814
160929
  }
160815
160930
  return child;
@@ -160828,26 +160943,26 @@ function mapNonNull(arr, fn) {
160828
160943
  }
160829
160944
  var _PoisonState_instances,
160830
160945
  _PoisonState_invalidate,
160831
- _Context_instances,
160832
- _Context_temporariesUsedOutsideScope,
160833
- _Context_declarations,
160834
- _Context_reassignments,
160835
- _Context_dependencies,
160946
+ _Context_instances$1,
160947
+ _Context_temporariesUsedOutsideScope$1,
160948
+ _Context_declarations$1,
160949
+ _Context_reassignments$1,
160950
+ _Context_dependencies$1,
160836
160951
  _Context_properties,
160837
- _Context_temporaries,
160952
+ _Context_temporaries$1,
160838
160953
  _Context_inConditionalWithinScope,
160839
160954
  _Context_depsInCurrentConditional,
160840
- _Context_scopes,
160955
+ _Context_scopes$1,
160841
160956
  _Context_getProperty,
160842
- _Context_checkValidDependency,
160843
- _Context_isScopeActive;
160957
+ _Context_checkValidDependency$1,
160958
+ _Context_isScopeActive$1;
160844
160959
  function propagateScopeDependencies(fn) {
160845
160960
  const escapingTemporaries = {
160846
160961
  declarations: new Map(),
160847
160962
  usedOutsideDeclaringScope: new Set(),
160848
160963
  };
160849
160964
  visitReactiveFunction(fn, new FindPromotedTemporaries(), escapingTemporaries);
160850
- const context = new Context(escapingTemporaries.usedOutsideDeclaringScope);
160965
+ const context = new Context$1(escapingTemporaries.usedOutsideDeclaringScope);
160851
160966
  for (const param of fn.params) {
160852
160967
  if (param.kind === 'Identifier') {
160853
160968
  context.declare(param.identifier, {
@@ -161015,25 +161130,25 @@ class PoisonState {
161015
161130
  }
161016
161131
  this.isPoisoned = false;
161017
161132
  });
161018
- class Context {
161133
+ let Context$1 = class Context {
161019
161134
  constructor(temporariesUsedOutsideScope) {
161020
- _Context_instances.add(this);
161021
- _Context_temporariesUsedOutsideScope.set(this, void 0);
161022
- _Context_declarations.set(this, new Map());
161023
- _Context_reassignments.set(this, new Map());
161024
- _Context_dependencies.set(this, new ReactiveScopeDependencyTree());
161135
+ _Context_instances$1.add(this);
161136
+ _Context_temporariesUsedOutsideScope$1.set(this, void 0);
161137
+ _Context_declarations$1.set(this, new Map());
161138
+ _Context_reassignments$1.set(this, new Map());
161139
+ _Context_dependencies$1.set(this, new ReactiveScopeDependencyTree());
161025
161140
  _Context_properties.set(this, new Map());
161026
- _Context_temporaries.set(this, new Map());
161141
+ _Context_temporaries$1.set(this, new Map());
161027
161142
  _Context_inConditionalWithinScope.set(this, false);
161028
161143
  _Context_depsInCurrentConditional.set(
161029
161144
  this,
161030
161145
  new ReactiveScopeDependencyTree()
161031
161146
  );
161032
- _Context_scopes.set(this, empty());
161147
+ _Context_scopes$1.set(this, empty());
161033
161148
  this.poisonState = new PoisonState(new Set(), new Set(), false);
161034
161149
  __classPrivateFieldSet(
161035
161150
  this,
161036
- _Context_temporariesUsedOutsideScope,
161151
+ _Context_temporariesUsedOutsideScope$1,
161037
161152
  temporariesUsedOutsideScope,
161038
161153
  'f'
161039
161154
  );
@@ -161046,7 +161161,7 @@ class Context {
161046
161161
  );
161047
161162
  const previousDependencies = __classPrivateFieldGet(
161048
161163
  this,
161049
- _Context_dependencies,
161164
+ _Context_dependencies$1,
161050
161165
  'f'
161051
161166
  );
161052
161167
  const prevDepsInConditional = this.isPoisoned
@@ -161064,14 +161179,14 @@ class Context {
161064
161179
  __classPrivateFieldSet(this, _Context_inConditionalWithinScope, false, 'f');
161065
161180
  __classPrivateFieldSet(
161066
161181
  this,
161067
- _Context_dependencies,
161182
+ _Context_dependencies$1,
161068
161183
  scopedDependencies,
161069
161184
  'f'
161070
161185
  );
161071
161186
  __classPrivateFieldSet(
161072
161187
  this,
161073
- _Context_scopes,
161074
- __classPrivateFieldGet(this, _Context_scopes, 'f').push({
161188
+ _Context_scopes$1,
161189
+ __classPrivateFieldGet(this, _Context_scopes$1, 'f').push({
161075
161190
  value: scope,
161076
161191
  ownBlocks: empty(),
161077
161192
  }),
@@ -161081,17 +161196,17 @@ class Context {
161081
161196
  fn();
161082
161197
  __classPrivateFieldSet(
161083
161198
  this,
161084
- _Context_scopes,
161085
- __classPrivateFieldGet(this, _Context_scopes, 'f').pop(),
161199
+ _Context_scopes$1,
161200
+ __classPrivateFieldGet(this, _Context_scopes$1, 'f').pop(),
161086
161201
  'f'
161087
161202
  );
161088
161203
  this.poisonState.removeMaybePoisonedScope(
161089
161204
  scope.id,
161090
- __classPrivateFieldGet(this, _Context_scopes, 'f').value
161205
+ __classPrivateFieldGet(this, _Context_scopes$1, 'f').value
161091
161206
  );
161092
161207
  __classPrivateFieldSet(
161093
161208
  this,
161094
- _Context_dependencies,
161209
+ _Context_dependencies$1,
161095
161210
  previousDependencies,
161096
161211
  'f'
161097
161212
  );
@@ -161105,7 +161220,7 @@ class Context {
161105
161220
  scopedDependencies.deriveMinimalDependencies();
161106
161221
  __classPrivateFieldGet(
161107
161222
  this,
161108
- _Context_dependencies,
161223
+ _Context_dependencies$1,
161109
161224
  'f'
161110
161225
  ).addDepsFromInnerScope(
161111
161226
  scopedDependencies,
@@ -161113,9 +161228,9 @@ class Context {
161113
161228
  this.isPoisoned,
161114
161229
  __classPrivateFieldGet(
161115
161230
  this,
161116
- _Context_instances,
161231
+ _Context_instances$1,
161117
161232
  'm',
161118
- _Context_checkValidDependency
161233
+ _Context_checkValidDependency$1
161119
161234
  ).bind(this)
161120
161235
  );
161121
161236
  if (prevDepsInConditional != null) {
@@ -161124,9 +161239,9 @@ class Context {
161124
161239
  true,
161125
161240
  __classPrivateFieldGet(
161126
161241
  this,
161127
- _Context_instances,
161242
+ _Context_instances$1,
161128
161243
  'm',
161129
- _Context_checkValidDependency
161244
+ _Context_checkValidDependency$1
161130
161245
  ).bind(this)
161131
161246
  );
161132
161247
  __classPrivateFieldSet(
@@ -161141,12 +161256,12 @@ class Context {
161141
161256
  isUsedOutsideDeclaringScope(place) {
161142
161257
  return __classPrivateFieldGet(
161143
161258
  this,
161144
- _Context_temporariesUsedOutsideScope,
161259
+ _Context_temporariesUsedOutsideScope$1,
161145
161260
  'f'
161146
161261
  ).has(place.identifier.declarationId);
161147
161262
  }
161148
161263
  printDeps(includeAccesses = false) {
161149
- return __classPrivateFieldGet(this, _Context_dependencies, 'f').printDeps(
161264
+ return __classPrivateFieldGet(this, _Context_dependencies$1, 'f').printDeps(
161150
161265
  includeAccesses
161151
161266
  );
161152
161267
  }
@@ -161191,7 +161306,7 @@ class Context {
161191
161306
  promoteDepsFromExhaustiveConditionals(depsInConditionals) {
161192
161307
  __classPrivateFieldGet(
161193
161308
  this,
161194
- _Context_dependencies,
161309
+ _Context_dependencies$1,
161195
161310
  'f'
161196
161311
  ).promoteDepsFromExhaustiveConditionals(depsInConditionals);
161197
161312
  __classPrivateFieldGet(
@@ -161202,29 +161317,29 @@ class Context {
161202
161317
  }
161203
161318
  declare(identifier, decl) {
161204
161319
  if (
161205
- !__classPrivateFieldGet(this, _Context_declarations, 'f').has(
161320
+ !__classPrivateFieldGet(this, _Context_declarations$1, 'f').has(
161206
161321
  identifier.declarationId
161207
161322
  )
161208
161323
  ) {
161209
- __classPrivateFieldGet(this, _Context_declarations, 'f').set(
161324
+ __classPrivateFieldGet(this, _Context_declarations$1, 'f').set(
161210
161325
  identifier.declarationId,
161211
161326
  decl
161212
161327
  );
161213
161328
  }
161214
- __classPrivateFieldGet(this, _Context_reassignments, 'f').set(
161329
+ __classPrivateFieldGet(this, _Context_reassignments$1, 'f').set(
161215
161330
  identifier,
161216
161331
  decl
161217
161332
  );
161218
161333
  }
161219
161334
  declareTemporary(lvalue, place) {
161220
- __classPrivateFieldGet(this, _Context_temporaries, 'f').set(
161335
+ __classPrivateFieldGet(this, _Context_temporaries$1, 'f').set(
161221
161336
  lvalue.identifier,
161222
161337
  place
161223
161338
  );
161224
161339
  }
161225
161340
  resolveTemporary(place) {
161226
161341
  var _a;
161227
- return (_a = __classPrivateFieldGet(this, _Context_temporaries, 'f').get(
161342
+ return (_a = __classPrivateFieldGet(this, _Context_temporaries$1, 'f').get(
161228
161343
  place.identifier
161229
161344
  )) !== null && _a !== void 0
161230
161345
  ? _a
@@ -161233,7 +161348,7 @@ class Context {
161233
161348
  declareProperty(lvalue, object, property, optional) {
161234
161349
  const nextDependency = __classPrivateFieldGet(
161235
161350
  this,
161236
- _Context_instances,
161351
+ _Context_instances$1,
161237
161352
  'm',
161238
161353
  _Context_getProperty
161239
161354
  ).call(this, object, property, optional);
@@ -161243,7 +161358,7 @@ class Context {
161243
161358
  );
161244
161359
  }
161245
161360
  get currentScope() {
161246
- return __classPrivateFieldGet(this, _Context_scopes, 'f');
161361
+ return __classPrivateFieldGet(this, _Context_scopes$1, 'f');
161247
161362
  }
161248
161363
  get isPoisoned() {
161249
161364
  return this.poisonState.isPoisoned;
@@ -161266,7 +161381,7 @@ class Context {
161266
161381
  visitProperty(object, property, optional) {
161267
161382
  const nextDependency = __classPrivateFieldGet(
161268
161383
  this,
161269
- _Context_instances,
161384
+ _Context_instances$1,
161270
161385
  'm',
161271
161386
  _Context_getProperty
161272
161387
  ).call(this, object, property, optional);
@@ -161275,7 +161390,7 @@ class Context {
161275
161390
  visitDependency(maybeDependency) {
161276
161391
  const originalDeclaration = __classPrivateFieldGet(
161277
161392
  this,
161278
- _Context_declarations,
161393
+ _Context_declarations$1,
161279
161394
  'f'
161280
161395
  ).get(maybeDependency.identifier.declarationId);
161281
161396
  if (
@@ -161286,9 +161401,9 @@ class Context {
161286
161401
  if (
161287
161402
  !__classPrivateFieldGet(
161288
161403
  this,
161289
- _Context_instances,
161404
+ _Context_instances$1,
161290
161405
  'm',
161291
- _Context_isScopeActive
161406
+ _Context_isScopeActive$1
161292
161407
  ).call(this, scope.value) &&
161293
161408
  !Iterable_some(
161294
161409
  scope.value.declarations.values(),
@@ -161307,9 +161422,9 @@ class Context {
161307
161422
  if (
161308
161423
  __classPrivateFieldGet(
161309
161424
  this,
161310
- _Context_instances,
161425
+ _Context_instances$1,
161311
161426
  'm',
161312
- _Context_checkValidDependency
161427
+ _Context_checkValidDependency$1
161313
161428
  ).call(this, maybeDependency)
161314
161429
  ) {
161315
161430
  const isPoisoned = this.isPoisoned;
@@ -161317,7 +161432,7 @@ class Context {
161317
161432
  maybeDependency,
161318
161433
  isPoisoned
161319
161434
  );
161320
- __classPrivateFieldGet(this, _Context_dependencies, 'f').add(
161435
+ __classPrivateFieldGet(this, _Context_dependencies$1, 'f').add(
161321
161436
  maybeDependency,
161322
161437
  __classPrivateFieldGet(this, _Context_inConditionalWithinScope, 'f') ||
161323
161438
  isPoisoned
@@ -161339,9 +161454,9 @@ class Context {
161339
161454
  ) &&
161340
161455
  __classPrivateFieldGet(
161341
161456
  this,
161342
- _Context_instances,
161457
+ _Context_instances$1,
161343
161458
  'm',
161344
- _Context_checkValidDependency
161459
+ _Context_checkValidDependency$1
161345
161460
  ).call(this, {identifier: place.identifier, path: []})
161346
161461
  ) {
161347
161462
  currentScope.reassignments.add(place.identifier);
@@ -161350,7 +161465,7 @@ class Context {
161350
161465
  pushLabeledBlock(id) {
161351
161466
  const currentScope = __classPrivateFieldGet(
161352
161467
  this,
161353
- _Context_scopes,
161468
+ _Context_scopes$1,
161354
161469
  'f'
161355
161470
  ).value;
161356
161471
  if (currentScope != null) {
@@ -161360,7 +161475,7 @@ class Context {
161360
161475
  popLabeledBlock(id) {
161361
161476
  const currentScope = __classPrivateFieldGet(
161362
161477
  this,
161363
- _Context_scopes,
161478
+ _Context_scopes$1,
161364
161479
  'f'
161365
161480
  ).value;
161366
161481
  if (currentScope != null) {
@@ -161373,17 +161488,17 @@ class Context {
161373
161488
  }
161374
161489
  this.poisonState.removeMaybePoisonedBlock(id, currentScope);
161375
161490
  }
161376
- }
161377
- (_Context_temporariesUsedOutsideScope = new WeakMap()),
161378
- (_Context_declarations = new WeakMap()),
161379
- (_Context_reassignments = new WeakMap()),
161380
- (_Context_dependencies = new WeakMap()),
161491
+ };
161492
+ (_Context_temporariesUsedOutsideScope$1 = new WeakMap()),
161493
+ (_Context_declarations$1 = new WeakMap()),
161494
+ (_Context_reassignments$1 = new WeakMap()),
161495
+ (_Context_dependencies$1 = new WeakMap()),
161381
161496
  (_Context_properties = new WeakMap()),
161382
- (_Context_temporaries = new WeakMap()),
161497
+ (_Context_temporaries$1 = new WeakMap()),
161383
161498
  (_Context_inConditionalWithinScope = new WeakMap()),
161384
161499
  (_Context_depsInCurrentConditional = new WeakMap()),
161385
- (_Context_scopes = new WeakMap()),
161386
- (_Context_instances = new WeakSet()),
161500
+ (_Context_scopes$1 = new WeakMap()),
161501
+ (_Context_instances$1 = new WeakSet()),
161387
161502
  (_Context_getProperty = function _Context_getProperty(
161388
161503
  object,
161389
161504
  property,
@@ -161407,7 +161522,7 @@ class Context {
161407
161522
  objectDependency.path.push({property: property, optional: optional});
161408
161523
  return objectDependency;
161409
161524
  }),
161410
- (_Context_checkValidDependency = function _Context_checkValidDependency(
161525
+ (_Context_checkValidDependency$1 = function _Context_checkValidDependency(
161411
161526
  maybeDependency
161412
161527
  ) {
161413
161528
  var _a, _b, _c, _d;
@@ -161427,11 +161542,11 @@ class Context {
161427
161542
  }
161428
161543
  const identifier = maybeDependency.identifier;
161429
161544
  const currentDeclaration =
161430
- (_b = __classPrivateFieldGet(this, _Context_reassignments, 'f').get(
161545
+ (_b = __classPrivateFieldGet(this, _Context_reassignments$1, 'f').get(
161431
161546
  identifier
161432
161547
  )) !== null && _b !== void 0
161433
161548
  ? _b
161434
- : __classPrivateFieldGet(this, _Context_declarations, 'f').get(
161549
+ : __classPrivateFieldGet(this, _Context_declarations$1, 'f').get(
161435
161550
  identifier.declarationId
161436
161551
  );
161437
161552
  const currentScope =
@@ -161448,11 +161563,11 @@ class Context {
161448
161563
  : _d.value) !== currentScope)
161449
161564
  );
161450
161565
  }),
161451
- (_Context_isScopeActive = function _Context_isScopeActive(scope) {
161452
- if (__classPrivateFieldGet(this, _Context_scopes, 'f') === null) {
161566
+ (_Context_isScopeActive$1 = function _Context_isScopeActive(scope) {
161567
+ if (__classPrivateFieldGet(this, _Context_scopes$1, 'f') === null) {
161453
161568
  return false;
161454
161569
  }
161455
- return __classPrivateFieldGet(this, _Context_scopes, 'f').find(
161570
+ return __classPrivateFieldGet(this, _Context_scopes$1, 'f').find(
161456
161571
  state => state.value === scope
161457
161572
  );
161458
161573
  });
@@ -161975,6 +162090,248 @@ let Visitor$8 = class Visitor extends ReactiveFunctionTransform {
161975
162090
  return {kind: 'keep'};
161976
162091
  }
161977
162092
  };
162093
+ function inferOperandEffect(state, place) {
162094
+ const value = state.kind(place);
162095
+ CompilerError.invariant(value != null, {
162096
+ reason: 'Expected operand to have a kind',
162097
+ loc: null,
162098
+ });
162099
+ switch (place.effect) {
162100
+ case exports.Effect.Store:
162101
+ case exports.Effect.Mutate: {
162102
+ if (isRefOrRefValue(place.identifier)) {
162103
+ break;
162104
+ } else if (value.kind === exports.ValueKind.Context) {
162105
+ return {
162106
+ kind: 'ContextMutation',
162107
+ loc: place.loc,
162108
+ effect: place.effect,
162109
+ places: value.context.size === 0 ? new Set([place]) : value.context,
162110
+ };
162111
+ } else if (
162112
+ value.kind !== exports.ValueKind.Mutable &&
162113
+ value.kind !== exports.ValueKind.Primitive
162114
+ ) {
162115
+ let reason = getWriteErrorReason(value);
162116
+ return {
162117
+ kind:
162118
+ value.reason.size === 1 && value.reason.has(ValueReason.Global)
162119
+ ? 'GlobalMutation'
162120
+ : 'ReactMutation',
162121
+ error: {
162122
+ reason: reason,
162123
+ description:
162124
+ place.identifier.name !== null &&
162125
+ place.identifier.name.kind === 'named'
162126
+ ? `Found mutation of \`${place.identifier.name.value}\``
162127
+ : null,
162128
+ loc: place.loc,
162129
+ suggestions: null,
162130
+ severity: exports.ErrorSeverity.InvalidReact,
162131
+ },
162132
+ };
162133
+ }
162134
+ break;
162135
+ }
162136
+ }
162137
+ return null;
162138
+ }
162139
+ function inheritFunctionEffects(state, place) {
162140
+ const effects = inferFunctionInstrEffects(state, place);
162141
+ return effects
162142
+ .flatMap(effect => {
162143
+ if (effect.kind === 'GlobalMutation' || effect.kind === 'ReactMutation') {
162144
+ return [effect];
162145
+ } else {
162146
+ const effects = [];
162147
+ CompilerError.invariant(effect.kind === 'ContextMutation', {
162148
+ reason: 'Expected ContextMutation',
162149
+ loc: null,
162150
+ });
162151
+ for (const place of effect.places) {
162152
+ if (state.isDefined(place)) {
162153
+ const replayedEffect = inferOperandEffect(
162154
+ state,
162155
+ Object.assign(Object.assign({}, place), {
162156
+ loc: effect.loc,
162157
+ effect: effect.effect,
162158
+ })
162159
+ );
162160
+ if (replayedEffect != null) {
162161
+ if (replayedEffect.kind === 'ContextMutation') {
162162
+ effects.push(effect);
162163
+ } else {
162164
+ effects.push(replayedEffect);
162165
+ }
162166
+ }
162167
+ }
162168
+ }
162169
+ return effects;
162170
+ }
162171
+ })
162172
+ .filter(effect => effect != null);
162173
+ }
162174
+ function inferFunctionInstrEffects(state, place) {
162175
+ const effects = [];
162176
+ const instrs = state.values(place);
162177
+ CompilerError.invariant(instrs != null, {
162178
+ reason: 'Expected operand to have instructions',
162179
+ loc: null,
162180
+ });
162181
+ for (const instr of instrs) {
162182
+ if (
162183
+ (instr.kind === 'FunctionExpression' || instr.kind === 'ObjectMethod') &&
162184
+ instr.loweredFunc.func.effects != null
162185
+ ) {
162186
+ effects.push(...instr.loweredFunc.func.effects);
162187
+ }
162188
+ }
162189
+ return effects;
162190
+ }
162191
+ function operandEffects(state, place, filterRenderSafe) {
162192
+ const functionEffects = [];
162193
+ const effect = inferOperandEffect(state, place);
162194
+ effect && functionEffects.push(effect);
162195
+ functionEffects.push(...inheritFunctionEffects(state, place));
162196
+ if (filterRenderSafe) {
162197
+ return functionEffects.filter(effect => !isEffectSafeOutsideRender(effect));
162198
+ } else {
162199
+ return functionEffects;
162200
+ }
162201
+ }
162202
+ function inferInstructionFunctionEffects(env, state, instr) {
162203
+ var _a, _b;
162204
+ var _c;
162205
+ const functionEffects = [];
162206
+ switch (instr.value.kind) {
162207
+ case 'JsxExpression': {
162208
+ if (instr.value.tag.kind === 'Identifier') {
162209
+ functionEffects.push(...operandEffects(state, instr.value.tag, false));
162210
+ }
162211
+ (_a = instr.value.children) === null || _a === void 0
162212
+ ? void 0
162213
+ : _a.forEach(child =>
162214
+ functionEffects.push(...operandEffects(state, child, false))
162215
+ );
162216
+ for (const attr of instr.value.props) {
162217
+ if (attr.kind === 'JsxSpreadAttribute') {
162218
+ functionEffects.push(...operandEffects(state, attr.argument, false));
162219
+ } else {
162220
+ functionEffects.push(...operandEffects(state, attr.place, true));
162221
+ }
162222
+ }
162223
+ break;
162224
+ }
162225
+ case 'ObjectMethod':
162226
+ case 'FunctionExpression': {
162227
+ for (const operand of eachInstructionOperand(instr)) {
162228
+ (_b = (_c = instr.value.loweredFunc.func).effects) !== null &&
162229
+ _b !== void 0
162230
+ ? _b
162231
+ : (_c.effects = []);
162232
+ instr.value.loweredFunc.func.effects.push(
162233
+ ...inferFunctionInstrEffects(state, operand)
162234
+ );
162235
+ }
162236
+ break;
162237
+ }
162238
+ case 'MethodCall':
162239
+ case 'CallExpression': {
162240
+ let callee;
162241
+ if (instr.value.kind === 'MethodCall') {
162242
+ callee = instr.value.property;
162243
+ functionEffects.push(
162244
+ ...operandEffects(state, instr.value.receiver, false)
162245
+ );
162246
+ } else {
162247
+ callee = instr.value.callee;
162248
+ }
162249
+ functionEffects.push(...operandEffects(state, callee, false));
162250
+ let isHook = getHookKind(env, callee.identifier) != null;
162251
+ for (const arg of instr.value.args) {
162252
+ const place = arg.kind === 'Identifier' ? arg : arg.place;
162253
+ functionEffects.push(...operandEffects(state, place, isHook));
162254
+ }
162255
+ break;
162256
+ }
162257
+ case 'StartMemoize':
162258
+ case 'FinishMemoize':
162259
+ case 'LoadLocal':
162260
+ case 'StoreLocal': {
162261
+ break;
162262
+ }
162263
+ case 'StoreGlobal': {
162264
+ functionEffects.push({
162265
+ kind: 'GlobalMutation',
162266
+ error: {
162267
+ reason:
162268
+ 'Unexpected reassignment of a variable which was defined outside of the component. Components and hooks should be pure and side-effect free, but variable reassignment is a form of side-effect. If this variable is used in rendering, use useState instead. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render)',
162269
+ loc: instr.loc,
162270
+ suggestions: null,
162271
+ severity: exports.ErrorSeverity.InvalidReact,
162272
+ },
162273
+ });
162274
+ break;
162275
+ }
162276
+ default: {
162277
+ for (const operand of eachInstructionOperand(instr)) {
162278
+ functionEffects.push(...operandEffects(state, operand, false));
162279
+ }
162280
+ }
162281
+ }
162282
+ return functionEffects;
162283
+ }
162284
+ function inferTerminalFunctionEffects(state, block) {
162285
+ const functionEffects = [];
162286
+ for (const operand of eachTerminalOperand(block.terminal)) {
162287
+ functionEffects.push(...operandEffects(state, operand, true));
162288
+ }
162289
+ return functionEffects;
162290
+ }
162291
+ function raiseFunctionEffectErrors(functionEffects) {
162292
+ functionEffects.forEach(eff => {
162293
+ switch (eff.kind) {
162294
+ case 'ReactMutation':
162295
+ case 'GlobalMutation': {
162296
+ CompilerError.throw(eff.error);
162297
+ }
162298
+ case 'ContextMutation': {
162299
+ CompilerError.throw({
162300
+ severity: exports.ErrorSeverity.Invariant,
162301
+ reason: `Unexpected ContextMutation in top-level function effects`,
162302
+ loc: eff.loc,
162303
+ });
162304
+ }
162305
+ default:
162306
+ assertExhaustive(
162307
+ eff,
162308
+ `Unexpected function effect kind \`${eff.kind}\``
162309
+ );
162310
+ }
162311
+ });
162312
+ }
162313
+ function isEffectSafeOutsideRender(effect) {
162314
+ return effect.kind === 'GlobalMutation';
162315
+ }
162316
+ function getWriteErrorReason(abstractValue) {
162317
+ if (abstractValue.reason.has(ValueReason.Global)) {
162318
+ return 'Writing to a variable defined outside a component or hook is not allowed. Consider using an effect';
162319
+ } else if (abstractValue.reason.has(ValueReason.JsxCaptured)) {
162320
+ return 'Updating a value used previously in JSX is not allowed. Consider moving the mutation before the JSX';
162321
+ } else if (abstractValue.reason.has(ValueReason.Context)) {
162322
+ return `Mutating a value returned from 'useContext()', which should not be mutated`;
162323
+ } else if (abstractValue.reason.has(ValueReason.KnownReturnSignature)) {
162324
+ return 'Mutating a value returned from a function whose return value should not be mutated';
162325
+ } else if (abstractValue.reason.has(ValueReason.ReactiveFunctionArgument)) {
162326
+ return 'Mutating component props or hook arguments is not allowed. Consider using a local variable instead';
162327
+ } else if (abstractValue.reason.has(ValueReason.State)) {
162328
+ return "Mutating a value returned from 'useState()', which should not be mutated. Use the setter function to update instead";
162329
+ } else if (abstractValue.reason.has(ValueReason.ReducerState)) {
162330
+ return "Mutating a value returned from 'useReducer()', which should not be mutated. Use the dispatch function to update instead";
162331
+ } else {
162332
+ return 'This mutates a variable that React considers immutable';
162333
+ }
162334
+ }
161978
162335
  var _InferenceState_env, _InferenceState_values, _InferenceState_variables;
161979
162336
  const UndefinedValue = {
161980
162337
  kind: 'Primitive',
@@ -162074,35 +162431,16 @@ function inferReferenceEffects(fn, options = {isFunctionExpression: false}) {
162074
162431
  }
162075
162432
  statesByBlock.set(blockId, incomingState);
162076
162433
  const state = incomingState.clone();
162077
- inferBlock(fn.env, functionEffects, state, block);
162434
+ inferBlock(fn.env, state, block, functionEffects);
162078
162435
  for (const nextBlockId of eachTerminalSuccessor(block.terminal)) {
162079
162436
  queue(nextBlockId, state);
162080
162437
  }
162081
162438
  }
162082
162439
  }
162083
- if (!options.isFunctionExpression) {
162084
- functionEffects.forEach(eff => {
162085
- switch (eff.kind) {
162086
- case 'ReactMutation':
162087
- case 'GlobalMutation': {
162088
- CompilerError.throw(eff.error);
162089
- }
162090
- case 'ContextMutation': {
162091
- CompilerError.throw({
162092
- severity: exports.ErrorSeverity.Invariant,
162093
- reason: `Unexpected ContextMutation in top-level function effects`,
162094
- loc: eff.loc,
162095
- });
162096
- }
162097
- default:
162098
- assertExhaustive(
162099
- eff,
162100
- `Unexpected function effect kind \`${eff.kind}\``
162101
- );
162102
- }
162103
- });
162104
- } else {
162440
+ if (options.isFunctionExpression) {
162105
162441
  fn.effects = functionEffects;
162442
+ } else {
162443
+ raiseFunctionEffectErrors(functionEffects);
162106
162444
  }
162107
162445
  }
162108
162446
  class InferenceState {
@@ -162208,7 +162546,7 @@ class InferenceState {
162208
162546
  place.identifier.id
162209
162547
  );
162210
162548
  }
162211
- referenceAndRecordEffects(place, effectKind, reason, functionEffects) {
162549
+ referenceAndRecordEffects(freezeActions, place, effectKind, reason) {
162212
162550
  const values = __classPrivateFieldGet(
162213
162551
  this,
162214
162552
  _InferenceState_variables,
@@ -162227,43 +162565,8 @@ class InferenceState {
162227
162565
  : exports.Effect.Read;
162228
162566
  return;
162229
162567
  }
162230
- for (const value of values) {
162231
- if (
162232
- (value.kind === 'FunctionExpression' ||
162233
- value.kind === 'ObjectMethod') &&
162234
- value.loweredFunc.func.effects != null
162235
- ) {
162236
- for (const effect of value.loweredFunc.func.effects) {
162237
- if (
162238
- effect.kind === 'GlobalMutation' ||
162239
- effect.kind === 'ReactMutation'
162240
- ) {
162241
- functionEffects.push(effect);
162242
- } else {
162243
- for (const place of effect.places) {
162244
- if (this.isDefined(place)) {
162245
- const replayedEffect = this.reference(
162246
- Object.assign(Object.assign({}, place), {loc: effect.loc}),
162247
- effect.effect,
162248
- reason
162249
- );
162250
- if (replayedEffect != null) {
162251
- if (replayedEffect.kind === 'ContextMutation') {
162252
- functionEffects.push(effect);
162253
- } else {
162254
- functionEffects.push(replayedEffect);
162255
- }
162256
- }
162257
- }
162258
- }
162259
- }
162260
- }
162261
- }
162262
- }
162263
- const functionEffect = this.reference(place, effectKind, reason);
162264
- if (functionEffect !== null) {
162265
- functionEffects.push(functionEffect);
162266
- }
162568
+ const action = this.reference(place, effectKind, reason);
162569
+ action && freezeActions.push(action);
162267
162570
  }
162268
162571
  freezeValues(values, reason) {
162269
162572
  for (const value of values) {
@@ -162309,7 +162612,7 @@ class InferenceState {
162309
162612
  });
162310
162613
  let valueKind = this.kind(place);
162311
162614
  let effect = null;
162312
- let functionEffect = null;
162615
+ let freeze = null;
162313
162616
  switch (effectKind) {
162314
162617
  case exports.Effect.Freeze: {
162315
162618
  if (
@@ -162324,7 +162627,7 @@ class InferenceState {
162324
162627
  reason: reasonSet,
162325
162628
  context: new Set(),
162326
162629
  };
162327
- this.freezeValues(values, reasonSet);
162630
+ freeze = {values: values, reason: reasonSet};
162328
162631
  } else {
162329
162632
  effect = exports.Effect.Read;
162330
162633
  }
@@ -162342,80 +162645,10 @@ class InferenceState {
162342
162645
  break;
162343
162646
  }
162344
162647
  case exports.Effect.Mutate: {
162345
- if (isRefOrRefValue(place.identifier));
162346
- else if (valueKind.kind === exports.ValueKind.Context) {
162347
- functionEffect = {
162348
- kind: 'ContextMutation',
162349
- loc: place.loc,
162350
- effect: effectKind,
162351
- places:
162352
- valueKind.context.size === 0
162353
- ? new Set([place])
162354
- : valueKind.context,
162355
- };
162356
- } else if (
162357
- valueKind.kind !== exports.ValueKind.Mutable &&
162358
- valueKind.kind !== exports.ValueKind.Primitive
162359
- ) {
162360
- let reason = getWriteErrorReason(valueKind);
162361
- functionEffect = {
162362
- kind:
162363
- valueKind.reason.size === 1 &&
162364
- valueKind.reason.has(ValueReason.Global)
162365
- ? 'GlobalMutation'
162366
- : 'ReactMutation',
162367
- error: {
162368
- reason: reason,
162369
- description:
162370
- place.identifier.name !== null &&
162371
- place.identifier.name.kind === 'named'
162372
- ? `Found mutation of \`${place.identifier.name.value}\``
162373
- : null,
162374
- loc: place.loc,
162375
- suggestions: null,
162376
- severity: exports.ErrorSeverity.InvalidReact,
162377
- },
162378
- };
162379
- }
162380
162648
  effect = exports.Effect.Mutate;
162381
162649
  break;
162382
162650
  }
162383
162651
  case exports.Effect.Store: {
162384
- if (isRefOrRefValue(place.identifier));
162385
- else if (valueKind.kind === exports.ValueKind.Context) {
162386
- functionEffect = {
162387
- kind: 'ContextMutation',
162388
- loc: place.loc,
162389
- effect: effectKind,
162390
- places:
162391
- valueKind.context.size === 0
162392
- ? new Set([place])
162393
- : valueKind.context,
162394
- };
162395
- } else if (
162396
- valueKind.kind !== exports.ValueKind.Mutable &&
162397
- valueKind.kind !== exports.ValueKind.Primitive
162398
- ) {
162399
- let reason = getWriteErrorReason(valueKind);
162400
- functionEffect = {
162401
- kind:
162402
- valueKind.reason.size === 1 &&
162403
- valueKind.reason.has(ValueReason.Global)
162404
- ? 'GlobalMutation'
162405
- : 'ReactMutation',
162406
- error: {
162407
- reason: reason,
162408
- description:
162409
- place.identifier.name !== null &&
162410
- place.identifier.name.kind === 'named'
162411
- ? `Found mutation of \`${place.identifier.name.value}\``
162412
- : null,
162413
- loc: place.loc,
162414
- suggestions: null,
162415
- severity: exports.ErrorSeverity.InvalidReact,
162416
- },
162417
- };
162418
- }
162419
162652
  effect = isObjectType(place.identifier)
162420
162653
  ? exports.Effect.Store
162421
162654
  : exports.Effect.Mutate;
@@ -162461,7 +162694,7 @@ class InferenceState {
162461
162694
  suggestions: null,
162462
162695
  });
162463
162696
  place.effect = effect;
162464
- return functionEffect;
162697
+ return freeze;
162465
162698
  }
162466
162699
  merge(other) {
162467
162700
  let nextValues = null;
@@ -162716,29 +162949,31 @@ function mergeAbstractValues(a, b) {
162716
162949
  }
162717
162950
  return {kind: kind, reason: reason, context: context};
162718
162951
  }
162719
- function inferBlock(env, functionEffects, state, block) {
162952
+ function inferBlock(env, state, block, functionEffects) {
162720
162953
  var _a, _b, _c, _d;
162721
- var _e;
162722
162954
  for (const phi of block.phis) {
162723
162955
  state.inferPhi(phi);
162724
162956
  }
162725
162957
  for (const instr of block.instructions) {
162726
162958
  const instrValue = instr.value;
162727
- let effect = null;
162728
- let lvalueEffect = exports.Effect.ConditionallyMutate;
162729
- let valueKind;
162959
+ const defaultLvalueEffect = exports.Effect.ConditionallyMutate;
162960
+ let continuation;
162961
+ const freezeActions = [];
162730
162962
  switch (instrValue.kind) {
162731
162963
  case 'BinaryExpression': {
162732
- valueKind = {
162733
- kind: exports.ValueKind.Primitive,
162734
- reason: new Set([ValueReason.Other]),
162735
- context: new Set(),
162964
+ continuation = {
162965
+ kind: 'initialize',
162966
+ valueKind: {
162967
+ kind: exports.ValueKind.Primitive,
162968
+ reason: new Set([ValueReason.Other]),
162969
+ context: new Set(),
162970
+ },
162971
+ effect: {kind: exports.Effect.Read, reason: ValueReason.Other},
162736
162972
  };
162737
- effect = {kind: exports.Effect.Read, reason: ValueReason.Other};
162738
162973
  break;
162739
162974
  }
162740
162975
  case 'ArrayExpression': {
162741
- valueKind = hasContextRefOperand(state, instrValue)
162976
+ const valueKind = hasContextRefOperand(state, instrValue)
162742
162977
  ? {
162743
162978
  kind: exports.ValueKind.Context,
162744
162979
  reason: new Set([ValueReason.Other]),
@@ -162749,37 +162984,42 @@ function inferBlock(env, functionEffects, state, block) {
162749
162984
  reason: new Set([ValueReason.Other]),
162750
162985
  context: new Set(),
162751
162986
  };
162752
- effect = {kind: exports.Effect.Capture, reason: ValueReason.Other};
162753
- lvalueEffect = exports.Effect.Store;
162987
+ continuation = {
162988
+ kind: 'initialize',
162989
+ valueKind: valueKind,
162990
+ effect: {kind: exports.Effect.Capture, reason: ValueReason.Other},
162991
+ lvalueEffect: exports.Effect.Store,
162992
+ };
162754
162993
  break;
162755
162994
  }
162756
162995
  case 'NewExpression': {
162757
- valueKind = {
162996
+ const valueKind = {
162758
162997
  kind: exports.ValueKind.Mutable,
162759
162998
  reason: new Set([ValueReason.Other]),
162760
162999
  context: new Set(),
162761
163000
  };
162762
163001
  state.referenceAndRecordEffects(
163002
+ freezeActions,
162763
163003
  instrValue.callee,
162764
163004
  exports.Effect.Read,
162765
- ValueReason.Other,
162766
- functionEffects
163005
+ ValueReason.Other
162767
163006
  );
162768
163007
  for (const operand of eachCallArgument(instrValue.args)) {
162769
163008
  state.referenceAndRecordEffects(
163009
+ freezeActions,
162770
163010
  operand,
162771
163011
  exports.Effect.ConditionallyMutate,
162772
- ValueReason.Other,
162773
- functionEffects
163012
+ ValueReason.Other
162774
163013
  );
162775
163014
  }
162776
163015
  state.initialize(instrValue, valueKind);
162777
163016
  state.define(instr.lvalue, instrValue);
162778
- instr.lvalue.effect = lvalueEffect;
162779
- continue;
163017
+ instr.lvalue.effect = exports.Effect.ConditionallyMutate;
163018
+ continuation = {kind: 'funeffects'};
163019
+ break;
162780
163020
  }
162781
163021
  case 'ObjectExpression': {
162782
- valueKind = hasContextRefOperand(state, instrValue)
163022
+ const valueKind = hasContextRefOperand(state, instrValue)
162783
163023
  ? {
162784
163024
  kind: exports.ValueKind.Context,
162785
163025
  reason: new Set([ValueReason.Other]),
@@ -162795,26 +163035,26 @@ function inferBlock(env, functionEffects, state, block) {
162795
163035
  case 'ObjectProperty': {
162796
163036
  if (property.key.kind === 'computed') {
162797
163037
  state.referenceAndRecordEffects(
163038
+ freezeActions,
162798
163039
  property.key.name,
162799
163040
  exports.Effect.Freeze,
162800
- ValueReason.Other,
162801
- functionEffects
163041
+ ValueReason.Other
162802
163042
  );
162803
163043
  }
162804
163044
  state.referenceAndRecordEffects(
163045
+ freezeActions,
162805
163046
  property.place,
162806
163047
  exports.Effect.Capture,
162807
- ValueReason.Other,
162808
- functionEffects
163048
+ ValueReason.Other
162809
163049
  );
162810
163050
  break;
162811
163051
  }
162812
163052
  case 'Spread': {
162813
163053
  state.referenceAndRecordEffects(
163054
+ freezeActions,
162814
163055
  property.place,
162815
163056
  exports.Effect.Capture,
162816
- ValueReason.Other,
162817
- functionEffects
163057
+ ValueReason.Other
162818
163058
  );
162819
163059
  break;
162820
163060
  }
@@ -162829,64 +163069,66 @@ function inferBlock(env, functionEffects, state, block) {
162829
163069
  state.initialize(instrValue, valueKind);
162830
163070
  state.define(instr.lvalue, instrValue);
162831
163071
  instr.lvalue.effect = exports.Effect.Store;
162832
- continue;
163072
+ continuation = {kind: 'funeffects'};
163073
+ break;
162833
163074
  }
162834
163075
  case 'UnaryExpression': {
162835
- valueKind = {
162836
- kind: exports.ValueKind.Primitive,
162837
- reason: new Set([ValueReason.Other]),
162838
- context: new Set(),
163076
+ continuation = {
163077
+ kind: 'initialize',
163078
+ valueKind: {
163079
+ kind: exports.ValueKind.Primitive,
163080
+ reason: new Set([ValueReason.Other]),
163081
+ context: new Set(),
163082
+ },
163083
+ effect: {kind: exports.Effect.Read, reason: ValueReason.Other},
162839
163084
  };
162840
- effect = {kind: exports.Effect.Read, reason: ValueReason.Other};
162841
163085
  break;
162842
163086
  }
162843
163087
  case 'UnsupportedNode': {
162844
- valueKind = {
162845
- kind: exports.ValueKind.Mutable,
162846
- reason: new Set([ValueReason.Other]),
162847
- context: new Set(),
163088
+ continuation = {
163089
+ kind: 'initialize',
163090
+ valueKind: {
163091
+ kind: exports.ValueKind.Mutable,
163092
+ reason: new Set([ValueReason.Other]),
163093
+ context: new Set(),
163094
+ },
163095
+ effect: null,
162848
163096
  };
162849
163097
  break;
162850
163098
  }
162851
163099
  case 'JsxExpression': {
162852
163100
  if (instrValue.tag.kind === 'Identifier') {
162853
163101
  state.referenceAndRecordEffects(
163102
+ freezeActions,
162854
163103
  instrValue.tag,
162855
163104
  exports.Effect.Freeze,
162856
- ValueReason.JsxCaptured,
162857
- functionEffects
163105
+ ValueReason.JsxCaptured
162858
163106
  );
162859
163107
  }
162860
163108
  if (instrValue.children !== null) {
162861
163109
  for (const child of instrValue.children) {
162862
163110
  state.referenceAndRecordEffects(
163111
+ freezeActions,
162863
163112
  child,
162864
163113
  exports.Effect.Freeze,
162865
- ValueReason.JsxCaptured,
162866
- functionEffects
163114
+ ValueReason.JsxCaptured
162867
163115
  );
162868
163116
  }
162869
163117
  }
162870
163118
  for (const attr of instrValue.props) {
162871
163119
  if (attr.kind === 'JsxSpreadAttribute') {
162872
163120
  state.referenceAndRecordEffects(
163121
+ freezeActions,
162873
163122
  attr.argument,
162874
163123
  exports.Effect.Freeze,
162875
- ValueReason.JsxCaptured,
162876
- functionEffects
163124
+ ValueReason.JsxCaptured
162877
163125
  );
162878
163126
  } else {
162879
- const propEffects = [];
162880
163127
  state.referenceAndRecordEffects(
163128
+ freezeActions,
162881
163129
  attr.place,
162882
163130
  exports.Effect.Freeze,
162883
- ValueReason.JsxCaptured,
162884
- propEffects
162885
- );
162886
- functionEffects.push(
162887
- ...propEffects.filter(
162888
- effect => !isEffectSafeOutsideRender(effect)
162889
- )
163131
+ ValueReason.JsxCaptured
162890
163132
  );
162891
163133
  }
162892
163134
  }
@@ -162897,63 +163139,86 @@ function inferBlock(env, functionEffects, state, block) {
162897
163139
  });
162898
163140
  state.define(instr.lvalue, instrValue);
162899
163141
  instr.lvalue.effect = exports.Effect.ConditionallyMutate;
162900
- continue;
163142
+ continuation = {kind: 'funeffects'};
163143
+ break;
162901
163144
  }
162902
163145
  case 'JsxFragment': {
162903
- valueKind = {
162904
- kind: exports.ValueKind.Frozen,
162905
- reason: new Set([ValueReason.Other]),
162906
- context: new Set(),
163146
+ continuation = {
163147
+ kind: 'initialize',
163148
+ valueKind: {
163149
+ kind: exports.ValueKind.Frozen,
163150
+ reason: new Set([ValueReason.Other]),
163151
+ context: new Set(),
163152
+ },
163153
+ effect: {kind: exports.Effect.Freeze, reason: ValueReason.Other},
162907
163154
  };
162908
- effect = {kind: exports.Effect.Freeze, reason: ValueReason.Other};
162909
163155
  break;
162910
163156
  }
162911
163157
  case 'TemplateLiteral': {
162912
- valueKind = {
162913
- kind: exports.ValueKind.Primitive,
162914
- reason: new Set([ValueReason.Other]),
162915
- context: new Set(),
163158
+ continuation = {
163159
+ kind: 'initialize',
163160
+ valueKind: {
163161
+ kind: exports.ValueKind.Primitive,
163162
+ reason: new Set([ValueReason.Other]),
163163
+ context: new Set(),
163164
+ },
163165
+ effect: {kind: exports.Effect.Read, reason: ValueReason.Other},
162916
163166
  };
162917
- effect = {kind: exports.Effect.Read, reason: ValueReason.Other};
162918
163167
  break;
162919
163168
  }
162920
163169
  case 'RegExpLiteral': {
162921
- valueKind = {
162922
- kind: exports.ValueKind.Mutable,
162923
- reason: new Set([ValueReason.Other]),
162924
- context: new Set(),
162925
- };
162926
- effect = {
162927
- kind: exports.Effect.ConditionallyMutate,
162928
- reason: ValueReason.Other,
163170
+ continuation = {
163171
+ kind: 'initialize',
163172
+ valueKind: {
163173
+ kind: exports.ValueKind.Mutable,
163174
+ reason: new Set([ValueReason.Other]),
163175
+ context: new Set(),
163176
+ },
163177
+ effect: {
163178
+ kind: exports.Effect.ConditionallyMutate,
163179
+ reason: ValueReason.Other,
163180
+ },
162929
163181
  };
162930
163182
  break;
162931
163183
  }
162932
163184
  case 'MetaProperty': {
162933
163185
  if (instrValue.meta !== 'import' || instrValue.property !== 'meta') {
162934
- continue;
163186
+ continuation = {kind: 'funeffects'};
163187
+ break;
162935
163188
  }
162936
- valueKind = {
162937
- kind: exports.ValueKind.Global,
162938
- reason: new Set([ValueReason.Global]),
162939
- context: new Set(),
163189
+ continuation = {
163190
+ kind: 'initialize',
163191
+ valueKind: {
163192
+ kind: exports.ValueKind.Global,
163193
+ reason: new Set([ValueReason.Global]),
163194
+ context: new Set(),
163195
+ },
163196
+ effect: null,
162940
163197
  };
162941
163198
  break;
162942
163199
  }
162943
163200
  case 'LoadGlobal':
162944
- valueKind = {
162945
- kind: exports.ValueKind.Global,
162946
- reason: new Set([ValueReason.Global]),
162947
- context: new Set(),
163201
+ continuation = {
163202
+ kind: 'initialize',
163203
+ valueKind: {
163204
+ kind: exports.ValueKind.Global,
163205
+ reason: new Set([ValueReason.Global]),
163206
+ context: new Set(),
163207
+ },
163208
+ effect: null,
162948
163209
  };
162949
163210
  break;
162950
163211
  case 'Debugger':
162951
163212
  case 'JSXText':
162952
163213
  case 'Primitive': {
162953
- valueKind = {
162954
- kind: exports.ValueKind.Primitive,
162955
- reason: new Set([ValueReason.Other]),
162956
- context: new Set(),
163214
+ continuation = {
163215
+ kind: 'initialize',
163216
+ valueKind: {
163217
+ kind: exports.ValueKind.Primitive,
163218
+ reason: new Set([ValueReason.Other]),
163219
+ context: new Set(),
163220
+ },
163221
+ effect: null,
162957
163222
  };
162958
163223
  break;
162959
163224
  }
@@ -162962,32 +163227,16 @@ function inferBlock(env, functionEffects, state, block) {
162962
163227
  let hasMutableOperand = false;
162963
163228
  for (const operand of eachInstructionOperand(instr)) {
162964
163229
  state.referenceAndRecordEffects(
163230
+ freezeActions,
162965
163231
  operand,
162966
163232
  operand.effect === exports.Effect.Unknown
162967
163233
  ? exports.Effect.Read
162968
163234
  : operand.effect,
162969
- ValueReason.Other,
162970
- []
163235
+ ValueReason.Other
162971
163236
  );
162972
163237
  if (isMutableEffect(operand.effect, operand.loc));
162973
163238
  hasMutableOperand ||
162974
163239
  (hasMutableOperand = isMutableEffect(operand.effect, operand.loc));
162975
- const values = state.values(operand);
162976
- for (const value of values) {
162977
- if (
162978
- (value.kind === 'ObjectMethod' ||
162979
- value.kind === 'FunctionExpression') &&
162980
- value.loweredFunc.func.effects !== null
162981
- ) {
162982
- (_a = (_e = instrValue.loweredFunc.func).effects) !== null &&
162983
- _a !== void 0
162984
- ? _a
162985
- : (_e.effects = []);
162986
- instrValue.loweredFunc.func.effects.push(
162987
- ...value.loweredFunc.func.effects
162988
- );
162989
- }
162990
- }
162991
163240
  }
162992
163241
  state.initialize(instrValue, {
162993
163242
  kind: hasMutableOperand
@@ -162998,7 +163247,8 @@ function inferBlock(env, functionEffects, state, block) {
162998
163247
  });
162999
163248
  state.define(instr.lvalue, instrValue);
163000
163249
  instr.lvalue.effect = exports.Effect.Store;
163001
- continue;
163250
+ continuation = {kind: 'funeffects'};
163251
+ break;
163002
163252
  }
163003
163253
  case 'TaggedTemplateExpression': {
163004
163254
  const operands = [...eachInstructionValueOperand(instrValue)];
@@ -163013,19 +163263,19 @@ function inferBlock(env, functionEffects, state, block) {
163013
163263
  instrValue.tag.identifier.type
163014
163264
  );
163015
163265
  let calleeEffect =
163016
- (_b =
163266
+ (_a =
163017
163267
  signature === null || signature === void 0
163018
163268
  ? void 0
163019
- : signature.calleeEffect) !== null && _b !== void 0
163020
- ? _b
163269
+ : signature.calleeEffect) !== null && _a !== void 0
163270
+ ? _a
163021
163271
  : exports.Effect.ConditionallyMutate;
163022
163272
  const returnValueKind =
163023
163273
  signature !== null
163024
163274
  ? {
163025
163275
  kind: signature.returnValueKind,
163026
163276
  reason: new Set([
163027
- (_c = signature.returnValueReason) !== null && _c !== void 0
163028
- ? _c
163277
+ (_b = signature.returnValueReason) !== null && _b !== void 0
163278
+ ? _b
163029
163279
  : ValueReason.KnownReturnSignature,
163030
163280
  ]),
163031
163281
  context: new Set(),
@@ -163036,15 +163286,16 @@ function inferBlock(env, functionEffects, state, block) {
163036
163286
  context: new Set(),
163037
163287
  };
163038
163288
  state.referenceAndRecordEffects(
163289
+ freezeActions,
163039
163290
  instrValue.tag,
163040
163291
  calleeEffect,
163041
- ValueReason.Other,
163042
- functionEffects
163292
+ ValueReason.Other
163043
163293
  );
163044
163294
  state.initialize(instrValue, returnValueKind);
163045
163295
  state.define(instr.lvalue, instrValue);
163046
163296
  instr.lvalue.effect = exports.Effect.ConditionallyMutate;
163047
- continue;
163297
+ continuation = {kind: 'funeffects'};
163298
+ break;
163048
163299
  }
163049
163300
  case 'CallExpression': {
163050
163301
  const signature = getFunctionCallSignature(
@@ -163058,8 +163309,8 @@ function inferBlock(env, functionEffects, state, block) {
163058
163309
  ? {
163059
163310
  kind: signature.returnValueKind,
163060
163311
  reason: new Set([
163061
- (_d = signature.returnValueReason) !== null && _d !== void 0
163062
- ? _d
163312
+ (_c = signature.returnValueReason) !== null && _c !== void 0
163313
+ ? _c
163063
163314
  : ValueReason.KnownReturnSignature,
163064
163315
  ]),
163065
163316
  context: new Set(),
@@ -163070,47 +163321,40 @@ function inferBlock(env, functionEffects, state, block) {
163070
163321
  context: new Set(),
163071
163322
  };
163072
163323
  let hasCaptureArgument = false;
163073
- let isHook = getHookKind(env, instrValue.callee.identifier) != null;
163074
163324
  for (let i = 0; i < instrValue.args.length; i++) {
163075
- const argumentEffects = [];
163076
163325
  const arg = instrValue.args[i];
163077
163326
  const place = arg.kind === 'Identifier' ? arg : arg.place;
163078
163327
  if (effects !== null) {
163079
163328
  state.referenceAndRecordEffects(
163329
+ freezeActions,
163080
163330
  place,
163081
163331
  effects[i],
163082
- ValueReason.Other,
163083
- argumentEffects
163332
+ ValueReason.Other
163084
163333
  );
163085
163334
  } else {
163086
163335
  state.referenceAndRecordEffects(
163336
+ freezeActions,
163087
163337
  place,
163088
163338
  exports.Effect.ConditionallyMutate,
163089
- ValueReason.Other,
163090
- argumentEffects
163339
+ ValueReason.Other
163091
163340
  );
163092
163341
  }
163093
- functionEffects.push(
163094
- ...argumentEffects.filter(
163095
- argEffect => !isHook || !isEffectSafeOutsideRender(argEffect)
163096
- )
163097
- );
163098
163342
  hasCaptureArgument ||
163099
163343
  (hasCaptureArgument = place.effect === exports.Effect.Capture);
163100
163344
  }
163101
163345
  if (signature !== null) {
163102
163346
  state.referenceAndRecordEffects(
163347
+ freezeActions,
163103
163348
  instrValue.callee,
163104
163349
  signature.calleeEffect,
163105
- ValueReason.Other,
163106
- functionEffects
163350
+ ValueReason.Other
163107
163351
  );
163108
163352
  } else {
163109
163353
  state.referenceAndRecordEffects(
163354
+ freezeActions,
163110
163355
  instrValue.callee,
163111
163356
  exports.Effect.ConditionallyMutate,
163112
- ValueReason.Other,
163113
- functionEffects
163357
+ ValueReason.Other
163114
163358
  );
163115
163359
  }
163116
163360
  hasCaptureArgument ||
@@ -163121,7 +163365,8 @@ function inferBlock(env, functionEffects, state, block) {
163121
163365
  instr.lvalue.effect = hasCaptureArgument
163122
163366
  ? exports.Effect.Store
163123
163367
  : exports.Effect.ConditionallyMutate;
163124
- continue;
163368
+ continuation = {kind: 'funeffects'};
163369
+ break;
163125
163370
  }
163126
163371
  case 'MethodCall': {
163127
163372
  CompilerError.invariant(state.isDefined(instrValue.receiver), {
@@ -163132,10 +163377,10 @@ function inferBlock(env, functionEffects, state, block) {
163132
163377
  suggestions: null,
163133
163378
  });
163134
163379
  state.referenceAndRecordEffects(
163380
+ freezeActions,
163135
163381
  instrValue.property,
163136
163382
  exports.Effect.Read,
163137
- ValueReason.Other,
163138
- functionEffects
163383
+ ValueReason.Other
163139
163384
  );
163140
163385
  const signature = getFunctionCallSignature(
163141
163386
  env,
@@ -163161,17 +163406,17 @@ function inferBlock(env, functionEffects, state, block) {
163161
163406
  for (const arg of instrValue.args) {
163162
163407
  const place = arg.kind === 'Identifier' ? arg : arg.place;
163163
163408
  state.referenceAndRecordEffects(
163409
+ freezeActions,
163164
163410
  place,
163165
163411
  exports.Effect.Read,
163166
- ValueReason.Other,
163167
- functionEffects
163412
+ ValueReason.Other
163168
163413
  );
163169
163414
  }
163170
163415
  state.referenceAndRecordEffects(
163416
+ freezeActions,
163171
163417
  instrValue.receiver,
163172
163418
  exports.Effect.Capture,
163173
- ValueReason.Other,
163174
- functionEffects
163419
+ ValueReason.Other
163175
163420
  );
163176
163421
  state.initialize(instrValue, returnValueKind);
163177
163422
  state.define(instr.lvalue, instrValue);
@@ -163179,52 +163424,46 @@ function inferBlock(env, functionEffects, state, block) {
163179
163424
  instrValue.receiver.effect === exports.Effect.Capture
163180
163425
  ? exports.Effect.Store
163181
163426
  : exports.Effect.ConditionallyMutate;
163182
- continue;
163427
+ continuation = {kind: 'funeffects'};
163428
+ break;
163183
163429
  }
163184
163430
  const effects =
163185
163431
  signature !== null ? getFunctionEffects(instrValue, signature) : null;
163186
163432
  let hasCaptureArgument = false;
163187
- let isHook = getHookKind(env, instrValue.property.identifier) != null;
163188
163433
  for (let i = 0; i < instrValue.args.length; i++) {
163189
- const argumentEffects = [];
163190
163434
  const arg = instrValue.args[i];
163191
163435
  const place = arg.kind === 'Identifier' ? arg : arg.place;
163192
163436
  if (effects !== null) {
163193
163437
  state.referenceAndRecordEffects(
163438
+ freezeActions,
163194
163439
  place,
163195
163440
  effects[i],
163196
- ValueReason.Other,
163197
- argumentEffects
163441
+ ValueReason.Other
163198
163442
  );
163199
163443
  } else {
163200
163444
  state.referenceAndRecordEffects(
163445
+ freezeActions,
163201
163446
  place,
163202
163447
  exports.Effect.ConditionallyMutate,
163203
- ValueReason.Other,
163204
- argumentEffects
163448
+ ValueReason.Other
163205
163449
  );
163206
163450
  }
163207
- functionEffects.push(
163208
- ...argumentEffects.filter(
163209
- argEffect => !isHook || !isEffectSafeOutsideRender(argEffect)
163210
- )
163211
- );
163212
163451
  hasCaptureArgument ||
163213
163452
  (hasCaptureArgument = place.effect === exports.Effect.Capture);
163214
163453
  }
163215
163454
  if (signature !== null) {
163216
163455
  state.referenceAndRecordEffects(
163456
+ freezeActions,
163217
163457
  instrValue.receiver,
163218
163458
  signature.calleeEffect,
163219
- ValueReason.Other,
163220
- functionEffects
163459
+ ValueReason.Other
163221
163460
  );
163222
163461
  } else {
163223
163462
  state.referenceAndRecordEffects(
163463
+ freezeActions,
163224
163464
  instrValue.receiver,
163225
163465
  exports.Effect.ConditionallyMutate,
163226
- ValueReason.Other,
163227
- functionEffects
163466
+ ValueReason.Other
163228
163467
  );
163229
163468
  }
163230
163469
  hasCaptureArgument ||
@@ -163235,7 +163474,8 @@ function inferBlock(env, functionEffects, state, block) {
163235
163474
  instr.lvalue.effect = hasCaptureArgument
163236
163475
  ? exports.Effect.Store
163237
163476
  : exports.Effect.ConditionallyMutate;
163238
- continue;
163477
+ continuation = {kind: 'funeffects'};
163478
+ break;
163239
163479
  }
163240
163480
  case 'PropertyStore': {
163241
163481
  const effect =
@@ -163243,43 +163483,48 @@ function inferBlock(env, functionEffects, state, block) {
163243
163483
  ? exports.Effect.ConditionallyMutate
163244
163484
  : exports.Effect.Capture;
163245
163485
  state.referenceAndRecordEffects(
163486
+ freezeActions,
163246
163487
  instrValue.value,
163247
163488
  effect,
163248
- ValueReason.Other,
163249
- functionEffects
163489
+ ValueReason.Other
163250
163490
  );
163251
163491
  state.referenceAndRecordEffects(
163492
+ freezeActions,
163252
163493
  instrValue.object,
163253
163494
  exports.Effect.Store,
163254
- ValueReason.Other,
163255
- functionEffects
163495
+ ValueReason.Other
163256
163496
  );
163257
163497
  const lvalue = instr.lvalue;
163258
163498
  state.alias(lvalue, instrValue.value);
163259
163499
  lvalue.effect = exports.Effect.Store;
163260
- continue;
163500
+ continuation = {kind: 'funeffects'};
163501
+ break;
163261
163502
  }
163262
163503
  case 'PropertyDelete': {
163263
- valueKind = {
163264
- kind: exports.ValueKind.Primitive,
163265
- reason: new Set([ValueReason.Other]),
163266
- context: new Set(),
163504
+ continuation = {
163505
+ kind: 'initialize',
163506
+ valueKind: {
163507
+ kind: exports.ValueKind.Primitive,
163508
+ reason: new Set([ValueReason.Other]),
163509
+ context: new Set(),
163510
+ },
163511
+ effect: {kind: exports.Effect.Mutate, reason: ValueReason.Other},
163267
163512
  };
163268
- effect = {kind: exports.Effect.Mutate, reason: ValueReason.Other};
163269
163513
  break;
163270
163514
  }
163271
163515
  case 'PropertyLoad': {
163272
163516
  state.referenceAndRecordEffects(
163517
+ freezeActions,
163273
163518
  instrValue.object,
163274
163519
  exports.Effect.Read,
163275
- ValueReason.Other,
163276
- functionEffects
163520
+ ValueReason.Other
163277
163521
  );
163278
163522
  const lvalue = instr.lvalue;
163279
163523
  lvalue.effect = exports.Effect.ConditionallyMutate;
163280
163524
  state.initialize(instrValue, state.kind(instrValue.object));
163281
163525
  state.define(lvalue, instrValue);
163282
- continue;
163526
+ continuation = {kind: 'funeffects'};
163527
+ break;
163283
163528
  }
163284
163529
  case 'ComputedStore': {
163285
163530
  const effect =
@@ -163287,40 +163532,41 @@ function inferBlock(env, functionEffects, state, block) {
163287
163532
  ? exports.Effect.ConditionallyMutate
163288
163533
  : exports.Effect.Capture;
163289
163534
  state.referenceAndRecordEffects(
163535
+ freezeActions,
163290
163536
  instrValue.value,
163291
163537
  effect,
163292
- ValueReason.Other,
163293
- functionEffects
163538
+ ValueReason.Other
163294
163539
  );
163295
163540
  state.referenceAndRecordEffects(
163541
+ freezeActions,
163296
163542
  instrValue.property,
163297
163543
  exports.Effect.Capture,
163298
- ValueReason.Other,
163299
- functionEffects
163544
+ ValueReason.Other
163300
163545
  );
163301
163546
  state.referenceAndRecordEffects(
163547
+ freezeActions,
163302
163548
  instrValue.object,
163303
163549
  exports.Effect.Store,
163304
- ValueReason.Other,
163305
- functionEffects
163550
+ ValueReason.Other
163306
163551
  );
163307
163552
  const lvalue = instr.lvalue;
163308
163553
  state.alias(lvalue, instrValue.value);
163309
163554
  lvalue.effect = exports.Effect.Store;
163310
- continue;
163555
+ continuation = {kind: 'funeffects'};
163556
+ break;
163311
163557
  }
163312
163558
  case 'ComputedDelete': {
163313
163559
  state.referenceAndRecordEffects(
163560
+ freezeActions,
163314
163561
  instrValue.object,
163315
163562
  exports.Effect.Mutate,
163316
- ValueReason.Other,
163317
- functionEffects
163563
+ ValueReason.Other
163318
163564
  );
163319
163565
  state.referenceAndRecordEffects(
163566
+ freezeActions,
163320
163567
  instrValue.property,
163321
163568
  exports.Effect.Read,
163322
- ValueReason.Other,
163323
- functionEffects
163569
+ ValueReason.Other
163324
163570
  );
163325
163571
  state.initialize(instrValue, {
163326
163572
  kind: exports.ValueKind.Primitive,
@@ -163329,69 +163575,73 @@ function inferBlock(env, functionEffects, state, block) {
163329
163575
  });
163330
163576
  state.define(instr.lvalue, instrValue);
163331
163577
  instr.lvalue.effect = exports.Effect.Mutate;
163332
- continue;
163578
+ continuation = {kind: 'funeffects'};
163579
+ break;
163333
163580
  }
163334
163581
  case 'ComputedLoad': {
163335
163582
  state.referenceAndRecordEffects(
163583
+ freezeActions,
163336
163584
  instrValue.object,
163337
163585
  exports.Effect.Read,
163338
- ValueReason.Other,
163339
- functionEffects
163586
+ ValueReason.Other
163340
163587
  );
163341
163588
  state.referenceAndRecordEffects(
163589
+ freezeActions,
163342
163590
  instrValue.property,
163343
163591
  exports.Effect.Read,
163344
- ValueReason.Other,
163345
- functionEffects
163592
+ ValueReason.Other
163346
163593
  );
163347
163594
  const lvalue = instr.lvalue;
163348
163595
  lvalue.effect = exports.Effect.ConditionallyMutate;
163349
163596
  state.initialize(instrValue, state.kind(instrValue.object));
163350
163597
  state.define(lvalue, instrValue);
163351
- continue;
163598
+ continuation = {kind: 'funeffects'};
163599
+ break;
163352
163600
  }
163353
163601
  case 'Await': {
163354
163602
  state.initialize(instrValue, state.kind(instrValue.value));
163355
163603
  state.referenceAndRecordEffects(
163604
+ freezeActions,
163356
163605
  instrValue.value,
163357
163606
  exports.Effect.ConditionallyMutate,
163358
- ValueReason.Other,
163359
- functionEffects
163607
+ ValueReason.Other
163360
163608
  );
163361
163609
  const lvalue = instr.lvalue;
163362
163610
  lvalue.effect = exports.Effect.ConditionallyMutate;
163363
163611
  state.alias(lvalue, instrValue.value);
163364
- continue;
163612
+ continuation = {kind: 'funeffects'};
163613
+ break;
163365
163614
  }
163366
163615
  case 'TypeCastExpression': {
163367
163616
  state.initialize(instrValue, state.kind(instrValue.value));
163368
163617
  state.referenceAndRecordEffects(
163618
+ freezeActions,
163369
163619
  instrValue.value,
163370
163620
  exports.Effect.Read,
163371
- ValueReason.Other,
163372
- functionEffects
163621
+ ValueReason.Other
163373
163622
  );
163374
163623
  const lvalue = instr.lvalue;
163375
163624
  lvalue.effect = exports.Effect.ConditionallyMutate;
163376
163625
  state.alias(lvalue, instrValue.value);
163377
- continue;
163626
+ continuation = {kind: 'funeffects'};
163627
+ break;
163378
163628
  }
163379
163629
  case 'StartMemoize':
163380
163630
  case 'FinishMemoize': {
163381
163631
  for (const val of eachInstructionValueOperand(instrValue)) {
163382
163632
  if (env.config.enablePreserveExistingMemoizationGuarantees) {
163383
163633
  state.referenceAndRecordEffects(
163634
+ freezeActions,
163384
163635
  val,
163385
163636
  exports.Effect.Freeze,
163386
- ValueReason.Other,
163387
- []
163637
+ ValueReason.Other
163388
163638
  );
163389
163639
  } else {
163390
163640
  state.referenceAndRecordEffects(
163641
+ freezeActions,
163391
163642
  val,
163392
163643
  exports.Effect.Read,
163393
- ValueReason.Other,
163394
- []
163644
+ ValueReason.Other
163395
163645
  );
163396
163646
  }
163397
163647
  }
@@ -163403,7 +163653,8 @@ function inferBlock(env, functionEffects, state, block) {
163403
163653
  context: new Set(),
163404
163654
  });
163405
163655
  state.define(lvalue, instrValue);
163406
- continue;
163656
+ continuation = {kind: 'funeffects'};
163657
+ break;
163407
163658
  }
163408
163659
  case 'LoadLocal': {
163409
163660
  const lvalue = instr.lvalue;
@@ -163413,28 +163664,30 @@ function inferBlock(env, functionEffects, state, block) {
163413
163664
  ? exports.Effect.ConditionallyMutate
163414
163665
  : exports.Effect.Capture;
163415
163666
  state.referenceAndRecordEffects(
163667
+ freezeActions,
163416
163668
  instrValue.place,
163417
163669
  effect,
163418
- ValueReason.Other,
163419
- []
163670
+ ValueReason.Other
163420
163671
  );
163421
163672
  lvalue.effect = exports.Effect.ConditionallyMutate;
163422
163673
  state.alias(lvalue, instrValue.place);
163423
- continue;
163674
+ continuation = {kind: 'funeffects'};
163675
+ break;
163424
163676
  }
163425
163677
  case 'LoadContext': {
163426
163678
  state.referenceAndRecordEffects(
163679
+ freezeActions,
163427
163680
  instrValue.place,
163428
163681
  exports.Effect.Capture,
163429
- ValueReason.Other,
163430
- functionEffects
163682
+ ValueReason.Other
163431
163683
  );
163432
163684
  const lvalue = instr.lvalue;
163433
163685
  lvalue.effect = exports.Effect.ConditionallyMutate;
163434
163686
  const valueKind = state.kind(instrValue.place);
163435
163687
  state.initialize(instrValue, valueKind);
163436
163688
  state.define(lvalue, instrValue);
163437
- continue;
163689
+ continuation = {kind: 'funeffects'};
163690
+ break;
163438
163691
  }
163439
163692
  case 'DeclareLocal': {
163440
163693
  const value = UndefinedValue;
@@ -163453,7 +163706,8 @@ function inferBlock(env, functionEffects, state, block) {
163453
163706
  }
163454
163707
  );
163455
163708
  state.define(instrValue.lvalue.place, value);
163456
- continue;
163709
+ continuation = {kind: 'funeffects'};
163710
+ break;
163457
163711
  }
163458
163712
  case 'DeclareContext': {
163459
163713
  state.initialize(instrValue, {
@@ -163462,7 +163716,8 @@ function inferBlock(env, functionEffects, state, block) {
163462
163716
  context: new Set(),
163463
163717
  });
163464
163718
  state.define(instrValue.lvalue.place, instrValue);
163465
- continue;
163719
+ continuation = {kind: 'funeffects'};
163720
+ break;
163466
163721
  }
163467
163722
  case 'PostfixUpdate':
163468
163723
  case 'PrefixUpdate': {
@@ -163472,17 +163727,18 @@ function inferBlock(env, functionEffects, state, block) {
163472
163727
  ? exports.Effect.ConditionallyMutate
163473
163728
  : exports.Effect.Capture;
163474
163729
  state.referenceAndRecordEffects(
163730
+ freezeActions,
163475
163731
  instrValue.value,
163476
163732
  effect,
163477
- ValueReason.Other,
163478
- functionEffects
163733
+ ValueReason.Other
163479
163734
  );
163480
163735
  const lvalue = instr.lvalue;
163481
163736
  state.alias(lvalue, instrValue.value);
163482
163737
  lvalue.effect = exports.Effect.Store;
163483
163738
  state.alias(instrValue.lvalue, instrValue.value);
163484
163739
  instrValue.lvalue.effect = exports.Effect.Store;
163485
- continue;
163740
+ continuation = {kind: 'funeffects'};
163741
+ break;
163486
163742
  }
163487
163743
  case 'StoreLocal': {
163488
163744
  const effect =
@@ -163491,56 +163747,49 @@ function inferBlock(env, functionEffects, state, block) {
163491
163747
  ? exports.Effect.ConditionallyMutate
163492
163748
  : exports.Effect.Capture;
163493
163749
  state.referenceAndRecordEffects(
163750
+ freezeActions,
163494
163751
  instrValue.value,
163495
163752
  effect,
163496
- ValueReason.Other,
163497
- []
163753
+ ValueReason.Other
163498
163754
  );
163499
163755
  const lvalue = instr.lvalue;
163500
163756
  state.alias(lvalue, instrValue.value);
163501
163757
  lvalue.effect = exports.Effect.Store;
163502
163758
  state.alias(instrValue.lvalue.place, instrValue.value);
163503
163759
  instrValue.lvalue.place.effect = exports.Effect.Store;
163504
- continue;
163760
+ continuation = {kind: 'funeffects'};
163761
+ break;
163505
163762
  }
163506
163763
  case 'StoreContext': {
163507
163764
  state.referenceAndRecordEffects(
163765
+ freezeActions,
163508
163766
  instrValue.value,
163509
163767
  exports.Effect.ConditionallyMutate,
163510
- ValueReason.Other,
163511
- functionEffects
163768
+ ValueReason.Other
163512
163769
  );
163513
163770
  state.referenceAndRecordEffects(
163771
+ freezeActions,
163514
163772
  instrValue.lvalue.place,
163515
163773
  exports.Effect.Mutate,
163516
- ValueReason.Other,
163517
- functionEffects
163774
+ ValueReason.Other
163518
163775
  );
163519
163776
  const lvalue = instr.lvalue;
163520
163777
  state.alias(lvalue, instrValue.value);
163521
163778
  lvalue.effect = exports.Effect.Store;
163522
- continue;
163779
+ continuation = {kind: 'funeffects'};
163780
+ break;
163523
163781
  }
163524
163782
  case 'StoreGlobal': {
163525
163783
  state.referenceAndRecordEffects(
163784
+ freezeActions,
163526
163785
  instrValue.value,
163527
163786
  exports.Effect.Capture,
163528
- ValueReason.Other,
163529
- functionEffects
163787
+ ValueReason.Other
163530
163788
  );
163531
163789
  const lvalue = instr.lvalue;
163532
163790
  lvalue.effect = exports.Effect.Store;
163533
- functionEffects.push({
163534
- kind: 'GlobalMutation',
163535
- error: {
163536
- reason:
163537
- 'Unexpected reassignment of a variable which was defined outside of the component. Components and hooks should be pure and side-effect free, but variable reassignment is a form of side-effect. If this variable is used in rendering, use useState instead. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render)',
163538
- loc: instr.loc,
163539
- suggestions: null,
163540
- severity: exports.ErrorSeverity.InvalidReact,
163541
- },
163542
- });
163543
- continue;
163791
+ continuation = {kind: 'funeffects'};
163792
+ break;
163544
163793
  }
163545
163794
  case 'Destructure': {
163546
163795
  let effect = exports.Effect.Capture;
@@ -163554,10 +163803,10 @@ function inferBlock(env, functionEffects, state, block) {
163554
163803
  }
163555
163804
  }
163556
163805
  state.referenceAndRecordEffects(
163806
+ freezeActions,
163557
163807
  instrValue.value,
163558
163808
  effect,
163559
- ValueReason.Other,
163560
- functionEffects
163809
+ ValueReason.Other
163561
163810
  );
163562
163811
  const lvalue = instr.lvalue;
163563
163812
  state.alias(lvalue, instrValue.value);
@@ -163566,13 +163815,16 @@ function inferBlock(env, functionEffects, state, block) {
163566
163815
  state.alias(place, instrValue.value);
163567
163816
  place.effect = exports.Effect.Store;
163568
163817
  }
163569
- continue;
163818
+ continuation = {kind: 'funeffects'};
163819
+ break;
163570
163820
  }
163571
163821
  case 'GetIterator': {
163572
163822
  const kind = state.kind(instrValue.collection).kind;
163573
163823
  const isMutable =
163574
163824
  kind === exports.ValueKind.Mutable ||
163575
163825
  kind === exports.ValueKind.Context;
163826
+ let effect;
163827
+ let valueKind;
163576
163828
  if (!isMutable || isArrayType(instrValue.collection.identifier)) {
163577
163829
  effect = {kind: exports.Effect.Read, reason: ValueReason.Other};
163578
163830
  valueKind = {
@@ -163584,34 +163836,43 @@ function inferBlock(env, functionEffects, state, block) {
163584
163836
  effect = {kind: exports.Effect.Capture, reason: ValueReason.Other};
163585
163837
  valueKind = state.kind(instrValue.collection);
163586
163838
  }
163587
- lvalueEffect = exports.Effect.Store;
163839
+ continuation = {
163840
+ kind: 'initialize',
163841
+ effect: effect,
163842
+ valueKind: valueKind,
163843
+ lvalueEffect: exports.Effect.Store,
163844
+ };
163588
163845
  break;
163589
163846
  }
163590
163847
  case 'IteratorNext': {
163591
163848
  state.referenceAndRecordEffects(
163849
+ freezeActions,
163592
163850
  instrValue.iterator,
163593
163851
  exports.Effect.ConditionallyMutate,
163594
- ValueReason.Other,
163595
- functionEffects
163852
+ ValueReason.Other
163596
163853
  );
163597
163854
  state.referenceAndRecordEffects(
163855
+ freezeActions,
163598
163856
  instrValue.collection,
163599
163857
  exports.Effect.Capture,
163600
- ValueReason.Other,
163601
- functionEffects
163858
+ ValueReason.Other
163602
163859
  );
163603
163860
  state.initialize(instrValue, state.kind(instrValue.collection));
163604
163861
  state.define(instr.lvalue, instrValue);
163605
163862
  instr.lvalue.effect = exports.Effect.Store;
163606
- continue;
163863
+ continuation = {kind: 'funeffects'};
163864
+ break;
163607
163865
  }
163608
163866
  case 'NextPropertyOf': {
163609
- effect = {kind: exports.Effect.Read, reason: ValueReason.Other};
163610
- lvalueEffect = exports.Effect.Store;
163611
- valueKind = {
163612
- kind: exports.ValueKind.Primitive,
163613
- reason: new Set([ValueReason.Other]),
163614
- context: new Set(),
163867
+ continuation = {
163868
+ kind: 'initialize',
163869
+ effect: {kind: exports.Effect.Read, reason: ValueReason.Other},
163870
+ lvalueEffect: exports.Effect.Store,
163871
+ valueKind: {
163872
+ kind: exports.ValueKind.Primitive,
163873
+ reason: new Set([ValueReason.Other]),
163874
+ context: new Set(),
163875
+ },
163615
163876
  };
163616
163877
  break;
163617
163878
  }
@@ -163619,24 +163880,34 @@ function inferBlock(env, functionEffects, state, block) {
163619
163880
  assertExhaustive(instrValue, 'Unexpected instruction kind');
163620
163881
  }
163621
163882
  }
163622
- for (const operand of eachInstructionOperand(instr)) {
163623
- CompilerError.invariant(effect != null, {
163624
- reason: `effectKind must be set for instruction value \`${instrValue.kind}\``,
163625
- description: null,
163626
- loc: instrValue.loc,
163627
- suggestions: null,
163628
- });
163629
- state.referenceAndRecordEffects(
163630
- operand,
163631
- effect.kind,
163632
- effect.reason,
163633
- functionEffects
163634
- );
163635
- }
163636
- state.initialize(instrValue, valueKind);
163637
- state.define(instr.lvalue, instrValue);
163638
- instr.lvalue.effect = lvalueEffect;
163883
+ if (continuation.kind === 'initialize') {
163884
+ for (const operand of eachInstructionOperand(instr)) {
163885
+ CompilerError.invariant(continuation.effect != null, {
163886
+ reason: `effectKind must be set for instruction value \`${instrValue.kind}\``,
163887
+ description: null,
163888
+ loc: instrValue.loc,
163889
+ suggestions: null,
163890
+ });
163891
+ state.referenceAndRecordEffects(
163892
+ freezeActions,
163893
+ operand,
163894
+ continuation.effect.kind,
163895
+ continuation.effect.reason
163896
+ );
163897
+ }
163898
+ state.initialize(instrValue, continuation.valueKind);
163899
+ state.define(instr.lvalue, instrValue);
163900
+ instr.lvalue.effect =
163901
+ (_d = continuation.lvalueEffect) !== null && _d !== void 0
163902
+ ? _d
163903
+ : defaultLvalueEffect;
163904
+ }
163905
+ functionEffects.push(...inferInstructionFunctionEffects(env, state, instr));
163906
+ freezeActions.forEach(({values: values, reason: reason}) =>
163907
+ state.freezeValues(values, reason)
163908
+ );
163639
163909
  }
163910
+ const terminalFreezeActions = [];
163640
163911
  for (const operand of eachTerminalOperand(block.terminal)) {
163641
163912
  let effect;
163642
163913
  if (block.terminal.kind === 'return' || block.terminal.kind === 'throw') {
@@ -163651,17 +163922,17 @@ function inferBlock(env, functionEffects, state, block) {
163651
163922
  } else {
163652
163923
  effect = exports.Effect.Read;
163653
163924
  }
163654
- const propEffects = [];
163655
163925
  state.referenceAndRecordEffects(
163926
+ terminalFreezeActions,
163656
163927
  operand,
163657
163928
  effect,
163658
- ValueReason.Other,
163659
- propEffects
163660
- );
163661
- functionEffects.push(
163662
- ...propEffects.filter(effect => !isEffectSafeOutsideRender(effect))
163929
+ ValueReason.Other
163663
163930
  );
163664
163931
  }
163932
+ functionEffects.push(...inferTerminalFunctionEffects(state, block));
163933
+ terminalFreezeActions.forEach(({values: values, reason: reason}) =>
163934
+ state.freezeValues(values, reason)
163935
+ );
163665
163936
  }
163666
163937
  function hasContextRefOperand(state, instrValue) {
163667
163938
  for (const place of eachInstructionValueOperand(instrValue)) {
@@ -163728,28 +163999,6 @@ function areArgumentsImmutableAndNonMutating(state, args) {
163728
163999
  }
163729
164000
  return true;
163730
164001
  }
163731
- function isEffectSafeOutsideRender(effect) {
163732
- return effect.kind === 'GlobalMutation';
163733
- }
163734
- function getWriteErrorReason(abstractValue) {
163735
- if (abstractValue.reason.has(ValueReason.Global)) {
163736
- return 'Writing to a variable defined outside a component or hook is not allowed. Consider using an effect';
163737
- } else if (abstractValue.reason.has(ValueReason.JsxCaptured)) {
163738
- return 'Updating a value used previously in JSX is not allowed. Consider moving the mutation before the JSX';
163739
- } else if (abstractValue.reason.has(ValueReason.Context)) {
163740
- return `Mutating a value returned from 'useContext()', which should not be mutated`;
163741
- } else if (abstractValue.reason.has(ValueReason.KnownReturnSignature)) {
163742
- return 'Mutating a value returned from a function whose return value should not be mutated';
163743
- } else if (abstractValue.reason.has(ValueReason.ReactiveFunctionArgument)) {
163744
- return 'Mutating component props or hook arguments is not allowed. Consider using a local variable instead';
163745
- } else if (abstractValue.reason.has(ValueReason.State)) {
163746
- return "Mutating a value returned from 'useState()', which should not be mutated. Use the setter function to update instead";
163747
- } else if (abstractValue.reason.has(ValueReason.ReducerState)) {
163748
- return "Mutating a value returned from 'useReducer()', which should not be mutated. Use the dispatch function to update instead";
163749
- } else {
163750
- return 'This mutates a variable that React considers immutable';
163751
- }
163752
- }
163753
164002
  function pruneNonEscapingScopes(fn) {
163754
164003
  const state = new State(fn.env);
163755
164004
  for (const param of fn.params) {
@@ -169445,6 +169694,917 @@ function validateNoJSXInTryStatement(fn) {
169445
169694
  throw errors;
169446
169695
  }
169447
169696
  }
169697
+ var _Tree_instances, _a, _Tree_getOrCreateRoot, _Tree_getOrCreateProperty;
169698
+ function collectHoistablePropertyLoads(fn, temporaries) {
169699
+ const nodes = collectPropertyLoadsInBlocks(fn, temporaries);
169700
+ propagateNonNull(fn, nodes);
169701
+ const nodesKeyedByScopeId = new Map();
169702
+ for (const [_, block] of fn.body.blocks) {
169703
+ if (block.terminal.kind === 'scope') {
169704
+ nodesKeyedByScopeId.set(
169705
+ block.terminal.scope.id,
169706
+ nodes.get(block.terminal.block)
169707
+ );
169708
+ }
169709
+ }
169710
+ return nodesKeyedByScopeId;
169711
+ }
169712
+ function getProperty(object, propertyName, temporaries) {
169713
+ const resolvedDependency = temporaries.get(object.identifier.id);
169714
+ let property;
169715
+ if (resolvedDependency == null) {
169716
+ property = {
169717
+ identifier: object.identifier,
169718
+ path: [{property: propertyName, optional: false}],
169719
+ };
169720
+ } else {
169721
+ property = {
169722
+ identifier: resolvedDependency.identifier,
169723
+ path: [
169724
+ ...resolvedDependency.path,
169725
+ {property: propertyName, optional: false},
169726
+ ],
169727
+ };
169728
+ }
169729
+ return property;
169730
+ }
169731
+ class Tree {
169732
+ constructor() {
169733
+ _Tree_instances.add(this);
169734
+ this.roots = new Map();
169735
+ }
169736
+ getPropertyLoadNode(n) {
169737
+ CompilerError.invariant(n.path.length > 0, {
169738
+ reason:
169739
+ '[CollectHoistablePropertyLoads] Expected property node, found root node',
169740
+ loc: GeneratedSource,
169741
+ });
169742
+ let currNode = __classPrivateFieldGet(
169743
+ this,
169744
+ _Tree_instances,
169745
+ 'm',
169746
+ _Tree_getOrCreateRoot
169747
+ ).call(this, n.identifier);
169748
+ for (let i = 0; i < n.path.length - 1; i++) {
169749
+ currNode = assertNonNull(currNode.properties.get(n.path[i].property));
169750
+ }
169751
+ return __classPrivateFieldGet(_a, _a, 'm', _Tree_getOrCreateProperty).call(
169752
+ _a,
169753
+ currNode,
169754
+ n.path.at(-1).property
169755
+ );
169756
+ }
169757
+ }
169758
+ (_a = Tree),
169759
+ (_Tree_instances = new WeakSet()),
169760
+ (_Tree_getOrCreateRoot = function _Tree_getOrCreateRoot(identifier) {
169761
+ let rootNode = this.roots.get(identifier);
169762
+ if (rootNode === undefined) {
169763
+ rootNode = {
169764
+ root: identifier,
169765
+ properties: new Map(),
169766
+ fullPath: {identifier: identifier, path: []},
169767
+ parent: null,
169768
+ };
169769
+ this.roots.set(identifier, rootNode);
169770
+ }
169771
+ return rootNode;
169772
+ }),
169773
+ (_Tree_getOrCreateProperty = function _Tree_getOrCreateProperty(
169774
+ node,
169775
+ property
169776
+ ) {
169777
+ let child = node.properties.get(property);
169778
+ if (child == null) {
169779
+ child = {
169780
+ properties: new Map(),
169781
+ parent: node,
169782
+ fullPath: {
169783
+ identifier: node.fullPath.identifier,
169784
+ path: node.fullPath.path.concat([
169785
+ {property: property, optional: false},
169786
+ ]),
169787
+ },
169788
+ };
169789
+ node.properties.set(property, child);
169790
+ }
169791
+ return child;
169792
+ });
169793
+ function collectPropertyLoadsInBlocks(fn, temporaries) {
169794
+ const knownImmutableIdentifiers = new Set();
169795
+ if (fn.fnType === 'Component' || fn.fnType === 'Hook') {
169796
+ for (const p of fn.params) {
169797
+ if (p.kind === 'Identifier') {
169798
+ knownImmutableIdentifiers.add(p.identifier);
169799
+ }
169800
+ }
169801
+ }
169802
+ const tree = new Tree();
169803
+ const nodes = new Map();
169804
+ for (const [_, block] of fn.body.blocks) {
169805
+ const assumedNonNullObjects = new Set();
169806
+ for (const instr of block.instructions) {
169807
+ if (instr.value.kind === 'PropertyLoad') {
169808
+ const property = getProperty(
169809
+ instr.value.object,
169810
+ instr.value.property,
169811
+ temporaries
169812
+ );
169813
+ const propertyNode = tree.getPropertyLoadNode(property);
169814
+ const object = instr.value.object.identifier;
169815
+ const isMutableAtInstr =
169816
+ object.mutableRange.end > object.mutableRange.start + 1 &&
169817
+ object.scope != null &&
169818
+ inRange(instr, object.scope.range);
169819
+ if (
169820
+ !isMutableAtInstr ||
169821
+ knownImmutableIdentifiers.has(propertyNode.fullPath.identifier)
169822
+ ) {
169823
+ let curr = propertyNode.parent;
169824
+ while (curr != null) {
169825
+ assumedNonNullObjects.add(curr);
169826
+ curr = curr.parent;
169827
+ }
169828
+ }
169829
+ }
169830
+ }
169831
+ nodes.set(block.id, {
169832
+ block: block,
169833
+ assumedNonNullObjects: assumedNonNullObjects,
169834
+ });
169835
+ }
169836
+ return nodes;
169837
+ }
169838
+ function propagateNonNull(fn, nodes) {
169839
+ const blockSuccessors = new Map();
169840
+ const terminalPreds = new Set();
169841
+ for (const [blockId, block] of fn.body.blocks) {
169842
+ for (const pred of block.preds) {
169843
+ getOrInsertDefault(blockSuccessors, pred, new Set()).add(blockId);
169844
+ }
169845
+ if (block.terminal.kind === 'throw' || block.terminal.kind === 'return') {
169846
+ terminalPreds.add(blockId);
169847
+ }
169848
+ }
169849
+ function recursivelyPropagateNonNull(
169850
+ nodeId,
169851
+ direction,
169852
+ traversalState,
169853
+ nonNullObjectsByBlock
169854
+ ) {
169855
+ var _b;
169856
+ if (traversalState.has(nodeId)) {
169857
+ return false;
169858
+ }
169859
+ traversalState.set(nodeId, 'active');
169860
+ const node = nodes.get(nodeId);
169861
+ if (node == null) {
169862
+ CompilerError.invariant(false, {
169863
+ reason: `Bad node ${nodeId}, kind: ${direction}`,
169864
+ loc: GeneratedSource,
169865
+ });
169866
+ }
169867
+ const neighbors = Array.from(
169868
+ direction === 'backward'
169869
+ ? (_b = blockSuccessors.get(nodeId)) !== null && _b !== void 0
169870
+ ? _b
169871
+ : []
169872
+ : node.block.preds
169873
+ );
169874
+ let changed = false;
169875
+ for (const pred of neighbors) {
169876
+ if (!traversalState.has(pred)) {
169877
+ const neighborChanged = recursivelyPropagateNonNull(
169878
+ pred,
169879
+ direction,
169880
+ traversalState,
169881
+ nonNullObjectsByBlock
169882
+ );
169883
+ changed || (changed = neighborChanged);
169884
+ }
169885
+ }
169886
+ const neighborAccesses = Set_intersect(
169887
+ Array.from(neighbors)
169888
+ .filter(n => traversalState.get(n) === 'done')
169889
+ .map(n => assertNonNull(nonNullObjectsByBlock.get(n)))
169890
+ );
169891
+ const prevObjects = assertNonNull(nonNullObjectsByBlock.get(nodeId));
169892
+ const newObjects = Set_union(prevObjects, neighborAccesses);
169893
+ nonNullObjectsByBlock.set(nodeId, newObjects);
169894
+ traversalState.set(nodeId, 'done');
169895
+ changed || (changed = prevObjects.size !== newObjects.size);
169896
+ return changed;
169897
+ }
169898
+ const fromEntry = new Map();
169899
+ const fromExit = new Map();
169900
+ for (const [blockId, blockInfo] of nodes) {
169901
+ fromEntry.set(blockId, blockInfo.assumedNonNullObjects);
169902
+ fromExit.set(blockId, blockInfo.assumedNonNullObjects);
169903
+ }
169904
+ const traversalState = new Map();
169905
+ const reversedBlocks = [...fn.body.blocks];
169906
+ reversedBlocks.reverse();
169907
+ let i = 0;
169908
+ let changed;
169909
+ do {
169910
+ i++;
169911
+ changed = false;
169912
+ for (const [blockId] of fn.body.blocks) {
169913
+ const forwardChanged = recursivelyPropagateNonNull(
169914
+ blockId,
169915
+ 'forward',
169916
+ traversalState,
169917
+ fromEntry
169918
+ );
169919
+ changed || (changed = forwardChanged);
169920
+ }
169921
+ traversalState.clear();
169922
+ for (const [blockId] of reversedBlocks) {
169923
+ const backwardChanged = recursivelyPropagateNonNull(
169924
+ blockId,
169925
+ 'backward',
169926
+ traversalState,
169927
+ fromExit
169928
+ );
169929
+ changed || (changed = backwardChanged);
169930
+ }
169931
+ traversalState.clear();
169932
+ } while (changed);
169933
+ CompilerError.invariant(i <= 2, {
169934
+ reason: 'require fixed-point iteration',
169935
+ description: `#iterations = ${i}`,
169936
+ loc: GeneratedSource,
169937
+ });
169938
+ CompilerError.invariant(
169939
+ fromEntry.size === fromExit.size && fromEntry.size === nodes.size,
169940
+ {
169941
+ reason:
169942
+ 'bad sizes after calculating fromEntry + fromExit ' +
169943
+ `${fromEntry.size} ${fromExit.size} ${nodes.size}`,
169944
+ loc: GeneratedSource,
169945
+ }
169946
+ );
169947
+ for (const [id, node] of nodes) {
169948
+ node.assumedNonNullObjects = Set_union(
169949
+ assertNonNull(fromEntry.get(id)),
169950
+ assertNonNull(fromExit.get(id))
169951
+ );
169952
+ }
169953
+ }
169954
+ function assertNonNull(value, source) {
169955
+ CompilerError.invariant(value != null, {
169956
+ reason: 'Unexpected null',
169957
+ description: source != null ? `(from ${source})` : null,
169958
+ loc: GeneratedSource,
169959
+ });
169960
+ return value;
169961
+ }
169962
+ var _ReactiveScopeDependencyTreeHIR_instances,
169963
+ _ReactiveScopeDependencyTreeHIR_roots,
169964
+ _ReactiveScopeDependencyTreeHIR_getOrCreateRoot;
169965
+ class ReactiveScopeDependencyTreeHIR {
169966
+ constructor() {
169967
+ _ReactiveScopeDependencyTreeHIR_instances.add(this);
169968
+ _ReactiveScopeDependencyTreeHIR_roots.set(this, new Map());
169969
+ }
169970
+ addDependency(dep) {
169971
+ const {path: path} = dep;
169972
+ let currNode = __classPrivateFieldGet(
169973
+ this,
169974
+ _ReactiveScopeDependencyTreeHIR_instances,
169975
+ 'm',
169976
+ _ReactiveScopeDependencyTreeHIR_getOrCreateRoot
169977
+ ).call(this, dep.identifier, false);
169978
+ const accessType = PropertyAccessType.Access;
169979
+ currNode.accessType = merge(currNode.accessType, accessType);
169980
+ for (const property of path) {
169981
+ let currChild = getOrMakeProperty(currNode, property.property);
169982
+ currChild.accessType = merge(currChild.accessType, accessType);
169983
+ currNode = currChild;
169984
+ }
169985
+ currNode.accessType = merge(
169986
+ currNode.accessType,
169987
+ PropertyAccessType.Dependency
169988
+ );
169989
+ }
169990
+ markNodesNonNull(dep) {
169991
+ const accessType = PropertyAccessType.NonNullAccess;
169992
+ let currNode = __classPrivateFieldGet(
169993
+ this,
169994
+ _ReactiveScopeDependencyTreeHIR_roots,
169995
+ 'f'
169996
+ ).get(dep.identifier);
169997
+ let cursor = 0;
169998
+ while (currNode != null && cursor < dep.path.length) {
169999
+ currNode.accessType = merge(currNode.accessType, accessType);
170000
+ currNode = currNode.properties.get(dep.path[cursor++].property);
170001
+ }
170002
+ if (currNode != null) {
170003
+ currNode.accessType = merge(currNode.accessType, accessType);
170004
+ }
170005
+ }
170006
+ deriveMinimalDependencies() {
170007
+ const results = new Set();
170008
+ for (const [rootId, rootNode] of __classPrivateFieldGet(
170009
+ this,
170010
+ _ReactiveScopeDependencyTreeHIR_roots,
170011
+ 'f'
170012
+ ).entries()) {
170013
+ {
170014
+ assertWellFormedTree(rootNode);
170015
+ }
170016
+ const deps = deriveMinimalDependenciesInSubtree(rootNode, []);
170017
+ for (const dep of deps) {
170018
+ results.add({
170019
+ identifier: rootId,
170020
+ path: dep.path.map(s => ({property: s, optional: false})),
170021
+ });
170022
+ }
170023
+ }
170024
+ return results;
170025
+ }
170026
+ printDeps(includeAccesses) {
170027
+ let res = [];
170028
+ for (const [rootId, rootNode] of __classPrivateFieldGet(
170029
+ this,
170030
+ _ReactiveScopeDependencyTreeHIR_roots,
170031
+ 'f'
170032
+ ).entries()) {
170033
+ const rootResults = printSubtree(rootNode, includeAccesses).map(
170034
+ result => `${printIdentifier(rootId)}.${result}`
170035
+ );
170036
+ res.push(rootResults);
170037
+ }
170038
+ return res.flat().join('\n');
170039
+ }
170040
+ }
170041
+ (_ReactiveScopeDependencyTreeHIR_roots = new WeakMap()),
170042
+ (_ReactiveScopeDependencyTreeHIR_instances = new WeakSet()),
170043
+ (_ReactiveScopeDependencyTreeHIR_getOrCreateRoot =
170044
+ function _ReactiveScopeDependencyTreeHIR_getOrCreateRoot(
170045
+ identifier,
170046
+ isNonNull
170047
+ ) {
170048
+ let rootNode = __classPrivateFieldGet(
170049
+ this,
170050
+ _ReactiveScopeDependencyTreeHIR_roots,
170051
+ 'f'
170052
+ ).get(identifier);
170053
+ if (rootNode === undefined) {
170054
+ rootNode = {
170055
+ properties: new Map(),
170056
+ accessType: isNonNull
170057
+ ? PropertyAccessType.NonNullAccess
170058
+ : PropertyAccessType.Access,
170059
+ };
170060
+ __classPrivateFieldGet(
170061
+ this,
170062
+ _ReactiveScopeDependencyTreeHIR_roots,
170063
+ 'f'
170064
+ ).set(identifier, rootNode);
170065
+ }
170066
+ return rootNode;
170067
+ });
170068
+ var PropertyAccessType;
170069
+ (function (PropertyAccessType) {
170070
+ PropertyAccessType['Access'] = 'Access';
170071
+ PropertyAccessType['NonNullAccess'] = 'NonNullAccess';
170072
+ PropertyAccessType['Dependency'] = 'Dependency';
170073
+ PropertyAccessType['NonNullDependency'] = 'NonNullDependency';
170074
+ })(PropertyAccessType || (PropertyAccessType = {}));
170075
+ const MIN_ACCESS_TYPE = PropertyAccessType.Access;
170076
+ function isNonNull(access) {
170077
+ return (
170078
+ access === PropertyAccessType.NonNullAccess ||
170079
+ access === PropertyAccessType.NonNullDependency
170080
+ );
170081
+ }
170082
+ function isDependency(access) {
170083
+ return (
170084
+ access === PropertyAccessType.Dependency ||
170085
+ access === PropertyAccessType.NonNullDependency
170086
+ );
170087
+ }
170088
+ function merge(access1, access2) {
170089
+ const resultisNonNull = isNonNull(access1) || isNonNull(access2);
170090
+ const resultIsDependency = isDependency(access1) || isDependency(access2);
170091
+ if (resultisNonNull) {
170092
+ if (resultIsDependency) {
170093
+ return PropertyAccessType.NonNullDependency;
170094
+ } else {
170095
+ return PropertyAccessType.NonNullAccess;
170096
+ }
170097
+ } else {
170098
+ if (resultIsDependency) {
170099
+ return PropertyAccessType.Dependency;
170100
+ } else {
170101
+ return PropertyAccessType.Access;
170102
+ }
170103
+ }
170104
+ }
170105
+ function assertWellFormedTree(node) {
170106
+ let nonNullInChildren = false;
170107
+ for (const childNode of node.properties.values()) {
170108
+ assertWellFormedTree(childNode);
170109
+ nonNullInChildren || (nonNullInChildren = isNonNull(childNode.accessType));
170110
+ }
170111
+ if (nonNullInChildren) {
170112
+ CompilerError.invariant(isNonNull(node.accessType), {
170113
+ reason:
170114
+ '[DeriveMinimialDependencies] Not well formed tree, unexpected non-null node',
170115
+ description: node.accessType,
170116
+ loc: GeneratedSource,
170117
+ });
170118
+ }
170119
+ }
170120
+ function deriveMinimalDependenciesInSubtree(node, path) {
170121
+ if (isDependency(node.accessType)) {
170122
+ return [{path: path}];
170123
+ } else {
170124
+ if (isNonNull(node.accessType)) {
170125
+ const result = [];
170126
+ for (const [childName, childNode] of node.properties) {
170127
+ result.push(
170128
+ ...deriveMinimalDependenciesInSubtree(childNode, [...path, childName])
170129
+ );
170130
+ }
170131
+ return result;
170132
+ } else {
170133
+ return [{path: path}];
170134
+ }
170135
+ }
170136
+ }
170137
+ function printSubtree(node, includeAccesses) {
170138
+ const results = [];
170139
+ for (const [propertyName, propertyNode] of node.properties) {
170140
+ if (includeAccesses || isDependency(propertyNode.accessType)) {
170141
+ results.push(`${propertyName} (${propertyNode.accessType})`);
170142
+ }
170143
+ const propertyResults = printSubtree(propertyNode, includeAccesses);
170144
+ results.push(...propertyResults.map(result => `${propertyName}.${result}`));
170145
+ }
170146
+ return results;
170147
+ }
170148
+ function getOrMakeProperty(node, property) {
170149
+ let child = node.properties.get(property);
170150
+ if (child == null) {
170151
+ child = {properties: new Map(), accessType: MIN_ACCESS_TYPE};
170152
+ node.properties.set(property, child);
170153
+ }
170154
+ return child;
170155
+ }
170156
+ var _Context_instances,
170157
+ _Context_declarations,
170158
+ _Context_reassignments,
170159
+ _Context_scopes,
170160
+ _Context_dependencies,
170161
+ _Context_temporaries,
170162
+ _Context_temporariesUsedOutsideScope,
170163
+ _Context_checkValidDependency,
170164
+ _Context_isScopeActive;
170165
+ function propagateScopeDependenciesHIR(fn) {
170166
+ const usedOutsideDeclaringScope =
170167
+ findTemporariesUsedOutsideDeclaringScope(fn);
170168
+ const temporaries = collectTemporariesSidemap(fn, usedOutsideDeclaringScope);
170169
+ const hoistablePropertyLoads = collectHoistablePropertyLoads(fn, temporaries);
170170
+ const scopeDeps = collectDependencies(
170171
+ fn,
170172
+ usedOutsideDeclaringScope,
170173
+ temporaries
170174
+ );
170175
+ for (const [scope, deps] of scopeDeps) {
170176
+ const tree = new ReactiveScopeDependencyTreeHIR();
170177
+ for (const dep of deps) {
170178
+ tree.addDependency(Object.assign({}, dep));
170179
+ }
170180
+ recordHoistablePropertyReads(hoistablePropertyLoads, scope.id, tree);
170181
+ const candidates = tree.deriveMinimalDependencies();
170182
+ for (const candidateDep of candidates) {
170183
+ if (
170184
+ !Iterable_some(
170185
+ scope.dependencies,
170186
+ existingDep =>
170187
+ existingDep.identifier.declarationId ===
170188
+ candidateDep.identifier.declarationId &&
170189
+ areEqualPaths(existingDep.path, candidateDep.path)
170190
+ )
170191
+ )
170192
+ scope.dependencies.add(candidateDep);
170193
+ }
170194
+ }
170195
+ }
170196
+ function findTemporariesUsedOutsideDeclaringScope(fn) {
170197
+ const declarations = new Map();
170198
+ const prunedScopes = new Set();
170199
+ const scopeTraversal = new ScopeBlockTraversal();
170200
+ const usedOutsideDeclaringScope = new Set();
170201
+ function handlePlace(place) {
170202
+ const declaringScope = declarations.get(place.identifier.declarationId);
170203
+ if (
170204
+ declaringScope != null &&
170205
+ !scopeTraversal.isScopeActive(declaringScope) &&
170206
+ !prunedScopes.has(declaringScope)
170207
+ ) {
170208
+ usedOutsideDeclaringScope.add(place.identifier.declarationId);
170209
+ }
170210
+ }
170211
+ function handleInstruction(instr) {
170212
+ const scope = scopeTraversal.currentScope;
170213
+ if (scope == null || prunedScopes.has(scope)) {
170214
+ return;
170215
+ }
170216
+ switch (instr.value.kind) {
170217
+ case 'LoadLocal':
170218
+ case 'LoadContext':
170219
+ case 'PropertyLoad': {
170220
+ declarations.set(instr.lvalue.identifier.declarationId, scope);
170221
+ break;
170222
+ }
170223
+ }
170224
+ }
170225
+ for (const [blockId, block] of fn.body.blocks) {
170226
+ scopeTraversal.recordScopes(block);
170227
+ const scopeStartInfo = scopeTraversal.blockInfos.get(blockId);
170228
+ if (
170229
+ (scopeStartInfo === null || scopeStartInfo === void 0
170230
+ ? void 0
170231
+ : scopeStartInfo.kind) === 'begin' &&
170232
+ scopeStartInfo.pruned
170233
+ ) {
170234
+ prunedScopes.add(scopeStartInfo.scope.id);
170235
+ }
170236
+ for (const instr of block.instructions) {
170237
+ for (const place of eachInstructionOperand(instr)) {
170238
+ handlePlace(place);
170239
+ }
170240
+ handleInstruction(instr);
170241
+ }
170242
+ for (const place of eachTerminalOperand(block.terminal)) {
170243
+ handlePlace(place);
170244
+ }
170245
+ }
170246
+ return usedOutsideDeclaringScope;
170247
+ }
170248
+ function collectTemporariesSidemap(fn, usedOutsideDeclaringScope) {
170249
+ const temporaries = new Map();
170250
+ for (const [_, block] of fn.body.blocks) {
170251
+ for (const instr of block.instructions) {
170252
+ const {value: value, lvalue: lvalue} = instr;
170253
+ const usedOutside = usedOutsideDeclaringScope.has(
170254
+ lvalue.identifier.declarationId
170255
+ );
170256
+ if (value.kind === 'PropertyLoad' && !usedOutside) {
170257
+ const property = getProperty(value.object, value.property, temporaries);
170258
+ temporaries.set(lvalue.identifier.id, property);
170259
+ } else if (
170260
+ value.kind === 'LoadLocal' &&
170261
+ lvalue.identifier.name == null &&
170262
+ value.place.identifier.name !== null &&
170263
+ !usedOutside
170264
+ ) {
170265
+ temporaries.set(lvalue.identifier.id, {
170266
+ identifier: value.place.identifier,
170267
+ path: [],
170268
+ });
170269
+ }
170270
+ }
170271
+ }
170272
+ return temporaries;
170273
+ }
170274
+ class Context {
170275
+ constructor(temporariesUsedOutsideScope, temporaries) {
170276
+ _Context_instances.add(this);
170277
+ _Context_declarations.set(this, new Map());
170278
+ _Context_reassignments.set(this, new Map());
170279
+ _Context_scopes.set(this, empty());
170280
+ _Context_dependencies.set(this, empty());
170281
+ this.deps = new Map();
170282
+ _Context_temporaries.set(this, void 0);
170283
+ _Context_temporariesUsedOutsideScope.set(this, void 0);
170284
+ __classPrivateFieldSet(
170285
+ this,
170286
+ _Context_temporariesUsedOutsideScope,
170287
+ temporariesUsedOutsideScope,
170288
+ 'f'
170289
+ );
170290
+ __classPrivateFieldSet(this, _Context_temporaries, temporaries, 'f');
170291
+ }
170292
+ enterScope(scope) {
170293
+ __classPrivateFieldSet(
170294
+ this,
170295
+ _Context_dependencies,
170296
+ __classPrivateFieldGet(this, _Context_dependencies, 'f').push([]),
170297
+ 'f'
170298
+ );
170299
+ __classPrivateFieldSet(
170300
+ this,
170301
+ _Context_scopes,
170302
+ __classPrivateFieldGet(this, _Context_scopes, 'f').push(scope),
170303
+ 'f'
170304
+ );
170305
+ }
170306
+ exitScope(scope, pruned) {
170307
+ var _a;
170308
+ const scopedDependencies = __classPrivateFieldGet(
170309
+ this,
170310
+ _Context_dependencies,
170311
+ 'f'
170312
+ ).value;
170313
+ CompilerError.invariant(scopedDependencies != null, {
170314
+ reason: '[PropagateScopeDeps]: Unexpected scope mismatch',
170315
+ loc: scope.loc,
170316
+ });
170317
+ __classPrivateFieldSet(
170318
+ this,
170319
+ _Context_scopes,
170320
+ __classPrivateFieldGet(this, _Context_scopes, 'f').pop(),
170321
+ 'f'
170322
+ );
170323
+ __classPrivateFieldSet(
170324
+ this,
170325
+ _Context_dependencies,
170326
+ __classPrivateFieldGet(this, _Context_dependencies, 'f').pop(),
170327
+ 'f'
170328
+ );
170329
+ for (const dep of scopedDependencies) {
170330
+ if (
170331
+ __classPrivateFieldGet(
170332
+ this,
170333
+ _Context_instances,
170334
+ 'm',
170335
+ _Context_checkValidDependency
170336
+ ).call(this, dep)
170337
+ ) {
170338
+ (_a = __classPrivateFieldGet(
170339
+ this,
170340
+ _Context_dependencies,
170341
+ 'f'
170342
+ ).value) === null || _a === void 0
170343
+ ? void 0
170344
+ : _a.push(dep);
170345
+ }
170346
+ }
170347
+ if (!pruned) {
170348
+ this.deps.set(scope, scopedDependencies);
170349
+ }
170350
+ }
170351
+ isUsedOutsideDeclaringScope(place) {
170352
+ return __classPrivateFieldGet(
170353
+ this,
170354
+ _Context_temporariesUsedOutsideScope,
170355
+ 'f'
170356
+ ).has(place.identifier.declarationId);
170357
+ }
170358
+ declare(identifier, decl) {
170359
+ if (
170360
+ !__classPrivateFieldGet(this, _Context_declarations, 'f').has(
170361
+ identifier.declarationId
170362
+ )
170363
+ ) {
170364
+ __classPrivateFieldGet(this, _Context_declarations, 'f').set(
170365
+ identifier.declarationId,
170366
+ decl
170367
+ );
170368
+ }
170369
+ __classPrivateFieldGet(this, _Context_reassignments, 'f').set(
170370
+ identifier,
170371
+ decl
170372
+ );
170373
+ }
170374
+ get currentScope() {
170375
+ return __classPrivateFieldGet(this, _Context_scopes, 'f');
170376
+ }
170377
+ visitOperand(place) {
170378
+ var _a;
170379
+ this.visitDependency(
170380
+ (_a = __classPrivateFieldGet(this, _Context_temporaries, 'f').get(
170381
+ place.identifier.id
170382
+ )) !== null && _a !== void 0
170383
+ ? _a
170384
+ : {identifier: place.identifier, path: []}
170385
+ );
170386
+ }
170387
+ visitProperty(object, property) {
170388
+ const nextDependency = getProperty(
170389
+ object,
170390
+ property,
170391
+ __classPrivateFieldGet(this, _Context_temporaries, 'f')
170392
+ );
170393
+ this.visitDependency(nextDependency);
170394
+ }
170395
+ visitDependency(maybeDependency) {
170396
+ const originalDeclaration = __classPrivateFieldGet(
170397
+ this,
170398
+ _Context_declarations,
170399
+ 'f'
170400
+ ).get(maybeDependency.identifier.declarationId);
170401
+ if (
170402
+ originalDeclaration !== undefined &&
170403
+ originalDeclaration.scope.value !== null
170404
+ ) {
170405
+ originalDeclaration.scope.each(scope => {
170406
+ if (
170407
+ !__classPrivateFieldGet(
170408
+ this,
170409
+ _Context_instances,
170410
+ 'm',
170411
+ _Context_isScopeActive
170412
+ ).call(this, scope) &&
170413
+ !Iterable_some(
170414
+ scope.declarations.values(),
170415
+ decl =>
170416
+ decl.identifier.declarationId ===
170417
+ maybeDependency.identifier.declarationId
170418
+ )
170419
+ ) {
170420
+ scope.declarations.set(maybeDependency.identifier.id, {
170421
+ identifier: maybeDependency.identifier,
170422
+ scope: originalDeclaration.scope.value,
170423
+ });
170424
+ }
170425
+ });
170426
+ }
170427
+ if (
170428
+ __classPrivateFieldGet(
170429
+ this,
170430
+ _Context_instances,
170431
+ 'm',
170432
+ _Context_checkValidDependency
170433
+ ).call(this, maybeDependency)
170434
+ ) {
170435
+ __classPrivateFieldGet(this, _Context_dependencies, 'f').value.push(
170436
+ maybeDependency
170437
+ );
170438
+ }
170439
+ }
170440
+ visitReassignment(place) {
170441
+ const currentScope = this.currentScope.value;
170442
+ if (
170443
+ currentScope != null &&
170444
+ !Iterable_some(
170445
+ currentScope.reassignments,
170446
+ identifier =>
170447
+ identifier.declarationId === place.identifier.declarationId
170448
+ ) &&
170449
+ __classPrivateFieldGet(
170450
+ this,
170451
+ _Context_instances,
170452
+ 'm',
170453
+ _Context_checkValidDependency
170454
+ ).call(this, {identifier: place.identifier, path: []})
170455
+ ) {
170456
+ currentScope.reassignments.add(place.identifier);
170457
+ }
170458
+ }
170459
+ }
170460
+ (_Context_declarations = new WeakMap()),
170461
+ (_Context_reassignments = new WeakMap()),
170462
+ (_Context_scopes = new WeakMap()),
170463
+ (_Context_dependencies = new WeakMap()),
170464
+ (_Context_temporaries = new WeakMap()),
170465
+ (_Context_temporariesUsedOutsideScope = new WeakMap()),
170466
+ (_Context_instances = new WeakSet()),
170467
+ (_Context_checkValidDependency = function _Context_checkValidDependency(
170468
+ maybeDependency
170469
+ ) {
170470
+ var _a, _b;
170471
+ if (
170472
+ isUseRefType(maybeDependency.identifier) &&
170473
+ ((_a = maybeDependency.path.at(0)) === null || _a === void 0
170474
+ ? void 0
170475
+ : _a.property) === 'current'
170476
+ ) {
170477
+ return false;
170478
+ }
170479
+ if (isRefValueType(maybeDependency.identifier)) {
170480
+ return false;
170481
+ }
170482
+ if (isObjectMethodType(maybeDependency.identifier)) {
170483
+ return false;
170484
+ }
170485
+ const identifier = maybeDependency.identifier;
170486
+ const currentDeclaration =
170487
+ (_b = __classPrivateFieldGet(this, _Context_reassignments, 'f').get(
170488
+ identifier
170489
+ )) !== null && _b !== void 0
170490
+ ? _b
170491
+ : __classPrivateFieldGet(this, _Context_declarations, 'f').get(
170492
+ identifier.declarationId
170493
+ );
170494
+ const currentScope = this.currentScope.value;
170495
+ return (
170496
+ currentScope != null &&
170497
+ currentDeclaration !== undefined &&
170498
+ currentDeclaration.id < currentScope.range.start
170499
+ );
170500
+ }),
170501
+ (_Context_isScopeActive = function _Context_isScopeActive(scope) {
170502
+ if (__classPrivateFieldGet(this, _Context_scopes, 'f') === null) {
170503
+ return false;
170504
+ }
170505
+ return __classPrivateFieldGet(this, _Context_scopes, 'f').find(
170506
+ state => state === scope
170507
+ );
170508
+ });
170509
+ function handleInstruction(instr, context) {
170510
+ const {id: id, value: value, lvalue: lvalue} = instr;
170511
+ if (value.kind === 'LoadLocal') {
170512
+ if (
170513
+ value.place.identifier.name === null ||
170514
+ lvalue.identifier.name !== null ||
170515
+ context.isUsedOutsideDeclaringScope(lvalue)
170516
+ ) {
170517
+ context.visitOperand(value.place);
170518
+ }
170519
+ } else if (value.kind === 'PropertyLoad') {
170520
+ if (context.isUsedOutsideDeclaringScope(lvalue)) {
170521
+ context.visitProperty(value.object, value.property);
170522
+ }
170523
+ } else if (value.kind === 'StoreLocal') {
170524
+ context.visitOperand(value.value);
170525
+ if (value.lvalue.kind === InstructionKind.Reassign) {
170526
+ context.visitReassignment(value.lvalue.place);
170527
+ }
170528
+ context.declare(value.lvalue.place.identifier, {
170529
+ id: id,
170530
+ scope: context.currentScope,
170531
+ });
170532
+ } else if (value.kind === 'DeclareLocal' || value.kind === 'DeclareContext') {
170533
+ context.declare(value.lvalue.place.identifier, {
170534
+ id: id,
170535
+ scope: context.currentScope,
170536
+ });
170537
+ } else if (value.kind === 'Destructure') {
170538
+ context.visitOperand(value.value);
170539
+ for (const place of eachPatternOperand(value.lvalue.pattern)) {
170540
+ if (value.lvalue.kind === InstructionKind.Reassign) {
170541
+ context.visitReassignment(place);
170542
+ }
170543
+ context.declare(place.identifier, {id: id, scope: context.currentScope});
170544
+ }
170545
+ } else {
170546
+ for (const operand of eachInstructionValueOperand(value)) {
170547
+ context.visitOperand(operand);
170548
+ }
170549
+ }
170550
+ context.declare(lvalue.identifier, {id: id, scope: context.currentScope});
170551
+ }
170552
+ function collectDependencies(fn, usedOutsideDeclaringScope, temporaries) {
170553
+ const context = new Context(usedOutsideDeclaringScope, temporaries);
170554
+ for (const param of fn.params) {
170555
+ if (param.kind === 'Identifier') {
170556
+ context.declare(param.identifier, {
170557
+ id: makeInstructionId(0),
170558
+ scope: empty(),
170559
+ });
170560
+ } else {
170561
+ context.declare(param.place.identifier, {
170562
+ id: makeInstructionId(0),
170563
+ scope: empty(),
170564
+ });
170565
+ }
170566
+ }
170567
+ const scopeTraversal = new ScopeBlockTraversal();
170568
+ for (const [blockId, block] of fn.body.blocks) {
170569
+ scopeTraversal.recordScopes(block);
170570
+ const scopeBlockInfo = scopeTraversal.blockInfos.get(blockId);
170571
+ if (
170572
+ (scopeBlockInfo === null || scopeBlockInfo === void 0
170573
+ ? void 0
170574
+ : scopeBlockInfo.kind) === 'begin'
170575
+ ) {
170576
+ context.enterScope(scopeBlockInfo.scope);
170577
+ } else if (
170578
+ (scopeBlockInfo === null || scopeBlockInfo === void 0
170579
+ ? void 0
170580
+ : scopeBlockInfo.kind) === 'end'
170581
+ ) {
170582
+ context.exitScope(
170583
+ scopeBlockInfo.scope,
170584
+ scopeBlockInfo === null || scopeBlockInfo === void 0
170585
+ ? void 0
170586
+ : scopeBlockInfo.pruned
170587
+ );
170588
+ }
170589
+ for (const instr of block.instructions) {
170590
+ handleInstruction(instr, context);
170591
+ }
170592
+ for (const place of eachTerminalOperand(block.terminal)) {
170593
+ context.visitOperand(place);
170594
+ }
170595
+ }
170596
+ return context.deps;
170597
+ }
170598
+ function recordHoistablePropertyReads(nodes, scopeId, tree) {
170599
+ const node = nodes.get(scopeId);
170600
+ CompilerError.invariant(node != null, {
170601
+ reason: '[PropagateScopeDependencies] Scope not found in tracked blocks',
170602
+ loc: GeneratedSource,
170603
+ });
170604
+ for (const item of node.assumedNonNullObjects) {
170605
+ tree.markNodesNonNull(Object.assign({}, item.fullPath));
170606
+ }
170607
+ }
169448
170608
  function* run(
169449
170609
  func,
169450
170610
  config,
@@ -169596,6 +170756,10 @@ function* runWithEnvironment(func, env) {
169596
170756
  yield log({kind: 'hir', name: 'FlattenScopesWithHooksOrUseHIR', value: hir});
169597
170757
  assertTerminalSuccessorsExist(hir);
169598
170758
  assertTerminalPredsExist(hir);
170759
+ if (env.config.enablePropagateDepsInHIR) {
170760
+ propagateScopeDependenciesHIR(hir);
170761
+ yield log({kind: 'hir', name: 'PropagateScopeDependenciesHIR', value: hir});
170762
+ }
169599
170763
  const reactiveFunction = buildReactiveFunction(hir);
169600
170764
  yield log({
169601
170765
  kind: 'reactive',
@@ -169610,12 +170774,14 @@ function* runWithEnvironment(func, env) {
169610
170774
  value: reactiveFunction,
169611
170775
  });
169612
170776
  assertScopeInstructionsWithinScopes(reactiveFunction);
169613
- propagateScopeDependencies(reactiveFunction);
169614
- yield log({
169615
- kind: 'reactive',
169616
- name: 'PropagateScopeDependencies',
169617
- value: reactiveFunction,
169618
- });
170777
+ if (!env.config.enablePropagateDepsInHIR) {
170778
+ propagateScopeDependencies(reactiveFunction);
170779
+ yield log({
170780
+ kind: 'reactive',
170781
+ name: 'PropagateScopeDependencies',
170782
+ value: reactiveFunction,
170783
+ });
170784
+ }
169619
170785
  pruneNonEscapingScopes(reactiveFunction);
169620
170786
  yield log({
169621
170787
  kind: 'reactive',