babel-plugin-react-compiler 0.0.0-experimental-50915ff-20241206 → 0.0.0-experimental-16e4ce7-20241209

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 +89 -75
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -129921,9 +129921,7 @@ function lowerStatement(builder, stmtPath, label = null) {
129921
129921
  _26,
129922
129922
  _27,
129923
129923
  _28,
129924
- _29,
129925
- _30,
129926
- _31;
129924
+ _29;
129927
129925
  const stmtNode = stmtPath.node;
129928
129926
  switch (stmtNode.type) {
129929
129927
  case 'ThrowStatement': {
@@ -130765,6 +130763,12 @@ function lowerStatement(builder, stmtPath, label = null) {
130765
130763
  ? _14
130766
130764
  : GeneratedSource;
130767
130765
  let test;
130766
+ const advanceIterator = lowerValueToTemporary(builder, {
130767
+ kind: 'IteratorNext',
130768
+ loc: leftLoc,
130769
+ iterator: Object.assign({}, iterator),
130770
+ collection: Object.assign({}, value),
130771
+ });
130768
130772
  if (left.isVariableDeclaration()) {
130769
130773
  const declarations = left.get('declarations');
130770
130774
  CompilerError.invariant(declarations.length === 1, {
@@ -130774,12 +130778,6 @@ function lowerStatement(builder, stmtPath, label = null) {
130774
130778
  suggestions: null,
130775
130779
  });
130776
130780
  const id = declarations[0].get('id');
130777
- const advanceIterator = lowerValueToTemporary(builder, {
130778
- kind: 'IteratorNext',
130779
- loc: leftLoc,
130780
- iterator: Object.assign({}, iterator),
130781
- collection: Object.assign({}, value),
130782
- });
130783
130781
  const assign = lowerAssignment(
130784
130782
  builder,
130785
130783
  leftLoc,
@@ -130790,13 +130788,19 @@ function lowerStatement(builder, stmtPath, label = null) {
130790
130788
  );
130791
130789
  test = lowerValueToTemporary(builder, assign);
130792
130790
  } else {
130793
- builder.errors.push({
130794
- reason: `(BuildHIR::lowerStatement) Handle ${left.type} inits in ForOfStatement`,
130795
- severity: exports.ErrorSeverity.Todo,
130796
- loc: (_16 = left.node.loc) !== null && _16 !== void 0 ? _16 : null,
130797
- suggestions: null,
130791
+ CompilerError.invariant(left.isLVal(), {
130792
+ loc: leftLoc,
130793
+ reason: 'Expected ForOf init to be a variable declaration or lval',
130798
130794
  });
130799
- return;
130795
+ const assign = lowerAssignment(
130796
+ builder,
130797
+ leftLoc,
130798
+ InstructionKind.Reassign,
130799
+ left,
130800
+ advanceIterator,
130801
+ 'Assignment'
130802
+ );
130803
+ test = lowerValueToTemporary(builder, assign);
130800
130804
  }
130801
130805
  builder.terminateWithContinuation(
130802
130806
  {
@@ -130806,8 +130810,8 @@ function lowerStatement(builder, stmtPath, label = null) {
130806
130810
  consequent: loopBlock,
130807
130811
  alternate: continuationBlock.id,
130808
130812
  loc:
130809
- (_17 = stmt.node.loc) !== null && _17 !== void 0
130810
- ? _17
130813
+ (_16 = stmt.node.loc) !== null && _16 !== void 0
130814
+ ? _16
130811
130815
  : GeneratedSource,
130812
130816
  fallthrough: continuationBlock.id,
130813
130817
  },
@@ -130837,8 +130841,8 @@ function lowerStatement(builder, stmtPath, label = null) {
130837
130841
  })
130838
130842
  );
130839
130843
  const loc =
130840
- (_18 = stmt.node.loc) !== null && _18 !== void 0
130841
- ? _18
130844
+ (_17 = stmt.node.loc) !== null && _17 !== void 0
130845
+ ? _17
130842
130846
  : GeneratedSource;
130843
130847
  const value = lowerExpressionToTemporary(builder, stmt.get('right'));
130844
130848
  builder.terminateWithContinuation(
@@ -130854,24 +130858,24 @@ function lowerStatement(builder, stmtPath, label = null) {
130854
130858
  );
130855
130859
  const left = stmt.get('left');
130856
130860
  const leftLoc =
130857
- (_19 = left.node.loc) !== null && _19 !== void 0
130858
- ? _19
130861
+ (_18 = left.node.loc) !== null && _18 !== void 0
130862
+ ? _18
130859
130863
  : GeneratedSource;
130860
130864
  let test;
130865
+ const nextPropertyTemp = lowerValueToTemporary(builder, {
130866
+ kind: 'NextPropertyOf',
130867
+ loc: leftLoc,
130868
+ value: value,
130869
+ });
130861
130870
  if (left.isVariableDeclaration()) {
130862
130871
  const declarations = left.get('declarations');
130863
130872
  CompilerError.invariant(declarations.length === 1, {
130864
130873
  reason: `Expected only one declaration in the init of a ForInStatement, got ${declarations.length}`,
130865
130874
  description: null,
130866
- loc: (_20 = left.node.loc) !== null && _20 !== void 0 ? _20 : null,
130875
+ loc: (_19 = left.node.loc) !== null && _19 !== void 0 ? _19 : null,
130867
130876
  suggestions: null,
130868
130877
  });
130869
130878
  const id = declarations[0].get('id');
130870
- const nextPropertyTemp = lowerValueToTemporary(builder, {
130871
- kind: 'NextPropertyOf',
130872
- loc: leftLoc,
130873
- value: value,
130874
- });
130875
130879
  const assign = lowerAssignment(
130876
130880
  builder,
130877
130881
  leftLoc,
@@ -130882,13 +130886,19 @@ function lowerStatement(builder, stmtPath, label = null) {
130882
130886
  );
130883
130887
  test = lowerValueToTemporary(builder, assign);
130884
130888
  } else {
130885
- builder.errors.push({
130886
- reason: `(BuildHIR::lowerStatement) Handle ${left.type} inits in ForInStatement`,
130887
- severity: exports.ErrorSeverity.Todo,
130888
- loc: (_21 = left.node.loc) !== null && _21 !== void 0 ? _21 : null,
130889
- suggestions: null,
130889
+ CompilerError.invariant(left.isLVal(), {
130890
+ loc: leftLoc,
130891
+ reason: 'Expected ForIn init to be a variable declaration or lval',
130890
130892
  });
130891
- return;
130893
+ const assign = lowerAssignment(
130894
+ builder,
130895
+ leftLoc,
130896
+ InstructionKind.Reassign,
130897
+ left,
130898
+ nextPropertyTemp,
130899
+ 'Assignment'
130900
+ );
130901
+ test = lowerValueToTemporary(builder, assign);
130892
130902
  }
130893
130903
  builder.terminateWithContinuation(
130894
130904
  {
@@ -130899,8 +130909,8 @@ function lowerStatement(builder, stmtPath, label = null) {
130899
130909
  alternate: continuationBlock.id,
130900
130910
  fallthrough: continuationBlock.id,
130901
130911
  loc:
130902
- (_22 = stmt.node.loc) !== null && _22 !== void 0
130903
- ? _22
130912
+ (_20 = stmt.node.loc) !== null && _20 !== void 0
130913
+ ? _20
130904
130914
  : GeneratedSource,
130905
130915
  },
130906
130916
  continuationBlock
@@ -130910,8 +130920,8 @@ function lowerStatement(builder, stmtPath, label = null) {
130910
130920
  case 'DebuggerStatement': {
130911
130921
  const stmt = stmtPath;
130912
130922
  const loc =
130913
- (_23 = stmt.node.loc) !== null && _23 !== void 0
130914
- ? _23
130923
+ (_21 = stmt.node.loc) !== null && _21 !== void 0
130924
+ ? _21
130915
130925
  : GeneratedSource;
130916
130926
  builder.push({
130917
130927
  id: makeInstructionId(0),
@@ -130932,7 +130942,7 @@ function lowerStatement(builder, stmtPath, label = null) {
130932
130942
  builder.errors.push({
130933
130943
  reason: `(BuildHIR::lowerStatement) Handle TryStatement without a catch clause`,
130934
130944
  severity: exports.ErrorSeverity.Todo,
130935
- loc: (_24 = stmt.node.loc) !== null && _24 !== void 0 ? _24 : null,
130945
+ loc: (_22 = stmt.node.loc) !== null && _22 !== void 0 ? _22 : null,
130936
130946
  suggestions: null,
130937
130947
  });
130938
130948
  return;
@@ -130941,7 +130951,7 @@ function lowerStatement(builder, stmtPath, label = null) {
130941
130951
  builder.errors.push({
130942
130952
  reason: `(BuildHIR::lowerStatement) Handle TryStatement with a finalizer ('finally') clause`,
130943
130953
  severity: exports.ErrorSeverity.Todo,
130944
- loc: (_25 = stmt.node.loc) !== null && _25 !== void 0 ? _25 : null,
130954
+ loc: (_23 = stmt.node.loc) !== null && _23 !== void 0 ? _23 : null,
130945
130955
  suggestions: null,
130946
130956
  });
130947
130957
  }
@@ -130951,15 +130961,15 @@ function lowerStatement(builder, stmtPath, label = null) {
130951
130961
  const place = {
130952
130962
  kind: 'Identifier',
130953
130963
  identifier: builder.makeTemporary(
130954
- (_26 = handlerBindingPath.node.loc) !== null && _26 !== void 0
130955
- ? _26
130964
+ (_24 = handlerBindingPath.node.loc) !== null && _24 !== void 0
130965
+ ? _24
130956
130966
  : GeneratedSource
130957
130967
  ),
130958
130968
  effect: exports.Effect.Unknown,
130959
130969
  reactive: false,
130960
130970
  loc:
130961
- (_27 = handlerBindingPath.node.loc) !== null && _27 !== void 0
130962
- ? _27
130971
+ (_25 = handlerBindingPath.node.loc) !== null && _25 !== void 0
130972
+ ? _25
130963
130973
  : GeneratedSource,
130964
130974
  };
130965
130975
  promoteTemporary(place.identifier);
@@ -130971,8 +130981,8 @@ function lowerStatement(builder, stmtPath, label = null) {
130971
130981
  },
130972
130982
  type: null,
130973
130983
  loc:
130974
- (_28 = handlerBindingPath.node.loc) !== null && _28 !== void 0
130975
- ? _28
130984
+ (_26 = handlerBindingPath.node.loc) !== null && _26 !== void 0
130985
+ ? _26
130976
130986
  : GeneratedSource,
130977
130987
  });
130978
130988
  handlerBinding = {path: handlerBindingPath, place: place};
@@ -131032,8 +131042,8 @@ function lowerStatement(builder, stmtPath, label = null) {
131032
131042
  fallthrough: continuationBlock.id,
131033
131043
  id: makeInstructionId(0),
131034
131044
  loc:
131035
- (_29 = stmt.node.loc) !== null && _29 !== void 0
131036
- ? _29
131045
+ (_27 = stmt.node.loc) !== null && _27 !== void 0
131046
+ ? _27
131037
131047
  : GeneratedSource,
131038
131048
  },
131039
131049
  continuationBlock
@@ -131073,14 +131083,14 @@ function lowerStatement(builder, stmtPath, label = null) {
131073
131083
  builder.errors.push({
131074
131084
  reason: `(BuildHIR::lowerStatement) Handle ${stmtPath.type} statements`,
131075
131085
  severity: exports.ErrorSeverity.Todo,
131076
- loc: (_30 = stmtPath.node.loc) !== null && _30 !== void 0 ? _30 : null,
131086
+ loc: (_28 = stmtPath.node.loc) !== null && _28 !== void 0 ? _28 : null,
131077
131087
  suggestions: null,
131078
131088
  });
131079
131089
  lowerValueToTemporary(builder, {
131080
131090
  kind: 'UnsupportedNode',
131081
131091
  loc:
131082
- (_31 = stmtPath.node.loc) !== null && _31 !== void 0
131083
- ? _31
131092
+ (_29 = stmtPath.node.loc) !== null && _29 !== void 0
131093
+ ? _29
131084
131094
  : GeneratedSource,
131085
131095
  node: stmtPath.node,
131086
131096
  });
@@ -145203,19 +145213,6 @@ function codegenInstructionNullable(cx, instr) {
145203
145213
  }
145204
145214
  function codegenForInit(cx, init) {
145205
145215
  if (init.kind === 'SequenceExpression') {
145206
- for (const instr of init.instructions) {
145207
- if (instr.value.kind === 'DeclareContext') {
145208
- CompilerError.throwTodo({
145209
- reason: `Support for loops where the index variable is a context variable`,
145210
- loc: instr.loc,
145211
- description:
145212
- instr.value.lvalue.place.identifier.name != null
145213
- ? `\`${instr.value.lvalue.place.identifier.name.value}\` is a context variable`
145214
- : null,
145215
- suggestions: null,
145216
- });
145217
- }
145218
- }
145219
145216
  const body = codegenBlock(
145220
145217
  cx,
145221
145218
  init.instructions.map(instruction => ({
@@ -145226,20 +145223,37 @@ function codegenForInit(cx, init) {
145226
145223
  const declarators = [];
145227
145224
  let kind = 'const';
145228
145225
  body.forEach(instr => {
145229
- CompilerError.invariant(
145230
- instr.type === 'VariableDeclaration' &&
145231
- (instr.kind === 'let' || instr.kind === 'const'),
145232
- {
145233
- reason: 'Expected a variable declaration',
145234
- loc: init.loc,
145235
- description: `Got ${instr.type}`,
145236
- suggestions: null,
145226
+ var _a;
145227
+ let top = undefined;
145228
+ if (
145229
+ instr.type === 'ExpressionStatement' &&
145230
+ instr.expression.type === 'AssignmentExpression' &&
145231
+ instr.expression.operator === '=' &&
145232
+ instr.expression.left.type === 'Identifier' &&
145233
+ ((_a = top = declarators.at(-1)) === null || _a === void 0
145234
+ ? void 0
145235
+ : _a.id.type) === 'Identifier' &&
145236
+ (top === null || top === void 0 ? void 0 : top.id.name) ===
145237
+ instr.expression.left.name &&
145238
+ (top === null || top === void 0 ? void 0 : top.init) == null
145239
+ ) {
145240
+ top.init = instr.expression.right;
145241
+ } else {
145242
+ CompilerError.invariant(
145243
+ instr.type === 'VariableDeclaration' &&
145244
+ (instr.kind === 'let' || instr.kind === 'const'),
145245
+ {
145246
+ reason: 'Expected a variable declaration',
145247
+ loc: init.loc,
145248
+ description: `Got ${instr.type}`,
145249
+ suggestions: null,
145250
+ }
145251
+ );
145252
+ if (instr.kind === 'let') {
145253
+ kind = 'let';
145237
145254
  }
145238
- );
145239
- if (instr.kind === 'let') {
145240
- kind = 'let';
145255
+ declarators.push(...instr.declarations);
145241
145256
  }
145242
- declarators.push(...instr.declarations);
145243
145257
  });
145244
145258
  CompilerError.invariant(declarators.length > 0, {
145245
145259
  reason: 'Expected a variable declaration',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-plugin-react-compiler",
3
- "version": "0.0.0-experimental-50915ff-20241206",
3
+ "version": "0.0.0-experimental-16e4ce7-20241209",
4
4
  "description": "Babel plugin for React Compiler.",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",