babel-plugin-react-compiler 19.0.0-beta-df7b47d-20241124 → 19.0.0-beta-37ed2a7-20241206

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 +70 -33
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -136800,6 +136800,10 @@ const testComplexConfigDefaults = {
136800
136800
  },
136801
136801
  numRequiredArgs: 2,
136802
136802
  },
136803
+ {
136804
+ function: {source: 'useEffectWrapper', importSpecifierName: 'default'},
136805
+ numRequiredArgs: 1,
136806
+ },
136803
136807
  ],
136804
136808
  };
136805
136809
  function parseConfigPragmaForTests(pragma) {
@@ -137376,6 +137380,7 @@ function tryParseExternalFunction(maybeExternalFunction) {
137376
137380
  suggestions: null,
137377
137381
  });
137378
137382
  }
137383
+ const DEFAULT_EXPORT = 'default';
137379
137384
  var _MergedBlocks_map;
137380
137385
  function mergeConsecutiveBlocks(fn) {
137381
137386
  const merged = new MergedBlocks();
@@ -139817,7 +139822,15 @@ function addMemoCacheFunctionImportDeclaration(program, moduleName, localName) {
139817
139822
  );
139818
139823
  }
139819
139824
  z.enum(['all_errors', 'critical_errors', 'none']);
139820
- const CompilerReactTargetSchema = z.enum(['17', '18', '19']);
139825
+ const CompilerReactTargetSchema = z.union([
139826
+ z.literal('17'),
139827
+ z.literal('18'),
139828
+ z.literal('19'),
139829
+ z.object({
139830
+ kind: z.literal('donotuse_meta_internal'),
139831
+ runtimeModule: z.string().default('react'),
139832
+ }),
139833
+ ]);
139821
139834
  z.enum(['infer', 'syntax', 'annotation', 'all']);
139822
139835
  const defaultOptions = {
139823
139836
  compilationMode: 'infer',
@@ -151524,6 +151537,7 @@ function inferEffectDependencies(fn) {
151524
151537
  }
151525
151538
  const autodepFnLoads = new Map();
151526
151539
  const scopeInfos = new Map();
151540
+ const loadGlobals = new Set();
151527
151541
  const reactiveIds = inferReactiveIdentifiers(fn);
151528
151542
  for (const [, block] of fn.body.blocks) {
151529
151543
  if (
@@ -151545,15 +151559,22 @@ function inferEffectDependencies(fn) {
151545
151559
  const {value: value, lvalue: lvalue} = instr;
151546
151560
  if (value.kind === 'FunctionExpression') {
151547
151561
  fnExpressions.set(lvalue.identifier.id, instr);
151548
- } else if (
151549
- value.kind === 'LoadGlobal' &&
151550
- value.binding.kind === 'ImportSpecifier'
151551
- ) {
151552
- const moduleTargets = autodepFnConfigs.get(value.binding.module);
151553
- if (moduleTargets != null) {
151554
- const numRequiredArgs = moduleTargets.get(value.binding.imported);
151555
- if (numRequiredArgs != null) {
151556
- autodepFnLoads.set(lvalue.identifier.id, numRequiredArgs);
151562
+ } else if (value.kind === 'LoadGlobal') {
151563
+ loadGlobals.add(lvalue.identifier.id);
151564
+ if (
151565
+ value.binding.kind === 'ImportSpecifier' ||
151566
+ value.binding.kind === 'ImportDefault'
151567
+ ) {
151568
+ const moduleTargets = autodepFnConfigs.get(value.binding.module);
151569
+ if (moduleTargets != null) {
151570
+ const importSpecifierName =
151571
+ value.binding.kind === 'ImportSpecifier'
151572
+ ? value.binding.imported
151573
+ : DEFAULT_EXPORT;
151574
+ const numRequiredArgs = moduleTargets.get(importSpecifierName);
151575
+ if (numRequiredArgs != null) {
151576
+ autodepFnLoads.set(lvalue.identifier.id, numRequiredArgs);
151577
+ }
151557
151578
  }
151558
151579
  }
151559
151580
  } else if (
@@ -151561,6 +151582,15 @@ function inferEffectDependencies(fn) {
151561
151582
  autodepFnLoads.get(value.callee.identifier.id) === value.args.length &&
151562
151583
  value.args[0].kind === 'Identifier'
151563
151584
  ) {
151585
+ const effectDeps = [];
151586
+ const newInstructions = [];
151587
+ const deps = {
151588
+ kind: 'ArrayExpression',
151589
+ elements: effectDeps,
151590
+ loc: GeneratedSource,
151591
+ };
151592
+ const depsPlace = createTemporaryPlace(fn.env, GeneratedSource);
151593
+ depsPlace.effect = exports.Effect.Read;
151564
151594
  const fnExpr = fnExpressions.get(value.args[0].identifier.id);
151565
151595
  if (fnExpr != null) {
151566
151596
  const scopeInfo =
@@ -151578,8 +151608,6 @@ function inferEffectDependencies(fn) {
151578
151608
  loc: fnExpr.loc,
151579
151609
  });
151580
151610
  }
151581
- const effectDeps = [];
151582
- const newInstructions = [];
151583
151611
  for (const dep of scopeInfo.deps) {
151584
151612
  const {place: place, instructions: instructions} =
151585
151613
  writeDependencyToInstructions(
@@ -151591,13 +151619,21 @@ function inferEffectDependencies(fn) {
151591
151619
  newInstructions.push(...instructions);
151592
151620
  effectDeps.push(place);
151593
151621
  }
151594
- const deps = {
151595
- kind: 'ArrayExpression',
151596
- elements: effectDeps,
151622
+ newInstructions.push({
151623
+ id: makeInstructionId(0),
151597
151624
  loc: GeneratedSource,
151598
- };
151599
- const depsPlace = createTemporaryPlace(fn.env, GeneratedSource);
151600
- depsPlace.effect = exports.Effect.Read;
151625
+ lvalue: Object.assign(Object.assign({}, depsPlace), {
151626
+ effect: exports.Effect.Mutate,
151627
+ }),
151628
+ value: deps,
151629
+ });
151630
+ value.args.push(
151631
+ Object.assign(Object.assign({}, depsPlace), {
151632
+ effect: exports.Effect.Freeze,
151633
+ })
151634
+ );
151635
+ rewriteInstrs.set(instr.id, newInstructions);
151636
+ } else if (loadGlobals.has(value.args[0].identifier.id)) {
151601
151637
  newInstructions.push({
151602
151638
  id: makeInstructionId(0),
151603
151639
  loc: GeneratedSource,
@@ -151660,6 +151696,9 @@ function writeDependencyToInstructions(dep, reactive, env, loc) {
151660
151696
  if (path.optional) {
151661
151697
  break;
151662
151698
  }
151699
+ if (path.property === 'current') {
151700
+ break;
151701
+ }
151663
151702
  const nextValue = createTemporaryPlace(env, GeneratedSource);
151664
151703
  nextValue.reactive = reactive;
151665
151704
  instructions.push({
@@ -158495,26 +158534,24 @@ function checkFunctionReferencedBeforeDeclarationAtTopLevel(program, fns) {
158495
158534
  return errors.details.length > 0 ? errors : null;
158496
158535
  }
158497
158536
  function getReactCompilerRuntimeModule(opts) {
158498
- let moduleName = null;
158499
- switch (opts.target) {
158500
- case '17':
158501
- case '18': {
158502
- moduleName = 'react-compiler-runtime';
158503
- break;
158504
- }
158505
- case '19': {
158506
- moduleName = 'react/compiler-runtime';
158507
- break;
158508
- }
158509
- default:
158510
- CompilerError.invariant(moduleName != null, {
158537
+ if (opts.target === '19') {
158538
+ return 'react/compiler-runtime';
158539
+ } else if (opts.target === '17' || opts.target === '18') {
158540
+ return 'react-compiler-runtime';
158541
+ } else {
158542
+ CompilerError.invariant(
158543
+ opts.target != null &&
158544
+ opts.target.kind === 'donotuse_meta_internal' &&
158545
+ typeof opts.target.runtimeModule === 'string',
158546
+ {
158511
158547
  reason: 'Expected target to already be validated',
158512
158548
  description: null,
158513
158549
  loc: null,
158514
158550
  suggestions: null,
158515
- });
158551
+ }
158552
+ );
158553
+ return opts.target.runtimeModule;
158516
158554
  }
158517
- return moduleName;
158518
158555
  }
158519
158556
  function hasModule(name) {
158520
158557
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-plugin-react-compiler",
3
- "version": "19.0.0-beta-df7b47d-20241124",
3
+ "version": "19.0.0-beta-37ed2a7-20241206",
4
4
  "description": "Babel plugin for React Compiler.",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",