flow-api-translator 0.10.0 → 0.10.1

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.
@@ -103,7 +103,7 @@ const getTransforms = (code, scopeManager) => {
103
103
 
104
104
 
105
105
  if (variableDef == null) {
106
- return VALID_REACT_IMPORTS.has(id.name);
106
+ return VALID_REACT_IMPORTS.has(id.name) || id.name.startsWith('React$');
107
107
  }
108
108
 
109
109
  const def = variableDef.defs[0]; // Detect:
@@ -421,50 +421,48 @@ const getTransforms = (code, scopeManager) => {
421
421
  if (referencedId.type === 'Identifier') {
422
422
  const exportedVar = topScope.set.get(referencedId.name);
423
423
 
424
- if (exportedVar == null || exportedVar.defs.length !== 1) {
425
- throw unexpectedTranslationError(referencedId, `Unable to find exported variable ${referencedId.name}`);
426
- }
427
-
428
- const def = exportedVar.defs[0];
424
+ if (exportedVar != null && exportedVar.defs.length === 1) {
425
+ const def = exportedVar.defs[0];
429
426
 
430
- switch (def.type) {
431
- case 'ImportBinding':
432
- {
433
- // `import type { Wut } from 'mod'; declare export default Wut;`
434
- // `import { type Wut } from 'mod'; declare export default Wut;`
435
- // these cases should be wrapped in a variable because they're exporting a type, not a value
436
- const specifier = def.node;
427
+ switch (def.type) {
428
+ case 'ImportBinding':
429
+ {
430
+ // `import type { Wut } from 'mod'; declare export default Wut;`
431
+ // `import { type Wut } from 'mod'; declare export default Wut;`
432
+ // these cases should be wrapped in a variable because they're exporting a type, not a value
433
+ const specifier = def.node;
437
434
 
438
- if (specifier.importKind === 'type' || specifier.parent.importKind === 'type') {
439
- // fallthrough to the "default" handling
440
- break;
441
- } // intentional fallthrough to the "value" handling
435
+ if (specifier.importKind === 'type' || specifier.parent.importKind === 'type') {
436
+ // fallthrough to the "default" handling
437
+ break;
438
+ } // intentional fallthrough to the "value" handling
442
439
 
443
- }
440
+ }
444
441
 
445
- case 'ClassName':
446
- case 'Enum':
447
- case 'FunctionName':
448
- case 'ImplicitGlobalVariable':
449
- case 'Variable':
450
- // there's already a variable defined to hold the type
451
- return {
452
- type: 'ExportDefaultDeclaration',
453
- declaration: {
454
- type: 'Identifier',
455
- name: referencedId.name
456
- },
457
- exportKind: 'value'
458
- };
459
-
460
- case 'CatchClause':
461
- case 'Parameter':
462
- case 'TypeParameter':
463
- throw translationError(def.node, `Unexpected variable def type: ${def.type}`);
464
-
465
- case 'Type':
466
- // fallthrough to the "default" handling
467
- break;
442
+ case 'ClassName':
443
+ case 'Enum':
444
+ case 'FunctionName':
445
+ case 'ImplicitGlobalVariable':
446
+ case 'Variable':
447
+ // there's already a variable defined to hold the type
448
+ return {
449
+ type: 'ExportDefaultDeclaration',
450
+ declaration: {
451
+ type: 'Identifier',
452
+ name: referencedId.name
453
+ },
454
+ exportKind: 'value'
455
+ };
456
+
457
+ case 'CatchClause':
458
+ case 'Parameter':
459
+ case 'TypeParameter':
460
+ throw translationError(def.node, `Unexpected variable def type: ${def.type}`);
461
+
462
+ case 'Type':
463
+ // fallthrough to the "default" handling
464
+ break;
465
+ }
468
466
  }
469
467
  } // intentional fallthrough to the "default" handling
470
468
 
@@ -1361,14 +1359,6 @@ const getTransforms = (code, scopeManager) => {
1361
1359
  };
1362
1360
  }
1363
1361
 
1364
- case '$Subtype':
1365
- case '$Supertype':
1366
- {
1367
- // These types are deprecated and shouldn't be used in any modern code
1368
- // so let's not even bother trying to figure it out
1369
- throw unsupportedTranslationError(node, fullTypeName);
1370
- }
1371
-
1372
1362
  case '$Values':
1373
1363
  {
1374
1364
  // `$Values<T>` => `T[keyof T]`
@@ -1422,8 +1412,32 @@ const getTransforms = (code, scopeManager) => {
1422
1412
 
1423
1413
 
1424
1414
  if (isReactImport(baseId)) {
1415
+ const reactId = {
1416
+ type: 'Identifier',
1417
+ name: `React`
1418
+ };
1419
+
1425
1420
  switch (fullTypeName) {
1421
+ case 'React$Context':
1422
+ case 'React.Context':
1423
+ return {
1424
+ type: 'TSTypeReference',
1425
+ typeName: {
1426
+ type: 'TSQualifiedName',
1427
+ left: reactId,
1428
+ right: {
1429
+ type: 'Identifier',
1430
+ name: `Context`
1431
+ }
1432
+ },
1433
+ typeParameters: {
1434
+ type: 'TSTypeParameterInstantiation',
1435
+ params: assertHasExactlyNTypeParameters(1)
1436
+ }
1437
+ };
1426
1438
  // React.Node -> React.ReactNode
1439
+
1440
+ case 'React$Node':
1427
1441
  case 'React.Node':
1428
1442
  {
1429
1443
  assertHasExactlyNTypeParameters(0);
@@ -1431,7 +1445,7 @@ const getTransforms = (code, scopeManager) => {
1431
1445
  type: 'TSTypeReference',
1432
1446
  typeName: {
1433
1447
  type: 'TSQualifiedName',
1434
- left: transform.Identifier(baseId, false),
1448
+ left: reactId,
1435
1449
  right: {
1436
1450
  type: 'Identifier',
1437
1451
  name: `ReactNode`
@@ -1442,13 +1456,14 @@ const getTransforms = (code, scopeManager) => {
1442
1456
  }
1443
1457
  // React.Element<typeof Component> -> React.ReactElement<typeof Component>
1444
1458
 
1459
+ case 'React$Element':
1445
1460
  case 'React.Element':
1446
1461
  {
1447
1462
  return {
1448
1463
  type: 'TSTypeReference',
1449
1464
  typeName: {
1450
1465
  type: 'TSQualifiedName',
1451
- left: transform.Identifier(baseId, false),
1466
+ left: reactId,
1452
1467
  right: {
1453
1468
  type: 'Identifier',
1454
1469
  name: `ReactElement`
@@ -1460,8 +1475,46 @@ const getTransforms = (code, scopeManager) => {
1460
1475
  }
1461
1476
  };
1462
1477
  }
1478
+ // React.ElementRef<typeof Component> -> React.ElementRef<typeof Component>
1479
+ // React$ElementRef<typeof Component> -> React.ElementRef<typeof Component>
1480
+
1481
+ case 'React$ElementRef':
1482
+ case 'React.ElementRef':
1483
+ return {
1484
+ type: 'TSTypeReference',
1485
+ typeName: {
1486
+ type: 'TSQualifiedName',
1487
+ left: reactId,
1488
+ right: {
1489
+ type: 'Identifier',
1490
+ name: `ElementRef`
1491
+ }
1492
+ },
1493
+ typeParameters: {
1494
+ type: 'TSTypeParameterInstantiation',
1495
+ params: assertHasExactlyNTypeParameters(1)
1496
+ }
1497
+ };
1498
+ // React$Fragment -> React.Fragment
1499
+ // React.Fragment -> React.Fragment
1500
+
1501
+ case 'React$FragmentType':
1502
+ case 'React.Fragment':
1503
+ assertHasExactlyNTypeParameters(0);
1504
+ return {
1505
+ type: 'TSTypeReference',
1506
+ typeName: {
1507
+ type: 'TSQualifiedName',
1508
+ left: reactId,
1509
+ right: {
1510
+ type: 'Identifier',
1511
+ name: `Fragment`
1512
+ }
1513
+ }
1514
+ };
1463
1515
  // React.MixedElement -> JSX.Element
1464
1516
 
1517
+ case 'React$MixedElement':
1465
1518
  case 'React.MixedElement':
1466
1519
  {
1467
1520
  assertHasExactlyNTypeParameters(0);
@@ -1481,10 +1534,16 @@ const getTransforms = (code, scopeManager) => {
1481
1534
  typeParameters: undefined
1482
1535
  };
1483
1536
  }
1484
- // React.AbstractComponent<Config> -> React.ForwardRefExoticComponent<Config>
1537
+ // React.AbstractComponent<Config> -> React.ForwardRefExoticComponent<Config & React.RefAttributes<unknown>>
1485
1538
  // React.AbstractComponent<Config, Instance> -> React.ForwardRefExoticComponent<Config & React.RefAttributes<Instance>>
1539
+ // React$AbstractComponent<Config, Instance> -> React.ForwardRefExoticComponent<Config & React.RefAttributes<Instance>>
1540
+ // React.ComponentType<Config> -> React.ForwardRefExoticComponent<Config & React.RefAttributes<unknown>>
1541
+ // React$ComponentType<Config> -> React.ForwardRefExoticComponent<Config & React.RefAttributes<unknown>>
1486
1542
 
1487
1543
  case 'React.AbstractComponent':
1544
+ case 'React$AbstractComponent':
1545
+ case 'React.ComponentType':
1546
+ case 'React$ComponentType':
1488
1547
  {
1489
1548
  const typeParameters = node.typeParameters;
1490
1549
 
@@ -1499,36 +1558,34 @@ const getTransforms = (code, scopeManager) => {
1499
1558
  }
1500
1559
 
1501
1560
  let newTypeParam = transform.TypeAnnotationType(params[0]);
1502
-
1503
- if (params[1] != null) {
1504
- newTypeParam = {
1505
- type: 'TSIntersectionType',
1506
- types: [newTypeParam, {
1507
- type: 'TSTypeReference',
1508
- typeName: {
1509
- type: 'TSQualifiedName',
1510
- left: {
1511
- type: 'Identifier',
1512
- name: 'React'
1513
- },
1514
- right: {
1515
- type: 'Identifier',
1516
- name: 'RefAttributes'
1517
- }
1561
+ newTypeParam = {
1562
+ type: 'TSIntersectionType',
1563
+ types: [newTypeParam, {
1564
+ type: 'TSTypeReference',
1565
+ typeName: {
1566
+ type: 'TSQualifiedName',
1567
+ left: {
1568
+ type: 'Identifier',
1569
+ name: 'React'
1518
1570
  },
1519
- typeParameters: {
1520
- type: 'TSTypeParameterInstantiation',
1521
- params: [transform.TypeAnnotationType(params[1])]
1571
+ right: {
1572
+ type: 'Identifier',
1573
+ name: 'RefAttributes'
1522
1574
  }
1523
- }]
1524
- };
1525
- }
1526
-
1575
+ },
1576
+ typeParameters: {
1577
+ type: 'TSTypeParameterInstantiation',
1578
+ params: [params[1] ? transform.TypeAnnotationType(params[1]) : {
1579
+ type: 'TSUnknownKeyword'
1580
+ }]
1581
+ }
1582
+ }]
1583
+ };
1527
1584
  return {
1528
1585
  type: 'TSTypeReference',
1529
1586
  typeName: {
1530
1587
  type: 'TSQualifiedName',
1531
- left: transform.Identifier(baseId, false),
1588
+ left: reactId,
1532
1589
  right: {
1533
1590
  type: 'Identifier',
1534
1591
  name: `ForwardRefExoticComponent`
@@ -1540,6 +1597,9 @@ const getTransforms = (code, scopeManager) => {
1540
1597
  }
1541
1598
  };
1542
1599
  }
1600
+
1601
+ default:
1602
+ throw unsupportedTranslationError(node, fullTypeName);
1543
1603
  }
1544
1604
  }
1545
1605
 
@@ -1610,8 +1670,6 @@ const getTransforms = (code, scopeManager) => {
1610
1670
  importKind: importKind != null ? importKind : 'value',
1611
1671
  source: transform.StringLiteral(node.source),
1612
1672
  specifiers: node.specifiers.map(spec => {
1613
- var _spec$importKind;
1614
-
1615
1673
  switch (spec.type) {
1616
1674
  case 'ImportDefaultSpecifier':
1617
1675
  return {
@@ -1633,7 +1691,7 @@ const getTransforms = (code, scopeManager) => {
1633
1691
 
1634
1692
  return {
1635
1693
  type: 'ImportSpecifier',
1636
- importKind: (_spec$importKind = spec.importKind) != null ? _spec$importKind : 'value',
1694
+ importKind: spec.importKind === 'type' ? 'type' : null,
1637
1695
  imported: transform.Identifier(spec.imported, false),
1638
1696
  local: transform.Identifier(spec.local, false)
1639
1697
  };
@@ -107,7 +107,7 @@ const getTransforms = (code: string, scopeManager: ScopeManager) => {
107
107
 
108
108
  // No variable found, it must be global. Using the `React` variable is enough in this case.
109
109
  if (variableDef == null) {
110
- return VALID_REACT_IMPORTS.has(id.name);
110
+ return VALID_REACT_IMPORTS.has(id.name) || id.name.startsWith('React$');
111
111
  }
112
112
 
113
113
  const def = variableDef.defs[0];
@@ -466,56 +466,51 @@ const getTransforms = (code: string, scopeManager: ScopeManager) => {
466
466
  // only Identifiers can be handled here.
467
467
  if (referencedId.type === 'Identifier') {
468
468
  const exportedVar = topScope.set.get(referencedId.name);
469
- if (exportedVar == null || exportedVar.defs.length !== 1) {
470
- throw unexpectedTranslationError(
471
- referencedId,
472
- `Unable to find exported variable ${referencedId.name}`,
473
- );
474
- }
475
-
476
- const def = exportedVar.defs[0];
477
- switch (def.type) {
478
- case 'ImportBinding': {
479
- // `import type { Wut } from 'mod'; declare export default Wut;`
480
- // `import { type Wut } from 'mod'; declare export default Wut;`
481
- // these cases should be wrapped in a variable because they're exporting a type, not a value
482
- const specifier = def.node;
483
- if (
484
- specifier.importKind === 'type' ||
485
- specifier.parent.importKind === 'type'
486
- ) {
469
+ if (exportedVar != null && exportedVar.defs.length === 1) {
470
+ const def = exportedVar.defs[0];
471
+ switch (def.type) {
472
+ case 'ImportBinding': {
473
+ // `import type { Wut } from 'mod'; declare export default Wut;`
474
+ // `import { type Wut } from 'mod'; declare export default Wut;`
475
+ // these cases should be wrapped in a variable because they're exporting a type, not a value
476
+ const specifier = def.node;
477
+ if (
478
+ specifier.importKind === 'type' ||
479
+ specifier.parent.importKind === 'type'
480
+ ) {
481
+ // fallthrough to the "default" handling
482
+ break;
483
+ }
484
+
485
+ // intentional fallthrough to the "value" handling
486
+ }
487
+ case 'ClassName':
488
+ case 'Enum':
489
+ case 'FunctionName':
490
+ case 'ImplicitGlobalVariable':
491
+ case 'Variable':
492
+ // there's already a variable defined to hold the type
493
+ return {
494
+ type: 'ExportDefaultDeclaration',
495
+ declaration: {
496
+ type: 'Identifier',
497
+ name: referencedId.name,
498
+ },
499
+ exportKind: 'value',
500
+ };
501
+
502
+ case 'CatchClause':
503
+ case 'Parameter':
504
+ case 'TypeParameter':
505
+ throw translationError(
506
+ def.node,
507
+ `Unexpected variable def type: ${def.type}`,
508
+ );
509
+
510
+ case 'Type':
487
511
  // fallthrough to the "default" handling
488
512
  break;
489
- }
490
-
491
- // intentional fallthrough to the "value" handling
492
513
  }
493
- case 'ClassName':
494
- case 'Enum':
495
- case 'FunctionName':
496
- case 'ImplicitGlobalVariable':
497
- case 'Variable':
498
- // there's already a variable defined to hold the type
499
- return {
500
- type: 'ExportDefaultDeclaration',
501
- declaration: {
502
- type: 'Identifier',
503
- name: referencedId.name,
504
- },
505
- exportKind: 'value',
506
- };
507
-
508
- case 'CatchClause':
509
- case 'Parameter':
510
- case 'TypeParameter':
511
- throw translationError(
512
- def.node,
513
- `Unexpected variable def type: ${def.type}`,
514
- );
515
-
516
- case 'Type':
517
- // fallthrough to the "default" handling
518
- break;
519
514
  }
520
515
  }
521
516
 
@@ -1498,13 +1493,6 @@ const getTransforms = (code: string, scopeManager: ScopeManager) => {
1498
1493
  };
1499
1494
  }
1500
1495
 
1501
- case '$Subtype':
1502
- case '$Supertype': {
1503
- // These types are deprecated and shouldn't be used in any modern code
1504
- // so let's not even bother trying to figure it out
1505
- throw unsupportedTranslationError(node, fullTypeName);
1506
- }
1507
-
1508
1496
  case '$Values': {
1509
1497
  // `$Values<T>` => `T[keyof T]`
1510
1498
  const transformedType = assertHasExactlyNTypeParameters(1)[0];
@@ -1560,15 +1548,38 @@ const getTransforms = (code: string, scopeManager: ScopeManager) => {
1560
1548
 
1561
1549
  // React special conversion:
1562
1550
  if (isReactImport(baseId)) {
1551
+ const reactId = {
1552
+ type: 'Identifier',
1553
+ name: `React`,
1554
+ };
1555
+
1563
1556
  switch (fullTypeName) {
1557
+ case 'React$Context':
1558
+ case 'React.Context':
1559
+ return {
1560
+ type: 'TSTypeReference',
1561
+ typeName: {
1562
+ type: 'TSQualifiedName',
1563
+ left: reactId,
1564
+ right: {
1565
+ type: 'Identifier',
1566
+ name: `Context`,
1567
+ },
1568
+ },
1569
+ typeParameters: {
1570
+ type: 'TSTypeParameterInstantiation',
1571
+ params: assertHasExactlyNTypeParameters(1),
1572
+ },
1573
+ };
1564
1574
  // React.Node -> React.ReactNode
1575
+ case 'React$Node':
1565
1576
  case 'React.Node': {
1566
1577
  assertHasExactlyNTypeParameters(0);
1567
1578
  return {
1568
1579
  type: 'TSTypeReference',
1569
1580
  typeName: {
1570
1581
  type: 'TSQualifiedName',
1571
- left: transform.Identifier(baseId, false),
1582
+ left: reactId,
1572
1583
  right: {
1573
1584
  type: 'Identifier',
1574
1585
  name: `ReactNode`,
@@ -1578,12 +1589,13 @@ const getTransforms = (code: string, scopeManager: ScopeManager) => {
1578
1589
  };
1579
1590
  }
1580
1591
  // React.Element<typeof Component> -> React.ReactElement<typeof Component>
1592
+ case 'React$Element':
1581
1593
  case 'React.Element': {
1582
1594
  return {
1583
1595
  type: 'TSTypeReference',
1584
1596
  typeName: {
1585
1597
  type: 'TSQualifiedName',
1586
- left: transform.Identifier(baseId, false),
1598
+ left: reactId,
1587
1599
  right: {
1588
1600
  type: 'Identifier',
1589
1601
  name: `ReactElement`,
@@ -1595,7 +1607,43 @@ const getTransforms = (code: string, scopeManager: ScopeManager) => {
1595
1607
  },
1596
1608
  };
1597
1609
  }
1610
+ // React.ElementRef<typeof Component> -> React.ElementRef<typeof Component>
1611
+ // React$ElementRef<typeof Component> -> React.ElementRef<typeof Component>
1612
+ case 'React$ElementRef':
1613
+ case 'React.ElementRef':
1614
+ return {
1615
+ type: 'TSTypeReference',
1616
+ typeName: {
1617
+ type: 'TSQualifiedName',
1618
+ left: reactId,
1619
+ right: {
1620
+ type: 'Identifier',
1621
+ name: `ElementRef`,
1622
+ },
1623
+ },
1624
+ typeParameters: {
1625
+ type: 'TSTypeParameterInstantiation',
1626
+ params: assertHasExactlyNTypeParameters(1),
1627
+ },
1628
+ };
1629
+ // React$Fragment -> React.Fragment
1630
+ // React.Fragment -> React.Fragment
1631
+ case 'React$FragmentType':
1632
+ case 'React.Fragment':
1633
+ assertHasExactlyNTypeParameters(0);
1634
+ return {
1635
+ type: 'TSTypeReference',
1636
+ typeName: {
1637
+ type: 'TSQualifiedName',
1638
+ left: reactId,
1639
+ right: {
1640
+ type: 'Identifier',
1641
+ name: `Fragment`,
1642
+ },
1643
+ },
1644
+ };
1598
1645
  // React.MixedElement -> JSX.Element
1646
+ case 'React$MixedElement':
1599
1647
  case 'React.MixedElement': {
1600
1648
  assertHasExactlyNTypeParameters(0);
1601
1649
  return {
@@ -1614,9 +1662,15 @@ const getTransforms = (code: string, scopeManager: ScopeManager) => {
1614
1662
  typeParameters: undefined,
1615
1663
  };
1616
1664
  }
1617
- // React.AbstractComponent<Config> -> React.ForwardRefExoticComponent<Config>
1665
+ // React.AbstractComponent<Config> -> React.ForwardRefExoticComponent<Config & React.RefAttributes<unknown>>
1618
1666
  // React.AbstractComponent<Config, Instance> -> React.ForwardRefExoticComponent<Config & React.RefAttributes<Instance>>
1619
- case 'React.AbstractComponent': {
1667
+ // React$AbstractComponent<Config, Instance> -> React.ForwardRefExoticComponent<Config & React.RefAttributes<Instance>>
1668
+ // React.ComponentType<Config> -> React.ForwardRefExoticComponent<Config & React.RefAttributes<unknown>>
1669
+ // React$ComponentType<Config> -> React.ForwardRefExoticComponent<Config & React.RefAttributes<unknown>>
1670
+ case 'React.AbstractComponent':
1671
+ case 'React$AbstractComponent':
1672
+ case 'React.ComponentType':
1673
+ case 'React$ComponentType': {
1620
1674
  const typeParameters = node.typeParameters;
1621
1675
  if (typeParameters == null || typeParameters.params.length === 0) {
1622
1676
  throw translationError(
@@ -1633,38 +1687,42 @@ const getTransforms = (code: string, scopeManager: ScopeManager) => {
1633
1687
  }
1634
1688
 
1635
1689
  let newTypeParam = transform.TypeAnnotationType(params[0]);
1636
- if (params[1] != null) {
1637
- newTypeParam = {
1638
- type: 'TSIntersectionType',
1639
- types: [
1640
- newTypeParam,
1641
- {
1642
- type: 'TSTypeReference',
1643
- typeName: {
1644
- type: 'TSQualifiedName',
1645
- left: {
1646
- type: 'Identifier',
1647
- name: 'React',
1648
- },
1649
- right: {
1650
- type: 'Identifier',
1651
- name: 'RefAttributes',
1652
- },
1690
+ newTypeParam = {
1691
+ type: 'TSIntersectionType',
1692
+ types: [
1693
+ newTypeParam,
1694
+ {
1695
+ type: 'TSTypeReference',
1696
+ typeName: {
1697
+ type: 'TSQualifiedName',
1698
+ left: {
1699
+ type: 'Identifier',
1700
+ name: 'React',
1653
1701
  },
1654
- typeParameters: {
1655
- type: 'TSTypeParameterInstantiation',
1656
- params: [transform.TypeAnnotationType(params[1])],
1702
+ right: {
1703
+ type: 'Identifier',
1704
+ name: 'RefAttributes',
1657
1705
  },
1658
1706
  },
1659
- ],
1660
- };
1661
- }
1707
+ typeParameters: {
1708
+ type: 'TSTypeParameterInstantiation',
1709
+ params: [
1710
+ params[1]
1711
+ ? transform.TypeAnnotationType(params[1])
1712
+ : {
1713
+ type: 'TSUnknownKeyword',
1714
+ },
1715
+ ],
1716
+ },
1717
+ },
1718
+ ],
1719
+ };
1662
1720
 
1663
1721
  return {
1664
1722
  type: 'TSTypeReference',
1665
1723
  typeName: {
1666
1724
  type: 'TSQualifiedName',
1667
- left: transform.Identifier(baseId, false),
1725
+ left: reactId,
1668
1726
  right: {
1669
1727
  type: 'Identifier',
1670
1728
  name: `ForwardRefExoticComponent`,
@@ -1676,6 +1734,8 @@ const getTransforms = (code: string, scopeManager: ScopeManager) => {
1676
1734
  },
1677
1735
  };
1678
1736
  }
1737
+ default:
1738
+ throw unsupportedTranslationError(node, fullTypeName);
1679
1739
  }
1680
1740
  }
1681
1741
 
@@ -1787,7 +1847,7 @@ const getTransforms = (code: string, scopeManager: ScopeManager) => {
1787
1847
  }
1788
1848
  return {
1789
1849
  type: 'ImportSpecifier',
1790
- importKind: spec.importKind ?? 'value',
1850
+ importKind: spec.importKind === 'type' ? 'type' : null,
1791
1851
  imported: transform.Identifier(spec.imported, false),
1792
1852
  local: transform.Identifier(spec.local, false),
1793
1853
  };
@@ -650,7 +650,7 @@ export interface ImportSpecifier extends BaseNode {
650
650
  +type: 'ImportSpecifier';
651
651
  +local: Identifier;
652
652
  +imported: Identifier;
653
- +importKind: ImportKind;
653
+ +importKind: ?ImportKind;
654
654
  }
655
655
  export type IterationStatement =
656
656
  | DoWhileStatement
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flow-api-translator",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
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",
@@ -12,9 +12,10 @@
12
12
  "@babel/code-frame": "^7.16.0",
13
13
  "@typescript-eslint/visitor-keys": "^5.42.0",
14
14
  "flow-enums-runtime": "^0.0.6",
15
- "hermes-estree": "0.10.0",
16
- "hermes-parser": "0.10.0",
17
- "hermes-transform": "0.10.0"
15
+ "hermes-eslint": "0.10.1",
16
+ "hermes-estree": "0.10.1",
17
+ "hermes-parser": "0.10.1",
18
+ "hermes-transform": "0.10.1"
18
19
  },
19
20
  "peerDependencies": {
20
21
  "prettier": "^2.7.1"