babel-plugin-react-compiler 0.0.0-experimental-3cea1f4-20250324 → 0.0.0-experimental-a9d296d-20250326

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.
Files changed (2) hide show
  1. package/dist/index.js +58 -15
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -132444,6 +132444,10 @@ function pruneHoistedContexts(fn) {
132444
132444
  const hoistedIdentifiers = /* @__PURE__ */ new Map();
132445
132445
  visitReactiveFunction(fn, new Visitor3(), hoistedIdentifiers);
132446
132446
  }
132447
+ var REWRITTEN_HOISTED_CONST = Symbol(
132448
+ "REWRITTEN_HOISTED_CONST"
132449
+ );
132450
+ var REWRITTEN_HOISTED_LET = Symbol("REWRITTEN_HOISTED_LET");
132447
132451
  var Visitor3 = class extends ReactiveFunctionTransform {
132448
132452
  transformInstruction(instruction, state) {
132449
132453
  this.visitInstruction(instruction, state);
@@ -132468,25 +132472,64 @@ var Visitor3 = class extends ReactiveFunctionTransform {
132468
132472
  );
132469
132473
  return { kind: "remove" };
132470
132474
  }
132471
- if (instruction.value.kind === "StoreContext" && state.has(instruction.value.lvalue.place.identifier.declarationId)) {
132475
+ if (instruction.value.kind === "StoreContext") {
132472
132476
  const kind = state.get(
132473
132477
  instruction.value.lvalue.place.identifier.declarationId
132474
132478
  );
132475
- return {
132476
- kind: "replace",
132477
- value: {
132478
- kind: "instruction",
132479
- instruction: __spreadProps(__spreadValues({}, instruction), {
132480
- value: __spreadProps(__spreadValues({}, instruction.value), {
132481
- lvalue: __spreadProps(__spreadValues({}, instruction.value.lvalue), {
132482
- kind
132483
- }),
132484
- type: null,
132485
- kind: "StoreLocal"
132486
- })
132487
- })
132479
+ if (kind != null) {
132480
+ CompilerError.invariant(kind !== REWRITTEN_HOISTED_CONST, {
132481
+ reason: "Expected exactly one store to a hoisted const variable",
132482
+ loc: instruction.loc
132483
+ });
132484
+ if (kind === "Const" /* Const */ || kind === "Function" /* Function */) {
132485
+ state.set(
132486
+ instruction.value.lvalue.place.identifier.declarationId,
132487
+ REWRITTEN_HOISTED_CONST
132488
+ );
132489
+ return {
132490
+ kind: "replace",
132491
+ value: {
132492
+ kind: "instruction",
132493
+ instruction: __spreadProps(__spreadValues({}, instruction), {
132494
+ value: __spreadProps(__spreadValues({}, instruction.value), {
132495
+ lvalue: __spreadProps(__spreadValues({}, instruction.value.lvalue), {
132496
+ kind
132497
+ }),
132498
+ type: null,
132499
+ kind: "StoreLocal"
132500
+ })
132501
+ })
132502
+ }
132503
+ };
132504
+ } else if (kind !== REWRITTEN_HOISTED_LET) {
132505
+ state.set(
132506
+ instruction.value.lvalue.place.identifier.declarationId,
132507
+ REWRITTEN_HOISTED_LET
132508
+ );
132509
+ return {
132510
+ kind: "replace-many",
132511
+ value: [
132512
+ {
132513
+ kind: "instruction",
132514
+ instruction: {
132515
+ id: instruction.id,
132516
+ lvalue: null,
132517
+ value: {
132518
+ kind: "DeclareContext",
132519
+ lvalue: {
132520
+ kind: "Let" /* Let */,
132521
+ place: __spreadValues({}, instruction.value.lvalue.place)
132522
+ },
132523
+ loc: instruction.value.loc
132524
+ },
132525
+ loc: instruction.loc
132526
+ }
132527
+ },
132528
+ { kind: "instruction", instruction }
132529
+ ]
132530
+ };
132488
132531
  }
132489
- };
132532
+ }
132490
132533
  }
132491
132534
  return { kind: "keep" };
132492
132535
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-plugin-react-compiler",
3
- "version": "0.0.0-experimental-3cea1f4-20250324",
3
+ "version": "0.0.0-experimental-a9d296d-20250326",
4
4
  "description": "Babel plugin for React Compiler.",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",