babel-plugin-react-compiler 0.0.0-experimental-5f79ba2-20240815 → 0.0.0-experimental-1f3db3d-20240818

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
@@ -136076,6 +136076,9 @@ function isUseRefType(id) {
136076
136076
  function isUseStateType(id) {
136077
136077
  return id.type.kind === 'Object' && id.type.shapeId === 'BuiltInUseState';
136078
136078
  }
136079
+ function isRefOrRefValue(id) {
136080
+ return isUseRefType(id) || isRefValueType(id);
136081
+ }
136079
136082
  function isSetStateType(id) {
136080
136083
  return id.type.kind === 'Function' && id.type.shapeId === 'BuiltInSetState';
136081
136084
  }
@@ -140004,8 +140007,7 @@ function lowerStatement(builder, stmtPath, label = null) {
140004
140007
  _28,
140005
140008
  _29,
140006
140009
  _30,
140007
- _31,
140008
- _32;
140010
+ _31;
140009
140011
  const stmtNode = stmtPath.node;
140010
140012
  switch (stmtNode.type) {
140011
140013
  case 'ThrowStatement': {
@@ -140185,18 +140187,6 @@ function lowerStatement(builder, stmtPath, label = null) {
140185
140187
  : GeneratedSource,
140186
140188
  });
140187
140189
  continue;
140188
- } else if (!binding.path.get('id').isIdentifier()) {
140189
- builder.errors.push({
140190
- severity: exports.ErrorSeverity.Todo,
140191
- reason: 'Unsupported variable declaration type for hoisting',
140192
- description: `variable "${binding.identifier.name}" declared with ${binding.path.get('id').type}`,
140193
- suggestions: null,
140194
- loc:
140195
- (_g = id.parentPath.node.loc) !== null && _g !== void 0
140196
- ? _g
140197
- : GeneratedSource,
140198
- });
140199
- continue;
140200
140190
  } else if (
140201
140191
  binding.kind !== 'const' &&
140202
140192
  binding.kind !== 'var' &&
@@ -140208,8 +140198,8 @@ function lowerStatement(builder, stmtPath, label = null) {
140208
140198
  description: `variable "${binding.identifier.name}" declared with ${binding.kind}`,
140209
140199
  suggestions: null,
140210
140200
  loc:
140211
- (_h = id.parentPath.node.loc) !== null && _h !== void 0
140212
- ? _h
140201
+ (_g = id.parentPath.node.loc) !== null && _g !== void 0
140202
+ ? _g
140213
140203
  : GeneratedSource,
140214
140204
  });
140215
140205
  continue;
@@ -140219,8 +140209,8 @@ function lowerStatement(builder, stmtPath, label = null) {
140219
140209
  reason:
140220
140210
  'Expected hoisted binding to be a local identifier, not a global',
140221
140211
  loc:
140222
- (_j = id.node.loc) !== null && _j !== void 0
140223
- ? _j
140212
+ (_h = id.node.loc) !== null && _h !== void 0
140213
+ ? _h
140224
140214
  : GeneratedSource,
140225
140215
  });
140226
140216
  const place = {
@@ -140229,8 +140219,8 @@ function lowerStatement(builder, stmtPath, label = null) {
140229
140219
  kind: 'Identifier',
140230
140220
  reactive: false,
140231
140221
  loc:
140232
- (_k = id.node.loc) !== null && _k !== void 0
140233
- ? _k
140222
+ (_j = id.node.loc) !== null && _j !== void 0
140223
+ ? _j
140234
140224
  : GeneratedSource,
140235
140225
  };
140236
140226
  const kind =
@@ -140243,8 +140233,8 @@ function lowerStatement(builder, stmtPath, label = null) {
140243
140233
  kind: 'DeclareContext',
140244
140234
  lvalue: {kind: kind, place: place},
140245
140235
  loc:
140246
- (_l = id.node.loc) !== null && _l !== void 0
140247
- ? _l
140236
+ (_k = id.node.loc) !== null && _k !== void 0
140237
+ ? _k
140248
140238
  : GeneratedSource,
140249
140239
  });
140250
140240
  builder.environment.addHoistedIdentifier(binding.identifier);
@@ -140256,11 +140246,11 @@ function lowerStatement(builder, stmtPath, label = null) {
140256
140246
  case 'BreakStatement': {
140257
140247
  const stmt = stmtPath;
140258
140248
  const block = builder.lookupBreak(
140259
- (_o =
140260
- (_m = stmt.node.label) === null || _m === void 0
140249
+ (_m =
140250
+ (_l = stmt.node.label) === null || _l === void 0
140261
140251
  ? void 0
140262
- : _m.name) !== null && _o !== void 0
140263
- ? _o
140252
+ : _l.name) !== null && _m !== void 0
140253
+ ? _m
140264
140254
  : null
140265
140255
  );
140266
140256
  builder.terminate(
@@ -140270,8 +140260,8 @@ function lowerStatement(builder, stmtPath, label = null) {
140270
140260
  variant: GotoVariant.Break,
140271
140261
  id: makeInstructionId(0),
140272
140262
  loc:
140273
- (_p = stmt.node.loc) !== null && _p !== void 0
140274
- ? _p
140263
+ (_o = stmt.node.loc) !== null && _o !== void 0
140264
+ ? _o
140275
140265
  : GeneratedSource,
140276
140266
  },
140277
140267
  'block'
@@ -140281,11 +140271,11 @@ function lowerStatement(builder, stmtPath, label = null) {
140281
140271
  case 'ContinueStatement': {
140282
140272
  const stmt = stmtPath;
140283
140273
  const block = builder.lookupContinue(
140284
- (_r =
140285
- (_q = stmt.node.label) === null || _q === void 0
140274
+ (_q =
140275
+ (_p = stmt.node.label) === null || _p === void 0
140286
140276
  ? void 0
140287
- : _q.name) !== null && _r !== void 0
140288
- ? _r
140277
+ : _p.name) !== null && _q !== void 0
140278
+ ? _q
140289
140279
  : null
140290
140280
  );
140291
140281
  builder.terminate(
@@ -140295,8 +140285,8 @@ function lowerStatement(builder, stmtPath, label = null) {
140295
140285
  variant: GotoVariant.Continue,
140296
140286
  id: makeInstructionId(0),
140297
140287
  loc:
140298
- (_s = stmt.node.loc) !== null && _s !== void 0
140299
- ? _s
140288
+ (_r = stmt.node.loc) !== null && _r !== void 0
140289
+ ? _r
140300
140290
  : GeneratedSource,
140301
140291
  },
140302
140292
  'block'
@@ -140394,8 +140384,8 @@ function lowerStatement(builder, stmtPath, label = null) {
140394
140384
  {
140395
140385
  kind: 'for',
140396
140386
  loc:
140397
- (_t = stmtNode.loc) !== null && _t !== void 0
140398
- ? _t
140387
+ (_s = stmtNode.loc) !== null && _s !== void 0
140388
+ ? _s
140399
140389
  : GeneratedSource,
140400
140390
  init: initBlock,
140401
140391
  test: testBlock.id,
@@ -140411,7 +140401,7 @@ function lowerStatement(builder, stmtPath, label = null) {
140411
140401
  builder.errors.push({
140412
140402
  reason: `(BuildHIR::lowerStatement) Handle empty test in ForStatement`,
140413
140403
  severity: exports.ErrorSeverity.Todo,
140414
- loc: (_u = stmt.node.loc) !== null && _u !== void 0 ? _u : null,
140404
+ loc: (_t = stmt.node.loc) !== null && _t !== void 0 ? _t : null,
140415
140405
  suggestions: null,
140416
140406
  });
140417
140407
  } else {
@@ -140423,8 +140413,8 @@ function lowerStatement(builder, stmtPath, label = null) {
140423
140413
  alternate: continuationBlock.id,
140424
140414
  id: makeInstructionId(0),
140425
140415
  loc:
140426
- (_v = stmt.node.loc) !== null && _v !== void 0
140427
- ? _v
140416
+ (_u = stmt.node.loc) !== null && _u !== void 0
140417
+ ? _u
140428
140418
  : GeneratedSource,
140429
140419
  },
140430
140420
  continuationBlock
@@ -140454,7 +140444,7 @@ function lowerStatement(builder, stmtPath, label = null) {
140454
140444
  })
140455
140445
  );
140456
140446
  const loc =
140457
- (_w = stmt.node.loc) !== null && _w !== void 0 ? _w : GeneratedSource;
140447
+ (_v = stmt.node.loc) !== null && _v !== void 0 ? _v : GeneratedSource;
140458
140448
  builder.terminateWithContinuation(
140459
140449
  {
140460
140450
  kind: 'while',
@@ -140474,7 +140464,7 @@ function lowerStatement(builder, stmtPath, label = null) {
140474
140464
  alternate: continuationBlock.id,
140475
140465
  id: makeInstructionId(0),
140476
140466
  loc:
140477
- (_x = stmt.node.loc) !== null && _x !== void 0 ? _x : GeneratedSource,
140467
+ (_w = stmt.node.loc) !== null && _w !== void 0 ? _w : GeneratedSource,
140478
140468
  };
140479
140469
  builder.terminateWithContinuation(terminal, continuationBlock);
140480
140470
  return;
@@ -140518,8 +140508,8 @@ function lowerStatement(builder, stmtPath, label = null) {
140518
140508
  fallthrough: continuationBlock.id,
140519
140509
  id: makeInstructionId(0),
140520
140510
  loc:
140521
- (_y = stmt.node.loc) !== null && _y !== void 0
140522
- ? _y
140511
+ (_x = stmt.node.loc) !== null && _x !== void 0
140512
+ ? _x
140523
140513
  : GeneratedSource,
140524
140514
  },
140525
140515
  continuationBlock
@@ -140542,7 +140532,7 @@ function lowerStatement(builder, stmtPath, label = null) {
140542
140532
  builder.errors.push({
140543
140533
  reason: `Expected at most one \`default\` branch in a switch statement, this code should have failed to parse`,
140544
140534
  severity: exports.ErrorSeverity.InvalidJS,
140545
- loc: (_z = case_.node.loc) !== null && _z !== void 0 ? _z : null,
140535
+ loc: (_y = case_.node.loc) !== null && _y !== void 0 ? _y : null,
140546
140536
  suggestions: null,
140547
140537
  });
140548
140538
  break;
@@ -140590,8 +140580,8 @@ function lowerStatement(builder, stmtPath, label = null) {
140590
140580
  fallthrough: continuationBlock.id,
140591
140581
  id: makeInstructionId(0),
140592
140582
  loc:
140593
- (_0 = stmt.node.loc) !== null && _0 !== void 0
140594
- ? _0
140583
+ (_z = stmt.node.loc) !== null && _z !== void 0
140584
+ ? _z
140595
140585
  : GeneratedSource,
140596
140586
  },
140597
140587
  continuationBlock
@@ -140605,7 +140595,7 @@ function lowerStatement(builder, stmtPath, label = null) {
140605
140595
  builder.errors.push({
140606
140596
  reason: `(BuildHIR::lowerStatement) Handle ${nodeKind} kinds in VariableDeclaration`,
140607
140597
  severity: exports.ErrorSeverity.Todo,
140608
- loc: (_1 = stmt.node.loc) !== null && _1 !== void 0 ? _1 : null,
140598
+ loc: (_0 = stmt.node.loc) !== null && _0 !== void 0 ? _0 : null,
140609
140599
  suggestions: null,
140610
140600
  });
140611
140601
  return;
@@ -140619,8 +140609,8 @@ function lowerStatement(builder, stmtPath, label = null) {
140619
140609
  const value = lowerExpressionToTemporary(builder, init);
140620
140610
  lowerAssignment(
140621
140611
  builder,
140622
- (_2 = stmt.node.loc) !== null && _2 !== void 0
140623
- ? _2
140612
+ (_1 = stmt.node.loc) !== null && _1 !== void 0
140613
+ ? _1
140624
140614
  : GeneratedSource,
140625
140615
  kind,
140626
140616
  id,
@@ -140635,7 +140625,7 @@ function lowerStatement(builder, stmtPath, label = null) {
140635
140625
  builder.errors.push({
140636
140626
  reason: `(BuildHIR::lowerAssignment) Could not find binding for declaration.`,
140637
140627
  severity: exports.ErrorSeverity.Invariant,
140638
- loc: (_3 = id.node.loc) !== null && _3 !== void 0 ? _3 : null,
140628
+ loc: (_2 = id.node.loc) !== null && _2 !== void 0 ? _2 : null,
140639
140629
  suggestions: null,
140640
140630
  });
140641
140631
  } else {
@@ -140645,8 +140635,8 @@ function lowerStatement(builder, stmtPath, label = null) {
140645
140635
  kind: 'Identifier',
140646
140636
  reactive: false,
140647
140637
  loc:
140648
- (_4 = id.node.loc) !== null && _4 !== void 0
140649
- ? _4
140638
+ (_3 = id.node.loc) !== null && _3 !== void 0
140639
+ ? _3
140650
140640
  : GeneratedSource,
140651
140641
  };
140652
140642
  if (builder.isContextIdentifier(id)) {
@@ -140655,7 +140645,7 @@ function lowerStatement(builder, stmtPath, label = null) {
140655
140645
  builder.errors.push({
140656
140646
  reason: `Expect \`const\` declaration not to be reassigned`,
140657
140647
  severity: exports.ErrorSeverity.InvalidJS,
140658
- loc: (_5 = id.node.loc) !== null && _5 !== void 0 ? _5 : null,
140648
+ loc: (_4 = id.node.loc) !== null && _4 !== void 0 ? _4 : null,
140659
140649
  suggestions: [
140660
140650
  {
140661
140651
  description: 'Change to a `let` declaration',
@@ -140670,8 +140660,8 @@ function lowerStatement(builder, stmtPath, label = null) {
140670
140660
  kind: 'DeclareContext',
140671
140661
  lvalue: {kind: InstructionKind.Let, place: place},
140672
140662
  loc:
140673
- (_6 = id.node.loc) !== null && _6 !== void 0
140674
- ? _6
140663
+ (_5 = id.node.loc) !== null && _5 !== void 0
140664
+ ? _5
140675
140665
  : GeneratedSource,
140676
140666
  });
140677
140667
  } else {
@@ -140691,8 +140681,8 @@ function lowerStatement(builder, stmtPath, label = null) {
140691
140681
  lvalue: {kind: kind, place: place},
140692
140682
  type: type,
140693
140683
  loc:
140694
- (_7 = id.node.loc) !== null && _7 !== void 0
140695
- ? _7
140684
+ (_6 = id.node.loc) !== null && _6 !== void 0
140685
+ ? _6
140696
140686
  : GeneratedSource,
140697
140687
  });
140698
140688
  }
@@ -140702,7 +140692,7 @@ function lowerStatement(builder, stmtPath, label = null) {
140702
140692
  reason: `Expected variable declaration to be an identifier if no initializer was provided`,
140703
140693
  description: `Got a \`${id.type}\``,
140704
140694
  severity: exports.ErrorSeverity.InvalidJS,
140705
- loc: (_8 = stmt.node.loc) !== null && _8 !== void 0 ? _8 : null,
140695
+ loc: (_7 = stmt.node.loc) !== null && _7 !== void 0 ? _7 : null,
140706
140696
  suggestions: null,
140707
140697
  });
140708
140698
  }
@@ -140737,7 +140727,7 @@ function lowerStatement(builder, stmtPath, label = null) {
140737
140727
  })
140738
140728
  );
140739
140729
  const loc =
140740
- (_9 = stmt.node.loc) !== null && _9 !== void 0 ? _9 : GeneratedSource;
140730
+ (_8 = stmt.node.loc) !== null && _8 !== void 0 ? _8 : GeneratedSource;
140741
140731
  builder.terminateWithContinuation(
140742
140732
  {
140743
140733
  kind: 'do-while',
@@ -140767,7 +140757,7 @@ function lowerStatement(builder, stmtPath, label = null) {
140767
140757
  CompilerError.invariant(stmt.get('id').type === 'Identifier', {
140768
140758
  reason: 'function declarations must have a name',
140769
140759
  description: null,
140770
- loc: (_10 = stmt.node.loc) !== null && _10 !== void 0 ? _10 : null,
140760
+ loc: (_9 = stmt.node.loc) !== null && _9 !== void 0 ? _9 : null,
140771
140761
  suggestions: null,
140772
140762
  });
140773
140763
  const id = stmt.get('id');
@@ -140777,8 +140767,8 @@ function lowerStatement(builder, stmtPath, label = null) {
140777
140767
  );
140778
140768
  lowerAssignment(
140779
140769
  builder,
140780
- (_11 = stmt.node.loc) !== null && _11 !== void 0
140781
- ? _11
140770
+ (_10 = stmt.node.loc) !== null && _10 !== void 0
140771
+ ? _10
140782
140772
  : GeneratedSource,
140783
140773
  InstructionKind.Let,
140784
140774
  id,
@@ -140796,7 +140786,7 @@ function lowerStatement(builder, stmtPath, label = null) {
140796
140786
  builder.errors.push({
140797
140787
  reason: `(BuildHIR::lowerStatement) Handle for-await loops`,
140798
140788
  severity: exports.ErrorSeverity.Todo,
140799
- loc: (_12 = stmt.node.loc) !== null && _12 !== void 0 ? _12 : null,
140789
+ loc: (_11 = stmt.node.loc) !== null && _11 !== void 0 ? _11 : null,
140800
140790
  suggestions: null,
140801
140791
  });
140802
140792
  return;
@@ -140819,8 +140809,8 @@ function lowerStatement(builder, stmtPath, label = null) {
140819
140809
  })
140820
140810
  );
140821
140811
  const loc =
140822
- (_13 = stmt.node.loc) !== null && _13 !== void 0
140823
- ? _13
140812
+ (_12 = stmt.node.loc) !== null && _12 !== void 0
140813
+ ? _12
140824
140814
  : GeneratedSource;
140825
140815
  const value = lowerExpressionToTemporary(builder, stmt.get('right'));
140826
140816
  builder.terminateWithContinuation(
@@ -140847,16 +140837,16 @@ function lowerStatement(builder, stmtPath, label = null) {
140847
140837
  block: testBlock.id,
140848
140838
  variant: GotoVariant.Break,
140849
140839
  loc:
140850
- (_14 = stmt.node.loc) !== null && _14 !== void 0
140851
- ? _14
140840
+ (_13 = stmt.node.loc) !== null && _13 !== void 0
140841
+ ? _13
140852
140842
  : GeneratedSource,
140853
140843
  },
140854
140844
  testBlock
140855
140845
  );
140856
140846
  const left = stmt.get('left');
140857
140847
  const leftLoc =
140858
- (_15 = left.node.loc) !== null && _15 !== void 0
140859
- ? _15
140848
+ (_14 = left.node.loc) !== null && _14 !== void 0
140849
+ ? _14
140860
140850
  : GeneratedSource;
140861
140851
  let test;
140862
140852
  if (left.isVariableDeclaration()) {
@@ -140864,7 +140854,7 @@ function lowerStatement(builder, stmtPath, label = null) {
140864
140854
  CompilerError.invariant(declarations.length === 1, {
140865
140855
  reason: `Expected only one declaration in the init of a ForOfStatement, got ${declarations.length}`,
140866
140856
  description: null,
140867
- loc: (_16 = left.node.loc) !== null && _16 !== void 0 ? _16 : null,
140857
+ loc: (_15 = left.node.loc) !== null && _15 !== void 0 ? _15 : null,
140868
140858
  suggestions: null,
140869
140859
  });
140870
140860
  const id = declarations[0].get('id');
@@ -140887,7 +140877,7 @@ function lowerStatement(builder, stmtPath, label = null) {
140887
140877
  builder.errors.push({
140888
140878
  reason: `(BuildHIR::lowerStatement) Handle ${left.type} inits in ForOfStatement`,
140889
140879
  severity: exports.ErrorSeverity.Todo,
140890
- loc: (_17 = left.node.loc) !== null && _17 !== void 0 ? _17 : null,
140880
+ loc: (_16 = left.node.loc) !== null && _16 !== void 0 ? _16 : null,
140891
140881
  suggestions: null,
140892
140882
  });
140893
140883
  return;
@@ -140900,8 +140890,8 @@ function lowerStatement(builder, stmtPath, label = null) {
140900
140890
  consequent: loopBlock,
140901
140891
  alternate: continuationBlock.id,
140902
140892
  loc:
140903
- (_18 = stmt.node.loc) !== null && _18 !== void 0
140904
- ? _18
140893
+ (_17 = stmt.node.loc) !== null && _17 !== void 0
140894
+ ? _17
140905
140895
  : GeneratedSource,
140906
140896
  },
140907
140897
  continuationBlock
@@ -140930,8 +140920,8 @@ function lowerStatement(builder, stmtPath, label = null) {
140930
140920
  })
140931
140921
  );
140932
140922
  const loc =
140933
- (_19 = stmt.node.loc) !== null && _19 !== void 0
140934
- ? _19
140923
+ (_18 = stmt.node.loc) !== null && _18 !== void 0
140924
+ ? _18
140935
140925
  : GeneratedSource;
140936
140926
  const value = lowerExpressionToTemporary(builder, stmt.get('right'));
140937
140927
  builder.terminateWithContinuation(
@@ -140947,8 +140937,8 @@ function lowerStatement(builder, stmtPath, label = null) {
140947
140937
  );
140948
140938
  const left = stmt.get('left');
140949
140939
  const leftLoc =
140950
- (_20 = left.node.loc) !== null && _20 !== void 0
140951
- ? _20
140940
+ (_19 = left.node.loc) !== null && _19 !== void 0
140941
+ ? _19
140952
140942
  : GeneratedSource;
140953
140943
  let test;
140954
140944
  if (left.isVariableDeclaration()) {
@@ -140956,7 +140946,7 @@ function lowerStatement(builder, stmtPath, label = null) {
140956
140946
  CompilerError.invariant(declarations.length === 1, {
140957
140947
  reason: `Expected only one declaration in the init of a ForInStatement, got ${declarations.length}`,
140958
140948
  description: null,
140959
- loc: (_21 = left.node.loc) !== null && _21 !== void 0 ? _21 : null,
140949
+ loc: (_20 = left.node.loc) !== null && _20 !== void 0 ? _20 : null,
140960
140950
  suggestions: null,
140961
140951
  });
140962
140952
  const id = declarations[0].get('id');
@@ -140978,7 +140968,7 @@ function lowerStatement(builder, stmtPath, label = null) {
140978
140968
  builder.errors.push({
140979
140969
  reason: `(BuildHIR::lowerStatement) Handle ${left.type} inits in ForInStatement`,
140980
140970
  severity: exports.ErrorSeverity.Todo,
140981
- loc: (_22 = left.node.loc) !== null && _22 !== void 0 ? _22 : null,
140971
+ loc: (_21 = left.node.loc) !== null && _21 !== void 0 ? _21 : null,
140982
140972
  suggestions: null,
140983
140973
  });
140984
140974
  return;
@@ -140991,8 +140981,8 @@ function lowerStatement(builder, stmtPath, label = null) {
140991
140981
  consequent: loopBlock,
140992
140982
  alternate: continuationBlock.id,
140993
140983
  loc:
140994
- (_23 = stmt.node.loc) !== null && _23 !== void 0
140995
- ? _23
140984
+ (_22 = stmt.node.loc) !== null && _22 !== void 0
140985
+ ? _22
140996
140986
  : GeneratedSource,
140997
140987
  },
140998
140988
  continuationBlock
@@ -141002,8 +140992,8 @@ function lowerStatement(builder, stmtPath, label = null) {
141002
140992
  case 'DebuggerStatement': {
141003
140993
  const stmt = stmtPath;
141004
140994
  const loc =
141005
- (_24 = stmt.node.loc) !== null && _24 !== void 0
141006
- ? _24
140995
+ (_23 = stmt.node.loc) !== null && _23 !== void 0
140996
+ ? _23
141007
140997
  : GeneratedSource;
141008
140998
  builder.push({
141009
140999
  id: makeInstructionId(0),
@@ -141024,7 +141014,7 @@ function lowerStatement(builder, stmtPath, label = null) {
141024
141014
  builder.errors.push({
141025
141015
  reason: `(BuildHIR::lowerStatement) Handle TryStatement without a catch clause`,
141026
141016
  severity: exports.ErrorSeverity.Todo,
141027
- loc: (_25 = stmt.node.loc) !== null && _25 !== void 0 ? _25 : null,
141017
+ loc: (_24 = stmt.node.loc) !== null && _24 !== void 0 ? _24 : null,
141028
141018
  suggestions: null,
141029
141019
  });
141030
141020
  return;
@@ -141033,7 +141023,7 @@ function lowerStatement(builder, stmtPath, label = null) {
141033
141023
  builder.errors.push({
141034
141024
  reason: `(BuildHIR::lowerStatement) Handle TryStatement with a finalizer ('finally') clause`,
141035
141025
  severity: exports.ErrorSeverity.Todo,
141036
- loc: (_26 = stmt.node.loc) !== null && _26 !== void 0 ? _26 : null,
141026
+ loc: (_25 = stmt.node.loc) !== null && _25 !== void 0 ? _25 : null,
141037
141027
  suggestions: null,
141038
141028
  });
141039
141029
  }
@@ -141043,15 +141033,15 @@ function lowerStatement(builder, stmtPath, label = null) {
141043
141033
  const place = {
141044
141034
  kind: 'Identifier',
141045
141035
  identifier: builder.makeTemporary(
141046
- (_27 = handlerBindingPath.node.loc) !== null && _27 !== void 0
141047
- ? _27
141036
+ (_26 = handlerBindingPath.node.loc) !== null && _26 !== void 0
141037
+ ? _26
141048
141038
  : GeneratedSource
141049
141039
  ),
141050
141040
  effect: exports.Effect.Unknown,
141051
141041
  reactive: false,
141052
141042
  loc:
141053
- (_28 = handlerBindingPath.node.loc) !== null && _28 !== void 0
141054
- ? _28
141043
+ (_27 = handlerBindingPath.node.loc) !== null && _27 !== void 0
141044
+ ? _27
141055
141045
  : GeneratedSource,
141056
141046
  };
141057
141047
  promoteTemporary(place.identifier);
@@ -141063,8 +141053,8 @@ function lowerStatement(builder, stmtPath, label = null) {
141063
141053
  },
141064
141054
  type: null,
141065
141055
  loc:
141066
- (_29 = handlerBindingPath.node.loc) !== null && _29 !== void 0
141067
- ? _29
141056
+ (_28 = handlerBindingPath.node.loc) !== null && _28 !== void 0
141057
+ ? _28
141068
141058
  : GeneratedSource,
141069
141059
  });
141070
141060
  handlerBinding = {path: handlerBindingPath, place: place};
@@ -141124,8 +141114,8 @@ function lowerStatement(builder, stmtPath, label = null) {
141124
141114
  fallthrough: continuationBlock.id,
141125
141115
  id: makeInstructionId(0),
141126
141116
  loc:
141127
- (_30 = stmt.node.loc) !== null && _30 !== void 0
141128
- ? _30
141117
+ (_29 = stmt.node.loc) !== null && _29 !== void 0
141118
+ ? _29
141129
141119
  : GeneratedSource,
141130
141120
  },
141131
141121
  continuationBlock
@@ -141165,14 +141155,14 @@ function lowerStatement(builder, stmtPath, label = null) {
141165
141155
  builder.errors.push({
141166
141156
  reason: `(BuildHIR::lowerStatement) Handle ${stmtPath.type} statements`,
141167
141157
  severity: exports.ErrorSeverity.Todo,
141168
- loc: (_31 = stmtPath.node.loc) !== null && _31 !== void 0 ? _31 : null,
141158
+ loc: (_30 = stmtPath.node.loc) !== null && _30 !== void 0 ? _30 : null,
141169
141159
  suggestions: null,
141170
141160
  });
141171
141161
  lowerValueToTemporary(builder, {
141172
141162
  kind: 'UnsupportedNode',
141173
141163
  loc:
141174
- (_32 = stmtPath.node.loc) !== null && _32 !== void 0
141175
- ? _32
141164
+ (_31 = stmtPath.node.loc) !== null && _31 !== void 0
141165
+ ? _31
141176
141166
  : GeneratedSource,
141177
141167
  node: stmtPath.node,
141178
141168
  });
@@ -141269,7 +141259,10 @@ function lowerExpression(builder, exprPath) {
141269
141259
  _17,
141270
141260
  _18,
141271
141261
  _19,
141272
- _20;
141262
+ _20,
141263
+ _21,
141264
+ _22,
141265
+ _23;
141273
141266
  const exprNode = exprPath.node;
141274
141267
  const exprLoc =
141275
141268
  (_a = exprNode.loc) !== null && _a !== void 0 ? _a : GeneratedSource;
@@ -142216,12 +142209,67 @@ function lowerExpression(builder, exprPath) {
142216
142209
  case 'UpdateExpression': {
142217
142210
  let expr = exprPath;
142218
142211
  const argument = expr.get('argument');
142212
+ if (argument.isMemberExpression()) {
142213
+ const binaryOperator = expr.node.operator === '++' ? '+' : '-';
142214
+ const leftExpr = argument;
142215
+ const {
142216
+ object: object,
142217
+ property: property,
142218
+ value: value,
142219
+ } = lowerMemberExpression(builder, leftExpr);
142220
+ const previousValuePlace = lowerValueToTemporary(builder, value);
142221
+ const updatedValue = lowerValueToTemporary(builder, {
142222
+ kind: 'BinaryExpression',
142223
+ operator: binaryOperator,
142224
+ left: Object.assign({}, previousValuePlace),
142225
+ right: lowerValueToTemporary(builder, {
142226
+ kind: 'Primitive',
142227
+ value: 1,
142228
+ loc: GeneratedSource,
142229
+ }),
142230
+ loc:
142231
+ (_14 = leftExpr.node.loc) !== null && _14 !== void 0
142232
+ ? _14
142233
+ : GeneratedSource,
142234
+ });
142235
+ let newValuePlace;
142236
+ if (typeof property === 'string') {
142237
+ newValuePlace = lowerValueToTemporary(builder, {
142238
+ kind: 'PropertyStore',
142239
+ object: Object.assign({}, object),
142240
+ property: property,
142241
+ value: Object.assign({}, updatedValue),
142242
+ loc:
142243
+ (_15 = leftExpr.node.loc) !== null && _15 !== void 0
142244
+ ? _15
142245
+ : GeneratedSource,
142246
+ });
142247
+ } else {
142248
+ newValuePlace = lowerValueToTemporary(builder, {
142249
+ kind: 'ComputedStore',
142250
+ object: Object.assign({}, object),
142251
+ property: Object.assign({}, property),
142252
+ value: Object.assign({}, updatedValue),
142253
+ loc:
142254
+ (_16 = leftExpr.node.loc) !== null && _16 !== void 0
142255
+ ? _16
142256
+ : GeneratedSource,
142257
+ });
142258
+ }
142259
+ return {
142260
+ kind: 'LoadLocal',
142261
+ place: expr.node.prefix
142262
+ ? Object.assign({}, newValuePlace)
142263
+ : Object.assign({}, previousValuePlace),
142264
+ loc: exprLoc,
142265
+ };
142266
+ }
142219
142267
  if (!argument.isIdentifier()) {
142220
142268
  builder.errors.push({
142221
142269
  reason: `(BuildHIR::lowerExpression) Handle UpdateExpression with ${argument.type} argument`,
142222
142270
  severity: exports.ErrorSeverity.Todo,
142223
142271
  loc:
142224
- (_14 = exprPath.node.loc) !== null && _14 !== void 0 ? _14 : null,
142272
+ (_17 = exprPath.node.loc) !== null && _17 !== void 0 ? _17 : null,
142225
142273
  suggestions: null,
142226
142274
  });
142227
142275
  return {kind: 'UnsupportedNode', node: exprNode, loc: exprLoc};
@@ -142230,15 +142278,15 @@ function lowerExpression(builder, exprPath) {
142230
142278
  reason: `(BuildHIR::lowerExpression) Handle UpdateExpression to variables captured within lambdas.`,
142231
142279
  severity: exports.ErrorSeverity.Todo,
142232
142280
  loc:
142233
- (_15 = exprPath.node.loc) !== null && _15 !== void 0 ? _15 : null,
142281
+ (_18 = exprPath.node.loc) !== null && _18 !== void 0 ? _18 : null,
142234
142282
  suggestions: null,
142235
142283
  });
142236
142284
  return {kind: 'UnsupportedNode', node: exprNode, loc: exprLoc};
142237
142285
  }
142238
142286
  const lvalue = lowerIdentifierForAssignment(
142239
142287
  builder,
142240
- (_16 = argument.node.loc) !== null && _16 !== void 0
142241
- ? _16
142288
+ (_19 = argument.node.loc) !== null && _19 !== void 0
142289
+ ? _19
142242
142290
  : GeneratedSource,
142243
142291
  InstructionKind.Reassign,
142244
142292
  argument
@@ -142288,8 +142336,8 @@ function lowerExpression(builder, exprPath) {
142288
142336
  pattern: expr.node.pattern,
142289
142337
  flags: expr.node.flags,
142290
142338
  loc:
142291
- (_17 = expr.node.loc) !== null && _17 !== void 0
142292
- ? _17
142339
+ (_20 = expr.node.loc) !== null && _20 !== void 0
142340
+ ? _20
142293
142341
  : GeneratedSource,
142294
142342
  };
142295
142343
  }
@@ -142308,15 +142356,15 @@ function lowerExpression(builder, exprPath) {
142308
142356
  meta: expr.node.meta.name,
142309
142357
  property: expr.node.property.name,
142310
142358
  loc:
142311
- (_18 = expr.node.loc) !== null && _18 !== void 0
142312
- ? _18
142359
+ (_21 = expr.node.loc) !== null && _21 !== void 0
142360
+ ? _21
142313
142361
  : GeneratedSource,
142314
142362
  };
142315
142363
  }
142316
142364
  builder.errors.push({
142317
142365
  reason: `(BuildHIR::lowerExpression) Handle MetaProperty expressions other than import.meta`,
142318
142366
  severity: exports.ErrorSeverity.Todo,
142319
- loc: (_19 = exprPath.node.loc) !== null && _19 !== void 0 ? _19 : null,
142367
+ loc: (_22 = exprPath.node.loc) !== null && _22 !== void 0 ? _22 : null,
142320
142368
  suggestions: null,
142321
142369
  });
142322
142370
  return {kind: 'UnsupportedNode', node: exprNode, loc: exprLoc};
@@ -142325,7 +142373,7 @@ function lowerExpression(builder, exprPath) {
142325
142373
  builder.errors.push({
142326
142374
  reason: `(BuildHIR::lowerExpression) Handle ${exprPath.type} expressions`,
142327
142375
  severity: exports.ErrorSeverity.Todo,
142328
- loc: (_20 = exprPath.node.loc) !== null && _20 !== void 0 ? _20 : null,
142376
+ loc: (_23 = exprPath.node.loc) !== null && _23 !== void 0 ? _23 : null,
142329
142377
  suggestions: null,
142330
142378
  });
142331
142379
  return {kind: 'UnsupportedNode', node: exprNode, loc: exprLoc};
@@ -150194,7 +150242,7 @@ const EnvironmentConfigSchema = z.object({
150194
150242
  enableUseTypeAnnotations: z.boolean().default(false),
150195
150243
  enableReactiveScopesInHIR: z.boolean().default(true),
150196
150244
  validateHooksUsage: z.boolean().default(true),
150197
- validateRefAccessDuringRender: z.boolean().default(false),
150245
+ validateRefAccessDuringRender: z.boolean().default(true),
150198
150246
  validateNoSetStateInRender: z.boolean().default(true),
150199
150247
  validateNoSetStateInPassiveEffects: z.boolean().default(false),
150200
150248
  validateMemoizedEffectDependencies: z.boolean().default(false),
@@ -153943,7 +153991,7 @@ z.enum(['infer', 'syntax', 'annotation', 'all']);
153943
153991
  const defaultOptions = {
153944
153992
  compilationMode: 'infer',
153945
153993
  panicThreshold: 'none',
153946
- environment: {},
153994
+ environment: parseEnvironmentConfig({}).unwrap(),
153947
153995
  logger: null,
153948
153996
  gating: null,
153949
153997
  noEmit: false,
@@ -153963,7 +154011,19 @@ function parsePluginOptions(obj) {
153963
154011
  if (typeof value === 'string') {
153964
154012
  value = value.toLowerCase();
153965
154013
  }
153966
- if (isCompilerFlag(key)) {
154014
+ if (key === 'environment') {
154015
+ const environmentResult = parseEnvironmentConfig(value);
154016
+ if (environmentResult.isErr()) {
154017
+ CompilerError.throwInvalidConfig({
154018
+ reason:
154019
+ 'Error in validating environment config. This is an advanced setting and not meant to be used directly',
154020
+ description: environmentResult.unwrapErr().toString(),
154021
+ suggestions: null,
154022
+ loc: null,
154023
+ });
154024
+ }
154025
+ parsedOptions[key] = environmentResult.unwrap();
154026
+ } else if (isCompilerFlag(key)) {
153967
154027
  parsedOptions[key] = value;
153968
154028
  }
153969
154029
  }
@@ -162304,7 +162364,7 @@ class InferenceState {
162304
162364
  break;
162305
162365
  }
162306
162366
  case exports.Effect.Mutate: {
162307
- if (isRefValueType(place.identifier) || isUseRefType(place.identifier));
162367
+ if (isRefOrRefValue(place.identifier));
162308
162368
  else if (valueKind.kind === exports.ValueKind.Context) {
162309
162369
  functionEffect = {
162310
162370
  kind: 'ContextMutation',
@@ -162343,7 +162403,7 @@ class InferenceState {
162343
162403
  break;
162344
162404
  }
162345
162405
  case exports.Effect.Store: {
162346
- if (isRefValueType(place.identifier) || isUseRefType(place.identifier));
162406
+ if (isRefOrRefValue(place.identifier));
162347
162407
  else if (valueKind.kind === exports.ValueKind.Context) {
162348
162408
  functionEffect = {
162349
162409
  kind: 'ContextMutation',
@@ -164884,7 +164944,9 @@ function maybeAlias(aliases, lvalue, rvalue, id) {
164884
164944
  }
164885
164945
  }
164886
164946
  function infer$1(place, instrId) {
164887
- place.identifier.mutableRange.end = makeInstructionId(instrId + 1);
164947
+ if (!isRefOrRefValue(place.identifier)) {
164948
+ place.identifier.mutableRange.end = makeInstructionId(instrId + 1);
164949
+ }
164888
164950
  }
164889
164951
  function inferPlace(place, instrId, inferMutableRangeForStores) {
164890
164952
  switch (place.effect) {
@@ -164960,7 +165022,10 @@ function inferMutableLifetimes(func, inferMutableRangeForStores) {
164960
165022
  const declaration = contextVariableDeclarationInstructions.get(
164961
165023
  instr.value.lvalue.place.identifier
164962
165024
  );
164963
- if (declaration != null) {
165025
+ if (
165026
+ declaration != null &&
165027
+ !isRefOrRefValue(instr.value.lvalue.place.identifier)
165028
+ ) {
164964
165029
  const range = instr.value.lvalue.place.identifier.mutableRange;
164965
165030
  if (range.start === 0) {
164966
165031
  range.start = declaration;
@@ -164979,7 +165044,8 @@ function inferMutableRangesForAlias(_fn, aliases) {
164979
165044
  const aliasSets = aliases.buildSets();
164980
165045
  for (const aliasSet of aliasSets) {
164981
165046
  const mutatingIdentifiers = [...aliasSet].filter(
164982
- id => id.mutableRange.end - id.mutableRange.start > 1
165047
+ id =>
165048
+ id.mutableRange.end - id.mutableRange.start > 1 && !isRefOrRefValue(id)
164983
165049
  );
164984
165050
  if (mutatingIdentifiers.length > 0) {
164985
165051
  let lastMutatingInstructionId = 0;
@@ -164989,7 +165055,10 @@ function inferMutableRangesForAlias(_fn, aliases) {
164989
165055
  }
164990
165056
  }
164991
165057
  for (const alias of aliasSet) {
164992
- if (alias.mutableRange.end < lastMutatingInstructionId) {
165058
+ if (
165059
+ alias.mutableRange.end < lastMutatingInstructionId &&
165060
+ !isRefOrRefValue(alias)
165061
+ ) {
164993
165062
  alias.mutableRange.end = lastMutatingInstructionId;
164994
165063
  }
164995
165064
  }
@@ -165144,7 +165213,7 @@ function infer(loweredFunc, state, context) {
165144
165213
  } else {
165145
165214
  name = dep.identifier.name;
165146
165215
  }
165147
- if (isUseRefType(dep.identifier) || isRefValueType(dep.identifier)) {
165216
+ if (isRefOrRefValue(dep.identifier)) {
165148
165217
  dep.effect = exports.Effect.Capture;
165149
165218
  } else if (name !== null) {
165150
165219
  const effect = mutations.get(name.value);
@@ -167670,33 +167739,38 @@ function validateNoRefAccessInRender(fn) {
167670
167739
  validateNoRefAccessInRenderImpl(fn, refAccessingFunctions).unwrap();
167671
167740
  }
167672
167741
  function validateNoRefAccessInRenderImpl(fn, refAccessingFunctions) {
167742
+ var _a, _b, _c;
167673
167743
  const errors = new CompilerError();
167744
+ const lookupLocations = new Map();
167674
167745
  for (const [, block] of fn.body.blocks) {
167675
167746
  for (const instr of block.instructions) {
167676
167747
  switch (instr.value.kind) {
167677
167748
  case 'JsxExpression':
167678
167749
  case 'JsxFragment': {
167679
167750
  for (const operand of eachInstructionValueOperand(instr.value)) {
167680
- if (isRefValueType(operand.identifier)) {
167681
- errors.push({
167682
- severity: exports.ErrorSeverity.InvalidReact,
167683
- reason:
167684
- 'Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)',
167685
- loc: operand.loc,
167686
- description: `Cannot access ref value at ${printPlace(operand)}`,
167687
- suggestions: null,
167688
- });
167689
- }
167751
+ validateNoDirectRefValueAccess(errors, operand, lookupLocations);
167690
167752
  }
167691
167753
  break;
167692
167754
  }
167693
167755
  case 'PropertyLoad': {
167756
+ if (
167757
+ isRefValueType(instr.lvalue.identifier) &&
167758
+ instr.value.property === 'current'
167759
+ ) {
167760
+ lookupLocations.set(instr.lvalue.identifier.id, instr.loc);
167761
+ }
167694
167762
  break;
167695
167763
  }
167696
167764
  case 'LoadLocal': {
167697
167765
  if (refAccessingFunctions.has(instr.value.place.identifier.id)) {
167698
167766
  refAccessingFunctions.add(instr.lvalue.identifier.id);
167699
167767
  }
167768
+ if (isRefValueType(instr.lvalue.identifier)) {
167769
+ const loc = lookupLocations.get(instr.value.place.identifier.id);
167770
+ if (loc !== undefined) {
167771
+ lookupLocations.set(instr.lvalue.identifier.id, loc);
167772
+ }
167773
+ }
167700
167774
  break;
167701
167775
  }
167702
167776
  case 'StoreLocal': {
@@ -167704,6 +167778,13 @@ function validateNoRefAccessInRenderImpl(fn, refAccessingFunctions) {
167704
167778
  refAccessingFunctions.add(instr.value.lvalue.place.identifier.id);
167705
167779
  refAccessingFunctions.add(instr.lvalue.identifier.id);
167706
167780
  }
167781
+ if (isRefValueType(instr.value.lvalue.place.identifier)) {
167782
+ const loc = lookupLocations.get(instr.value.value.identifier.id);
167783
+ if (loc !== undefined) {
167784
+ lookupLocations.set(instr.value.lvalue.place.identifier.id, loc);
167785
+ lookupLocations.set(instr.lvalue.identifier.id, loc);
167786
+ }
167787
+ }
167707
167788
  break;
167708
167789
  }
167709
167790
  case 'ObjectMethod':
@@ -167749,7 +167830,11 @@ function validateNoRefAccessInRenderImpl(fn, refAccessingFunctions) {
167749
167830
  reason:
167750
167831
  'This function accesses a ref value (the `current` property), which may not be accessed during render. (https://react.dev/reference/react/useRef)',
167751
167832
  loc: callee.loc,
167752
- description: `Function ${printPlace(callee)} accesses a ref`,
167833
+ description:
167834
+ callee.identifier.name !== null &&
167835
+ callee.identifier.name.kind === 'named'
167836
+ ? `Function \`${callee.identifier.name.value}\` accesses a ref`
167837
+ : null,
167753
167838
  suggestions: null,
167754
167839
  });
167755
167840
  }
@@ -167758,7 +167843,10 @@ function validateNoRefAccessInRenderImpl(fn, refAccessingFunctions) {
167758
167843
  errors,
167759
167844
  refAccessingFunctions,
167760
167845
  operand,
167761
- operand.loc
167846
+ (_a = lookupLocations.get(operand.identifier.id)) !== null &&
167847
+ _a !== void 0
167848
+ ? _a
167849
+ : operand.loc
167762
167850
  );
167763
167851
  }
167764
167852
  }
@@ -167771,7 +167859,10 @@ function validateNoRefAccessInRenderImpl(fn, refAccessingFunctions) {
167771
167859
  errors,
167772
167860
  refAccessingFunctions,
167773
167861
  operand,
167774
- operand.loc
167862
+ (_b = lookupLocations.get(operand.identifier.id)) !== null &&
167863
+ _b !== void 0
167864
+ ? _b
167865
+ : operand.loc
167775
167866
  );
167776
167867
  }
167777
167868
  break;
@@ -167784,26 +167875,51 @@ function validateNoRefAccessInRenderImpl(fn, refAccessingFunctions) {
167784
167875
  errors,
167785
167876
  refAccessingFunctions,
167786
167877
  instr.value.object,
167787
- instr.loc
167878
+ (_c = lookupLocations.get(instr.value.object.identifier.id)) !==
167879
+ null && _c !== void 0
167880
+ ? _c
167881
+ : instr.loc
167788
167882
  );
167789
167883
  for (const operand of eachInstructionValueOperand(instr.value)) {
167790
167884
  if (operand === instr.value.object) {
167791
167885
  continue;
167792
167886
  }
167793
- validateNoRefValueAccess(errors, refAccessingFunctions, operand);
167887
+ validateNoRefValueAccess(
167888
+ errors,
167889
+ refAccessingFunctions,
167890
+ lookupLocations,
167891
+ operand
167892
+ );
167794
167893
  }
167795
167894
  break;
167796
167895
  }
167896
+ case 'StartMemoize':
167897
+ case 'FinishMemoize':
167898
+ break;
167797
167899
  default: {
167798
167900
  for (const operand of eachInstructionValueOperand(instr.value)) {
167799
- validateNoRefValueAccess(errors, refAccessingFunctions, operand);
167901
+ validateNoRefValueAccess(
167902
+ errors,
167903
+ refAccessingFunctions,
167904
+ lookupLocations,
167905
+ operand
167906
+ );
167800
167907
  }
167801
167908
  break;
167802
167909
  }
167803
167910
  }
167804
167911
  }
167805
167912
  for (const operand of eachTerminalOperand(block.terminal)) {
167806
- validateNoRefValueAccess(errors, refAccessingFunctions, operand);
167913
+ if (block.terminal.kind !== 'return') {
167914
+ validateNoRefValueAccess(
167915
+ errors,
167916
+ refAccessingFunctions,
167917
+ lookupLocations,
167918
+ operand
167919
+ );
167920
+ } else {
167921
+ validateNoDirectRefValueAccess(errors, operand, lookupLocations);
167922
+ }
167807
167923
  }
167808
167924
  }
167809
167925
  if (errors.hasErrors()) {
@@ -167812,7 +167928,13 @@ function validateNoRefAccessInRenderImpl(fn, refAccessingFunctions) {
167812
167928
  return Ok(undefined);
167813
167929
  }
167814
167930
  }
167815
- function validateNoRefValueAccess(errors, refAccessingFunctions, operand) {
167931
+ function validateNoRefValueAccess(
167932
+ errors,
167933
+ refAccessingFunctions,
167934
+ lookupLocations,
167935
+ operand
167936
+ ) {
167937
+ var _a;
167816
167938
  if (
167817
167939
  isRefValueType(operand.identifier) ||
167818
167940
  refAccessingFunctions.has(operand.identifier.id)
@@ -167821,16 +167943,23 @@ function validateNoRefValueAccess(errors, refAccessingFunctions, operand) {
167821
167943
  severity: exports.ErrorSeverity.InvalidReact,
167822
167944
  reason:
167823
167945
  'Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)',
167824
- loc: operand.loc,
167825
- description: `Cannot access ref value at ${printPlace(operand)}`,
167946
+ loc:
167947
+ (_a = lookupLocations.get(operand.identifier.id)) !== null &&
167948
+ _a !== void 0
167949
+ ? _a
167950
+ : operand.loc,
167951
+ description:
167952
+ operand.identifier.name !== null &&
167953
+ operand.identifier.name.kind === 'named'
167954
+ ? `Cannot access ref value \`${operand.identifier.name.value}\``
167955
+ : null,
167826
167956
  suggestions: null,
167827
167957
  });
167828
167958
  }
167829
167959
  }
167830
167960
  function validateNoRefAccess(errors, refAccessingFunctions, operand, loc) {
167831
167961
  if (
167832
- isRefValueType(operand.identifier) ||
167833
- isUseRefType(operand.identifier) ||
167962
+ isRefOrRefValue(operand.identifier) ||
167834
167963
  refAccessingFunctions.has(operand.identifier.id)
167835
167964
  ) {
167836
167965
  errors.push({
@@ -167847,6 +167976,27 @@ function validateNoRefAccess(errors, refAccessingFunctions, operand, loc) {
167847
167976
  });
167848
167977
  }
167849
167978
  }
167979
+ function validateNoDirectRefValueAccess(errors, operand, lookupLocations) {
167980
+ var _a;
167981
+ if (isRefValueType(operand.identifier)) {
167982
+ errors.push({
167983
+ severity: exports.ErrorSeverity.InvalidReact,
167984
+ reason:
167985
+ 'Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)',
167986
+ loc:
167987
+ (_a = lookupLocations.get(operand.identifier.id)) !== null &&
167988
+ _a !== void 0
167989
+ ? _a
167990
+ : operand.loc,
167991
+ description:
167992
+ operand.identifier.name !== null &&
167993
+ operand.identifier.name.kind === 'named'
167994
+ ? `Cannot access ref value \`${operand.identifier.name.value}\``
167995
+ : null,
167996
+ suggestions: null,
167997
+ });
167998
+ }
167999
+ }
167850
168000
  function validateNoSetStateInRender(fn) {
167851
168001
  const unconditionalSetStateFunctions = new Set();
167852
168002
  validateNoSetStateInRenderImpl(fn, unconditionalSetStateFunctions).unwrap();
@@ -169443,27 +169593,17 @@ function suppressionsToCompilerError(suppressionRanges) {
169443
169593
  }
169444
169594
  return error;
169445
169595
  }
169596
+ const OPT_IN_DIRECTIVES = new Set(['use forget', 'use memo']);
169597
+ const OPT_OUT_DIRECTIVES = new Set(['use no forget', 'use no memo']);
169446
169598
  function findDirectiveEnablingMemoization(directives) {
169447
- for (const directive of directives) {
169448
- const directiveValue = directive.value.value;
169449
- if (directiveValue === 'use forget' || directiveValue === 'use memo') {
169450
- return directive;
169451
- }
169452
- }
169453
- return null;
169599
+ return directives.filter(directive =>
169600
+ OPT_IN_DIRECTIVES.has(directive.value.value)
169601
+ );
169454
169602
  }
169455
- function findDirectiveDisablingMemoization(directives, options) {
169456
- for (const directive of directives) {
169457
- const directiveValue = directive.value.value;
169458
- if (
169459
- (directiveValue === 'use no forget' ||
169460
- directiveValue === 'use no memo') &&
169461
- !options.ignoreUseNoForget
169462
- ) {
169463
- return directive;
169464
- }
169465
- }
169466
- return null;
169603
+ function findDirectiveDisablingMemoization(directives) {
169604
+ return directives.filter(directive =>
169605
+ OPT_OUT_DIRECTIVES.has(directive.value.value)
169606
+ );
169467
169607
  }
169468
169608
  function isCriticalError(err) {
169469
169609
  return !(err instanceof CompilerError) || err.isCritical();
@@ -169476,7 +169616,7 @@ function isConfigError(err) {
169476
169616
  }
169477
169617
  return false;
169478
169618
  }
169479
- function handleError(err, pass, fnLoc) {
169619
+ function logError(err, pass, fnLoc) {
169480
169620
  var _a, _b;
169481
169621
  if (pass.opts.logger) {
169482
169622
  if (err instanceof CompilerError) {
@@ -169506,6 +169646,9 @@ function handleError(err, pass, fnLoc) {
169506
169646
  });
169507
169647
  }
169508
169648
  }
169649
+ }
169650
+ function handleError(err, pass, fnLoc) {
169651
+ logError(err, pass, fnLoc);
169509
169652
  if (
169510
169653
  pass.opts.panicThreshold === 'all_errors' ||
169511
169654
  (pass.opts.panicThreshold === 'critical_errors' && isCriticalError(err)) ||
@@ -169627,23 +169770,11 @@ function isFilePartOfSources(sources, filename) {
169627
169770
  return false;
169628
169771
  }
169629
169772
  function compileProgram(program, pass) {
169630
- var _a, _b, _c, _d;
169773
+ var _a, _b, _c;
169631
169774
  if (shouldSkipCompilation(program, pass)) {
169632
169775
  return;
169633
169776
  }
169634
- const environmentResult = parseEnvironmentConfig(
169635
- (_a = pass.opts.environment) !== null && _a !== void 0 ? _a : {}
169636
- );
169637
- if (environmentResult.isErr()) {
169638
- CompilerError.throwInvalidConfig({
169639
- reason:
169640
- 'Error in validating environment config. This is an advanced setting and not meant to be used directly',
169641
- description: environmentResult.unwrapErr().toString(),
169642
- suggestions: null,
169643
- loc: null,
169644
- });
169645
- }
169646
- const environment = environmentResult.unwrap();
169777
+ const environment = pass.opts.environment;
169647
169778
  const restrictedImportsErr = validateRestrictedImports(program, environment);
169648
169779
  if (restrictedImportsErr) {
169649
169780
  handleError(restrictedImportsErr, pass, null);
@@ -169651,13 +169782,13 @@ function compileProgram(program, pass) {
169651
169782
  }
169652
169783
  const useMemoCacheIdentifier = program.scope.generateUidIdentifier('c');
169653
169784
  const moduleName =
169654
- (_b = pass.opts.runtimeModule) !== null && _b !== void 0
169655
- ? _b
169785
+ (_a = pass.opts.runtimeModule) !== null && _a !== void 0
169786
+ ? _a
169656
169787
  : 'react/compiler-runtime';
169657
169788
  const suppressions = findProgramSuppressions(
169658
169789
  pass.comments,
169659
- (_c = pass.opts.eslintSuppressionRules) !== null && _c !== void 0
169660
- ? _c
169790
+ (_b = pass.opts.eslintSuppressionRules) !== null && _b !== void 0
169791
+ ? _b
169661
169792
  : DEFAULT_ESLINT_SUPPRESSIONS,
169662
169793
  pass.opts.flowSuppressions
169663
169794
  );
@@ -169690,22 +169821,40 @@ function compileProgram(program, pass) {
169690
169821
  },
169691
169822
  Object.assign(Object.assign({}, pass), {
169692
169823
  opts: Object.assign(Object.assign({}, pass.opts), pass.opts),
169693
- filename: (_d = pass.filename) !== null && _d !== void 0 ? _d : null,
169824
+ filename: (_c = pass.filename) !== null && _c !== void 0 ? _c : null,
169694
169825
  })
169695
169826
  );
169696
169827
  const processFn = (fn, fnType) => {
169697
- var _a, _b, _c, _d, _e, _f;
169828
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
169829
+ let optInDirectives = [];
169830
+ let optOutDirectives = [];
169831
+ if (fn.node.body.type === 'BlockStatement') {
169832
+ optInDirectives = findDirectiveEnablingMemoization(
169833
+ fn.node.body.directives
169834
+ );
169835
+ optOutDirectives = findDirectiveDisablingMemoization(
169836
+ fn.node.body.directives
169837
+ );
169838
+ }
169698
169839
  if (lintError != null) {
169699
169840
  const suppressionsInFunction = filterSuppressionsThatAffectFunction(
169700
169841
  suppressions,
169701
169842
  fn
169702
169843
  );
169703
169844
  if (suppressionsInFunction.length > 0) {
169704
- handleError(
169705
- lintError,
169706
- pass,
169707
- (_a = fn.node.loc) !== null && _a !== void 0 ? _a : null
169708
- );
169845
+ if (optOutDirectives.length > 0) {
169846
+ logError(
169847
+ lintError,
169848
+ pass,
169849
+ (_a = fn.node.loc) !== null && _a !== void 0 ? _a : null
169850
+ );
169851
+ } else {
169852
+ handleError(
169853
+ lintError,
169854
+ pass,
169855
+ (_b = fn.node.loc) !== null && _b !== void 0 ? _b : null
169856
+ );
169857
+ }
169709
169858
  }
169710
169859
  }
169711
169860
  let compiledFn;
@@ -169719,17 +169868,17 @@ function compileProgram(program, pass) {
169719
169868
  pass.filename,
169720
169869
  pass.code
169721
169870
  );
169722
- (_b = pass.opts.logger) === null || _b === void 0
169871
+ (_c = pass.opts.logger) === null || _c === void 0
169723
169872
  ? void 0
169724
- : _b.logEvent(pass.filename, {
169873
+ : _c.logEvent(pass.filename, {
169725
169874
  kind: 'CompileSuccess',
169726
- fnLoc: (_c = fn.node.loc) !== null && _c !== void 0 ? _c : null,
169875
+ fnLoc: (_d = fn.node.loc) !== null && _d !== void 0 ? _d : null,
169727
169876
  fnName:
169728
- (_e =
169729
- (_d = compiledFn.id) === null || _d === void 0
169877
+ (_f =
169878
+ (_e = compiledFn.id) === null || _e === void 0
169730
169879
  ? void 0
169731
- : _d.name) !== null && _e !== void 0
169732
- ? _e
169880
+ : _e.name) !== null && _f !== void 0
169881
+ ? _f
169733
169882
  : null,
169734
169883
  memoSlots: compiledFn.memoSlotsUsed,
169735
169884
  memoBlocks: compiledFn.memoBlocks,
@@ -169738,14 +169887,43 @@ function compileProgram(program, pass) {
169738
169887
  prunedMemoValues: compiledFn.prunedMemoValues,
169739
169888
  });
169740
169889
  } catch (err) {
169890
+ if (fn.node.body.type === 'BlockStatement') {
169891
+ if (optOutDirectives.length > 0) {
169892
+ logError(
169893
+ err,
169894
+ pass,
169895
+ (_g = fn.node.loc) !== null && _g !== void 0 ? _g : null
169896
+ );
169897
+ return null;
169898
+ }
169899
+ }
169741
169900
  hasCriticalError || (hasCriticalError = isCriticalError(err));
169742
169901
  handleError(
169743
169902
  err,
169744
169903
  pass,
169745
- (_f = fn.node.loc) !== null && _f !== void 0 ? _f : null
169904
+ (_h = fn.node.loc) !== null && _h !== void 0 ? _h : null
169746
169905
  );
169747
169906
  return null;
169748
169907
  }
169908
+ if (optInDirectives.length > 0) {
169909
+ return compiledFn;
169910
+ } else if (pass.opts.compilationMode === 'annotation') {
169911
+ return null;
169912
+ }
169913
+ if (pass.opts.ignoreUseNoForget === false && optOutDirectives.length > 0) {
169914
+ for (const directive of optOutDirectives) {
169915
+ (_j = pass.opts.logger) === null || _j === void 0
169916
+ ? void 0
169917
+ : _j.logEvent(pass.filename, {
169918
+ kind: 'CompileSkip',
169919
+ fnLoc:
169920
+ (_k = fn.node.body.loc) !== null && _k !== void 0 ? _k : null,
169921
+ reason: `Skipped due to '${directive.value.value}' directive.`,
169922
+ loc: (_l = directive.loc) !== null && _l !== void 0 ? _l : null,
169923
+ });
169924
+ }
169925
+ return null;
169926
+ }
169749
169927
  if (!pass.opts.noEmit && !hasCriticalError) {
169750
169928
  return compiledFn;
169751
169929
  }
@@ -169782,6 +169960,12 @@ function compileProgram(program, pass) {
169782
169960
  originalFn: current.fn,
169783
169961
  });
169784
169962
  }
169963
+ const moduleScopeOptOutDirectives = findDirectiveDisablingMemoization(
169964
+ program.node.directives
169965
+ );
169966
+ if (moduleScopeOptOutDirectives.length > 0) {
169967
+ return;
169968
+ }
169785
169969
  if (pass.opts.gating != null) {
169786
169970
  const error = checkFunctionReferencedBeforeDeclarationAtTopLevel(
169787
169971
  program,
@@ -169854,7 +170038,7 @@ function compileProgram(program, pass) {
169854
170038
  }
169855
170039
  }
169856
170040
  function shouldSkipCompilation(program, pass) {
169857
- var _a, _b, _c;
170041
+ var _a;
169858
170042
  if (pass.opts.sources) {
169859
170043
  if (pass.filename === null) {
169860
170044
  const error = new CompilerError();
@@ -169874,28 +170058,9 @@ function shouldSkipCompilation(program, pass) {
169874
170058
  return true;
169875
170059
  }
169876
170060
  }
169877
- const useNoForget = findDirectiveDisablingMemoization(
169878
- program.node.directives,
169879
- pass.opts
169880
- );
169881
- if (useNoForget != null) {
169882
- (_a = pass.opts.logger) === null || _a === void 0
169883
- ? void 0
169884
- : _a.logEvent(pass.filename, {
169885
- kind: 'CompileError',
169886
- fnLoc: null,
169887
- detail: {
169888
- severity: exports.ErrorSeverity.Todo,
169889
- reason: 'Skipped due to "use no forget" directive.',
169890
- loc: (_b = useNoForget.loc) !== null && _b !== void 0 ? _b : null,
169891
- suggestions: null,
169892
- },
169893
- });
169894
- return true;
169895
- }
169896
170061
  const moduleName =
169897
- (_c = pass.opts.runtimeModule) !== null && _c !== void 0
169898
- ? _c
170062
+ (_a = pass.opts.runtimeModule) !== null && _a !== void 0
170063
+ ? _a
169899
170064
  : 'react/compiler-runtime';
169900
170065
  if (hasMemoCacheFunctionImport(program, moduleName)) {
169901
170066
  return true;
@@ -169903,35 +170068,14 @@ function shouldSkipCompilation(program, pass) {
169903
170068
  return false;
169904
170069
  }
169905
170070
  function getReactFunctionType(fn, pass, environment) {
169906
- var _a, _b, _c, _d, _e;
170071
+ var _a, _b;
169907
170072
  const hookPattern = environment.hookPattern;
169908
170073
  if (fn.node.body.type === 'BlockStatement') {
169909
- const useNoForget = findDirectiveDisablingMemoization(
169910
- fn.node.body.directives,
169911
- pass.opts
169912
- );
169913
- if (useNoForget != null) {
169914
- (_a = pass.opts.logger) === null || _a === void 0
169915
- ? void 0
169916
- : _a.logEvent(pass.filename, {
169917
- kind: 'CompileError',
169918
- fnLoc:
169919
- (_b = fn.node.body.loc) !== null && _b !== void 0 ? _b : null,
169920
- detail: {
169921
- severity: exports.ErrorSeverity.Todo,
169922
- reason: 'Skipped due to "use no forget" directive.',
169923
- loc: (_c = useNoForget.loc) !== null && _c !== void 0 ? _c : null,
169924
- suggestions: null,
169925
- },
169926
- });
169927
- return null;
169928
- }
169929
- if (findDirectiveEnablingMemoization(fn.node.body.directives) != null) {
169930
- return (_d = getComponentOrHookLike(fn, hookPattern)) !== null &&
169931
- _d !== void 0
169932
- ? _d
170074
+ if (findDirectiveEnablingMemoization(fn.node.body.directives).length > 0)
170075
+ return (_a = getComponentOrHookLike(fn, hookPattern)) !== null &&
170076
+ _a !== void 0
170077
+ ? _a
169933
170078
  : 'Other';
169934
- }
169935
170079
  }
169936
170080
  let componentSyntaxType = null;
169937
170081
  if (fn.isFunctionDeclaration()) {
@@ -169957,9 +170101,9 @@ function getReactFunctionType(fn, pass, environment) {
169957
170101
  if (fn.scope.getProgramParent() !== fn.scope.parent) {
169958
170102
  return null;
169959
170103
  }
169960
- return (_e = getComponentOrHookLike(fn, hookPattern)) !== null &&
169961
- _e !== void 0
169962
- ? _e
170104
+ return (_b = getComponentOrHookLike(fn, hookPattern)) !== null &&
170105
+ _b !== void 0
170106
+ ? _b
169963
170107
  : 'Other';
169964
170108
  }
169965
170109
  default: {
@@ -170363,6 +170507,7 @@ function runBabelPluginReactCompiler(
170363
170507
  }
170364
170508
  exports.CompilerError = CompilerError;
170365
170509
  exports.CompilerErrorDetail = CompilerErrorDetail;
170510
+ exports.OPT_OUT_DIRECTIVES = OPT_OUT_DIRECTIVES;
170366
170511
  exports.compile = compileFn;
170367
170512
  exports.compileProgram = compileProgram;
170368
170513
  exports.default = BabelPluginReactCompiler;