babel-plugin-react-compiler 0.0.0-experimental-702922b-20241115 → 0.0.0-experimental-ce0575a-20241118

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 +114 -71
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -132806,7 +132806,7 @@ function lowerJsxElementName(builder, exprPath) {
132806
132806
  }
132807
132807
  }
132808
132808
  function lowerJsxMemberExpression(builder, exprPath) {
132809
- var _a, _b;
132809
+ var _a, _b, _c;
132810
132810
  const loc =
132811
132811
  (_a = exprPath.node.loc) !== null && _a !== void 0 ? _a : GeneratedSource;
132812
132812
  const object = exprPath.get('object');
@@ -132820,7 +132820,15 @@ function lowerJsxMemberExpression(builder, exprPath) {
132820
132820
  loc: (_b = object.node.loc) !== null && _b !== void 0 ? _b : null,
132821
132821
  suggestions: null,
132822
132822
  });
132823
- objectPlace = lowerIdentifier(builder, object);
132823
+ const kind = getLoadKind(builder, object);
132824
+ objectPlace = lowerValueToTemporary(builder, {
132825
+ kind: kind,
132826
+ place: lowerIdentifier(builder, object),
132827
+ loc:
132828
+ (_c = exprPath.node.loc) !== null && _c !== void 0
132829
+ ? _c
132830
+ : GeneratedSource,
132831
+ });
132824
132832
  }
132825
132833
  const property = exprPath.get('property').node.name;
132826
132834
  return lowerValueToTemporary(builder, {
@@ -136664,6 +136672,7 @@ const EnvironmentConfigSchema = z.object({
136664
136672
  enablePreserveExistingManualUseMemo: z.boolean().default(false),
136665
136673
  enableForest: z.boolean().default(false),
136666
136674
  enableUseTypeAnnotations: z.boolean().default(false),
136675
+ enableFunctionDependencyRewrite: z.boolean().default(true),
136667
136676
  inlineJsxTransform: ReactElementSymbolSchema.nullable().default(null),
136668
136677
  validateHooksUsage: z.boolean().default(true),
136669
136678
  validateRefAccessDuringRender: z.boolean().default(true),
@@ -140883,6 +140892,9 @@ function deadCodeElimination(fn) {
140883
140892
  }
140884
140893
  }
140885
140894
  }
140895
+ retainWhere(fn.context, contextVar =>
140896
+ state.isIdOrNameUsed(contextVar.identifier)
140897
+ );
140886
140898
  }
140887
140899
  let State$2 = class State {
140888
140900
  constructor() {
@@ -141644,28 +141656,41 @@ function createPropsProperties(
141644
141656
  propAttributes.forEach(prop => {
141645
141657
  switch (prop.kind) {
141646
141658
  case 'JsxAttribute': {
141647
- if (prop.name === 'ref') {
141648
- refProperty = {
141649
- kind: 'ObjectProperty',
141650
- key: {name: 'ref', kind: 'string'},
141651
- type: 'property',
141652
- place: Object.assign({}, prop.place),
141653
- };
141654
- } else if (prop.name === 'key') {
141655
- keyProperty = {
141656
- kind: 'ObjectProperty',
141657
- key: {name: 'key', kind: 'string'},
141658
- type: 'property',
141659
- place: Object.assign({}, prop.place),
141660
- };
141661
- } else {
141662
- const attributeProperty = {
141663
- kind: 'ObjectProperty',
141664
- key: {name: prop.name, kind: 'string'},
141665
- type: 'property',
141666
- place: Object.assign({}, prop.place),
141667
- };
141668
- props.push(attributeProperty);
141659
+ switch (prop.name) {
141660
+ case 'key': {
141661
+ keyProperty = {
141662
+ kind: 'ObjectProperty',
141663
+ key: {name: 'key', kind: 'string'},
141664
+ type: 'property',
141665
+ place: Object.assign({}, prop.place),
141666
+ };
141667
+ break;
141668
+ }
141669
+ case 'ref': {
141670
+ refProperty = {
141671
+ kind: 'ObjectProperty',
141672
+ key: {name: 'ref', kind: 'string'},
141673
+ type: 'property',
141674
+ place: Object.assign({}, prop.place),
141675
+ };
141676
+ const refPropProperty = {
141677
+ kind: 'ObjectProperty',
141678
+ key: {name: 'ref', kind: 'string'},
141679
+ type: 'property',
141680
+ place: Object.assign({}, prop.place),
141681
+ };
141682
+ props.push(refPropProperty);
141683
+ break;
141684
+ }
141685
+ default: {
141686
+ const attributeProperty = {
141687
+ kind: 'ObjectProperty',
141688
+ key: {name: prop.name, kind: 'string'},
141689
+ type: 'property',
141690
+ place: Object.assign({}, prop.place),
141691
+ };
141692
+ props.push(attributeProperty);
141693
+ }
141669
141694
  }
141670
141695
  break;
141671
141696
  }
@@ -149872,12 +149897,18 @@ let Visitor$7 = class Visitor extends ReactiveFunctionVisitor {
149872
149897
  visitPrunedScope(scopeBlock, state) {
149873
149898
  this.traversePrunedScope(scopeBlock, state);
149874
149899
  for (const [id, decl] of scopeBlock.scope.declarations) {
149875
- if (!isPrimitiveType(decl.identifier)) {
149900
+ if (
149901
+ !isPrimitiveType(decl.identifier) &&
149902
+ !isStableRefType(decl.identifier, state)
149903
+ ) {
149876
149904
  state.add(id);
149877
149905
  }
149878
149906
  }
149879
149907
  }
149880
149908
  };
149909
+ function isStableRefType(identifier, reactiveIdentifiers) {
149910
+ return isUseRefType(identifier) && !reactiveIdentifiers.has(identifier.id);
149911
+ }
149881
149912
  function collectReactiveIdentifiers(fn) {
149882
149913
  const visitor = new Visitor$7();
149883
149914
  const state = new Set();
@@ -156337,6 +156368,7 @@ class Context {
156337
156368
  this.visitDependency(nextDependency);
156338
156369
  }
156339
156370
  visitDependency(maybeDependency) {
156371
+ var _a;
156340
156372
  const originalDeclaration = __classPrivateFieldGet(
156341
156373
  this,
156342
156374
  _Context_declarations,
@@ -156368,6 +156400,14 @@ class Context {
156368
156400
  }
156369
156401
  });
156370
156402
  }
156403
+ if (
156404
+ isUseRefType(maybeDependency.identifier) &&
156405
+ ((_a = maybeDependency.path.at(0)) === null || _a === void 0
156406
+ ? void 0
156407
+ : _a.property) === 'current'
156408
+ ) {
156409
+ maybeDependency = {identifier: maybeDependency.identifier, path: []};
156410
+ }
156371
156411
  if (
156372
156412
  __classPrivateFieldGet(
156373
156413
  this,
@@ -156411,15 +156451,7 @@ class Context {
156411
156451
  (_Context_checkValidDependency = function _Context_checkValidDependency(
156412
156452
  maybeDependency
156413
156453
  ) {
156414
- var _a, _b;
156415
- if (
156416
- isUseRefType(maybeDependency.identifier) &&
156417
- ((_a = maybeDependency.path.at(0)) === null || _a === void 0
156418
- ? void 0
156419
- : _a.property) === 'current'
156420
- ) {
156421
- return false;
156422
- }
156454
+ var _a;
156423
156455
  if (isRefValueType(maybeDependency.identifier)) {
156424
156456
  return false;
156425
156457
  }
@@ -156428,10 +156460,10 @@ class Context {
156428
156460
  }
156429
156461
  const identifier = maybeDependency.identifier;
156430
156462
  const currentDeclaration =
156431
- (_b = __classPrivateFieldGet(this, _Context_reassignments, 'f').get(
156463
+ (_a = __classPrivateFieldGet(this, _Context_reassignments, 'f').get(
156432
156464
  identifier
156433
- )) !== null && _b !== void 0
156434
- ? _b
156465
+ )) !== null && _a !== void 0
156466
+ ? _a
156435
156467
  : __classPrivateFieldGet(this, _Context_declarations, 'f').get(
156436
156468
  identifier.declarationId
156437
156469
  );
@@ -156514,46 +156546,57 @@ function collectDependencies(
156514
156546
  }
156515
156547
  }
156516
156548
  const scopeTraversal = new ScopeBlockTraversal();
156517
- for (const [blockId, block] of fn.body.blocks) {
156518
- scopeTraversal.recordScopes(block);
156519
- const scopeBlockInfo = scopeTraversal.blockInfos.get(blockId);
156520
- if (
156521
- (scopeBlockInfo === null || scopeBlockInfo === void 0
156522
- ? void 0
156523
- : scopeBlockInfo.kind) === 'begin'
156524
- ) {
156525
- context.enterScope(scopeBlockInfo.scope);
156526
- } else if (
156527
- (scopeBlockInfo === null || scopeBlockInfo === void 0
156528
- ? void 0
156529
- : scopeBlockInfo.kind) === 'end'
156530
- ) {
156531
- context.exitScope(
156532
- scopeBlockInfo.scope,
156533
- scopeBlockInfo === null || scopeBlockInfo === void 0
156549
+ const handleFunction = fn => {
156550
+ for (const [blockId, block] of fn.body.blocks) {
156551
+ scopeTraversal.recordScopes(block);
156552
+ const scopeBlockInfo = scopeTraversal.blockInfos.get(blockId);
156553
+ if (
156554
+ (scopeBlockInfo === null || scopeBlockInfo === void 0
156534
156555
  ? void 0
156535
- : scopeBlockInfo.pruned
156536
- );
156537
- }
156538
- for (const phi of block.phis) {
156539
- for (const operand of phi.operands) {
156540
- const maybeOptionalChain = temporaries.get(operand[1].identifier.id);
156541
- if (maybeOptionalChain) {
156542
- context.visitDependency(maybeOptionalChain);
156556
+ : scopeBlockInfo.kind) === 'begin'
156557
+ ) {
156558
+ context.enterScope(scopeBlockInfo.scope);
156559
+ } else if (
156560
+ (scopeBlockInfo === null || scopeBlockInfo === void 0
156561
+ ? void 0
156562
+ : scopeBlockInfo.kind) === 'end'
156563
+ ) {
156564
+ context.exitScope(scopeBlockInfo.scope, scopeBlockInfo.pruned);
156565
+ }
156566
+ for (const phi of block.phis) {
156567
+ for (const operand of phi.operands) {
156568
+ const maybeOptionalChain = temporaries.get(operand[1].identifier.id);
156569
+ if (maybeOptionalChain) {
156570
+ context.visitDependency(maybeOptionalChain);
156571
+ }
156543
156572
  }
156544
156573
  }
156545
- }
156546
- for (const instr of block.instructions) {
156547
- if (!processedInstrsInOptional.has(instr)) {
156548
- handleInstruction(instr, context);
156574
+ for (const instr of block.instructions) {
156575
+ if (
156576
+ fn.env.config.enableFunctionDependencyRewrite &&
156577
+ (instr.value.kind === 'FunctionExpression' ||
156578
+ instr.value.kind === 'ObjectMethod')
156579
+ ) {
156580
+ context.declare(instr.lvalue.identifier, {
156581
+ id: instr.id,
156582
+ scope: context.currentScope,
156583
+ });
156584
+ const wasInInnerFn = context.inInnerFn;
156585
+ context.inInnerFn = true;
156586
+ handleFunction(instr.value.loweredFunc.func);
156587
+ context.inInnerFn = wasInInnerFn;
156588
+ } else if (!processedInstrsInOptional.has(instr)) {
156589
+ handleInstruction(instr, context);
156590
+ }
156549
156591
  }
156550
- }
156551
- if (!processedInstrsInOptional.has(block.terminal)) {
156552
- for (const place of eachTerminalOperand(block.terminal)) {
156553
- context.visitOperand(place);
156592
+ if (!processedInstrsInOptional.has(block.terminal)) {
156593
+ for (const place of eachTerminalOperand(block.terminal)) {
156594
+ context.visitOperand(place);
156595
+ }
156554
156596
  }
156555
156597
  }
156556
- }
156598
+ };
156599
+ handleFunction(fn);
156557
156600
  return context.deps;
156558
156601
  }
156559
156602
  function outlineJSX(fn) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-plugin-react-compiler",
3
- "version": "0.0.0-experimental-702922b-20241115",
3
+ "version": "0.0.0-experimental-ce0575a-20241118",
4
4
  "description": "Babel plugin for React Compiler.",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",