flow-api-translator 0.34.0 → 0.36.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.
- package/dist/flowDefToTSDef.js +10 -9
- package/dist/flowDefToTSDef.js.flow +13 -5
- package/dist/src/flowDefToTSDef.js +10 -9
- package/package.json +5 -5
package/dist/flowDefToTSDef.js
CHANGED
|
@@ -85,6 +85,7 @@ function flowDefToTSDef(originalCode, ast, scopeManager, opts) {
|
|
|
85
85
|
for (const node of ast.body) {
|
|
86
86
|
if (node.type in transform) {
|
|
87
87
|
const result = transform[// $FlowExpectedError[prop-missing]
|
|
88
|
+
// $FlowFixMe[incompatible-type]
|
|
88
89
|
node.type]( // $FlowExpectedError[incompatible-type]
|
|
89
90
|
node);
|
|
90
91
|
tsBody.push(...(Array.isArray(result) ? result : [result]));
|
|
@@ -3120,7 +3121,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3120
3121
|
|
|
3121
3122
|
ObjectTypeAnnotation(node) {
|
|
3122
3123
|
if (node.properties.length === 1 && node.properties[0].type === 'ObjectTypeMappedTypeProperty') {
|
|
3123
|
-
var _prop$variance;
|
|
3124
|
+
var _prop$variance, _prop$variance2;
|
|
3124
3125
|
|
|
3125
3126
|
// Mapped Object Object types must not have other object properties.
|
|
3126
3127
|
const prop = node.properties[0];
|
|
@@ -3145,7 +3146,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3145
3146
|
name: prop.keyTparam.name
|
|
3146
3147
|
},
|
|
3147
3148
|
constraint: transformTypeAnnotationType(prop.sourceType),
|
|
3148
|
-
readonly: ((_prop$variance = prop.variance) == null ? void 0 : _prop$variance.kind) === 'plus',
|
|
3149
|
+
readonly: ((_prop$variance = prop.variance) == null ? void 0 : _prop$variance.kind) === 'plus' || ((_prop$variance2 = prop.variance) == null ? void 0 : _prop$variance2.kind) === 'readonly',
|
|
3149
3150
|
optional: prop.optional === 'Optional',
|
|
3150
3151
|
typeAnnotation: transformTypeAnnotationType(prop.propType),
|
|
3151
3152
|
nameType: null
|
|
@@ -3366,10 +3367,10 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3366
3367
|
},
|
|
3367
3368
|
|
|
3368
3369
|
ObjectTypeIndexer(node) {
|
|
3369
|
-
var _node$
|
|
3370
|
+
var _node$variance3, _node$variance4;
|
|
3370
3371
|
|
|
3371
3372
|
if (node.key.type === 'GenericTypeAnnotation') {
|
|
3372
|
-
var _node$variance;
|
|
3373
|
+
var _node$variance, _node$variance2;
|
|
3373
3374
|
|
|
3374
3375
|
const ident = node.key.id.type === 'Identifier' ? node.key.id : node.key.id.id;
|
|
3375
3376
|
return {
|
|
@@ -3391,7 +3392,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3391
3392
|
loc: DUMMY_LOC
|
|
3392
3393
|
}
|
|
3393
3394
|
},
|
|
3394
|
-
readonly: ((_node$variance = node.variance) == null ? void 0 : _node$variance.kind) === 'plus',
|
|
3395
|
+
readonly: ((_node$variance = node.variance) == null ? void 0 : _node$variance.kind) === 'plus' || ((_node$variance2 = node.variance) == null ? void 0 : _node$variance2.kind) === 'readonly',
|
|
3395
3396
|
static: node.static,
|
|
3396
3397
|
typeAnnotation: {
|
|
3397
3398
|
type: 'TSTypeAnnotation',
|
|
@@ -3414,7 +3415,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3414
3415
|
typeAnnotation: transformTypeAnnotationType(node.key)
|
|
3415
3416
|
}
|
|
3416
3417
|
}],
|
|
3417
|
-
readonly: ((_node$
|
|
3418
|
+
readonly: ((_node$variance3 = node.variance) == null ? void 0 : _node$variance3.kind) === 'plus' || ((_node$variance4 = node.variance) == null ? void 0 : _node$variance4.kind) === 'readonly',
|
|
3418
3419
|
static: node.static,
|
|
3419
3420
|
typeAnnotation: {
|
|
3420
3421
|
type: 'TSTypeAnnotation',
|
|
@@ -3425,7 +3426,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3425
3426
|
},
|
|
3426
3427
|
|
|
3427
3428
|
ObjectTypeProperty(node) {
|
|
3428
|
-
var _node$
|
|
3429
|
+
var _node$variance5, _node$variance6;
|
|
3429
3430
|
|
|
3430
3431
|
const [key, computed] = (() => {
|
|
3431
3432
|
if (node.key.type === 'Identifier' && node.key.name.startsWith('@@')) {
|
|
@@ -3509,7 +3510,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3509
3510
|
computed,
|
|
3510
3511
|
key,
|
|
3511
3512
|
optional: node.optional,
|
|
3512
|
-
readonly: ((_node$
|
|
3513
|
+
readonly: ((_node$variance5 = node.variance) == null ? void 0 : _node$variance5.kind) === 'plus' || ((_node$variance6 = node.variance) == null ? void 0 : _node$variance6.kind) === 'readonly',
|
|
3513
3514
|
static: node.static,
|
|
3514
3515
|
typeAnnotation: {
|
|
3515
3516
|
type: 'TSTypeAnnotation',
|
|
@@ -3631,7 +3632,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3631
3632
|
},
|
|
3632
3633
|
|
|
3633
3634
|
TupleTypeAnnotation(node) {
|
|
3634
|
-
const allReadOnly = node.elementTypes.length > 0 && node.elementTypes.every(element => element.type === 'TupleTypeLabeledElement' && element.variance != null && element.variance.kind === 'plus');
|
|
3635
|
+
const allReadOnly = node.elementTypes.length > 0 && node.elementTypes.every(element => element.type === 'TupleTypeLabeledElement' && element.variance != null && (element.variance.kind === 'plus' || element.variance.kind === 'readonly'));
|
|
3635
3636
|
const elems = node.elementTypes.map(element => {
|
|
3636
3637
|
switch (element.type) {
|
|
3637
3638
|
case 'TupleTypeLabeledElement':
|
|
@@ -99,6 +99,7 @@ export function flowDefToTSDef(
|
|
|
99
99
|
if (node.type in transform) {
|
|
100
100
|
const result: $FlowFixMe | Array<$FlowFixMe> = transform[
|
|
101
101
|
// $FlowExpectedError[prop-missing]
|
|
102
|
+
// $FlowFixMe[incompatible-type]
|
|
102
103
|
node.type
|
|
103
104
|
](
|
|
104
105
|
// $FlowExpectedError[incompatible-type]
|
|
@@ -3422,7 +3423,9 @@ const getTransforms = (
|
|
|
3422
3423
|
name: prop.keyTparam.name,
|
|
3423
3424
|
},
|
|
3424
3425
|
constraint: transformTypeAnnotationType(prop.sourceType),
|
|
3425
|
-
readonly:
|
|
3426
|
+
readonly:
|
|
3427
|
+
prop.variance?.kind === 'plus' ||
|
|
3428
|
+
prop.variance?.kind === 'readonly',
|
|
3426
3429
|
optional: prop.optional === 'Optional',
|
|
3427
3430
|
typeAnnotation: transformTypeAnnotationType(prop.propType),
|
|
3428
3431
|
nameType: null,
|
|
@@ -3699,7 +3702,9 @@ const getTransforms = (
|
|
|
3699
3702
|
loc: DUMMY_LOC,
|
|
3700
3703
|
},
|
|
3701
3704
|
},
|
|
3702
|
-
readonly:
|
|
3705
|
+
readonly:
|
|
3706
|
+
node.variance?.kind === 'plus' ||
|
|
3707
|
+
node.variance?.kind === 'readonly',
|
|
3703
3708
|
static: node.static,
|
|
3704
3709
|
typeAnnotation: {
|
|
3705
3710
|
type: 'TSTypeAnnotation',
|
|
@@ -3723,7 +3728,8 @@ const getTransforms = (
|
|
|
3723
3728
|
},
|
|
3724
3729
|
},
|
|
3725
3730
|
],
|
|
3726
|
-
readonly:
|
|
3731
|
+
readonly:
|
|
3732
|
+
node.variance?.kind === 'plus' || node.variance?.kind === 'readonly',
|
|
3727
3733
|
static: node.static,
|
|
3728
3734
|
typeAnnotation: {
|
|
3729
3735
|
type: 'TSTypeAnnotation',
|
|
@@ -3824,7 +3830,8 @@ const getTransforms = (
|
|
|
3824
3830
|
computed,
|
|
3825
3831
|
key,
|
|
3826
3832
|
optional: node.optional,
|
|
3827
|
-
readonly:
|
|
3833
|
+
readonly:
|
|
3834
|
+
node.variance?.kind === 'plus' || node.variance?.kind === 'readonly',
|
|
3828
3835
|
static: node.static,
|
|
3829
3836
|
typeAnnotation: {
|
|
3830
3837
|
type: 'TSTypeAnnotation',
|
|
@@ -3965,7 +3972,8 @@ const getTransforms = (
|
|
|
3965
3972
|
element =>
|
|
3966
3973
|
element.type === 'TupleTypeLabeledElement' &&
|
|
3967
3974
|
element.variance != null &&
|
|
3968
|
-
element.variance.kind === 'plus'
|
|
3975
|
+
(element.variance.kind === 'plus' ||
|
|
3976
|
+
element.variance.kind === 'readonly'),
|
|
3969
3977
|
);
|
|
3970
3978
|
const elems = node.elementTypes.map((element): TSESTree.TypeNode => {
|
|
3971
3979
|
switch (element.type) {
|
|
@@ -85,6 +85,7 @@ function flowDefToTSDef(originalCode, ast, scopeManager, opts) {
|
|
|
85
85
|
for (const node of ast.body) {
|
|
86
86
|
if (node.type in transform) {
|
|
87
87
|
const result = transform[// $FlowExpectedError[prop-missing]
|
|
88
|
+
// $FlowFixMe[incompatible-type]
|
|
88
89
|
node.type]( // $FlowExpectedError[incompatible-type]
|
|
89
90
|
node);
|
|
90
91
|
tsBody.push(...(Array.isArray(result) ? result : [result]));
|
|
@@ -3120,7 +3121,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3120
3121
|
|
|
3121
3122
|
ObjectTypeAnnotation(node) {
|
|
3122
3123
|
if (node.properties.length === 1 && node.properties[0].type === 'ObjectTypeMappedTypeProperty') {
|
|
3123
|
-
var _prop$variance;
|
|
3124
|
+
var _prop$variance, _prop$variance2;
|
|
3124
3125
|
|
|
3125
3126
|
// Mapped Object Object types must not have other object properties.
|
|
3126
3127
|
const prop = node.properties[0];
|
|
@@ -3145,7 +3146,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3145
3146
|
name: prop.keyTparam.name
|
|
3146
3147
|
},
|
|
3147
3148
|
constraint: transformTypeAnnotationType(prop.sourceType),
|
|
3148
|
-
readonly: ((_prop$variance = prop.variance) == null ? void 0 : _prop$variance.kind) === 'plus',
|
|
3149
|
+
readonly: ((_prop$variance = prop.variance) == null ? void 0 : _prop$variance.kind) === 'plus' || ((_prop$variance2 = prop.variance) == null ? void 0 : _prop$variance2.kind) === 'readonly',
|
|
3149
3150
|
optional: prop.optional === 'Optional',
|
|
3150
3151
|
typeAnnotation: transformTypeAnnotationType(prop.propType),
|
|
3151
3152
|
nameType: null
|
|
@@ -3366,10 +3367,10 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3366
3367
|
},
|
|
3367
3368
|
|
|
3368
3369
|
ObjectTypeIndexer(node) {
|
|
3369
|
-
var _node$
|
|
3370
|
+
var _node$variance3, _node$variance4;
|
|
3370
3371
|
|
|
3371
3372
|
if (node.key.type === 'GenericTypeAnnotation') {
|
|
3372
|
-
var _node$variance;
|
|
3373
|
+
var _node$variance, _node$variance2;
|
|
3373
3374
|
|
|
3374
3375
|
const ident = node.key.id.type === 'Identifier' ? node.key.id : node.key.id.id;
|
|
3375
3376
|
return {
|
|
@@ -3391,7 +3392,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3391
3392
|
loc: DUMMY_LOC
|
|
3392
3393
|
}
|
|
3393
3394
|
},
|
|
3394
|
-
readonly: ((_node$variance = node.variance) == null ? void 0 : _node$variance.kind) === 'plus',
|
|
3395
|
+
readonly: ((_node$variance = node.variance) == null ? void 0 : _node$variance.kind) === 'plus' || ((_node$variance2 = node.variance) == null ? void 0 : _node$variance2.kind) === 'readonly',
|
|
3395
3396
|
static: node.static,
|
|
3396
3397
|
typeAnnotation: {
|
|
3397
3398
|
type: 'TSTypeAnnotation',
|
|
@@ -3414,7 +3415,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3414
3415
|
typeAnnotation: transformTypeAnnotationType(node.key)
|
|
3415
3416
|
}
|
|
3416
3417
|
}],
|
|
3417
|
-
readonly: ((_node$
|
|
3418
|
+
readonly: ((_node$variance3 = node.variance) == null ? void 0 : _node$variance3.kind) === 'plus' || ((_node$variance4 = node.variance) == null ? void 0 : _node$variance4.kind) === 'readonly',
|
|
3418
3419
|
static: node.static,
|
|
3419
3420
|
typeAnnotation: {
|
|
3420
3421
|
type: 'TSTypeAnnotation',
|
|
@@ -3425,7 +3426,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3425
3426
|
},
|
|
3426
3427
|
|
|
3427
3428
|
ObjectTypeProperty(node) {
|
|
3428
|
-
var _node$
|
|
3429
|
+
var _node$variance5, _node$variance6;
|
|
3429
3430
|
|
|
3430
3431
|
const [key, computed] = (() => {
|
|
3431
3432
|
if (node.key.type === 'Identifier' && node.key.name.startsWith('@@')) {
|
|
@@ -3509,7 +3510,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3509
3510
|
computed,
|
|
3510
3511
|
key,
|
|
3511
3512
|
optional: node.optional,
|
|
3512
|
-
readonly: ((_node$
|
|
3513
|
+
readonly: ((_node$variance5 = node.variance) == null ? void 0 : _node$variance5.kind) === 'plus' || ((_node$variance6 = node.variance) == null ? void 0 : _node$variance6.kind) === 'readonly',
|
|
3513
3514
|
static: node.static,
|
|
3514
3515
|
typeAnnotation: {
|
|
3515
3516
|
type: 'TSTypeAnnotation',
|
|
@@ -3631,7 +3632,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3631
3632
|
},
|
|
3632
3633
|
|
|
3633
3634
|
TupleTypeAnnotation(node) {
|
|
3634
|
-
const allReadOnly = node.elementTypes.length > 0 && node.elementTypes.every(element => element.type === 'TupleTypeLabeledElement' && element.variance != null && element.variance.kind === 'plus');
|
|
3635
|
+
const allReadOnly = node.elementTypes.length > 0 && node.elementTypes.every(element => element.type === 'TupleTypeLabeledElement' && element.variance != null && (element.variance.kind === 'plus' || element.variance.kind === 'readonly'));
|
|
3635
3636
|
const elems = node.elementTypes.map(element => {
|
|
3636
3637
|
switch (element.type) {
|
|
3637
3638
|
case 'TupleTypeLabeledElement':
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flow-api-translator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.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": "8.38.0",
|
|
14
14
|
"@typescript-eslint/visitor-keys": "8.38.0",
|
|
15
15
|
"flow-enums-runtime": "^0.0.6",
|
|
16
|
-
"hermes-eslint": "0.
|
|
17
|
-
"hermes-estree": "0.
|
|
18
|
-
"hermes-parser": "0.
|
|
19
|
-
"hermes-transform": "0.
|
|
16
|
+
"hermes-eslint": "0.36.0",
|
|
17
|
+
"hermes-estree": "0.36.0",
|
|
18
|
+
"hermes-parser": "0.36.0",
|
|
19
|
+
"hermes-transform": "0.36.0",
|
|
20
20
|
"typescript": "5.3.2"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|