babel-plugin-react-compiler 0.0.0-experimental-de2cfda-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
@@ -162090,6 +162090,248 @@ let Visitor$8 = class Visitor extends ReactiveFunctionTransform {
162090
162090
  return {kind: 'keep'};
162091
162091
  }
162092
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
+ }
162093
162335
  var _InferenceState_env, _InferenceState_values, _InferenceState_variables;
162094
162336
  const UndefinedValue = {
162095
162337
  kind: 'Primitive',
@@ -162189,35 +162431,16 @@ function inferReferenceEffects(fn, options = {isFunctionExpression: false}) {
162189
162431
  }
162190
162432
  statesByBlock.set(blockId, incomingState);
162191
162433
  const state = incomingState.clone();
162192
- inferBlock(fn.env, functionEffects, state, block);
162434
+ inferBlock(fn.env, state, block, functionEffects);
162193
162435
  for (const nextBlockId of eachTerminalSuccessor(block.terminal)) {
162194
162436
  queue(nextBlockId, state);
162195
162437
  }
162196
162438
  }
162197
162439
  }
162198
- if (!options.isFunctionExpression) {
162199
- functionEffects.forEach(eff => {
162200
- switch (eff.kind) {
162201
- case 'ReactMutation':
162202
- case 'GlobalMutation': {
162203
- CompilerError.throw(eff.error);
162204
- }
162205
- case 'ContextMutation': {
162206
- CompilerError.throw({
162207
- severity: exports.ErrorSeverity.Invariant,
162208
- reason: `Unexpected ContextMutation in top-level function effects`,
162209
- loc: eff.loc,
162210
- });
162211
- }
162212
- default:
162213
- assertExhaustive(
162214
- eff,
162215
- `Unexpected function effect kind \`${eff.kind}\``
162216
- );
162217
- }
162218
- });
162219
- } else {
162440
+ if (options.isFunctionExpression) {
162220
162441
  fn.effects = functionEffects;
162442
+ } else {
162443
+ raiseFunctionEffectErrors(functionEffects);
162221
162444
  }
162222
162445
  }
162223
162446
  class InferenceState {
@@ -162323,7 +162546,7 @@ class InferenceState {
162323
162546
  place.identifier.id
162324
162547
  );
162325
162548
  }
162326
- referenceAndRecordEffects(place, effectKind, reason, functionEffects) {
162549
+ referenceAndRecordEffects(freezeActions, place, effectKind, reason) {
162327
162550
  const values = __classPrivateFieldGet(
162328
162551
  this,
162329
162552
  _InferenceState_variables,
@@ -162342,43 +162565,8 @@ class InferenceState {
162342
162565
  : exports.Effect.Read;
162343
162566
  return;
162344
162567
  }
162345
- for (const value of values) {
162346
- if (
162347
- (value.kind === 'FunctionExpression' ||
162348
- value.kind === 'ObjectMethod') &&
162349
- value.loweredFunc.func.effects != null
162350
- ) {
162351
- for (const effect of value.loweredFunc.func.effects) {
162352
- if (
162353
- effect.kind === 'GlobalMutation' ||
162354
- effect.kind === 'ReactMutation'
162355
- ) {
162356
- functionEffects.push(effect);
162357
- } else {
162358
- for (const place of effect.places) {
162359
- if (this.isDefined(place)) {
162360
- const replayedEffect = this.reference(
162361
- Object.assign(Object.assign({}, place), {loc: effect.loc}),
162362
- effect.effect,
162363
- reason
162364
- );
162365
- if (replayedEffect != null) {
162366
- if (replayedEffect.kind === 'ContextMutation') {
162367
- functionEffects.push(effect);
162368
- } else {
162369
- functionEffects.push(replayedEffect);
162370
- }
162371
- }
162372
- }
162373
- }
162374
- }
162375
- }
162376
- }
162377
- }
162378
- const functionEffect = this.reference(place, effectKind, reason);
162379
- if (functionEffect !== null) {
162380
- functionEffects.push(functionEffect);
162381
- }
162568
+ const action = this.reference(place, effectKind, reason);
162569
+ action && freezeActions.push(action);
162382
162570
  }
162383
162571
  freezeValues(values, reason) {
162384
162572
  for (const value of values) {
@@ -162424,7 +162612,7 @@ class InferenceState {
162424
162612
  });
162425
162613
  let valueKind = this.kind(place);
162426
162614
  let effect = null;
162427
- let functionEffect = null;
162615
+ let freeze = null;
162428
162616
  switch (effectKind) {
162429
162617
  case exports.Effect.Freeze: {
162430
162618
  if (
@@ -162439,7 +162627,7 @@ class InferenceState {
162439
162627
  reason: reasonSet,
162440
162628
  context: new Set(),
162441
162629
  };
162442
- this.freezeValues(values, reasonSet);
162630
+ freeze = {values: values, reason: reasonSet};
162443
162631
  } else {
162444
162632
  effect = exports.Effect.Read;
162445
162633
  }
@@ -162457,80 +162645,10 @@ class InferenceState {
162457
162645
  break;
162458
162646
  }
162459
162647
  case exports.Effect.Mutate: {
162460
- if (isRefOrRefValue(place.identifier));
162461
- else if (valueKind.kind === exports.ValueKind.Context) {
162462
- functionEffect = {
162463
- kind: 'ContextMutation',
162464
- loc: place.loc,
162465
- effect: effectKind,
162466
- places:
162467
- valueKind.context.size === 0
162468
- ? new Set([place])
162469
- : valueKind.context,
162470
- };
162471
- } else if (
162472
- valueKind.kind !== exports.ValueKind.Mutable &&
162473
- valueKind.kind !== exports.ValueKind.Primitive
162474
- ) {
162475
- let reason = getWriteErrorReason(valueKind);
162476
- functionEffect = {
162477
- kind:
162478
- valueKind.reason.size === 1 &&
162479
- valueKind.reason.has(ValueReason.Global)
162480
- ? 'GlobalMutation'
162481
- : 'ReactMutation',
162482
- error: {
162483
- reason: reason,
162484
- description:
162485
- place.identifier.name !== null &&
162486
- place.identifier.name.kind === 'named'
162487
- ? `Found mutation of \`${place.identifier.name.value}\``
162488
- : null,
162489
- loc: place.loc,
162490
- suggestions: null,
162491
- severity: exports.ErrorSeverity.InvalidReact,
162492
- },
162493
- };
162494
- }
162495
162648
  effect = exports.Effect.Mutate;
162496
162649
  break;
162497
162650
  }
162498
162651
  case exports.Effect.Store: {
162499
- if (isRefOrRefValue(place.identifier));
162500
- else if (valueKind.kind === exports.ValueKind.Context) {
162501
- functionEffect = {
162502
- kind: 'ContextMutation',
162503
- loc: place.loc,
162504
- effect: effectKind,
162505
- places:
162506
- valueKind.context.size === 0
162507
- ? new Set([place])
162508
- : valueKind.context,
162509
- };
162510
- } else if (
162511
- valueKind.kind !== exports.ValueKind.Mutable &&
162512
- valueKind.kind !== exports.ValueKind.Primitive
162513
- ) {
162514
- let reason = getWriteErrorReason(valueKind);
162515
- functionEffect = {
162516
- kind:
162517
- valueKind.reason.size === 1 &&
162518
- valueKind.reason.has(ValueReason.Global)
162519
- ? 'GlobalMutation'
162520
- : 'ReactMutation',
162521
- error: {
162522
- reason: reason,
162523
- description:
162524
- place.identifier.name !== null &&
162525
- place.identifier.name.kind === 'named'
162526
- ? `Found mutation of \`${place.identifier.name.value}\``
162527
- : null,
162528
- loc: place.loc,
162529
- suggestions: null,
162530
- severity: exports.ErrorSeverity.InvalidReact,
162531
- },
162532
- };
162533
- }
162534
162652
  effect = isObjectType(place.identifier)
162535
162653
  ? exports.Effect.Store
162536
162654
  : exports.Effect.Mutate;
@@ -162576,7 +162694,7 @@ class InferenceState {
162576
162694
  suggestions: null,
162577
162695
  });
162578
162696
  place.effect = effect;
162579
- return functionEffect;
162697
+ return freeze;
162580
162698
  }
162581
162699
  merge(other) {
162582
162700
  let nextValues = null;
@@ -162831,29 +162949,31 @@ function mergeAbstractValues(a, b) {
162831
162949
  }
162832
162950
  return {kind: kind, reason: reason, context: context};
162833
162951
  }
162834
- function inferBlock(env, functionEffects, state, block) {
162952
+ function inferBlock(env, state, block, functionEffects) {
162835
162953
  var _a, _b, _c, _d;
162836
- var _e;
162837
162954
  for (const phi of block.phis) {
162838
162955
  state.inferPhi(phi);
162839
162956
  }
162840
162957
  for (const instr of block.instructions) {
162841
162958
  const instrValue = instr.value;
162842
- let effect = null;
162843
- let lvalueEffect = exports.Effect.ConditionallyMutate;
162844
- let valueKind;
162959
+ const defaultLvalueEffect = exports.Effect.ConditionallyMutate;
162960
+ let continuation;
162961
+ const freezeActions = [];
162845
162962
  switch (instrValue.kind) {
162846
162963
  case 'BinaryExpression': {
162847
- valueKind = {
162848
- kind: exports.ValueKind.Primitive,
162849
- reason: new Set([ValueReason.Other]),
162850
- 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},
162851
162972
  };
162852
- effect = {kind: exports.Effect.Read, reason: ValueReason.Other};
162853
162973
  break;
162854
162974
  }
162855
162975
  case 'ArrayExpression': {
162856
- valueKind = hasContextRefOperand(state, instrValue)
162976
+ const valueKind = hasContextRefOperand(state, instrValue)
162857
162977
  ? {
162858
162978
  kind: exports.ValueKind.Context,
162859
162979
  reason: new Set([ValueReason.Other]),
@@ -162864,37 +162984,42 @@ function inferBlock(env, functionEffects, state, block) {
162864
162984
  reason: new Set([ValueReason.Other]),
162865
162985
  context: new Set(),
162866
162986
  };
162867
- effect = {kind: exports.Effect.Capture, reason: ValueReason.Other};
162868
- 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
+ };
162869
162993
  break;
162870
162994
  }
162871
162995
  case 'NewExpression': {
162872
- valueKind = {
162996
+ const valueKind = {
162873
162997
  kind: exports.ValueKind.Mutable,
162874
162998
  reason: new Set([ValueReason.Other]),
162875
162999
  context: new Set(),
162876
163000
  };
162877
163001
  state.referenceAndRecordEffects(
163002
+ freezeActions,
162878
163003
  instrValue.callee,
162879
163004
  exports.Effect.Read,
162880
- ValueReason.Other,
162881
- functionEffects
163005
+ ValueReason.Other
162882
163006
  );
162883
163007
  for (const operand of eachCallArgument(instrValue.args)) {
162884
163008
  state.referenceAndRecordEffects(
163009
+ freezeActions,
162885
163010
  operand,
162886
163011
  exports.Effect.ConditionallyMutate,
162887
- ValueReason.Other,
162888
- functionEffects
163012
+ ValueReason.Other
162889
163013
  );
162890
163014
  }
162891
163015
  state.initialize(instrValue, valueKind);
162892
163016
  state.define(instr.lvalue, instrValue);
162893
- instr.lvalue.effect = lvalueEffect;
162894
- continue;
163017
+ instr.lvalue.effect = exports.Effect.ConditionallyMutate;
163018
+ continuation = {kind: 'funeffects'};
163019
+ break;
162895
163020
  }
162896
163021
  case 'ObjectExpression': {
162897
- valueKind = hasContextRefOperand(state, instrValue)
163022
+ const valueKind = hasContextRefOperand(state, instrValue)
162898
163023
  ? {
162899
163024
  kind: exports.ValueKind.Context,
162900
163025
  reason: new Set([ValueReason.Other]),
@@ -162910,26 +163035,26 @@ function inferBlock(env, functionEffects, state, block) {
162910
163035
  case 'ObjectProperty': {
162911
163036
  if (property.key.kind === 'computed') {
162912
163037
  state.referenceAndRecordEffects(
163038
+ freezeActions,
162913
163039
  property.key.name,
162914
163040
  exports.Effect.Freeze,
162915
- ValueReason.Other,
162916
- functionEffects
163041
+ ValueReason.Other
162917
163042
  );
162918
163043
  }
162919
163044
  state.referenceAndRecordEffects(
163045
+ freezeActions,
162920
163046
  property.place,
162921
163047
  exports.Effect.Capture,
162922
- ValueReason.Other,
162923
- functionEffects
163048
+ ValueReason.Other
162924
163049
  );
162925
163050
  break;
162926
163051
  }
162927
163052
  case 'Spread': {
162928
163053
  state.referenceAndRecordEffects(
163054
+ freezeActions,
162929
163055
  property.place,
162930
163056
  exports.Effect.Capture,
162931
- ValueReason.Other,
162932
- functionEffects
163057
+ ValueReason.Other
162933
163058
  );
162934
163059
  break;
162935
163060
  }
@@ -162944,64 +163069,66 @@ function inferBlock(env, functionEffects, state, block) {
162944
163069
  state.initialize(instrValue, valueKind);
162945
163070
  state.define(instr.lvalue, instrValue);
162946
163071
  instr.lvalue.effect = exports.Effect.Store;
162947
- continue;
163072
+ continuation = {kind: 'funeffects'};
163073
+ break;
162948
163074
  }
162949
163075
  case 'UnaryExpression': {
162950
- valueKind = {
162951
- kind: exports.ValueKind.Primitive,
162952
- reason: new Set([ValueReason.Other]),
162953
- 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},
162954
163084
  };
162955
- effect = {kind: exports.Effect.Read, reason: ValueReason.Other};
162956
163085
  break;
162957
163086
  }
162958
163087
  case 'UnsupportedNode': {
162959
- valueKind = {
162960
- kind: exports.ValueKind.Mutable,
162961
- reason: new Set([ValueReason.Other]),
162962
- 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,
162963
163096
  };
162964
163097
  break;
162965
163098
  }
162966
163099
  case 'JsxExpression': {
162967
163100
  if (instrValue.tag.kind === 'Identifier') {
162968
163101
  state.referenceAndRecordEffects(
163102
+ freezeActions,
162969
163103
  instrValue.tag,
162970
163104
  exports.Effect.Freeze,
162971
- ValueReason.JsxCaptured,
162972
- functionEffects
163105
+ ValueReason.JsxCaptured
162973
163106
  );
162974
163107
  }
162975
163108
  if (instrValue.children !== null) {
162976
163109
  for (const child of instrValue.children) {
162977
163110
  state.referenceAndRecordEffects(
163111
+ freezeActions,
162978
163112
  child,
162979
163113
  exports.Effect.Freeze,
162980
- ValueReason.JsxCaptured,
162981
- functionEffects
163114
+ ValueReason.JsxCaptured
162982
163115
  );
162983
163116
  }
162984
163117
  }
162985
163118
  for (const attr of instrValue.props) {
162986
163119
  if (attr.kind === 'JsxSpreadAttribute') {
162987
163120
  state.referenceAndRecordEffects(
163121
+ freezeActions,
162988
163122
  attr.argument,
162989
163123
  exports.Effect.Freeze,
162990
- ValueReason.JsxCaptured,
162991
- functionEffects
163124
+ ValueReason.JsxCaptured
162992
163125
  );
162993
163126
  } else {
162994
- const propEffects = [];
162995
163127
  state.referenceAndRecordEffects(
163128
+ freezeActions,
162996
163129
  attr.place,
162997
163130
  exports.Effect.Freeze,
162998
- ValueReason.JsxCaptured,
162999
- propEffects
163000
- );
163001
- functionEffects.push(
163002
- ...propEffects.filter(
163003
- effect => !isEffectSafeOutsideRender(effect)
163004
- )
163131
+ ValueReason.JsxCaptured
163005
163132
  );
163006
163133
  }
163007
163134
  }
@@ -163012,63 +163139,86 @@ function inferBlock(env, functionEffects, state, block) {
163012
163139
  });
163013
163140
  state.define(instr.lvalue, instrValue);
163014
163141
  instr.lvalue.effect = exports.Effect.ConditionallyMutate;
163015
- continue;
163142
+ continuation = {kind: 'funeffects'};
163143
+ break;
163016
163144
  }
163017
163145
  case 'JsxFragment': {
163018
- valueKind = {
163019
- kind: exports.ValueKind.Frozen,
163020
- reason: new Set([ValueReason.Other]),
163021
- 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},
163022
163154
  };
163023
- effect = {kind: exports.Effect.Freeze, reason: ValueReason.Other};
163024
163155
  break;
163025
163156
  }
163026
163157
  case 'TemplateLiteral': {
163027
- valueKind = {
163028
- kind: exports.ValueKind.Primitive,
163029
- reason: new Set([ValueReason.Other]),
163030
- 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},
163031
163166
  };
163032
- effect = {kind: exports.Effect.Read, reason: ValueReason.Other};
163033
163167
  break;
163034
163168
  }
163035
163169
  case 'RegExpLiteral': {
163036
- valueKind = {
163037
- kind: exports.ValueKind.Mutable,
163038
- reason: new Set([ValueReason.Other]),
163039
- context: new Set(),
163040
- };
163041
- effect = {
163042
- kind: exports.Effect.ConditionallyMutate,
163043
- 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
+ },
163044
163181
  };
163045
163182
  break;
163046
163183
  }
163047
163184
  case 'MetaProperty': {
163048
163185
  if (instrValue.meta !== 'import' || instrValue.property !== 'meta') {
163049
- continue;
163186
+ continuation = {kind: 'funeffects'};
163187
+ break;
163050
163188
  }
163051
- valueKind = {
163052
- kind: exports.ValueKind.Global,
163053
- reason: new Set([ValueReason.Global]),
163054
- 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,
163055
163197
  };
163056
163198
  break;
163057
163199
  }
163058
163200
  case 'LoadGlobal':
163059
- valueKind = {
163060
- kind: exports.ValueKind.Global,
163061
- reason: new Set([ValueReason.Global]),
163062
- 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,
163063
163209
  };
163064
163210
  break;
163065
163211
  case 'Debugger':
163066
163212
  case 'JSXText':
163067
163213
  case 'Primitive': {
163068
- valueKind = {
163069
- kind: exports.ValueKind.Primitive,
163070
- reason: new Set([ValueReason.Other]),
163071
- 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,
163072
163222
  };
163073
163223
  break;
163074
163224
  }
@@ -163077,32 +163227,16 @@ function inferBlock(env, functionEffects, state, block) {
163077
163227
  let hasMutableOperand = false;
163078
163228
  for (const operand of eachInstructionOperand(instr)) {
163079
163229
  state.referenceAndRecordEffects(
163230
+ freezeActions,
163080
163231
  operand,
163081
163232
  operand.effect === exports.Effect.Unknown
163082
163233
  ? exports.Effect.Read
163083
163234
  : operand.effect,
163084
- ValueReason.Other,
163085
- []
163235
+ ValueReason.Other
163086
163236
  );
163087
163237
  if (isMutableEffect(operand.effect, operand.loc));
163088
163238
  hasMutableOperand ||
163089
163239
  (hasMutableOperand = isMutableEffect(operand.effect, operand.loc));
163090
- const values = state.values(operand);
163091
- for (const value of values) {
163092
- if (
163093
- (value.kind === 'ObjectMethod' ||
163094
- value.kind === 'FunctionExpression') &&
163095
- value.loweredFunc.func.effects !== null
163096
- ) {
163097
- (_a = (_e = instrValue.loweredFunc.func).effects) !== null &&
163098
- _a !== void 0
163099
- ? _a
163100
- : (_e.effects = []);
163101
- instrValue.loweredFunc.func.effects.push(
163102
- ...value.loweredFunc.func.effects
163103
- );
163104
- }
163105
- }
163106
163240
  }
163107
163241
  state.initialize(instrValue, {
163108
163242
  kind: hasMutableOperand
@@ -163113,7 +163247,8 @@ function inferBlock(env, functionEffects, state, block) {
163113
163247
  });
163114
163248
  state.define(instr.lvalue, instrValue);
163115
163249
  instr.lvalue.effect = exports.Effect.Store;
163116
- continue;
163250
+ continuation = {kind: 'funeffects'};
163251
+ break;
163117
163252
  }
163118
163253
  case 'TaggedTemplateExpression': {
163119
163254
  const operands = [...eachInstructionValueOperand(instrValue)];
@@ -163128,19 +163263,19 @@ function inferBlock(env, functionEffects, state, block) {
163128
163263
  instrValue.tag.identifier.type
163129
163264
  );
163130
163265
  let calleeEffect =
163131
- (_b =
163266
+ (_a =
163132
163267
  signature === null || signature === void 0
163133
163268
  ? void 0
163134
- : signature.calleeEffect) !== null && _b !== void 0
163135
- ? _b
163269
+ : signature.calleeEffect) !== null && _a !== void 0
163270
+ ? _a
163136
163271
  : exports.Effect.ConditionallyMutate;
163137
163272
  const returnValueKind =
163138
163273
  signature !== null
163139
163274
  ? {
163140
163275
  kind: signature.returnValueKind,
163141
163276
  reason: new Set([
163142
- (_c = signature.returnValueReason) !== null && _c !== void 0
163143
- ? _c
163277
+ (_b = signature.returnValueReason) !== null && _b !== void 0
163278
+ ? _b
163144
163279
  : ValueReason.KnownReturnSignature,
163145
163280
  ]),
163146
163281
  context: new Set(),
@@ -163151,15 +163286,16 @@ function inferBlock(env, functionEffects, state, block) {
163151
163286
  context: new Set(),
163152
163287
  };
163153
163288
  state.referenceAndRecordEffects(
163289
+ freezeActions,
163154
163290
  instrValue.tag,
163155
163291
  calleeEffect,
163156
- ValueReason.Other,
163157
- functionEffects
163292
+ ValueReason.Other
163158
163293
  );
163159
163294
  state.initialize(instrValue, returnValueKind);
163160
163295
  state.define(instr.lvalue, instrValue);
163161
163296
  instr.lvalue.effect = exports.Effect.ConditionallyMutate;
163162
- continue;
163297
+ continuation = {kind: 'funeffects'};
163298
+ break;
163163
163299
  }
163164
163300
  case 'CallExpression': {
163165
163301
  const signature = getFunctionCallSignature(
@@ -163173,8 +163309,8 @@ function inferBlock(env, functionEffects, state, block) {
163173
163309
  ? {
163174
163310
  kind: signature.returnValueKind,
163175
163311
  reason: new Set([
163176
- (_d = signature.returnValueReason) !== null && _d !== void 0
163177
- ? _d
163312
+ (_c = signature.returnValueReason) !== null && _c !== void 0
163313
+ ? _c
163178
163314
  : ValueReason.KnownReturnSignature,
163179
163315
  ]),
163180
163316
  context: new Set(),
@@ -163185,47 +163321,40 @@ function inferBlock(env, functionEffects, state, block) {
163185
163321
  context: new Set(),
163186
163322
  };
163187
163323
  let hasCaptureArgument = false;
163188
- let isHook = getHookKind(env, instrValue.callee.identifier) != null;
163189
163324
  for (let i = 0; i < instrValue.args.length; i++) {
163190
- const argumentEffects = [];
163191
163325
  const arg = instrValue.args[i];
163192
163326
  const place = arg.kind === 'Identifier' ? arg : arg.place;
163193
163327
  if (effects !== null) {
163194
163328
  state.referenceAndRecordEffects(
163329
+ freezeActions,
163195
163330
  place,
163196
163331
  effects[i],
163197
- ValueReason.Other,
163198
- argumentEffects
163332
+ ValueReason.Other
163199
163333
  );
163200
163334
  } else {
163201
163335
  state.referenceAndRecordEffects(
163336
+ freezeActions,
163202
163337
  place,
163203
163338
  exports.Effect.ConditionallyMutate,
163204
- ValueReason.Other,
163205
- argumentEffects
163339
+ ValueReason.Other
163206
163340
  );
163207
163341
  }
163208
- functionEffects.push(
163209
- ...argumentEffects.filter(
163210
- argEffect => !isHook || !isEffectSafeOutsideRender(argEffect)
163211
- )
163212
- );
163213
163342
  hasCaptureArgument ||
163214
163343
  (hasCaptureArgument = place.effect === exports.Effect.Capture);
163215
163344
  }
163216
163345
  if (signature !== null) {
163217
163346
  state.referenceAndRecordEffects(
163347
+ freezeActions,
163218
163348
  instrValue.callee,
163219
163349
  signature.calleeEffect,
163220
- ValueReason.Other,
163221
- functionEffects
163350
+ ValueReason.Other
163222
163351
  );
163223
163352
  } else {
163224
163353
  state.referenceAndRecordEffects(
163354
+ freezeActions,
163225
163355
  instrValue.callee,
163226
163356
  exports.Effect.ConditionallyMutate,
163227
- ValueReason.Other,
163228
- functionEffects
163357
+ ValueReason.Other
163229
163358
  );
163230
163359
  }
163231
163360
  hasCaptureArgument ||
@@ -163236,7 +163365,8 @@ function inferBlock(env, functionEffects, state, block) {
163236
163365
  instr.lvalue.effect = hasCaptureArgument
163237
163366
  ? exports.Effect.Store
163238
163367
  : exports.Effect.ConditionallyMutate;
163239
- continue;
163368
+ continuation = {kind: 'funeffects'};
163369
+ break;
163240
163370
  }
163241
163371
  case 'MethodCall': {
163242
163372
  CompilerError.invariant(state.isDefined(instrValue.receiver), {
@@ -163247,10 +163377,10 @@ function inferBlock(env, functionEffects, state, block) {
163247
163377
  suggestions: null,
163248
163378
  });
163249
163379
  state.referenceAndRecordEffects(
163380
+ freezeActions,
163250
163381
  instrValue.property,
163251
163382
  exports.Effect.Read,
163252
- ValueReason.Other,
163253
- functionEffects
163383
+ ValueReason.Other
163254
163384
  );
163255
163385
  const signature = getFunctionCallSignature(
163256
163386
  env,
@@ -163276,17 +163406,17 @@ function inferBlock(env, functionEffects, state, block) {
163276
163406
  for (const arg of instrValue.args) {
163277
163407
  const place = arg.kind === 'Identifier' ? arg : arg.place;
163278
163408
  state.referenceAndRecordEffects(
163409
+ freezeActions,
163279
163410
  place,
163280
163411
  exports.Effect.Read,
163281
- ValueReason.Other,
163282
- functionEffects
163412
+ ValueReason.Other
163283
163413
  );
163284
163414
  }
163285
163415
  state.referenceAndRecordEffects(
163416
+ freezeActions,
163286
163417
  instrValue.receiver,
163287
163418
  exports.Effect.Capture,
163288
- ValueReason.Other,
163289
- functionEffects
163419
+ ValueReason.Other
163290
163420
  );
163291
163421
  state.initialize(instrValue, returnValueKind);
163292
163422
  state.define(instr.lvalue, instrValue);
@@ -163294,52 +163424,46 @@ function inferBlock(env, functionEffects, state, block) {
163294
163424
  instrValue.receiver.effect === exports.Effect.Capture
163295
163425
  ? exports.Effect.Store
163296
163426
  : exports.Effect.ConditionallyMutate;
163297
- continue;
163427
+ continuation = {kind: 'funeffects'};
163428
+ break;
163298
163429
  }
163299
163430
  const effects =
163300
163431
  signature !== null ? getFunctionEffects(instrValue, signature) : null;
163301
163432
  let hasCaptureArgument = false;
163302
- let isHook = getHookKind(env, instrValue.property.identifier) != null;
163303
163433
  for (let i = 0; i < instrValue.args.length; i++) {
163304
- const argumentEffects = [];
163305
163434
  const arg = instrValue.args[i];
163306
163435
  const place = arg.kind === 'Identifier' ? arg : arg.place;
163307
163436
  if (effects !== null) {
163308
163437
  state.referenceAndRecordEffects(
163438
+ freezeActions,
163309
163439
  place,
163310
163440
  effects[i],
163311
- ValueReason.Other,
163312
- argumentEffects
163441
+ ValueReason.Other
163313
163442
  );
163314
163443
  } else {
163315
163444
  state.referenceAndRecordEffects(
163445
+ freezeActions,
163316
163446
  place,
163317
163447
  exports.Effect.ConditionallyMutate,
163318
- ValueReason.Other,
163319
- argumentEffects
163448
+ ValueReason.Other
163320
163449
  );
163321
163450
  }
163322
- functionEffects.push(
163323
- ...argumentEffects.filter(
163324
- argEffect => !isHook || !isEffectSafeOutsideRender(argEffect)
163325
- )
163326
- );
163327
163451
  hasCaptureArgument ||
163328
163452
  (hasCaptureArgument = place.effect === exports.Effect.Capture);
163329
163453
  }
163330
163454
  if (signature !== null) {
163331
163455
  state.referenceAndRecordEffects(
163456
+ freezeActions,
163332
163457
  instrValue.receiver,
163333
163458
  signature.calleeEffect,
163334
- ValueReason.Other,
163335
- functionEffects
163459
+ ValueReason.Other
163336
163460
  );
163337
163461
  } else {
163338
163462
  state.referenceAndRecordEffects(
163463
+ freezeActions,
163339
163464
  instrValue.receiver,
163340
163465
  exports.Effect.ConditionallyMutate,
163341
- ValueReason.Other,
163342
- functionEffects
163466
+ ValueReason.Other
163343
163467
  );
163344
163468
  }
163345
163469
  hasCaptureArgument ||
@@ -163350,7 +163474,8 @@ function inferBlock(env, functionEffects, state, block) {
163350
163474
  instr.lvalue.effect = hasCaptureArgument
163351
163475
  ? exports.Effect.Store
163352
163476
  : exports.Effect.ConditionallyMutate;
163353
- continue;
163477
+ continuation = {kind: 'funeffects'};
163478
+ break;
163354
163479
  }
163355
163480
  case 'PropertyStore': {
163356
163481
  const effect =
@@ -163358,43 +163483,48 @@ function inferBlock(env, functionEffects, state, block) {
163358
163483
  ? exports.Effect.ConditionallyMutate
163359
163484
  : exports.Effect.Capture;
163360
163485
  state.referenceAndRecordEffects(
163486
+ freezeActions,
163361
163487
  instrValue.value,
163362
163488
  effect,
163363
- ValueReason.Other,
163364
- functionEffects
163489
+ ValueReason.Other
163365
163490
  );
163366
163491
  state.referenceAndRecordEffects(
163492
+ freezeActions,
163367
163493
  instrValue.object,
163368
163494
  exports.Effect.Store,
163369
- ValueReason.Other,
163370
- functionEffects
163495
+ ValueReason.Other
163371
163496
  );
163372
163497
  const lvalue = instr.lvalue;
163373
163498
  state.alias(lvalue, instrValue.value);
163374
163499
  lvalue.effect = exports.Effect.Store;
163375
- continue;
163500
+ continuation = {kind: 'funeffects'};
163501
+ break;
163376
163502
  }
163377
163503
  case 'PropertyDelete': {
163378
- valueKind = {
163379
- kind: exports.ValueKind.Primitive,
163380
- reason: new Set([ValueReason.Other]),
163381
- 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},
163382
163512
  };
163383
- effect = {kind: exports.Effect.Mutate, reason: ValueReason.Other};
163384
163513
  break;
163385
163514
  }
163386
163515
  case 'PropertyLoad': {
163387
163516
  state.referenceAndRecordEffects(
163517
+ freezeActions,
163388
163518
  instrValue.object,
163389
163519
  exports.Effect.Read,
163390
- ValueReason.Other,
163391
- functionEffects
163520
+ ValueReason.Other
163392
163521
  );
163393
163522
  const lvalue = instr.lvalue;
163394
163523
  lvalue.effect = exports.Effect.ConditionallyMutate;
163395
163524
  state.initialize(instrValue, state.kind(instrValue.object));
163396
163525
  state.define(lvalue, instrValue);
163397
- continue;
163526
+ continuation = {kind: 'funeffects'};
163527
+ break;
163398
163528
  }
163399
163529
  case 'ComputedStore': {
163400
163530
  const effect =
@@ -163402,40 +163532,41 @@ function inferBlock(env, functionEffects, state, block) {
163402
163532
  ? exports.Effect.ConditionallyMutate
163403
163533
  : exports.Effect.Capture;
163404
163534
  state.referenceAndRecordEffects(
163535
+ freezeActions,
163405
163536
  instrValue.value,
163406
163537
  effect,
163407
- ValueReason.Other,
163408
- functionEffects
163538
+ ValueReason.Other
163409
163539
  );
163410
163540
  state.referenceAndRecordEffects(
163541
+ freezeActions,
163411
163542
  instrValue.property,
163412
163543
  exports.Effect.Capture,
163413
- ValueReason.Other,
163414
- functionEffects
163544
+ ValueReason.Other
163415
163545
  );
163416
163546
  state.referenceAndRecordEffects(
163547
+ freezeActions,
163417
163548
  instrValue.object,
163418
163549
  exports.Effect.Store,
163419
- ValueReason.Other,
163420
- functionEffects
163550
+ ValueReason.Other
163421
163551
  );
163422
163552
  const lvalue = instr.lvalue;
163423
163553
  state.alias(lvalue, instrValue.value);
163424
163554
  lvalue.effect = exports.Effect.Store;
163425
- continue;
163555
+ continuation = {kind: 'funeffects'};
163556
+ break;
163426
163557
  }
163427
163558
  case 'ComputedDelete': {
163428
163559
  state.referenceAndRecordEffects(
163560
+ freezeActions,
163429
163561
  instrValue.object,
163430
163562
  exports.Effect.Mutate,
163431
- ValueReason.Other,
163432
- functionEffects
163563
+ ValueReason.Other
163433
163564
  );
163434
163565
  state.referenceAndRecordEffects(
163566
+ freezeActions,
163435
163567
  instrValue.property,
163436
163568
  exports.Effect.Read,
163437
- ValueReason.Other,
163438
- functionEffects
163569
+ ValueReason.Other
163439
163570
  );
163440
163571
  state.initialize(instrValue, {
163441
163572
  kind: exports.ValueKind.Primitive,
@@ -163444,69 +163575,73 @@ function inferBlock(env, functionEffects, state, block) {
163444
163575
  });
163445
163576
  state.define(instr.lvalue, instrValue);
163446
163577
  instr.lvalue.effect = exports.Effect.Mutate;
163447
- continue;
163578
+ continuation = {kind: 'funeffects'};
163579
+ break;
163448
163580
  }
163449
163581
  case 'ComputedLoad': {
163450
163582
  state.referenceAndRecordEffects(
163583
+ freezeActions,
163451
163584
  instrValue.object,
163452
163585
  exports.Effect.Read,
163453
- ValueReason.Other,
163454
- functionEffects
163586
+ ValueReason.Other
163455
163587
  );
163456
163588
  state.referenceAndRecordEffects(
163589
+ freezeActions,
163457
163590
  instrValue.property,
163458
163591
  exports.Effect.Read,
163459
- ValueReason.Other,
163460
- functionEffects
163592
+ ValueReason.Other
163461
163593
  );
163462
163594
  const lvalue = instr.lvalue;
163463
163595
  lvalue.effect = exports.Effect.ConditionallyMutate;
163464
163596
  state.initialize(instrValue, state.kind(instrValue.object));
163465
163597
  state.define(lvalue, instrValue);
163466
- continue;
163598
+ continuation = {kind: 'funeffects'};
163599
+ break;
163467
163600
  }
163468
163601
  case 'Await': {
163469
163602
  state.initialize(instrValue, state.kind(instrValue.value));
163470
163603
  state.referenceAndRecordEffects(
163604
+ freezeActions,
163471
163605
  instrValue.value,
163472
163606
  exports.Effect.ConditionallyMutate,
163473
- ValueReason.Other,
163474
- functionEffects
163607
+ ValueReason.Other
163475
163608
  );
163476
163609
  const lvalue = instr.lvalue;
163477
163610
  lvalue.effect = exports.Effect.ConditionallyMutate;
163478
163611
  state.alias(lvalue, instrValue.value);
163479
- continue;
163612
+ continuation = {kind: 'funeffects'};
163613
+ break;
163480
163614
  }
163481
163615
  case 'TypeCastExpression': {
163482
163616
  state.initialize(instrValue, state.kind(instrValue.value));
163483
163617
  state.referenceAndRecordEffects(
163618
+ freezeActions,
163484
163619
  instrValue.value,
163485
163620
  exports.Effect.Read,
163486
- ValueReason.Other,
163487
- functionEffects
163621
+ ValueReason.Other
163488
163622
  );
163489
163623
  const lvalue = instr.lvalue;
163490
163624
  lvalue.effect = exports.Effect.ConditionallyMutate;
163491
163625
  state.alias(lvalue, instrValue.value);
163492
- continue;
163626
+ continuation = {kind: 'funeffects'};
163627
+ break;
163493
163628
  }
163494
163629
  case 'StartMemoize':
163495
163630
  case 'FinishMemoize': {
163496
163631
  for (const val of eachInstructionValueOperand(instrValue)) {
163497
163632
  if (env.config.enablePreserveExistingMemoizationGuarantees) {
163498
163633
  state.referenceAndRecordEffects(
163634
+ freezeActions,
163499
163635
  val,
163500
163636
  exports.Effect.Freeze,
163501
- ValueReason.Other,
163502
- []
163637
+ ValueReason.Other
163503
163638
  );
163504
163639
  } else {
163505
163640
  state.referenceAndRecordEffects(
163641
+ freezeActions,
163506
163642
  val,
163507
163643
  exports.Effect.Read,
163508
- ValueReason.Other,
163509
- []
163644
+ ValueReason.Other
163510
163645
  );
163511
163646
  }
163512
163647
  }
@@ -163518,7 +163653,8 @@ function inferBlock(env, functionEffects, state, block) {
163518
163653
  context: new Set(),
163519
163654
  });
163520
163655
  state.define(lvalue, instrValue);
163521
- continue;
163656
+ continuation = {kind: 'funeffects'};
163657
+ break;
163522
163658
  }
163523
163659
  case 'LoadLocal': {
163524
163660
  const lvalue = instr.lvalue;
@@ -163528,28 +163664,30 @@ function inferBlock(env, functionEffects, state, block) {
163528
163664
  ? exports.Effect.ConditionallyMutate
163529
163665
  : exports.Effect.Capture;
163530
163666
  state.referenceAndRecordEffects(
163667
+ freezeActions,
163531
163668
  instrValue.place,
163532
163669
  effect,
163533
- ValueReason.Other,
163534
- []
163670
+ ValueReason.Other
163535
163671
  );
163536
163672
  lvalue.effect = exports.Effect.ConditionallyMutate;
163537
163673
  state.alias(lvalue, instrValue.place);
163538
- continue;
163674
+ continuation = {kind: 'funeffects'};
163675
+ break;
163539
163676
  }
163540
163677
  case 'LoadContext': {
163541
163678
  state.referenceAndRecordEffects(
163679
+ freezeActions,
163542
163680
  instrValue.place,
163543
163681
  exports.Effect.Capture,
163544
- ValueReason.Other,
163545
- functionEffects
163682
+ ValueReason.Other
163546
163683
  );
163547
163684
  const lvalue = instr.lvalue;
163548
163685
  lvalue.effect = exports.Effect.ConditionallyMutate;
163549
163686
  const valueKind = state.kind(instrValue.place);
163550
163687
  state.initialize(instrValue, valueKind);
163551
163688
  state.define(lvalue, instrValue);
163552
- continue;
163689
+ continuation = {kind: 'funeffects'};
163690
+ break;
163553
163691
  }
163554
163692
  case 'DeclareLocal': {
163555
163693
  const value = UndefinedValue;
@@ -163568,7 +163706,8 @@ function inferBlock(env, functionEffects, state, block) {
163568
163706
  }
163569
163707
  );
163570
163708
  state.define(instrValue.lvalue.place, value);
163571
- continue;
163709
+ continuation = {kind: 'funeffects'};
163710
+ break;
163572
163711
  }
163573
163712
  case 'DeclareContext': {
163574
163713
  state.initialize(instrValue, {
@@ -163577,7 +163716,8 @@ function inferBlock(env, functionEffects, state, block) {
163577
163716
  context: new Set(),
163578
163717
  });
163579
163718
  state.define(instrValue.lvalue.place, instrValue);
163580
- continue;
163719
+ continuation = {kind: 'funeffects'};
163720
+ break;
163581
163721
  }
163582
163722
  case 'PostfixUpdate':
163583
163723
  case 'PrefixUpdate': {
@@ -163587,17 +163727,18 @@ function inferBlock(env, functionEffects, state, block) {
163587
163727
  ? exports.Effect.ConditionallyMutate
163588
163728
  : exports.Effect.Capture;
163589
163729
  state.referenceAndRecordEffects(
163730
+ freezeActions,
163590
163731
  instrValue.value,
163591
163732
  effect,
163592
- ValueReason.Other,
163593
- functionEffects
163733
+ ValueReason.Other
163594
163734
  );
163595
163735
  const lvalue = instr.lvalue;
163596
163736
  state.alias(lvalue, instrValue.value);
163597
163737
  lvalue.effect = exports.Effect.Store;
163598
163738
  state.alias(instrValue.lvalue, instrValue.value);
163599
163739
  instrValue.lvalue.effect = exports.Effect.Store;
163600
- continue;
163740
+ continuation = {kind: 'funeffects'};
163741
+ break;
163601
163742
  }
163602
163743
  case 'StoreLocal': {
163603
163744
  const effect =
@@ -163606,56 +163747,49 @@ function inferBlock(env, functionEffects, state, block) {
163606
163747
  ? exports.Effect.ConditionallyMutate
163607
163748
  : exports.Effect.Capture;
163608
163749
  state.referenceAndRecordEffects(
163750
+ freezeActions,
163609
163751
  instrValue.value,
163610
163752
  effect,
163611
- ValueReason.Other,
163612
- []
163753
+ ValueReason.Other
163613
163754
  );
163614
163755
  const lvalue = instr.lvalue;
163615
163756
  state.alias(lvalue, instrValue.value);
163616
163757
  lvalue.effect = exports.Effect.Store;
163617
163758
  state.alias(instrValue.lvalue.place, instrValue.value);
163618
163759
  instrValue.lvalue.place.effect = exports.Effect.Store;
163619
- continue;
163760
+ continuation = {kind: 'funeffects'};
163761
+ break;
163620
163762
  }
163621
163763
  case 'StoreContext': {
163622
163764
  state.referenceAndRecordEffects(
163765
+ freezeActions,
163623
163766
  instrValue.value,
163624
163767
  exports.Effect.ConditionallyMutate,
163625
- ValueReason.Other,
163626
- functionEffects
163768
+ ValueReason.Other
163627
163769
  );
163628
163770
  state.referenceAndRecordEffects(
163771
+ freezeActions,
163629
163772
  instrValue.lvalue.place,
163630
163773
  exports.Effect.Mutate,
163631
- ValueReason.Other,
163632
- functionEffects
163774
+ ValueReason.Other
163633
163775
  );
163634
163776
  const lvalue = instr.lvalue;
163635
163777
  state.alias(lvalue, instrValue.value);
163636
163778
  lvalue.effect = exports.Effect.Store;
163637
- continue;
163779
+ continuation = {kind: 'funeffects'};
163780
+ break;
163638
163781
  }
163639
163782
  case 'StoreGlobal': {
163640
163783
  state.referenceAndRecordEffects(
163784
+ freezeActions,
163641
163785
  instrValue.value,
163642
163786
  exports.Effect.Capture,
163643
- ValueReason.Other,
163644
- functionEffects
163787
+ ValueReason.Other
163645
163788
  );
163646
163789
  const lvalue = instr.lvalue;
163647
163790
  lvalue.effect = exports.Effect.Store;
163648
- functionEffects.push({
163649
- kind: 'GlobalMutation',
163650
- error: {
163651
- reason:
163652
- '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)',
163653
- loc: instr.loc,
163654
- suggestions: null,
163655
- severity: exports.ErrorSeverity.InvalidReact,
163656
- },
163657
- });
163658
- continue;
163791
+ continuation = {kind: 'funeffects'};
163792
+ break;
163659
163793
  }
163660
163794
  case 'Destructure': {
163661
163795
  let effect = exports.Effect.Capture;
@@ -163669,10 +163803,10 @@ function inferBlock(env, functionEffects, state, block) {
163669
163803
  }
163670
163804
  }
163671
163805
  state.referenceAndRecordEffects(
163806
+ freezeActions,
163672
163807
  instrValue.value,
163673
163808
  effect,
163674
- ValueReason.Other,
163675
- functionEffects
163809
+ ValueReason.Other
163676
163810
  );
163677
163811
  const lvalue = instr.lvalue;
163678
163812
  state.alias(lvalue, instrValue.value);
@@ -163681,13 +163815,16 @@ function inferBlock(env, functionEffects, state, block) {
163681
163815
  state.alias(place, instrValue.value);
163682
163816
  place.effect = exports.Effect.Store;
163683
163817
  }
163684
- continue;
163818
+ continuation = {kind: 'funeffects'};
163819
+ break;
163685
163820
  }
163686
163821
  case 'GetIterator': {
163687
163822
  const kind = state.kind(instrValue.collection).kind;
163688
163823
  const isMutable =
163689
163824
  kind === exports.ValueKind.Mutable ||
163690
163825
  kind === exports.ValueKind.Context;
163826
+ let effect;
163827
+ let valueKind;
163691
163828
  if (!isMutable || isArrayType(instrValue.collection.identifier)) {
163692
163829
  effect = {kind: exports.Effect.Read, reason: ValueReason.Other};
163693
163830
  valueKind = {
@@ -163699,34 +163836,43 @@ function inferBlock(env, functionEffects, state, block) {
163699
163836
  effect = {kind: exports.Effect.Capture, reason: ValueReason.Other};
163700
163837
  valueKind = state.kind(instrValue.collection);
163701
163838
  }
163702
- lvalueEffect = exports.Effect.Store;
163839
+ continuation = {
163840
+ kind: 'initialize',
163841
+ effect: effect,
163842
+ valueKind: valueKind,
163843
+ lvalueEffect: exports.Effect.Store,
163844
+ };
163703
163845
  break;
163704
163846
  }
163705
163847
  case 'IteratorNext': {
163706
163848
  state.referenceAndRecordEffects(
163849
+ freezeActions,
163707
163850
  instrValue.iterator,
163708
163851
  exports.Effect.ConditionallyMutate,
163709
- ValueReason.Other,
163710
- functionEffects
163852
+ ValueReason.Other
163711
163853
  );
163712
163854
  state.referenceAndRecordEffects(
163855
+ freezeActions,
163713
163856
  instrValue.collection,
163714
163857
  exports.Effect.Capture,
163715
- ValueReason.Other,
163716
- functionEffects
163858
+ ValueReason.Other
163717
163859
  );
163718
163860
  state.initialize(instrValue, state.kind(instrValue.collection));
163719
163861
  state.define(instr.lvalue, instrValue);
163720
163862
  instr.lvalue.effect = exports.Effect.Store;
163721
- continue;
163863
+ continuation = {kind: 'funeffects'};
163864
+ break;
163722
163865
  }
163723
163866
  case 'NextPropertyOf': {
163724
- effect = {kind: exports.Effect.Read, reason: ValueReason.Other};
163725
- lvalueEffect = exports.Effect.Store;
163726
- valueKind = {
163727
- kind: exports.ValueKind.Primitive,
163728
- reason: new Set([ValueReason.Other]),
163729
- 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
+ },
163730
163876
  };
163731
163877
  break;
163732
163878
  }
@@ -163734,24 +163880,34 @@ function inferBlock(env, functionEffects, state, block) {
163734
163880
  assertExhaustive(instrValue, 'Unexpected instruction kind');
163735
163881
  }
163736
163882
  }
163737
- for (const operand of eachInstructionOperand(instr)) {
163738
- CompilerError.invariant(effect != null, {
163739
- reason: `effectKind must be set for instruction value \`${instrValue.kind}\``,
163740
- description: null,
163741
- loc: instrValue.loc,
163742
- suggestions: null,
163743
- });
163744
- state.referenceAndRecordEffects(
163745
- operand,
163746
- effect.kind,
163747
- effect.reason,
163748
- functionEffects
163749
- );
163750
- }
163751
- state.initialize(instrValue, valueKind);
163752
- state.define(instr.lvalue, instrValue);
163753
- 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
+ );
163754
163909
  }
163910
+ const terminalFreezeActions = [];
163755
163911
  for (const operand of eachTerminalOperand(block.terminal)) {
163756
163912
  let effect;
163757
163913
  if (block.terminal.kind === 'return' || block.terminal.kind === 'throw') {
@@ -163766,17 +163922,17 @@ function inferBlock(env, functionEffects, state, block) {
163766
163922
  } else {
163767
163923
  effect = exports.Effect.Read;
163768
163924
  }
163769
- const propEffects = [];
163770
163925
  state.referenceAndRecordEffects(
163926
+ terminalFreezeActions,
163771
163927
  operand,
163772
163928
  effect,
163773
- ValueReason.Other,
163774
- propEffects
163775
- );
163776
- functionEffects.push(
163777
- ...propEffects.filter(effect => !isEffectSafeOutsideRender(effect))
163929
+ ValueReason.Other
163778
163930
  );
163779
163931
  }
163932
+ functionEffects.push(...inferTerminalFunctionEffects(state, block));
163933
+ terminalFreezeActions.forEach(({values: values, reason: reason}) =>
163934
+ state.freezeValues(values, reason)
163935
+ );
163780
163936
  }
163781
163937
  function hasContextRefOperand(state, instrValue) {
163782
163938
  for (const place of eachInstructionValueOperand(instrValue)) {
@@ -163843,28 +163999,6 @@ function areArgumentsImmutableAndNonMutating(state, args) {
163843
163999
  }
163844
164000
  return true;
163845
164001
  }
163846
- function isEffectSafeOutsideRender(effect) {
163847
- return effect.kind === 'GlobalMutation';
163848
- }
163849
- function getWriteErrorReason(abstractValue) {
163850
- if (abstractValue.reason.has(ValueReason.Global)) {
163851
- return 'Writing to a variable defined outside a component or hook is not allowed. Consider using an effect';
163852
- } else if (abstractValue.reason.has(ValueReason.JsxCaptured)) {
163853
- return 'Updating a value used previously in JSX is not allowed. Consider moving the mutation before the JSX';
163854
- } else if (abstractValue.reason.has(ValueReason.Context)) {
163855
- return `Mutating a value returned from 'useContext()', which should not be mutated`;
163856
- } else if (abstractValue.reason.has(ValueReason.KnownReturnSignature)) {
163857
- return 'Mutating a value returned from a function whose return value should not be mutated';
163858
- } else if (abstractValue.reason.has(ValueReason.ReactiveFunctionArgument)) {
163859
- return 'Mutating component props or hook arguments is not allowed. Consider using a local variable instead';
163860
- } else if (abstractValue.reason.has(ValueReason.State)) {
163861
- return "Mutating a value returned from 'useState()', which should not be mutated. Use the setter function to update instead";
163862
- } else if (abstractValue.reason.has(ValueReason.ReducerState)) {
163863
- return "Mutating a value returned from 'useReducer()', which should not be mutated. Use the dispatch function to update instead";
163864
- } else {
163865
- return 'This mutates a variable that React considers immutable';
163866
- }
163867
- }
163868
164002
  function pruneNonEscapingScopes(fn) {
163869
164003
  const state = new State(fn.env);
163870
164004
  for (const param of fn.params) {