flow-api-translator 0.26.0 → 0.28.0

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.
@@ -69,9 +69,9 @@ function transferProgramStatementProperties(stmt, orgStmt) {
69
69
  stmt.loc = orgStmt.loc;
70
70
  }
71
71
  /**
72
- * Consume an abribray Flow AST and convert it into a Type defintion file.
72
+ * Consume an arbitrary Flow AST and convert it into a type definition file.
73
73
  *
74
- * To do this all runtime logic will be stripped and only Type that describe the module boundary will remain.
74
+ * To do this all runtime logic will be stripped and only types that describe the module boundary will remain.
75
75
  */
76
76
 
77
77
 
@@ -355,8 +355,8 @@ function convertExpressionToTypeAnnotation(expr, context) {
355
355
 
356
356
  case 'Identifier':
357
357
  {
358
- return [_hermesTransform.t.GenericTypeAnnotation({
359
- id: _hermesTransform.t.Identifier({
358
+ return [_hermesTransform.t.TypeofTypeAnnotation({
359
+ argument: _hermesTransform.t.Identifier({
360
360
  name: expr.name
361
361
  })
362
362
  }), (0, _FlowAnalyze.analyzeTypeDependencies)(expr, context)];
@@ -381,6 +381,13 @@ function convertExpressionToTypeAnnotation(expr, context) {
381
381
  return [resultExpr, deps];
382
382
  }
383
383
 
384
+ case 'MemberExpression':
385
+ {
386
+ return [_hermesTransform.t.TypeofTypeAnnotation({
387
+ argument: convertExpressionToTypeofIdentifier(expr, context)
388
+ }), (0, _FlowAnalyze.analyzeTypeDependencies)(expr, context)];
389
+ }
390
+
384
391
  default:
385
392
  {
386
393
  return [(0, _ErrorUtils.flowFixMeOrError)(expr, `convertExpressionToTypeAnnotation: Unsupported expression of type "${expr.type}", a type annotation is required.`, context), []];
@@ -388,6 +395,12 @@ function convertExpressionToTypeAnnotation(expr, context) {
388
395
  }
389
396
  }
390
397
 
398
+ function inheritComments(fromNode, toNode) {
399
+ // $FlowFixMe[unclear-type]
400
+ toNode.comments = fromNode.comments;
401
+ return toNode;
402
+ }
403
+
391
404
  function convertObjectExpression(expr, context) {
392
405
  const [resultProperties, deps] = convertArray(expr.properties, prop => {
393
406
  switch (prop.type) {
@@ -411,11 +424,11 @@ function convertObjectExpression(expr, context) {
411
424
  }
412
425
 
413
426
  const [resultExpr, deps] = convertAFunction(prop.value, context);
414
- return [_hermesTransform.t.ObjectTypeMethodSignature({
427
+ return [inheritComments(prop, _hermesTransform.t.ObjectTypeMethodSignature({
415
428
  // $FlowFixMe[incompatible-call]
416
429
  key: (0, _hermesTransform.asDetachedNode)(prop.key),
417
430
  value: resultExpr
418
- }), deps];
431
+ })), deps];
419
432
  }
420
433
 
421
434
  if (prop.kind === 'get' || prop.kind === 'set') {
@@ -425,22 +438,22 @@ function convertObjectExpression(expr, context) {
425
438
 
426
439
  const kind = prop.kind;
427
440
  const [resultExpr, deps] = convertAFunction(prop.value, context);
428
- return [_hermesTransform.t.ObjectTypeAccessorSignature({
441
+ return [inheritComments(prop, _hermesTransform.t.ObjectTypeAccessorSignature({
429
442
  // $FlowFixMe[incompatible-call]
430
443
  key: (0, _hermesTransform.asDetachedNode)(prop.key),
431
444
  kind,
432
445
  value: resultExpr
433
- }), deps];
446
+ })), deps];
434
447
  }
435
448
 
436
449
  const [resultExpr, deps] = convertExpressionToTypeAnnotation(prop.value, context);
437
- return [_hermesTransform.t.ObjectTypePropertySignature({
450
+ return [inheritComments(prop, _hermesTransform.t.ObjectTypePropertySignature({
438
451
  // $FlowFixMe[incompatible-call]
439
452
  key: (0, _hermesTransform.asDetachedNode)(prop.key),
440
453
  value: resultExpr,
441
454
  optional: false,
442
455
  variance: null
443
- }), deps];
456
+ })), deps];
444
457
  }
445
458
  }
446
459
  });
@@ -777,6 +790,32 @@ function convertExpressionToIdentifier(node, context) {
777
790
  throw (0, _ErrorUtils.translationError)(node, `Expected ${node.type} to be an Identifier or Member with Identifier property, non-Super object.`, context);
778
791
  }
779
792
 
793
+ function convertExpressionToTypeofIdentifier(node, context) {
794
+ if (node.type === 'Identifier') {
795
+ return _hermesTransform.t.Identifier({
796
+ name: node.name
797
+ });
798
+ }
799
+
800
+ if (node.type === 'MemberExpression') {
801
+ const {
802
+ property,
803
+ object
804
+ } = node;
805
+
806
+ if (property.type === 'Identifier' && object.type !== 'Super') {
807
+ return _hermesTransform.t.QualifiedTypeofIdentifier({
808
+ qualification: convertExpressionToTypeofIdentifier(object, context),
809
+ id: _hermesTransform.t.Identifier({
810
+ name: property.name
811
+ })
812
+ });
813
+ }
814
+ }
815
+
816
+ throw (0, _ErrorUtils.translationError)(node, `Expected ${node.type} to be an Identifier or Member with Identifier property, non-Super object.`, context);
817
+ }
818
+
780
819
  function convertSuperClassHelper(detachedId, nodeForDependencies, superTypeParameters, context) {
781
820
  const [resultTypeParams, typeParamsDeps] = convertTypeParameterInstantiationOrNull(superTypeParameters, context);
782
821
  const superDeps = (0, _FlowAnalyze.analyzeTypeDependencies)(nodeForDependencies, context);
@@ -845,6 +884,8 @@ function convertClassMember(member, context) {
845
884
  switch (member.type) {
846
885
  case 'PropertyDefinition':
847
886
  {
887
+ var _member$value;
888
+
848
889
  // PrivateIdentifier's are not exposed so can be stripped.
849
890
  if (member.key.type === 'PrivateIdentifier') {
850
891
  return EMPTY_TRANSLATION_RESULT;
@@ -854,6 +895,18 @@ function convertClassMember(member, context) {
854
895
  throw (0, _ErrorUtils.translationError)(member.key, `ClassMember PropertyDefinition: Unsupported key type of "${member.key.type}"`, context);
855
896
  }
856
897
 
898
+ if (((_member$value = member.value) == null ? void 0 : _member$value.type) === 'ArrowFunctionExpression' && member.typeAnnotation == null) {
899
+ const [resultTypeAnnotation, deps] = convertAFunction(member.value, context);
900
+ return [_hermesTransform.t.ObjectTypePropertySignature({
901
+ // $FlowFixMe[incompatible-call]
902
+ key: (0, _hermesTransform.asDetachedNode)(member.key),
903
+ value: resultTypeAnnotation,
904
+ optional: member.optional,
905
+ static: member.static,
906
+ variance: member.variance
907
+ }), deps];
908
+ }
909
+
857
910
  const [resultTypeAnnotation, deps] = convertTypeAnnotation(member.typeAnnotation, member, context);
858
911
  return [_hermesTransform.t.ObjectTypePropertySignature({
859
912
  // $FlowFixMe[incompatible-call]
@@ -872,18 +925,21 @@ function convertClassMember(member, context) {
872
925
  return EMPTY_TRANSLATION_RESULT;
873
926
  }
874
927
 
875
- if (!(0, _hermesEstree.isIdentifier)(member.key) && !(0, _hermesEstree.isStringLiteral)(member.key) && !(0, _hermesEstree.isNumericLiteral)(member.key)) {
928
+ if (!(0, _hermesEstree.isIdentifier)(member.key) && !(0, _hermesEstree.isStringLiteral)(member.key) && !(0, _hermesEstree.isNumericLiteral)(member.key) && !((0, _hermesEstree.isMemberExpressionWithNonComputedProperty)(member.key) && member.key.object.type === 'Identifier' && member.key.object.name === 'Symbol' && ['iterator', 'asyncIterator'].includes(member.key.property.name))) {
876
929
  throw (0, _ErrorUtils.translationError)(member.key, `ClassMember PropertyDefinition: Unsupported key type of "${member.key.type}"`, context);
877
930
  }
878
931
 
879
932
  const [resultValue, deps] = convertAFunction(member.value, context);
933
+ const newKey = (0, _hermesEstree.isMemberExpressionWithNonComputedProperty)(member.key) && member.key.object.type === 'Identifier' && member.key.object.name === 'Symbol' ? _hermesTransform.t.Identifier({
934
+ name: `@@${member.key.property.name}`
935
+ }) : member.key;
880
936
 
881
937
  if (member.kind === 'get' || member.kind === 'set') {
882
938
  // accessors are methods - but flow accessor signatures are properties
883
939
  const kind = member.kind;
884
940
  return [_hermesTransform.t.ObjectTypeAccessorSignature({
885
941
  // $FlowFixMe[incompatible-call]
886
- key: (0, _hermesTransform.asDetachedNode)(member.key),
942
+ key: (0, _hermesTransform.asDetachedNode)(newKey),
887
943
  value: resultValue,
888
944
  static: member.static,
889
945
  kind
@@ -892,7 +948,7 @@ function convertClassMember(member, context) {
892
948
 
893
949
  return [_hermesTransform.t.ObjectTypeMethodSignature({
894
950
  // $FlowFixMe[incompatible-call]
895
- key: (0, _hermesTransform.asDetachedNode)(member.key),
951
+ key: (0, _hermesTransform.asDetachedNode)(newKey),
896
952
  value: resultValue,
897
953
  static: member.static
898
954
  }), deps];
@@ -1057,19 +1113,19 @@ function convertAFunction(func, context) {
1057
1113
  }
1058
1114
 
1059
1115
  function convertFunctionParameters(params, context) {
1060
- return params.reduce(([resultParams, restParam, paramsDeps], param) => {
1116
+ return params.reduce(([resultParams, restParam, paramsDeps], param, index) => {
1061
1117
  switch (param.type) {
1062
1118
  case 'Identifier':
1063
1119
  case 'ArrayPattern':
1064
1120
  case 'ObjectPattern':
1065
1121
  {
1066
- const [resultParam, deps] = convertBindingNameToFunctionTypeParam(param, context);
1122
+ const [resultParam, deps] = convertBindingNameToFunctionTypeParam(param, context, index, false);
1067
1123
  return [[...resultParams, resultParam], restParam, [...paramsDeps, ...deps]];
1068
1124
  }
1069
1125
 
1070
1126
  case 'AssignmentPattern':
1071
1127
  {
1072
- const [resultParam, deps] = convertBindingNameToFunctionTypeParam(param.left, context);
1128
+ const [resultParam, deps] = convertBindingNameToFunctionTypeParam(param.left, context, index, true);
1073
1129
  return [[...resultParams, resultParam], restParam, [...paramsDeps, ...deps]];
1074
1130
  }
1075
1131
 
@@ -1080,22 +1136,22 @@ function convertFunctionParameters(params, context) {
1080
1136
  }
1081
1137
 
1082
1138
  const [resultParam, deps] = convertBindingNameToFunctionTypeParam( // $FlowFixMe[incompatible-call] I dont think these other cases are possible
1083
- param.argument, context);
1139
+ param.argument, context, index, false);
1084
1140
  return [resultParams, resultParam, [...paramsDeps, ...deps]];
1085
1141
  }
1086
1142
  }
1087
1143
  }, [[], null, []]);
1088
1144
  }
1089
1145
 
1090
- function convertBindingNameToFunctionTypeParam(pat, context) {
1091
- const name = pat.type === 'Identifier' ? pat.name : null;
1146
+ function convertBindingNameToFunctionTypeParam(pat, context, index, isAssignment) {
1147
+ const name = pat.type === 'Identifier' ? pat.name : `$$PARAM_${index}$$`;
1092
1148
  const [resultParamTypeAnnotation, paramDeps] = convertTypeAnnotation(pat.typeAnnotation, pat, context);
1093
1149
  return [_hermesTransform.t.FunctionTypeParam({
1094
1150
  name: name != null ? _hermesTransform.t.Identifier({
1095
1151
  name
1096
1152
  }) : null,
1097
1153
  typeAnnotation: resultParamTypeAnnotation,
1098
- optional: pat.type === 'Identifier' ? pat.optional : false
1154
+ optional: isAssignment || (pat.type === 'Identifier' ? pat.optional : false)
1099
1155
  }), paramDeps];
1100
1156
  }
1101
1157
 
@@ -50,6 +50,7 @@ import type {
50
50
  ObjectTypeProperty,
51
51
  OpaqueType,
52
52
  QualifiedTypeIdentifier,
53
+ QualifiedTypeofIdentifier,
53
54
  Program,
54
55
  RestElement,
55
56
  Statement,
@@ -84,6 +85,7 @@ import {
84
85
  isStringLiteral,
85
86
  isNumericLiteral,
86
87
  isIdentifier,
88
+ isMemberExpressionWithNonComputedProperty,
87
89
  } from 'hermes-estree';
88
90
 
89
91
  const EMPTY_TRANSLATION_RESULT = [null, []];
@@ -149,9 +151,9 @@ function transferProgramStatementProperties(
149
151
  }
150
152
 
151
153
  /**
152
- * Consume an abribray Flow AST and convert it into a Type defintion file.
154
+ * Consume an arbitrary Flow AST and convert it into a type definition file.
153
155
  *
154
- * To do this all runtime logic will be stripped and only Type that describe the module boundary will remain.
156
+ * To do this all runtime logic will be stripped and only types that describe the module boundary will remain.
155
157
  */
156
158
  export default function flowToFlowDef(
157
159
  ast: Program,
@@ -443,7 +445,7 @@ function convertExpressionToTypeAnnotation(
443
445
  }
444
446
  case 'Identifier': {
445
447
  return [
446
- t.GenericTypeAnnotation({id: t.Identifier({name: expr.name})}),
448
+ t.TypeofTypeAnnotation({argument: t.Identifier({name: expr.name})}),
447
449
  analyzeTypeDependencies(expr, context),
448
450
  ];
449
451
  }
@@ -460,6 +462,14 @@ function convertExpressionToTypeAnnotation(
460
462
  const [resultExpr, deps] = convertAFunction(expr, context);
461
463
  return [resultExpr, deps];
462
464
  }
465
+ case 'MemberExpression': {
466
+ return [
467
+ t.TypeofTypeAnnotation({
468
+ argument: convertExpressionToTypeofIdentifier(expr, context),
469
+ }),
470
+ analyzeTypeDependencies(expr, context),
471
+ ];
472
+ }
463
473
  default: {
464
474
  return [
465
475
  flowFixMeOrError(
@@ -473,6 +483,15 @@ function convertExpressionToTypeAnnotation(
473
483
  }
474
484
  }
475
485
 
486
+ function inheritComments<T: DetachedNode<ESNode>>(
487
+ fromNode: ESNode,
488
+ toNode: T,
489
+ ): T {
490
+ // $FlowFixMe[unclear-type]
491
+ (toNode: any).comments = (fromNode: any).comments;
492
+ return toNode;
493
+ }
494
+
476
495
  function convertObjectExpression(
477
496
  expr: ObjectExpression,
478
497
  context: TranslationContext,
@@ -513,13 +532,16 @@ function convertObjectExpression(
513
532
 
514
533
  const [resultExpr, deps] = convertAFunction(prop.value, context);
515
534
  return [
516
- t.ObjectTypeMethodSignature({
517
- // $FlowFixMe[incompatible-call]
518
- key: asDetachedNode<
519
- Identifier | NumericLiteral | StringLiteral | Expression,
520
- >(prop.key),
521
- value: resultExpr,
522
- }),
535
+ inheritComments(
536
+ prop,
537
+ t.ObjectTypeMethodSignature({
538
+ // $FlowFixMe[incompatible-call]
539
+ key: asDetachedNode<
540
+ Identifier | NumericLiteral | StringLiteral | Expression,
541
+ >(prop.key),
542
+ value: resultExpr,
543
+ }),
544
+ ),
523
545
  deps,
524
546
  ];
525
547
  }
@@ -539,14 +561,17 @@ function convertObjectExpression(
539
561
  const kind = prop.kind;
540
562
  const [resultExpr, deps] = convertAFunction(prop.value, context);
541
563
  return [
542
- t.ObjectTypeAccessorSignature({
543
- // $FlowFixMe[incompatible-call]
544
- key: asDetachedNode<
545
- Identifier | NumericLiteral | StringLiteral | Expression,
546
- >(prop.key),
547
- kind,
548
- value: resultExpr,
549
- }),
564
+ inheritComments(
565
+ prop,
566
+ t.ObjectTypeAccessorSignature({
567
+ // $FlowFixMe[incompatible-call]
568
+ key: asDetachedNode<
569
+ Identifier | NumericLiteral | StringLiteral | Expression,
570
+ >(prop.key),
571
+ kind,
572
+ value: resultExpr,
573
+ }),
574
+ ),
550
575
  deps,
551
576
  ];
552
577
  }
@@ -557,15 +582,18 @@ function convertObjectExpression(
557
582
  );
558
583
 
559
584
  return [
560
- t.ObjectTypePropertySignature({
561
- // $FlowFixMe[incompatible-call]
562
- key: asDetachedNode<
563
- Identifier | NumericLiteral | StringLiteral | Expression,
564
- >(prop.key),
565
- value: resultExpr,
566
- optional: false,
567
- variance: null,
568
- }),
585
+ inheritComments(
586
+ prop,
587
+ t.ObjectTypePropertySignature({
588
+ // $FlowFixMe[incompatible-call]
589
+ key: asDetachedNode<
590
+ Identifier | NumericLiteral | StringLiteral | Expression,
591
+ >(prop.key),
592
+ value: resultExpr,
593
+ optional: false,
594
+ variance: null,
595
+ }),
596
+ ),
569
597
  deps,
570
598
  ];
571
599
  }
@@ -1003,6 +1031,31 @@ function convertExpressionToIdentifier(
1003
1031
  );
1004
1032
  }
1005
1033
 
1034
+ function convertExpressionToTypeofIdentifier(
1035
+ node: Expression,
1036
+ context: TranslationContext,
1037
+ ): DetachedNode<Identifier> | DetachedNode<QualifiedTypeofIdentifier> {
1038
+ if (node.type === 'Identifier') {
1039
+ return t.Identifier({name: node.name});
1040
+ }
1041
+
1042
+ if (node.type === 'MemberExpression') {
1043
+ const {property, object} = node;
1044
+ if (property.type === 'Identifier' && object.type !== 'Super') {
1045
+ return t.QualifiedTypeofIdentifier({
1046
+ qualification: convertExpressionToTypeofIdentifier(object, context),
1047
+ id: t.Identifier({name: property.name}),
1048
+ });
1049
+ }
1050
+ }
1051
+
1052
+ throw translationError(
1053
+ node,
1054
+ `Expected ${node.type} to be an Identifier or Member with Identifier property, non-Super object.`,
1055
+ context,
1056
+ );
1057
+ }
1058
+
1006
1059
  function convertSuperClassHelper(
1007
1060
  detachedId: DetachedNode<Identifier | QualifiedTypeIdentifier>,
1008
1061
  nodeForDependencies: ESNode,
@@ -1135,6 +1188,30 @@ function convertClassMember(
1135
1188
  );
1136
1189
  }
1137
1190
 
1191
+ if (
1192
+ member.value?.type === 'ArrowFunctionExpression' &&
1193
+ member.typeAnnotation == null
1194
+ ) {
1195
+ const [resultTypeAnnotation, deps] = convertAFunction(
1196
+ member.value,
1197
+ context,
1198
+ );
1199
+
1200
+ return [
1201
+ t.ObjectTypePropertySignature({
1202
+ // $FlowFixMe[incompatible-call]
1203
+ key: asDetachedNode<
1204
+ ClassPropertyNameComputed | ClassPropertyNameNonComputed,
1205
+ >(member.key),
1206
+ value: resultTypeAnnotation,
1207
+ optional: member.optional,
1208
+ static: member.static,
1209
+ variance: member.variance,
1210
+ }),
1211
+ deps,
1212
+ ];
1213
+ }
1214
+
1138
1215
  const [resultTypeAnnotation, deps] = convertTypeAnnotation(
1139
1216
  member.typeAnnotation,
1140
1217
  member,
@@ -1163,7 +1240,13 @@ function convertClassMember(
1163
1240
  if (
1164
1241
  !isIdentifier(member.key) &&
1165
1242
  !isStringLiteral(member.key) &&
1166
- !isNumericLiteral(member.key)
1243
+ !isNumericLiteral(member.key) &&
1244
+ !(
1245
+ isMemberExpressionWithNonComputedProperty(member.key) &&
1246
+ member.key.object.type === 'Identifier' &&
1247
+ member.key.object.name === 'Symbol' &&
1248
+ ['iterator', 'asyncIterator'].includes(member.key.property.name)
1249
+ )
1167
1250
  ) {
1168
1251
  throw translationError(
1169
1252
  member.key,
@@ -1174,15 +1257,23 @@ function convertClassMember(
1174
1257
 
1175
1258
  const [resultValue, deps] = convertAFunction(member.value, context);
1176
1259
 
1260
+ const newKey =
1261
+ isMemberExpressionWithNonComputedProperty(member.key) &&
1262
+ member.key.object.type === 'Identifier' &&
1263
+ member.key.object.name === 'Symbol'
1264
+ ? t.Identifier({name: `@@${member.key.property.name}`})
1265
+ : member.key;
1266
+
1177
1267
  if (member.kind === 'get' || member.kind === 'set') {
1178
1268
  // accessors are methods - but flow accessor signatures are properties
1179
1269
  const kind = member.kind;
1270
+
1180
1271
  return [
1181
1272
  t.ObjectTypeAccessorSignature({
1182
1273
  // $FlowFixMe[incompatible-call]
1183
1274
  key: asDetachedNode<
1184
1275
  ClassPropertyNameComputed | ClassPropertyNameNonComputed,
1185
- >(member.key),
1276
+ >(newKey),
1186
1277
  value: resultValue,
1187
1278
  static: member.static,
1188
1279
  kind,
@@ -1196,7 +1287,7 @@ function convertClassMember(
1196
1287
  // $FlowFixMe[incompatible-call]
1197
1288
  key: asDetachedNode<
1198
1289
  ClassPropertyNameComputed | ClassPropertyNameNonComputed,
1199
- >(member.key),
1290
+ >(newKey),
1200
1291
  value: resultValue,
1201
1292
  static: member.static,
1202
1293
  }),
@@ -1458,7 +1549,7 @@ function convertFunctionParameters(
1458
1549
  context: TranslationContext,
1459
1550
  ): TranslatedFunctionParametersResults {
1460
1551
  return params.reduce<TranslatedFunctionParametersResults>(
1461
- ([resultParams, restParam, paramsDeps], param) => {
1552
+ ([resultParams, restParam, paramsDeps], param, index) => {
1462
1553
  switch (param.type) {
1463
1554
  case 'Identifier':
1464
1555
  case 'ArrayPattern':
@@ -1466,6 +1557,8 @@ function convertFunctionParameters(
1466
1557
  const [resultParam, deps] = convertBindingNameToFunctionTypeParam(
1467
1558
  param,
1468
1559
  context,
1560
+ index,
1561
+ false,
1469
1562
  );
1470
1563
  return [
1471
1564
  [...resultParams, resultParam],
@@ -1477,6 +1570,8 @@ function convertFunctionParameters(
1477
1570
  const [resultParam, deps] = convertBindingNameToFunctionTypeParam(
1478
1571
  param.left,
1479
1572
  context,
1573
+ index,
1574
+ true,
1480
1575
  );
1481
1576
  return [
1482
1577
  [...resultParams, resultParam],
@@ -1496,6 +1591,8 @@ function convertFunctionParameters(
1496
1591
  // $FlowFixMe[incompatible-call] I dont think these other cases are possible
1497
1592
  param.argument,
1498
1593
  context,
1594
+ index,
1595
+ false,
1499
1596
  );
1500
1597
  return [resultParams, resultParam, [...paramsDeps, ...deps]];
1501
1598
  }
@@ -1508,8 +1605,10 @@ function convertFunctionParameters(
1508
1605
  function convertBindingNameToFunctionTypeParam(
1509
1606
  pat: BindingName,
1510
1607
  context: TranslationContext,
1608
+ index: number,
1609
+ isAssignment: boolean,
1511
1610
  ): TranslatedResult<FunctionTypeParam> {
1512
- const name = pat.type === 'Identifier' ? pat.name : null;
1611
+ const name = pat.type === 'Identifier' ? pat.name : `$$PARAM_${index}$$`;
1513
1612
  const [resultParamTypeAnnotation, paramDeps] = convertTypeAnnotation(
1514
1613
  pat.typeAnnotation,
1515
1614
  pat,
@@ -1519,7 +1618,8 @@ function convertBindingNameToFunctionTypeParam(
1519
1618
  t.FunctionTypeParam({
1520
1619
  name: name != null ? t.Identifier({name}) : null,
1521
1620
  typeAnnotation: resultParamTypeAnnotation,
1522
- optional: pat.type === 'Identifier' ? pat.optional : false,
1621
+ optional:
1622
+ isAssignment || (pat.type === 'Identifier' ? pat.optional : false),
1523
1623
  }),
1524
1624
  paramDeps,
1525
1625
  ];
@@ -455,6 +455,7 @@ export type Expression =
455
455
  | TSAsExpression
456
456
  | TSInstantiationExpression
457
457
  | TSNonNullExpression
458
+ | TSQualifiedName
458
459
  | TSTypeAssertion
459
460
  | UnaryExpression
460
461
  | UpdateExpression
@@ -772,6 +773,7 @@ export type LeftHandSideExpression =
772
773
  | ThisExpression
773
774
  | TSAsExpression
774
775
  | TSNonNullExpression
776
+ | TSQualifiedName
775
777
  | TSTypeAssertion;
776
778
  export interface LineComment extends BaseToken {
777
779
  +type: 'Line';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flow-api-translator",
3
- "version": "0.26.0",
3
+ "version": "0.28.0",
4
4
  "description": "Toolkit for creating Flow and TypeScript compatible libraries from Flow source code.",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",
@@ -13,10 +13,10 @@
13
13
  "@typescript-eslint/parser": "7.2.0",
14
14
  "@typescript-eslint/visitor-keys": "7.2.0",
15
15
  "flow-enums-runtime": "^0.0.6",
16
- "hermes-eslint": "0.26.0",
17
- "hermes-estree": "0.26.0",
18
- "hermes-parser": "0.26.0",
19
- "hermes-transform": "0.26.0",
16
+ "hermes-eslint": "0.28.0",
17
+ "hermes-estree": "0.28.0",
18
+ "hermes-parser": "0.28.0",
19
+ "hermes-transform": "0.28.0",
20
20
  "typescript": "5.3.2"
21
21
  },
22
22
  "peerDependencies": {