babel-plugin-react-compiler 0.0.0-experimental-e504e66-20241010 → 0.0.0-experimental-fa06e2c-20241014

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
@@ -111685,12 +111685,34 @@ var parse$1 = function parse(text, reviver) {
111685
111685
  function internalize(holder, name, reviver) {
111686
111686
  const value = holder[name];
111687
111687
  if (value != null && typeof value === 'object') {
111688
- for (const key in value) {
111689
- const replacement = internalize(value, key, reviver);
111690
- if (replacement === undefined) {
111691
- delete value[key];
111692
- } else {
111693
- value[key] = replacement;
111688
+ if (Array.isArray(value)) {
111689
+ for (let i = 0; i < value.length; i++) {
111690
+ const key = String(i);
111691
+ const replacement = internalize(value, key, reviver);
111692
+ if (replacement === undefined) {
111693
+ delete value[key];
111694
+ } else {
111695
+ Object.defineProperty(value, key, {
111696
+ value: replacement,
111697
+ writable: true,
111698
+ enumerable: true,
111699
+ configurable: true,
111700
+ });
111701
+ }
111702
+ }
111703
+ } else {
111704
+ for (const key in value) {
111705
+ const replacement = internalize(value, key, reviver);
111706
+ if (replacement === undefined) {
111707
+ delete value[key];
111708
+ } else {
111709
+ Object.defineProperty(value, key, {
111710
+ value: replacement,
111711
+ writable: true,
111712
+ enumerable: true,
111713
+ configurable: true,
111714
+ });
111715
+ }
111694
111716
  }
111695
111717
  }
111696
111718
  }
@@ -112383,7 +112405,12 @@ function push() {
112383
112405
  if (Array.isArray(parent)) {
112384
112406
  parent.push(value);
112385
112407
  } else {
112386
- parent[key] = value;
112408
+ Object.defineProperty(parent, key, {
112409
+ value: value,
112410
+ writable: true,
112411
+ enumerable: true,
112412
+ configurable: true,
112413
+ });
112387
112414
  }
112388
112415
  }
112389
112416
  if (value !== null && typeof value === 'object') {
@@ -124423,13 +124450,13 @@ function printInstruction(instr) {
124423
124450
  }
124424
124451
  function printPhi(phi) {
124425
124452
  const items = [];
124426
- items.push(printIdentifier(phi.id));
124427
- items.push(printMutableRange(phi.id));
124428
- items.push(printType(phi.id.type));
124453
+ items.push(printPlace(phi.place));
124454
+ items.push(printMutableRange(phi.place.identifier));
124455
+ items.push(printType(phi.place.identifier.type));
124429
124456
  items.push(': phi(');
124430
124457
  const phis = [];
124431
- for (const [blockId, id] of phi.operands) {
124432
- phis.push(`bb${blockId}: ${printIdentifier(id)}`);
124458
+ for (const [blockId, place] of phi.operands) {
124459
+ phis.push(`bb${blockId}: ${printPlace(place)}`);
124433
124460
  }
124434
124461
  items.push(phis.join(', '));
124435
124462
  items.push(')');
@@ -126167,9 +126194,9 @@ function assertConsistentIdentifiers(fn) {
126167
126194
  const assignments = new Set();
126168
126195
  for (const [, block] of fn.body.blocks) {
126169
126196
  for (const phi of block.phis) {
126170
- validate(identifiers, phi.id);
126197
+ validate(identifiers, phi.place.identifier);
126171
126198
  for (const [, operand] of phi.operands) {
126172
- validate(identifiers, operand);
126199
+ validate(identifiers, operand.identifier);
126173
126200
  }
126174
126201
  }
126175
126202
  for (const instr of block.instructions) {
@@ -126342,9 +126369,9 @@ function assertValidBlockNesting(fn) {
126342
126369
  function assertValidMutableRanges(fn) {
126343
126370
  for (const [, block] of fn.body.blocks) {
126344
126371
  for (const phi of block.phis) {
126345
- visitIdentifier(phi.id);
126372
+ visitIdentifier(phi.place.identifier);
126346
126373
  for (const [, operand] of phi.operands) {
126347
- visitIdentifier(operand);
126374
+ visitIdentifier(operand.identifier);
126348
126375
  }
126349
126376
  }
126350
126377
  for (const instr of block.instructions) {
@@ -135287,20 +135314,14 @@ function mergeConsecutiveBlocks(fn) {
135287
135314
  id: predecessor.terminal.id,
135288
135315
  lvalue: {
135289
135316
  kind: 'Identifier',
135290
- identifier: phi.id,
135317
+ identifier: phi.place.identifier,
135291
135318
  effect: exports.Effect.ConditionallyMutate,
135292
135319
  reactive: false,
135293
135320
  loc: GeneratedSource,
135294
135321
  },
135295
135322
  value: {
135296
135323
  kind: 'LoadLocal',
135297
- place: {
135298
- kind: 'Identifier',
135299
- identifier: operand,
135300
- effect: exports.Effect.Read,
135301
- reactive: false,
135302
- loc: GeneratedSource,
135303
- },
135324
+ place: Object.assign({}, operand),
135304
135325
  loc: GeneratedSource,
135305
135326
  },
135306
135327
  loc: GeneratedSource,
@@ -137226,8 +137247,9 @@ function findDisjointMutableValues(fn) {
137226
137247
  for (const [_, block] of fn.body.blocks) {
137227
137248
  for (const phi of block.phis) {
137228
137249
  if (
137229
- phi.id.mutableRange.start + 1 !== phi.id.mutableRange.end &&
137230
- phi.id.mutableRange.end >
137250
+ phi.place.identifier.mutableRange.start + 1 !==
137251
+ phi.place.identifier.mutableRange.end &&
137252
+ phi.place.identifier.mutableRange.end >
137231
137253
  ((_b =
137232
137254
  (_a = block.instructions.at(0)) === null || _a === void 0
137233
137255
  ? void 0
@@ -137235,18 +137257,20 @@ function findDisjointMutableValues(fn) {
137235
137257
  ? _b
137236
137258
  : block.terminal.id)
137237
137259
  ) {
137238
- const operands = [phi.id];
137239
- const declaration = declarations.get(phi.id.declarationId);
137260
+ const operands = [phi.place.identifier];
137261
+ const declaration = declarations.get(
137262
+ phi.place.identifier.declarationId
137263
+ );
137240
137264
  if (declaration !== undefined) {
137241
137265
  operands.push(declaration);
137242
137266
  }
137243
137267
  for (const [_, phiId] of phi.operands) {
137244
- operands.push(phiId);
137268
+ operands.push(phiId.identifier);
137245
137269
  }
137246
137270
  scopeIdentifiers.union(operands);
137247
137271
  } else if (fn.env.config.enableForest) {
137248
137272
  for (const [, phiId] of phi.operands) {
137249
- scopeIdentifiers.union([phi.id, phiId]);
137273
+ scopeIdentifiers.union([phi.place.identifier, phiId.identifier]);
137250
137274
  }
137251
137275
  }
137252
137276
  }
@@ -137938,26 +137962,18 @@ function eliminateRedundantPhi(fn, sharedRewrites) {
137938
137962
  }
137939
137963
  visited.add(blockId);
137940
137964
  phis: for (const phi of block.phis) {
137941
- phi.operands = new Map(
137942
- Array.from(phi.operands).map(([block, id]) => {
137943
- var _a;
137944
- return [
137945
- block,
137946
- (_a = rewrites.get(id)) !== null && _a !== void 0 ? _a : id,
137947
- ];
137948
- })
137949
- );
137965
+ phi.operands.forEach((place, _) => rewritePlace(place, rewrites));
137950
137966
  let same = null;
137951
137967
  for (const [_, operand] of phi.operands) {
137952
137968
  if (
137953
- (same !== null && operand.id === same.id) ||
137954
- operand.id === phi.id.id
137969
+ (same !== null && operand.identifier.id === same.id) ||
137970
+ operand.identifier.id === phi.place.identifier.id
137955
137971
  ) {
137956
137972
  continue;
137957
137973
  } else if (same !== null) {
137958
137974
  continue phis;
137959
137975
  } else {
137960
- same = operand;
137976
+ same = operand.identifier;
137961
137977
  }
137962
137978
  }
137963
137979
  CompilerError.invariant(same !== null, {
@@ -137966,7 +137982,7 @@ function eliminateRedundantPhi(fn, sharedRewrites) {
137966
137982
  loc: null,
137967
137983
  suggestions: null,
137968
137984
  });
137969
- rewrites.set(phi.id, same);
137985
+ rewrites.set(phi.place.identifier, same);
137970
137986
  block.phis.delete(phi);
137971
137987
  }
137972
137988
  for (const instr of block.instructions) {
@@ -138082,57 +138098,71 @@ class SSABuilder {
138082
138098
  }
138083
138099
  getPlace(oldPlace) {
138084
138100
  const newId = this.getIdAt(
138085
- oldPlace.identifier,
138101
+ oldPlace,
138086
138102
  __classPrivateFieldGet(this, _SSABuilder_current, 'f').id
138087
138103
  );
138088
138104
  return Object.assign(Object.assign({}, oldPlace), {identifier: newId});
138089
138105
  }
138090
- getIdAt(oldId, blockId) {
138106
+ getIdAt(oldPlace, blockId) {
138091
138107
  const block = __classPrivateFieldGet(this, _SSABuilder_blocks, 'f').get(
138092
138108
  blockId
138093
138109
  );
138094
138110
  const state = __classPrivateFieldGet(this, _SSABuilder_states, 'f').get(
138095
138111
  block
138096
138112
  );
138097
- if (state.defs.has(oldId)) {
138098
- return state.defs.get(oldId);
138113
+ if (state.defs.has(oldPlace.identifier)) {
138114
+ return state.defs.get(oldPlace.identifier);
138099
138115
  }
138100
138116
  if (block.preds.size == 0) {
138101
- __classPrivateFieldGet(this, _SSABuilder_unknown, 'f').add(oldId);
138102
- return oldId;
138117
+ __classPrivateFieldGet(this, _SSABuilder_unknown, 'f').add(
138118
+ oldPlace.identifier
138119
+ );
138120
+ return oldPlace.identifier;
138103
138121
  }
138104
138122
  if (this.unsealedPreds.get(block) > 0) {
138105
- const newId = this.makeId(oldId);
138106
- state.incompletePhis.push({oldId: oldId, newId: newId});
138107
- state.defs.set(oldId, newId);
138123
+ const newId = this.makeId(oldPlace.identifier);
138124
+ state.incompletePhis.push({
138125
+ oldPlace: oldPlace,
138126
+ newPlace: Object.assign(Object.assign({}, oldPlace), {
138127
+ identifier: newId,
138128
+ }),
138129
+ });
138130
+ state.defs.set(oldPlace.identifier, newId);
138108
138131
  return newId;
138109
138132
  }
138110
138133
  if (block.preds.size == 1) {
138111
138134
  const [pred] = block.preds;
138112
- const newId = this.getIdAt(oldId, pred);
138113
- state.defs.set(oldId, newId);
138135
+ const newId = this.getIdAt(oldPlace, pred);
138136
+ state.defs.set(oldPlace.identifier, newId);
138114
138137
  return newId;
138115
138138
  }
138116
- const newId = this.makeId(oldId);
138117
- state.defs.set(oldId, newId);
138118
- return this.addPhi(block, oldId, newId);
138139
+ const newId = this.makeId(oldPlace.identifier);
138140
+ state.defs.set(oldPlace.identifier, newId);
138141
+ return this.addPhi(
138142
+ block,
138143
+ oldPlace,
138144
+ Object.assign(Object.assign({}, oldPlace), {identifier: newId})
138145
+ );
138119
138146
  }
138120
- addPhi(block, oldId, newId) {
138147
+ addPhi(block, oldPlace, newPlace) {
138121
138148
  const predDefs = new Map();
138122
138149
  for (const predBlockId of block.preds) {
138123
- const predId = this.getIdAt(oldId, predBlockId);
138124
- predDefs.set(predBlockId, predId);
138150
+ const predId = this.getIdAt(oldPlace, predBlockId);
138151
+ predDefs.set(
138152
+ predBlockId,
138153
+ Object.assign(Object.assign({}, oldPlace), {identifier: predId})
138154
+ );
138125
138155
  }
138126
- const phi = {kind: 'Phi', id: newId, operands: predDefs};
138156
+ const phi = {kind: 'Phi', place: newPlace, operands: predDefs};
138127
138157
  block.phis.add(phi);
138128
- return newId;
138158
+ return newPlace.identifier;
138129
138159
  }
138130
138160
  fixIncompletePhis(block) {
138131
138161
  const state = __classPrivateFieldGet(this, _SSABuilder_states, 'f').get(
138132
138162
  block
138133
138163
  );
138134
138164
  for (const phi of state.incompletePhis) {
138135
- this.addPhi(block, phi.oldId, phi.newId);
138165
+ this.addPhi(block, phi.oldPlace, phi.newPlace);
138136
138166
  }
138137
138167
  }
138138
138168
  startBlock(block) {
@@ -138156,7 +138186,7 @@ class SSABuilder {
138156
138186
  }
138157
138187
  for (const incompletePhi of state.incompletePhis) {
138158
138188
  text.push(
138159
- ` iphi $${printIdentifier(incompletePhi.newId)} = $${printIdentifier(incompletePhi.oldId)}`
138189
+ ` iphi $${printPlace(incompletePhi.newPlace)} = $${printPlace(incompletePhi.oldPlace)}`
138160
138190
  );
138161
138191
  }
138162
138192
  }
@@ -138426,7 +138456,7 @@ function applyConstantPropagation(fn, constants) {
138426
138456
  for (const phi of block.phis) {
138427
138457
  let value = evaluatePhi(phi, constants);
138428
138458
  if (value !== null) {
138429
- constants.set(phi.id.id, value);
138459
+ constants.set(phi.place.identifier.id, value);
138430
138460
  }
138431
138461
  }
138432
138462
  for (let i = 0; i < block.instructions.length; i++) {
@@ -138467,7 +138497,9 @@ function evaluatePhi(phi, constants) {
138467
138497
  let value = null;
138468
138498
  for (const [, operand] of phi.operands) {
138469
138499
  const operandValue =
138470
- (_a = constants.get(operand.id)) !== null && _a !== void 0 ? _a : null;
138500
+ (_a = constants.get(operand.identifier.id)) !== null && _a !== void 0
138501
+ ? _a
138502
+ : null;
138471
138503
  if (operandValue === null) {
138472
138504
  return null;
138473
138505
  }
@@ -138800,7 +138832,7 @@ function deadCodeElimination(fn) {
138800
138832
  const state = findReferencedIdentifiers(fn);
138801
138833
  for (const [, block] of fn.body.blocks) {
138802
138834
  for (const phi of block.phis) {
138803
- if (!state.isIdOrNameUsed(phi.id)) {
138835
+ if (!state.isIdOrNameUsed(phi.place.identifier)) {
138804
138836
  block.phis.delete(phi);
138805
138837
  }
138806
138838
  }
@@ -138880,9 +138912,9 @@ function findReferencedIdentifiers(fn) {
138880
138912
  }
138881
138913
  }
138882
138914
  for (const phi of block.phis) {
138883
- if (state.isIdOrNameUsed(phi.id)) {
138915
+ if (state.isIdOrNameUsed(phi.place.identifier)) {
138884
138916
  for (const [_pred, operand] of phi.operands) {
138885
- state.reference(operand);
138917
+ state.reference(operand.identifier);
138886
138918
  }
138887
138919
  }
138888
138920
  }
@@ -139080,7 +139112,7 @@ function pruneMaybeThrows(fn) {
139080
139112
  CompilerError.invariant(mappedTerminal != null, {
139081
139113
  reason: `Expected non-existing phi operand's predecessor to have been mapped to a new terminal`,
139082
139114
  loc: GeneratedSource,
139083
- description: `Could not find mapping for predecessor bb${predecessor} in block bb${block.id} for phi ${printIdentifier(phi.id)}`,
139115
+ description: `Could not find mapping for predecessor bb${predecessor} in block bb${block.id} for phi ${printPlace(phi.place)}`,
139084
139116
  suggestions: null,
139085
139117
  });
139086
139118
  phi.operands.delete(predecessor);
@@ -147303,7 +147335,7 @@ class InferenceState {
147303
147335
  this,
147304
147336
  _InferenceState_variables,
147305
147337
  'f'
147306
- ).get(operand.id);
147338
+ ).get(operand.identifier.id);
147307
147339
  if (operandValues === undefined) continue;
147308
147340
  for (const v of operandValues) {
147309
147341
  values.add(v);
@@ -147311,7 +147343,7 @@ class InferenceState {
147311
147343
  }
147312
147344
  if (values.size > 0) {
147313
147345
  __classPrivateFieldGet(this, _InferenceState_variables, 'f').set(
147314
- phi.id.id,
147346
+ phi.place.identifier.id,
147315
147347
  values
147316
147348
  );
147317
147349
  }
@@ -149638,7 +149670,7 @@ function inferAliasForPhis(func, aliases) {
149638
149670
  for (const [_, block] of func.body.blocks) {
149639
149671
  for (const phi of block.phis) {
149640
149672
  const isPhiMutatedAfterCreation =
149641
- phi.id.mutableRange.end >
149673
+ phi.place.identifier.mutableRange.end >
149642
149674
  ((_b =
149643
149675
  (_a = block.instructions.at(0)) === null || _a === void 0
149644
149676
  ? void 0
@@ -149647,7 +149679,7 @@ function inferAliasForPhis(func, aliases) {
149647
149679
  : block.terminal.id);
149648
149680
  if (isPhiMutatedAfterCreation) {
149649
149681
  for (const [, operand] of phi.operands) {
149650
- aliases.union([phi.id, operand]);
149682
+ aliases.union([phi.place.identifier, operand.identifier]);
149651
149683
  }
149652
149684
  }
149653
149685
  }
@@ -149721,7 +149753,7 @@ function inferMutableLifetimes(func, inferMutableRangeForStores) {
149721
149753
  for (const [_, block] of func.body.blocks) {
149722
149754
  for (const phi of block.phis) {
149723
149755
  const isPhiMutatedAfterCreation =
149724
- phi.id.mutableRange.end >
149756
+ phi.place.identifier.mutableRange.end >
149725
149757
  ((_b =
149726
149758
  (_a = block.instructions.at(0)) === null || _a === void 0
149727
149759
  ? void 0
@@ -149731,14 +149763,18 @@ function inferMutableLifetimes(func, inferMutableRangeForStores) {
149731
149763
  if (
149732
149764
  inferMutableRangeForStores &&
149733
149765
  isPhiMutatedAfterCreation &&
149734
- phi.id.mutableRange.start === 0
149766
+ phi.place.identifier.mutableRange.start === 0
149735
149767
  ) {
149736
149768
  for (const [, operand] of phi.operands) {
149737
- if (phi.id.mutableRange.start === 0) {
149738
- phi.id.mutableRange.start = operand.mutableRange.start;
149769
+ if (phi.place.identifier.mutableRange.start === 0) {
149770
+ phi.place.identifier.mutableRange.start =
149771
+ operand.identifier.mutableRange.start;
149739
149772
  } else {
149740
- phi.id.mutableRange.start = makeInstructionId(
149741
- Math.min(phi.id.mutableRange.start, operand.mutableRange.start)
149773
+ phi.place.identifier.mutableRange.start = makeInstructionId(
149774
+ Math.min(
149775
+ phi.place.identifier.mutableRange.start,
149776
+ operand.identifier.mutableRange.start
149777
+ )
149742
149778
  );
149743
149779
  }
149744
149780
  }
@@ -150335,7 +150371,6 @@ function findOptionalPlaces(fn) {
150335
150371
  return optionals;
150336
150372
  }
150337
150373
  function inferReactivePlaces(fn) {
150338
- var _a;
150339
150374
  const reactiveIdentifiers = new ReactivityMap(findDisjointMutableValues(fn));
150340
150375
  for (const param of fn.params) {
150341
150376
  const place = param.kind === 'Identifier' ? param : param.place;
@@ -150380,26 +150415,25 @@ function inferReactivePlaces(fn) {
150380
150415
  return false;
150381
150416
  }
150382
150417
  do {
150383
- const identifierMapping = new Map();
150384
150418
  for (const [, block] of fn.body.blocks) {
150385
150419
  let hasReactiveControl = isReactiveControlledBlock(block.id);
150386
150420
  for (const phi of block.phis) {
150387
- if (reactiveIdentifiers.isReactiveIdentifier(phi.id)) {
150421
+ if (reactiveIdentifiers.isReactive(phi.place)) {
150388
150422
  continue;
150389
150423
  }
150390
150424
  let isPhiReactive = false;
150391
150425
  for (const [, operand] of phi.operands) {
150392
- if (reactiveIdentifiers.isReactiveIdentifier(operand)) {
150426
+ if (reactiveIdentifiers.isReactive(operand)) {
150393
150427
  isPhiReactive = true;
150394
150428
  break;
150395
150429
  }
150396
150430
  }
150397
150431
  if (isPhiReactive) {
150398
- reactiveIdentifiers.markReactiveIdentifier(phi.id);
150432
+ reactiveIdentifiers.markReactive(phi.place);
150399
150433
  } else {
150400
150434
  for (const [pred] of phi.operands) {
150401
150435
  if (isReactiveControlledBlock(pred)) {
150402
- reactiveIdentifiers.markReactiveIdentifier(phi.id);
150436
+ reactiveIdentifiers.markReactive(phi.place);
150403
150437
  break;
150404
150438
  }
150405
150439
  }
@@ -150441,10 +150475,6 @@ function inferReactivePlaces(fn) {
150441
150475
  case exports.Effect.ConditionallyMutate:
150442
150476
  case exports.Effect.Mutate: {
150443
150477
  if (isMutable(instruction, operand)) {
150444
- const resolvedId = identifierMapping.get(operand.identifier);
150445
- if (resolvedId !== undefined) {
150446
- reactiveIdentifiers.markReactiveIdentifier(resolvedId);
150447
- }
150448
150478
  reactiveIdentifiers.markReactive(operand);
150449
150479
  }
150450
150480
  break;
@@ -150470,32 +150500,6 @@ function inferReactivePlaces(fn) {
150470
150500
  }
150471
150501
  }
150472
150502
  }
150473
- switch (value.kind) {
150474
- case 'LoadLocal': {
150475
- identifierMapping.set(
150476
- instruction.lvalue.identifier,
150477
- value.place.identifier
150478
- );
150479
- break;
150480
- }
150481
- case 'PropertyLoad':
150482
- case 'ComputedLoad': {
150483
- const resolvedId =
150484
- (_a = identifierMapping.get(value.object.identifier)) !== null &&
150485
- _a !== void 0
150486
- ? _a
150487
- : value.object.identifier;
150488
- identifierMapping.set(instruction.lvalue.identifier, resolvedId);
150489
- break;
150490
- }
150491
- case 'LoadContext': {
150492
- identifierMapping.set(
150493
- instruction.lvalue.identifier,
150494
- value.place.identifier
150495
- );
150496
- break;
150497
- }
150498
- }
150499
150503
  }
150500
150504
  for (const operand of eachTerminalOperand(block.terminal)) {
150501
150505
  reactiveIdentifiers.isReactive(operand);
@@ -150551,32 +150555,26 @@ class ReactivityMap {
150551
150555
  this.aliasedIdentifiers = aliasedIdentifiers;
150552
150556
  }
150553
150557
  isReactive(place) {
150554
- const reactive = this.isReactiveIdentifier(place.identifier);
150555
- if (reactive) {
150556
- place.reactive = true;
150557
- }
150558
- return reactive;
150559
- }
150560
- isReactiveIdentifier(inputIdentifier) {
150561
150558
  var _a;
150562
150559
  const identifier =
150563
- (_a = this.aliasedIdentifiers.find(inputIdentifier)) !== null &&
150560
+ (_a = this.aliasedIdentifiers.find(place.identifier)) !== null &&
150564
150561
  _a !== void 0
150565
150562
  ? _a
150566
- : inputIdentifier;
150567
- return this.reactive.has(identifier.id);
150563
+ : place.identifier;
150564
+ const reactive = this.reactive.has(identifier.id);
150565
+ if (reactive) {
150566
+ place.reactive = true;
150567
+ }
150568
+ return reactive;
150568
150569
  }
150569
150570
  markReactive(place) {
150570
- place.reactive = true;
150571
- this.markReactiveIdentifier(place.identifier);
150572
- }
150573
- markReactiveIdentifier(inputIdentifier) {
150574
150571
  var _a;
150572
+ place.reactive = true;
150575
150573
  const identifier =
150576
- (_a = this.aliasedIdentifiers.find(inputIdentifier)) !== null &&
150574
+ (_a = this.aliasedIdentifiers.find(place.identifier)) !== null &&
150577
150575
  _a !== void 0
150578
150576
  ? _a
150579
- : inputIdentifier;
150577
+ : place.identifier;
150580
150578
  if (!this.reactive.has(identifier.id)) {
150581
150579
  this.hasChanges = true;
150582
150580
  this.reactive.add(identifier.id);
@@ -151606,7 +151604,7 @@ function inferTypes(func) {
151606
151604
  function apply(func, unifier) {
151607
151605
  for (const [_, block] of func.body.blocks) {
151608
151606
  for (const phi of block.phis) {
151609
- phi.id.type = unifier.get(phi.id.type);
151607
+ phi.place.identifier.type = unifier.get(phi.place.identifier.type);
151610
151608
  }
151611
151609
  for (const instr of block.instructions) {
151612
151610
  for (const operand of eachInstructionLValue(instr)) {
@@ -151650,9 +151648,9 @@ function* generate(func) {
151650
151648
  const returnTypes = [];
151651
151649
  for (const [_, block] of func.body.blocks) {
151652
151650
  for (const phi of block.phis) {
151653
- yield equation(phi.id.type, {
151651
+ yield equation(phi.place.identifier.type, {
151654
151652
  kind: 'Phi',
151655
- operands: [...phi.operands.values()].map(id => id.type),
151653
+ operands: [...phi.operands.values()].map(id => id.identifier.type),
151656
151654
  });
151657
151655
  }
151658
151656
  for (const instr of block.instructions) {
@@ -152321,16 +152319,17 @@ function validateHooksUsage(fn) {
152321
152319
  for (const [, block] of fn.body.blocks) {
152322
152320
  for (const phi of block.phis) {
152323
152321
  let kind =
152324
- phi.id.name !== null && isHookName$1(phi.id.name.value)
152322
+ phi.place.identifier.name !== null &&
152323
+ isHookName$1(phi.place.identifier.name.value)
152325
152324
  ? Kind.PotentialHook
152326
152325
  : Kind.Local;
152327
152326
  for (const [, operand] of phi.operands) {
152328
- const operandKind = valueKinds.get(operand.id);
152327
+ const operandKind = valueKinds.get(operand.identifier.id);
152329
152328
  if (operandKind !== undefined) {
152330
152329
  kind = joinKinds(kind, operandKind);
152331
152330
  }
152332
152331
  }
152333
- valueKinds.set(phi.id.id, kind);
152332
+ valueKinds.set(phi.place.identifier.id, kind);
152334
152333
  }
152335
152334
  for (const instr of block.instructions) {
152336
152335
  switch (instr.value.kind) {
@@ -152664,6 +152663,19 @@ function validateNoCapitalizedCalls(fn) {
152664
152663
  }
152665
152664
  }
152666
152665
  var _Env_changed;
152666
+ function makeRefId(id) {
152667
+ CompilerError.invariant(id >= 0 && Number.isInteger(id), {
152668
+ reason: 'Expected identifier id to be a non-negative integer',
152669
+ description: null,
152670
+ loc: null,
152671
+ suggestions: null,
152672
+ });
152673
+ return id;
152674
+ }
152675
+ let _refId = 0;
152676
+ function nextRefId() {
152677
+ return makeRefId(_refId++);
152678
+ }
152667
152679
  class Env extends Map {
152668
152680
  constructor() {
152669
152681
  super(...arguments);
@@ -152695,11 +152707,11 @@ function validateNoRefAccessInRender(fn) {
152695
152707
  const env = new Env();
152696
152708
  validateNoRefAccessInRenderImpl(fn, env).unwrap();
152697
152709
  }
152698
- function refTypeOfType(identifier) {
152699
- if (isRefValueType(identifier)) {
152710
+ function refTypeOfType(place) {
152711
+ if (isRefValueType(place.identifier)) {
152700
152712
  return {kind: 'RefValue'};
152701
- } else if (isUseRefType(identifier)) {
152702
- return {kind: 'Ref'};
152713
+ } else if (isUseRefType(place.identifier)) {
152714
+ return {kind: 'Ref', refId: nextRefId()};
152703
152715
  } else {
152704
152716
  return {kind: 'None'};
152705
152717
  }
@@ -152713,6 +152725,14 @@ function tyEqual(a, b) {
152713
152725
  return true;
152714
152726
  case 'Ref':
152715
152727
  return true;
152728
+ case 'Nullable':
152729
+ return true;
152730
+ case 'Guard':
152731
+ CompilerError.invariant(b.kind === 'Guard', {
152732
+ reason: 'Expected ref value',
152733
+ loc: null,
152734
+ });
152735
+ return a.refId === b.refId;
152716
152736
  case 'RefValue':
152717
152737
  CompilerError.invariant(b.kind === 'RefValue', {
152718
152738
  reason: 'Expected ref value',
@@ -152741,11 +152761,17 @@ function tyEqual(a, b) {
152741
152761
  function joinRefAccessTypes(...types) {
152742
152762
  function joinRefAccessRefTypes(a, b) {
152743
152763
  if (a.kind === 'RefValue') {
152744
- return a;
152764
+ if (b.kind === 'RefValue' && a.refId === b.refId) {
152765
+ return a;
152766
+ }
152767
+ return {kind: 'RefValue'};
152745
152768
  } else if (b.kind === 'RefValue') {
152746
152769
  return b;
152747
152770
  } else if (a.kind === 'Ref' || b.kind === 'Ref') {
152748
- return {kind: 'Ref'};
152771
+ if (a.kind === 'Ref' && b.kind === 'Ref' && a.refId === b.refId) {
152772
+ return a;
152773
+ }
152774
+ return {kind: 'Ref', refId: nextRefId()};
152749
152775
  } else {
152750
152776
  CompilerError.invariant(
152751
152777
  a.kind === 'Structure' && b.kind === 'Structure',
@@ -152778,6 +152804,16 @@ function joinRefAccessTypes(...types) {
152778
152804
  return b;
152779
152805
  } else if (b.kind === 'None') {
152780
152806
  return a;
152807
+ } else if (a.kind === 'Guard' || b.kind === 'Guard') {
152808
+ if (a.kind === 'Guard' && b.kind === 'Guard' && a.refId === b.refId) {
152809
+ return a;
152810
+ }
152811
+ return {kind: 'None'};
152812
+ } else if (a.kind === 'Nullable' || b.kind === 'Nullable') {
152813
+ if (a.kind === 'Nullable' && b.kind === 'Nullable') {
152814
+ return a;
152815
+ }
152816
+ return {kind: 'None'};
152781
152817
  } else {
152782
152818
  return joinRefAccessRefTypes(a, b);
152783
152819
  }
@@ -152786,7 +152822,7 @@ function joinRefAccessTypes(...types) {
152786
152822
  );
152787
152823
  }
152788
152824
  function validateNoRefAccessInRenderImpl(fn, env) {
152789
- var _a, _b, _c, _d, _e, _f;
152825
+ var _a, _b, _c, _d, _e, _f, _g, _h;
152790
152826
  let returnValues = [];
152791
152827
  let place;
152792
152828
  for (const param of fn.params) {
@@ -152795,21 +152831,23 @@ function validateNoRefAccessInRenderImpl(fn, env) {
152795
152831
  } else {
152796
152832
  place = param.place;
152797
152833
  }
152798
- const type = refTypeOfType(place.identifier);
152834
+ const type = refTypeOfType(place);
152799
152835
  env.set(place.identifier.id, type);
152800
152836
  }
152801
152837
  for (let i = 0; (i == 0 || env.hasChanged()) && i < 10; i++) {
152802
152838
  env.resetChanged();
152803
152839
  returnValues = [];
152840
+ const safeBlocks = new Map();
152804
152841
  const errors = new CompilerError();
152805
152842
  for (const [, block] of fn.body.blocks) {
152806
152843
  for (const phi of block.phis) {
152807
152844
  env.set(
152808
- phi.id.id,
152845
+ phi.place.identifier.id,
152809
152846
  joinRefAccessTypes(
152810
152847
  ...Array(...phi.operands.values()).map(operand => {
152811
152848
  var _a;
152812
- return (_a = env.get(operand.id)) !== null && _a !== void 0
152849
+ return (_a = env.get(operand.identifier.id)) !== null &&
152850
+ _a !== void 0
152813
152851
  ? _a
152814
152852
  : {kind: 'None'};
152815
152853
  })
@@ -152843,13 +152881,17 @@ function validateNoRefAccessInRenderImpl(fn, env) {
152843
152881
  ? void 0
152844
152882
  : objType.kind) === 'Ref'
152845
152883
  ) {
152846
- lookupType = {kind: 'RefValue', loc: instr.loc};
152884
+ lookupType = {
152885
+ kind: 'RefValue',
152886
+ loc: instr.loc,
152887
+ refId: objType.refId,
152888
+ };
152847
152889
  }
152848
152890
  env.set(
152849
152891
  instr.lvalue.identifier.id,
152850
152892
  lookupType !== null && lookupType !== void 0
152851
152893
  ? lookupType
152852
- : refTypeOfType(instr.lvalue.identifier)
152894
+ : refTypeOfType(instr.lvalue)
152853
152895
  );
152854
152896
  break;
152855
152897
  }
@@ -152860,7 +152902,7 @@ function validateNoRefAccessInRenderImpl(fn, env) {
152860
152902
  (_a = env.get(instr.value.place.identifier.id)) !== null &&
152861
152903
  _a !== void 0
152862
152904
  ? _a
152863
- : refTypeOfType(instr.lvalue.identifier)
152905
+ : refTypeOfType(instr.lvalue)
152864
152906
  );
152865
152907
  break;
152866
152908
  }
@@ -152871,14 +152913,14 @@ function validateNoRefAccessInRenderImpl(fn, env) {
152871
152913
  (_b = env.get(instr.value.value.identifier.id)) !== null &&
152872
152914
  _b !== void 0
152873
152915
  ? _b
152874
- : refTypeOfType(instr.value.lvalue.place.identifier)
152916
+ : refTypeOfType(instr.value.lvalue.place)
152875
152917
  );
152876
152918
  env.set(
152877
152919
  instr.lvalue.identifier.id,
152878
152920
  (_c = env.get(instr.value.value.identifier.id)) !== null &&
152879
152921
  _c !== void 0
152880
152922
  ? _c
152881
- : refTypeOfType(instr.lvalue.identifier)
152923
+ : refTypeOfType(instr.lvalue)
152882
152924
  );
152883
152925
  break;
152884
152926
  }
@@ -152896,14 +152938,14 @@ function validateNoRefAccessInRenderImpl(fn, env) {
152896
152938
  instr.lvalue.identifier.id,
152897
152939
  lookupType !== null && lookupType !== void 0
152898
152940
  ? lookupType
152899
- : refTypeOfType(instr.lvalue.identifier)
152941
+ : refTypeOfType(instr.lvalue)
152900
152942
  );
152901
152943
  for (const lval of eachPatternOperand(instr.value.lvalue.pattern)) {
152902
152944
  env.set(
152903
152945
  lval.identifier.id,
152904
152946
  lookupType !== null && lookupType !== void 0
152905
152947
  ? lookupType
152906
- : refTypeOfType(lval.identifier)
152948
+ : refTypeOfType(lval)
152907
152949
  );
152908
152950
  }
152909
152951
  break;
@@ -152980,7 +153022,11 @@ function validateNoRefAccessInRenderImpl(fn, env) {
152980
153022
  );
152981
153023
  }
152982
153024
  const value = joinRefAccessTypes(...types);
152983
- if (value.kind === 'None') {
153025
+ if (
153026
+ value.kind === 'None' ||
153027
+ value.kind === 'Guard' ||
153028
+ value.kind === 'Nullable'
153029
+ ) {
152984
153030
  env.set(instr.lvalue.identifier.id, {kind: 'None'});
152985
153031
  } else {
152986
153032
  env.set(instr.lvalue.identifier.id, {
@@ -152995,7 +153041,19 @@ function validateNoRefAccessInRenderImpl(fn, env) {
152995
153041
  case 'PropertyStore':
152996
153042
  case 'ComputedDelete':
152997
153043
  case 'ComputedStore': {
152998
- validateNoRefAccess(errors, env, instr.value.object, instr.loc);
153044
+ const safe = safeBlocks.get(block.id);
153045
+ const target = env.get(instr.value.object.identifier.id);
153046
+ if (
153047
+ instr.value.kind === 'PropertyStore' &&
153048
+ safe != null &&
153049
+ (target === null || target === void 0 ? void 0 : target.kind) ===
153050
+ 'Ref' &&
153051
+ target.refId === safe
153052
+ ) {
153053
+ safeBlocks.delete(block.id);
153054
+ } else {
153055
+ validateNoRefAccess(errors, env, instr.value.object, instr.loc);
153056
+ }
152999
153057
  for (const operand of eachInstructionValueOperand(instr.value)) {
153000
153058
  if (operand === instr.value.object) {
153001
153059
  continue;
@@ -153007,6 +153065,53 @@ function validateNoRefAccessInRenderImpl(fn, env) {
153007
153065
  case 'StartMemoize':
153008
153066
  case 'FinishMemoize':
153009
153067
  break;
153068
+ case 'Primitive': {
153069
+ if (instr.value.value == null) {
153070
+ env.set(instr.lvalue.identifier.id, {kind: 'Nullable'});
153071
+ }
153072
+ break;
153073
+ }
153074
+ case 'BinaryExpression': {
153075
+ const left = env.get(instr.value.left.identifier.id);
153076
+ const right = env.get(instr.value.right.identifier.id);
153077
+ let nullish = false;
153078
+ let refId = null;
153079
+ if (
153080
+ (left === null || left === void 0 ? void 0 : left.kind) ===
153081
+ 'RefValue' &&
153082
+ left.refId != null
153083
+ ) {
153084
+ refId = left.refId;
153085
+ } else if (
153086
+ (right === null || right === void 0 ? void 0 : right.kind) ===
153087
+ 'RefValue' &&
153088
+ right.refId != null
153089
+ ) {
153090
+ refId = right.refId;
153091
+ }
153092
+ if (
153093
+ (left === null || left === void 0 ? void 0 : left.kind) ===
153094
+ 'Nullable'
153095
+ ) {
153096
+ nullish = true;
153097
+ } else if (
153098
+ (right === null || right === void 0 ? void 0 : right.kind) ===
153099
+ 'Nullable'
153100
+ ) {
153101
+ nullish = true;
153102
+ }
153103
+ if (refId !== null && nullish) {
153104
+ env.set(instr.lvalue.identifier.id, {
153105
+ kind: 'Guard',
153106
+ refId: refId,
153107
+ });
153108
+ } else {
153109
+ for (const operand of eachInstructionValueOperand(instr.value)) {
153110
+ validateNoRefValueAccess(errors, env, operand);
153111
+ }
153112
+ }
153113
+ break;
153114
+ }
153010
153115
  default: {
153011
153116
  for (const operand of eachInstructionValueOperand(instr.value)) {
153012
153117
  validateNoRefValueAccess(errors, env, operand);
@@ -153014,36 +153119,61 @@ function validateNoRefAccessInRenderImpl(fn, env) {
153014
153119
  break;
153015
153120
  }
153016
153121
  }
153017
- if (isUseRefType(instr.lvalue.identifier)) {
153122
+ for (const operand of eachInstructionOperand(instr)) {
153123
+ guardCheck(errors, operand, env);
153124
+ }
153125
+ if (
153126
+ isUseRefType(instr.lvalue.identifier) &&
153127
+ ((_e = env.get(instr.lvalue.identifier.id)) === null || _e === void 0
153128
+ ? void 0
153129
+ : _e.kind) !== 'Ref'
153130
+ ) {
153018
153131
  env.set(
153019
153132
  instr.lvalue.identifier.id,
153020
153133
  joinRefAccessTypes(
153021
- (_e = env.get(instr.lvalue.identifier.id)) !== null &&
153022
- _e !== void 0
153023
- ? _e
153134
+ (_f = env.get(instr.lvalue.identifier.id)) !== null &&
153135
+ _f !== void 0
153136
+ ? _f
153024
153137
  : {kind: 'None'},
153025
- {kind: 'Ref'}
153138
+ {kind: 'Ref', refId: nextRefId()}
153026
153139
  )
153027
153140
  );
153028
153141
  }
153029
- if (isRefValueType(instr.lvalue.identifier)) {
153142
+ if (
153143
+ isRefValueType(instr.lvalue.identifier) &&
153144
+ ((_g = env.get(instr.lvalue.identifier.id)) === null || _g === void 0
153145
+ ? void 0
153146
+ : _g.kind) !== 'RefValue'
153147
+ ) {
153030
153148
  env.set(
153031
153149
  instr.lvalue.identifier.id,
153032
153150
  joinRefAccessTypes(
153033
- (_f = env.get(instr.lvalue.identifier.id)) !== null &&
153034
- _f !== void 0
153035
- ? _f
153151
+ (_h = env.get(instr.lvalue.identifier.id)) !== null &&
153152
+ _h !== void 0
153153
+ ? _h
153036
153154
  : {kind: 'None'},
153037
153155
  {kind: 'RefValue', loc: instr.loc}
153038
153156
  )
153039
153157
  );
153040
153158
  }
153041
153159
  }
153160
+ if (block.terminal.kind === 'if') {
153161
+ const test = env.get(block.terminal.test.identifier.id);
153162
+ if (
153163
+ (test === null || test === void 0 ? void 0 : test.kind) === 'Guard'
153164
+ ) {
153165
+ safeBlocks.set(block.terminal.consequent, test.refId);
153166
+ }
153167
+ }
153042
153168
  for (const operand of eachTerminalOperand(block.terminal)) {
153043
153169
  if (block.terminal.kind !== 'return') {
153044
153170
  validateNoRefValueAccess(errors, env, operand);
153171
+ if (block.terminal.kind !== 'if') {
153172
+ guardCheck(errors, operand, env);
153173
+ }
153045
153174
  } else {
153046
153175
  validateNoDirectRefValueAccess(errors, operand, env);
153176
+ guardCheck(errors, operand, env);
153047
153177
  returnValues.push(env.get(operand.identifier.id));
153048
153178
  }
153049
153179
  }
@@ -153069,6 +153199,27 @@ function destructure(type) {
153069
153199
  }
153070
153200
  return type;
153071
153201
  }
153202
+ function guardCheck(errors, operand, env) {
153203
+ var _a;
153204
+ if (
153205
+ ((_a = env.get(operand.identifier.id)) === null || _a === void 0
153206
+ ? void 0
153207
+ : _a.kind) === 'Guard'
153208
+ ) {
153209
+ errors.push({
153210
+ severity: exports.ErrorSeverity.InvalidReact,
153211
+ reason:
153212
+ 'Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)',
153213
+ loc: operand.loc,
153214
+ description:
153215
+ operand.identifier.name !== null &&
153216
+ operand.identifier.name.kind === 'named'
153217
+ ? `Cannot access ref value \`${operand.identifier.name.value}\``
153218
+ : null,
153219
+ suggestions: null,
153220
+ });
153221
+ }
153222
+ }
153072
153223
  function validateNoRefValueAccess(errors, env, operand) {
153073
153224
  var _a;
153074
153225
  const type = destructure(env.get(operand.identifier.id));
@@ -153876,21 +154027,24 @@ function propagatePhiTypes(fn) {
153876
154027
  const propagated = new Set();
153877
154028
  for (const [, block] of fn.body.blocks) {
153878
154029
  for (const phi of block.phis) {
153879
- if (phi.id.type.kind !== 'Type' || phi.id.name !== null) {
154030
+ if (
154031
+ phi.place.identifier.type.kind !== 'Type' ||
154032
+ phi.place.identifier.name !== null
154033
+ ) {
153880
154034
  continue;
153881
154035
  }
153882
154036
  let type = null;
153883
154037
  for (const [, operand] of phi.operands) {
153884
154038
  if (type === null) {
153885
- type = operand.type;
153886
- } else if (!typeEquals(type, operand.type)) {
154039
+ type = operand.identifier.type;
154040
+ } else if (!typeEquals(type, operand.identifier.type)) {
153887
154041
  type = null;
153888
154042
  break;
153889
154043
  }
153890
154044
  }
153891
154045
  if (type !== null) {
153892
- phi.id.type = type;
153893
- propagated.add(phi.id.id);
154046
+ phi.place.identifier.type = type;
154047
+ propagated.add(phi.place.identifier.id);
153894
154048
  }
153895
154049
  }
153896
154050
  for (const instr of block.instructions) {
@@ -155546,7 +155700,7 @@ function collectDependencies(
155546
155700
  }
155547
155701
  for (const phi of block.phis) {
155548
155702
  for (const operand of phi.operands) {
155549
- const maybeOptionalChain = temporaries.get(operand[1].id);
155703
+ const maybeOptionalChain = temporaries.get(operand[1].identifier.id);
155550
155704
  if (maybeOptionalChain) {
155551
155705
  context.visitDependency(maybeOptionalChain);
155552
155706
  }