flow-api-translator 0.29.0 → 0.30.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/TSDefToFlowDef.js +4 -4
- package/dist/TSDefToFlowDef.js.flow +37 -37
- package/dist/flowDefToTSDef.js +33 -6
- package/dist/flowDefToTSDef.js.flow +37 -10
- package/dist/flowToFlowDef.js +6 -0
- package/dist/flowToFlowDef.js.flow +6 -0
- package/dist/src/TSDefToFlowDef.js +4 -4
- package/dist/src/flowDefToTSDef.js +33 -6
- package/dist/src/flowToFlowDef.js +6 -0
- package/dist/utils/ts-estree-ast-types.js.flow +3 -3
- package/package.json +7 -7
package/dist/TSDefToFlowDef.js
CHANGED
|
@@ -161,7 +161,7 @@ const getTransforms = (originalCode, opts) => {
|
|
|
161
161
|
id: Transform.Identifier(node.id),
|
|
162
162
|
typeParameters: Transform.TSTypeParameterDeclarationOpt(node.typeParameters),
|
|
163
163
|
implements: (node.implements || []).map(impl => Transform.ClassImplements(impl)),
|
|
164
|
-
extends: Transform.ClassDeclarationSuperClass(node.superClass, node.
|
|
164
|
+
extends: Transform.ClassDeclarationSuperClass(node.superClass, node.superTypeArguments),
|
|
165
165
|
mixins: [],
|
|
166
166
|
body: Transform.ClassDeclarationBody(node.body)
|
|
167
167
|
});
|
|
@@ -230,7 +230,7 @@ const getTransforms = (originalCode, opts) => {
|
|
|
230
230
|
return constructFlowNode({
|
|
231
231
|
type: 'ClassImplements',
|
|
232
232
|
id: Transform.Identifier(node.expression),
|
|
233
|
-
typeParameters: Transform.TSTypeParameterInstantiationOpt(node.
|
|
233
|
+
typeParameters: Transform.TSTypeParameterInstantiationOpt(node.typeArguments)
|
|
234
234
|
});
|
|
235
235
|
}
|
|
236
236
|
|
|
@@ -1067,7 +1067,7 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1067
1067
|
return constructFlowNode({
|
|
1068
1068
|
type: 'InterfaceExtends',
|
|
1069
1069
|
id: Transform._expressionToIdOrQualifiedTypeId(node.expression, 'interface extends'),
|
|
1070
|
-
typeParameters: Transform.TSTypeParameterInstantiationOpt(node.
|
|
1070
|
+
typeParameters: Transform.TSTypeParameterInstantiationOpt(node.typeArguments)
|
|
1071
1071
|
});
|
|
1072
1072
|
}
|
|
1073
1073
|
|
|
@@ -1752,7 +1752,7 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1752
1752
|
return constructFlowNode({
|
|
1753
1753
|
type: 'GenericTypeAnnotation',
|
|
1754
1754
|
id: Transform.EntityNameToTypeIdentifier(node.typeName),
|
|
1755
|
-
typeParameters: Transform.TSTypeParameterInstantiationOpt(node.
|
|
1755
|
+
typeParameters: Transform.TSTypeParameterInstantiationOpt(node.typeArguments)
|
|
1756
1756
|
});
|
|
1757
1757
|
}
|
|
1758
1758
|
|
|
@@ -182,7 +182,7 @@ const getTransforms = (originalCode: string, opts: TranslationOptions) => {
|
|
|
182
182
|
),
|
|
183
183
|
extends: Transform.ClassDeclarationSuperClass(
|
|
184
184
|
node.superClass,
|
|
185
|
-
node.
|
|
185
|
+
node.superTypeArguments,
|
|
186
186
|
),
|
|
187
187
|
mixins: [],
|
|
188
188
|
body: Transform.ClassDeclarationBody(node.body),
|
|
@@ -257,7 +257,7 @@ const getTransforms = (originalCode: string, opts: TranslationOptions) => {
|
|
|
257
257
|
type: 'ClassImplements',
|
|
258
258
|
id: Transform.Identifier(node.expression),
|
|
259
259
|
typeParameters: Transform.TSTypeParameterInstantiationOpt(
|
|
260
|
-
node.
|
|
260
|
+
node.typeArguments,
|
|
261
261
|
),
|
|
262
262
|
});
|
|
263
263
|
}
|
|
@@ -588,7 +588,7 @@ const getTransforms = (originalCode: string, opts: TranslationOptions) => {
|
|
|
588
588
|
importKind:
|
|
589
589
|
specifier.importKind === 'value'
|
|
590
590
|
? null
|
|
591
|
-
: specifier.importKind ?? null,
|
|
591
|
+
: (specifier.importKind ?? null),
|
|
592
592
|
});
|
|
593
593
|
}
|
|
594
594
|
});
|
|
@@ -1183,7 +1183,7 @@ const getTransforms = (originalCode: string, opts: TranslationOptions) => {
|
|
|
1183
1183
|
'interface extends',
|
|
1184
1184
|
),
|
|
1185
1185
|
typeParameters: Transform.TSTypeParameterInstantiationOpt(
|
|
1186
|
-
node.
|
|
1186
|
+
node.typeArguments,
|
|
1187
1187
|
),
|
|
1188
1188
|
});
|
|
1189
1189
|
}
|
|
@@ -1263,11 +1263,11 @@ const getTransforms = (originalCode: string, opts: TranslationOptions) => {
|
|
|
1263
1263
|
node.optional === '+'
|
|
1264
1264
|
? 'PlusOptional'
|
|
1265
1265
|
: node.optional === '-'
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1266
|
+
? 'MinusOptional'
|
|
1267
|
+
: // eslint-disable-next-line no-extra-boolean-cast
|
|
1268
|
+
Boolean(node.optional)
|
|
1269
|
+
? 'Optional'
|
|
1270
|
+
: null,
|
|
1271
1271
|
});
|
|
1272
1272
|
return constructFlowNode<FlowESTree.ObjectTypeAnnotation>({
|
|
1273
1273
|
type: 'ObjectTypeAnnotation',
|
|
@@ -1293,13 +1293,13 @@ const getTransforms = (originalCode: string, opts: TranslationOptions) => {
|
|
|
1293
1293
|
body: [],
|
|
1294
1294
|
})
|
|
1295
1295
|
: node.body.type === 'TSModuleDeclaration'
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1296
|
+
? (() => {
|
|
1297
|
+
throw translationError(node, 'nested module declarations');
|
|
1298
|
+
})()
|
|
1299
|
+
: constructFlowNode<FlowESTree.BlockStatement>({
|
|
1300
|
+
type: 'BlockStatement',
|
|
1301
|
+
body: node.body.body.flatMap(s => Transform.Statement(s)),
|
|
1302
|
+
});
|
|
1303
1303
|
if (node.id.type === 'Literal') {
|
|
1304
1304
|
return constructFlowNode<FlowESTree.DeclareModule>({
|
|
1305
1305
|
type: 'DeclareModule',
|
|
@@ -1707,16 +1707,16 @@ const getTransforms = (originalCode: string, opts: TranslationOptions) => {
|
|
|
1707
1707
|
key.type === 'Identifier'
|
|
1708
1708
|
? Transform.Identifier(key, false)
|
|
1709
1709
|
: key.type === 'PrivateIdentifier'
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1710
|
+
? (constructFlowNode<FlowESTree.PrivateIdentifier>({
|
|
1711
|
+
type: 'PrivateIdentifier',
|
|
1712
|
+
name: key.name,
|
|
1713
|
+
}): $FlowFixMe)
|
|
1714
|
+
: constructFlowNode<FlowESTree.StringLiteral>({
|
|
1715
|
+
type: 'Literal',
|
|
1716
|
+
literalType: 'string',
|
|
1717
|
+
value: String(key.value),
|
|
1718
|
+
raw: JSON.stringify(String(key.value)),
|
|
1719
|
+
}),
|
|
1720
1720
|
value: Transform.TSTypeAnnotationOpt(
|
|
1721
1721
|
prop.typeAnnotation?.typeAnnotation,
|
|
1722
1722
|
),
|
|
@@ -1762,16 +1762,16 @@ const getTransforms = (originalCode: string, opts: TranslationOptions) => {
|
|
|
1762
1762
|
originalKey.type === 'Identifier'
|
|
1763
1763
|
? Transform.Identifier(originalKey, false)
|
|
1764
1764
|
: originalKey.type === 'PrivateIdentifier'
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1765
|
+
? (constructFlowNode<FlowESTree.PrivateIdentifier>({
|
|
1766
|
+
type: 'PrivateIdentifier',
|
|
1767
|
+
name: originalKey.name,
|
|
1768
|
+
}): $FlowFixMe)
|
|
1769
|
+
: constructFlowNode<FlowESTree.StringLiteral>({
|
|
1770
|
+
type: 'Literal',
|
|
1771
|
+
literalType: 'string',
|
|
1772
|
+
value: String(originalKey.value),
|
|
1773
|
+
raw: JSON.stringify(String(originalKey.value)),
|
|
1774
|
+
});
|
|
1775
1775
|
const value = Transform.TSFunctionType(
|
|
1776
1776
|
{
|
|
1777
1777
|
type: 'TSFunctionType',
|
|
@@ -1975,7 +1975,7 @@ const getTransforms = (originalCode: string, opts: TranslationOptions) => {
|
|
|
1975
1975
|
type: 'GenericTypeAnnotation',
|
|
1976
1976
|
id: Transform.EntityNameToTypeIdentifier(node.typeName),
|
|
1977
1977
|
typeParameters: Transform.TSTypeParameterInstantiationOpt(
|
|
1978
|
-
node.
|
|
1978
|
+
node.typeArguments,
|
|
1979
1979
|
),
|
|
1980
1980
|
});
|
|
1981
1981
|
}
|
package/dist/flowDefToTSDef.js
CHANGED
|
@@ -378,6 +378,11 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
378
378
|
const: false,
|
|
379
379
|
declare: true,
|
|
380
380
|
id: enumName,
|
|
381
|
+
body: {
|
|
382
|
+
type: 'TSEnumBody',
|
|
383
|
+
members,
|
|
384
|
+
loc: DUMMY_LOC
|
|
385
|
+
},
|
|
381
386
|
members
|
|
382
387
|
}, // flow also exports `.cast`, `.isValid`, `.members` and `.getName` for enums
|
|
383
388
|
// we can use declaration merging to declare these functions on the enum:
|
|
@@ -399,6 +404,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
399
404
|
loc: DUMMY_LOC,
|
|
400
405
|
declare: true,
|
|
401
406
|
id: enumName,
|
|
407
|
+
kind: 'namespace',
|
|
402
408
|
body: {
|
|
403
409
|
type: 'TSModuleBlock',
|
|
404
410
|
loc: DUMMY_LOC,
|
|
@@ -2060,15 +2066,19 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2060
2066
|
|
|
2061
2067
|
if (moduleName.type !== 'TSLiteralType' || moduleName.literal.type !== 'Literal' || typeof moduleName.literal.value !== 'string') {
|
|
2062
2068
|
throw translationError(node, '$Exports must have a string literal argument');
|
|
2063
|
-
}
|
|
2069
|
+
} // New AST format for `typeof import('module')`
|
|
2070
|
+
|
|
2064
2071
|
|
|
2065
2072
|
return {
|
|
2066
|
-
type: '
|
|
2073
|
+
type: 'TSTypeQuery',
|
|
2067
2074
|
loc: DUMMY_LOC,
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2075
|
+
exprName: {
|
|
2076
|
+
type: 'TSImportType',
|
|
2077
|
+
loc: DUMMY_LOC,
|
|
2078
|
+
argument: moduleName,
|
|
2079
|
+
qualifier: null,
|
|
2080
|
+
typeParameters: null
|
|
2081
|
+
}
|
|
2072
2082
|
};
|
|
2073
2083
|
}
|
|
2074
2084
|
|
|
@@ -2104,6 +2114,17 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2104
2114
|
in: false,
|
|
2105
2115
|
out: false
|
|
2106
2116
|
},
|
|
2117
|
+
key: {
|
|
2118
|
+
type: 'Identifier',
|
|
2119
|
+
loc: DUMMY_LOC,
|
|
2120
|
+
name: 'K'
|
|
2121
|
+
},
|
|
2122
|
+
constraint: {
|
|
2123
|
+
type: 'TSTypeOperator',
|
|
2124
|
+
loc: DUMMY_LOC,
|
|
2125
|
+
operator: 'keyof',
|
|
2126
|
+
typeAnnotation: assertHasExactlyNTypeParameters(1)[0]
|
|
2127
|
+
},
|
|
2107
2128
|
nameType: null,
|
|
2108
2129
|
typeAnnotation: {
|
|
2109
2130
|
type: 'TSTypeReference',
|
|
@@ -3108,6 +3129,12 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3108
3129
|
in: false,
|
|
3109
3130
|
out: false
|
|
3110
3131
|
},
|
|
3132
|
+
key: {
|
|
3133
|
+
type: 'Identifier',
|
|
3134
|
+
loc: DUMMY_LOC,
|
|
3135
|
+
name: prop.keyTparam.name
|
|
3136
|
+
},
|
|
3137
|
+
constraint: transformTypeAnnotationType(prop.sourceType),
|
|
3111
3138
|
readonly: ((_prop$variance = prop.variance) == null ? void 0 : _prop$variance.kind) === 'plus',
|
|
3112
3139
|
optional: prop.optional === 'Optional',
|
|
3113
3140
|
typeAnnotation: transformTypeAnnotationType(prop.propType),
|
|
@@ -424,6 +424,11 @@ const getTransforms = (
|
|
|
424
424
|
const: false,
|
|
425
425
|
declare: true,
|
|
426
426
|
id: enumName,
|
|
427
|
+
body: {
|
|
428
|
+
type: 'TSEnumBody',
|
|
429
|
+
members,
|
|
430
|
+
loc: DUMMY_LOC,
|
|
431
|
+
},
|
|
427
432
|
members,
|
|
428
433
|
},
|
|
429
434
|
// flow also exports `.cast`, `.isValid`, `.members` and `.getName` for enums
|
|
@@ -445,6 +450,7 @@ const getTransforms = (
|
|
|
445
450
|
loc: DUMMY_LOC,
|
|
446
451
|
declare: true,
|
|
447
452
|
id: enumName,
|
|
453
|
+
kind: 'namespace',
|
|
448
454
|
body: {
|
|
449
455
|
type: 'TSModuleBlock',
|
|
450
456
|
loc: DUMMY_LOC,
|
|
@@ -1065,8 +1071,8 @@ const getTransforms = (
|
|
|
1065
1071
|
superClass == null
|
|
1066
1072
|
? null
|
|
1067
1073
|
: superClass.id.type === 'QualifiedTypeIdentifier'
|
|
1068
|
-
|
|
1069
|
-
|
|
1074
|
+
? transform.QualifiedTypeIdentifier(superClass.id)
|
|
1075
|
+
: transform.Identifier((superClass.id: $FlowFixMe), false),
|
|
1070
1076
|
superTypeParameters: transform.TypeParameterInstantiation(
|
|
1071
1077
|
superClass?.typeParameters,
|
|
1072
1078
|
),
|
|
@@ -2289,14 +2295,18 @@ const getTransforms = (
|
|
|
2289
2295
|
);
|
|
2290
2296
|
}
|
|
2291
2297
|
|
|
2292
|
-
|
|
2293
|
-
|
|
2298
|
+
// New AST format for `typeof import('module')`
|
|
2299
|
+
return ({
|
|
2300
|
+
type: 'TSTypeQuery',
|
|
2294
2301
|
loc: DUMMY_LOC,
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2302
|
+
exprName: {
|
|
2303
|
+
type: 'TSImportType',
|
|
2304
|
+
loc: DUMMY_LOC,
|
|
2305
|
+
argument: moduleName,
|
|
2306
|
+
qualifier: null,
|
|
2307
|
+
typeParameters: null,
|
|
2308
|
+
},
|
|
2309
|
+
}: $FlowFixMe);
|
|
2300
2310
|
}
|
|
2301
2311
|
|
|
2302
2312
|
case '$FlowFixMe': {
|
|
@@ -2329,6 +2339,17 @@ const getTransforms = (
|
|
|
2329
2339
|
in: false,
|
|
2330
2340
|
out: false,
|
|
2331
2341
|
},
|
|
2342
|
+
key: {
|
|
2343
|
+
type: 'Identifier',
|
|
2344
|
+
loc: DUMMY_LOC,
|
|
2345
|
+
name: 'K',
|
|
2346
|
+
},
|
|
2347
|
+
constraint: {
|
|
2348
|
+
type: 'TSTypeOperator',
|
|
2349
|
+
loc: DUMMY_LOC,
|
|
2350
|
+
operator: 'keyof',
|
|
2351
|
+
typeAnnotation: assertHasExactlyNTypeParameters(1)[0],
|
|
2352
|
+
},
|
|
2332
2353
|
nameType: null,
|
|
2333
2354
|
typeAnnotation: {
|
|
2334
2355
|
type: 'TSTypeReference',
|
|
@@ -3202,7 +3223,7 @@ const getTransforms = (
|
|
|
3202
3223
|
loc: DUMMY_LOC,
|
|
3203
3224
|
assertions: node.assertions.map(transform.ImportAttribute),
|
|
3204
3225
|
importKind:
|
|
3205
|
-
importKind === 'typeof' ? 'type' : importKind ?? 'value',
|
|
3226
|
+
importKind === 'typeof' ? 'type' : (importKind ?? 'value'),
|
|
3206
3227
|
source: transform.StringLiteral(node.source),
|
|
3207
3228
|
specifiers,
|
|
3208
3229
|
},
|
|
@@ -3382,6 +3403,12 @@ const getTransforms = (
|
|
|
3382
3403
|
in: false,
|
|
3383
3404
|
out: false,
|
|
3384
3405
|
},
|
|
3406
|
+
key: {
|
|
3407
|
+
type: 'Identifier',
|
|
3408
|
+
loc: DUMMY_LOC,
|
|
3409
|
+
name: prop.keyTparam.name,
|
|
3410
|
+
},
|
|
3411
|
+
constraint: transformTypeAnnotationType(prop.sourceType),
|
|
3385
3412
|
readonly: prop.variance?.kind === 'plus',
|
|
3386
3413
|
optional: prop.optional === 'Optional',
|
|
3387
3414
|
typeAnnotation: transformTypeAnnotationType(prop.propType),
|
package/dist/flowToFlowDef.js
CHANGED
|
@@ -827,6 +827,7 @@ function convertSuperClassHelper(detachedId, nodeForDependencies, superTypeParam
|
|
|
827
827
|
|
|
828
828
|
function convertSuperClass(superClass, superTypeParameters, context) {
|
|
829
829
|
if (superClass == null) {
|
|
830
|
+
// $FlowFixMe[incompatible-return]
|
|
830
831
|
return EMPTY_TRANSLATION_RESULT;
|
|
831
832
|
}
|
|
832
833
|
|
|
@@ -888,6 +889,7 @@ function convertClassMember(member, context) {
|
|
|
888
889
|
|
|
889
890
|
// PrivateIdentifier's are not exposed so can be stripped.
|
|
890
891
|
if (member.key.type === 'PrivateIdentifier') {
|
|
892
|
+
// $FlowFixMe[incompatible-return]
|
|
891
893
|
return EMPTY_TRANSLATION_RESULT;
|
|
892
894
|
}
|
|
893
895
|
|
|
@@ -922,6 +924,7 @@ function convertClassMember(member, context) {
|
|
|
922
924
|
{
|
|
923
925
|
// PrivateIdentifier's are not exposed so can be stripped.
|
|
924
926
|
if (member.key.type === 'PrivateIdentifier') {
|
|
927
|
+
// $FlowFixMe[incompatible-return]
|
|
925
928
|
return EMPTY_TRANSLATION_RESULT;
|
|
926
929
|
}
|
|
927
930
|
|
|
@@ -1197,6 +1200,7 @@ function convertTypeAnnotationType(annot, container, context) {
|
|
|
1197
1200
|
|
|
1198
1201
|
function convertTypeAnnotationTypeOrNull(annot, context) {
|
|
1199
1202
|
if (annot == null) {
|
|
1203
|
+
// $FlowFixMe[incompatible-return]
|
|
1200
1204
|
return EMPTY_TRANSLATION_RESULT;
|
|
1201
1205
|
}
|
|
1202
1206
|
|
|
@@ -1205,6 +1209,7 @@ function convertTypeAnnotationTypeOrNull(annot, context) {
|
|
|
1205
1209
|
|
|
1206
1210
|
function convertTypeParameterDeclarationOrNull(decl, context) {
|
|
1207
1211
|
if (decl == null) {
|
|
1212
|
+
// $FlowFixMe[incompatible-return]
|
|
1208
1213
|
return EMPTY_TRANSLATION_RESULT;
|
|
1209
1214
|
}
|
|
1210
1215
|
|
|
@@ -1213,6 +1218,7 @@ function convertTypeParameterDeclarationOrNull(decl, context) {
|
|
|
1213
1218
|
|
|
1214
1219
|
function convertTypeParameterInstantiationOrNull(inst, context) {
|
|
1215
1220
|
if (inst == null) {
|
|
1221
|
+
// $FlowFixMe[incompatible-return]
|
|
1216
1222
|
return EMPTY_TRANSLATION_RESULT;
|
|
1217
1223
|
}
|
|
1218
1224
|
|
|
@@ -1080,6 +1080,7 @@ function convertSuperClass(
|
|
|
1080
1080
|
context: TranslationContext,
|
|
1081
1081
|
): TranslatedResultOrNull<InterfaceExtends> {
|
|
1082
1082
|
if (superClass == null) {
|
|
1083
|
+
// $FlowFixMe[incompatible-return]
|
|
1083
1084
|
return EMPTY_TRANSLATION_RESULT;
|
|
1084
1085
|
}
|
|
1085
1086
|
|
|
@@ -1174,6 +1175,7 @@ function convertClassMember(
|
|
|
1174
1175
|
case 'PropertyDefinition': {
|
|
1175
1176
|
// PrivateIdentifier's are not exposed so can be stripped.
|
|
1176
1177
|
if (member.key.type === 'PrivateIdentifier') {
|
|
1178
|
+
// $FlowFixMe[incompatible-return]
|
|
1177
1179
|
return EMPTY_TRANSLATION_RESULT;
|
|
1178
1180
|
}
|
|
1179
1181
|
if (
|
|
@@ -1241,6 +1243,7 @@ function convertClassMember(
|
|
|
1241
1243
|
case 'MethodDefinition': {
|
|
1242
1244
|
// PrivateIdentifier's are not exposed so can be stripped.
|
|
1243
1245
|
if (member.key.type === 'PrivateIdentifier') {
|
|
1246
|
+
// $FlowFixMe[incompatible-return]
|
|
1244
1247
|
return EMPTY_TRANSLATION_RESULT;
|
|
1245
1248
|
}
|
|
1246
1249
|
if (
|
|
@@ -1726,6 +1729,7 @@ function convertTypeAnnotationTypeOrNull(
|
|
|
1726
1729
|
context: TranslationContext,
|
|
1727
1730
|
): TranslatedResultOrNull<TypeAnnotationType> {
|
|
1728
1731
|
if (annot == null) {
|
|
1732
|
+
// $FlowFixMe[incompatible-return]
|
|
1729
1733
|
return EMPTY_TRANSLATION_RESULT;
|
|
1730
1734
|
}
|
|
1731
1735
|
|
|
@@ -1736,6 +1740,7 @@ function convertTypeParameterDeclarationOrNull(
|
|
|
1736
1740
|
context: TranslationContext,
|
|
1737
1741
|
): TranslatedResultOrNull<TypeParameterDeclaration> {
|
|
1738
1742
|
if (decl == null) {
|
|
1743
|
+
// $FlowFixMe[incompatible-return]
|
|
1739
1744
|
return EMPTY_TRANSLATION_RESULT;
|
|
1740
1745
|
}
|
|
1741
1746
|
return [asDetachedNode(decl), analyzeTypeDependencies(decl, context)];
|
|
@@ -1745,6 +1750,7 @@ function convertTypeParameterInstantiationOrNull(
|
|
|
1745
1750
|
context: TranslationContext,
|
|
1746
1751
|
): TranslatedResultOrNull<TypeParameterInstantiation> {
|
|
1747
1752
|
if (inst == null) {
|
|
1753
|
+
// $FlowFixMe[incompatible-return]
|
|
1748
1754
|
return EMPTY_TRANSLATION_RESULT;
|
|
1749
1755
|
}
|
|
1750
1756
|
return [asDetachedNode(inst), analyzeTypeDependencies(inst, context)];
|
|
@@ -161,7 +161,7 @@ const getTransforms = (originalCode, opts) => {
|
|
|
161
161
|
id: Transform.Identifier(node.id),
|
|
162
162
|
typeParameters: Transform.TSTypeParameterDeclarationOpt(node.typeParameters),
|
|
163
163
|
implements: (node.implements || []).map(impl => Transform.ClassImplements(impl)),
|
|
164
|
-
extends: Transform.ClassDeclarationSuperClass(node.superClass, node.
|
|
164
|
+
extends: Transform.ClassDeclarationSuperClass(node.superClass, node.superTypeArguments),
|
|
165
165
|
mixins: [],
|
|
166
166
|
body: Transform.ClassDeclarationBody(node.body)
|
|
167
167
|
});
|
|
@@ -230,7 +230,7 @@ const getTransforms = (originalCode, opts) => {
|
|
|
230
230
|
return constructFlowNode({
|
|
231
231
|
type: 'ClassImplements',
|
|
232
232
|
id: Transform.Identifier(node.expression),
|
|
233
|
-
typeParameters: Transform.TSTypeParameterInstantiationOpt(node.
|
|
233
|
+
typeParameters: Transform.TSTypeParameterInstantiationOpt(node.typeArguments)
|
|
234
234
|
});
|
|
235
235
|
}
|
|
236
236
|
|
|
@@ -1067,7 +1067,7 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1067
1067
|
return constructFlowNode({
|
|
1068
1068
|
type: 'InterfaceExtends',
|
|
1069
1069
|
id: Transform._expressionToIdOrQualifiedTypeId(node.expression, 'interface extends'),
|
|
1070
|
-
typeParameters: Transform.TSTypeParameterInstantiationOpt(node.
|
|
1070
|
+
typeParameters: Transform.TSTypeParameterInstantiationOpt(node.typeArguments)
|
|
1071
1071
|
});
|
|
1072
1072
|
}
|
|
1073
1073
|
|
|
@@ -1752,7 +1752,7 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1752
1752
|
return constructFlowNode({
|
|
1753
1753
|
type: 'GenericTypeAnnotation',
|
|
1754
1754
|
id: Transform.EntityNameToTypeIdentifier(node.typeName),
|
|
1755
|
-
typeParameters: Transform.TSTypeParameterInstantiationOpt(node.
|
|
1755
|
+
typeParameters: Transform.TSTypeParameterInstantiationOpt(node.typeArguments)
|
|
1756
1756
|
});
|
|
1757
1757
|
}
|
|
1758
1758
|
|
|
@@ -378,6 +378,11 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
378
378
|
const: false,
|
|
379
379
|
declare: true,
|
|
380
380
|
id: enumName,
|
|
381
|
+
body: {
|
|
382
|
+
type: 'TSEnumBody',
|
|
383
|
+
members,
|
|
384
|
+
loc: DUMMY_LOC
|
|
385
|
+
},
|
|
381
386
|
members
|
|
382
387
|
}, // flow also exports `.cast`, `.isValid`, `.members` and `.getName` for enums
|
|
383
388
|
// we can use declaration merging to declare these functions on the enum:
|
|
@@ -399,6 +404,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
399
404
|
loc: DUMMY_LOC,
|
|
400
405
|
declare: true,
|
|
401
406
|
id: enumName,
|
|
407
|
+
kind: 'namespace',
|
|
402
408
|
body: {
|
|
403
409
|
type: 'TSModuleBlock',
|
|
404
410
|
loc: DUMMY_LOC,
|
|
@@ -2060,15 +2066,19 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2060
2066
|
|
|
2061
2067
|
if (moduleName.type !== 'TSLiteralType' || moduleName.literal.type !== 'Literal' || typeof moduleName.literal.value !== 'string') {
|
|
2062
2068
|
throw translationError(node, '$Exports must have a string literal argument');
|
|
2063
|
-
}
|
|
2069
|
+
} // New AST format for `typeof import('module')`
|
|
2070
|
+
|
|
2064
2071
|
|
|
2065
2072
|
return {
|
|
2066
|
-
type: '
|
|
2073
|
+
type: 'TSTypeQuery',
|
|
2067
2074
|
loc: DUMMY_LOC,
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2075
|
+
exprName: {
|
|
2076
|
+
type: 'TSImportType',
|
|
2077
|
+
loc: DUMMY_LOC,
|
|
2078
|
+
argument: moduleName,
|
|
2079
|
+
qualifier: null,
|
|
2080
|
+
typeParameters: null
|
|
2081
|
+
}
|
|
2072
2082
|
};
|
|
2073
2083
|
}
|
|
2074
2084
|
|
|
@@ -2104,6 +2114,17 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2104
2114
|
in: false,
|
|
2105
2115
|
out: false
|
|
2106
2116
|
},
|
|
2117
|
+
key: {
|
|
2118
|
+
type: 'Identifier',
|
|
2119
|
+
loc: DUMMY_LOC,
|
|
2120
|
+
name: 'K'
|
|
2121
|
+
},
|
|
2122
|
+
constraint: {
|
|
2123
|
+
type: 'TSTypeOperator',
|
|
2124
|
+
loc: DUMMY_LOC,
|
|
2125
|
+
operator: 'keyof',
|
|
2126
|
+
typeAnnotation: assertHasExactlyNTypeParameters(1)[0]
|
|
2127
|
+
},
|
|
2107
2128
|
nameType: null,
|
|
2108
2129
|
typeAnnotation: {
|
|
2109
2130
|
type: 'TSTypeReference',
|
|
@@ -3108,6 +3129,12 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3108
3129
|
in: false,
|
|
3109
3130
|
out: false
|
|
3110
3131
|
},
|
|
3132
|
+
key: {
|
|
3133
|
+
type: 'Identifier',
|
|
3134
|
+
loc: DUMMY_LOC,
|
|
3135
|
+
name: prop.keyTparam.name
|
|
3136
|
+
},
|
|
3137
|
+
constraint: transformTypeAnnotationType(prop.sourceType),
|
|
3111
3138
|
readonly: ((_prop$variance = prop.variance) == null ? void 0 : _prop$variance.kind) === 'plus',
|
|
3112
3139
|
optional: prop.optional === 'Optional',
|
|
3113
3140
|
typeAnnotation: transformTypeAnnotationType(prop.propType),
|
|
@@ -827,6 +827,7 @@ function convertSuperClassHelper(detachedId, nodeForDependencies, superTypeParam
|
|
|
827
827
|
|
|
828
828
|
function convertSuperClass(superClass, superTypeParameters, context) {
|
|
829
829
|
if (superClass == null) {
|
|
830
|
+
// $FlowFixMe[incompatible-return]
|
|
830
831
|
return EMPTY_TRANSLATION_RESULT;
|
|
831
832
|
}
|
|
832
833
|
|
|
@@ -888,6 +889,7 @@ function convertClassMember(member, context) {
|
|
|
888
889
|
|
|
889
890
|
// PrivateIdentifier's are not exposed so can be stripped.
|
|
890
891
|
if (member.key.type === 'PrivateIdentifier') {
|
|
892
|
+
// $FlowFixMe[incompatible-return]
|
|
891
893
|
return EMPTY_TRANSLATION_RESULT;
|
|
892
894
|
}
|
|
893
895
|
|
|
@@ -922,6 +924,7 @@ function convertClassMember(member, context) {
|
|
|
922
924
|
{
|
|
923
925
|
// PrivateIdentifier's are not exposed so can be stripped.
|
|
924
926
|
if (member.key.type === 'PrivateIdentifier') {
|
|
927
|
+
// $FlowFixMe[incompatible-return]
|
|
925
928
|
return EMPTY_TRANSLATION_RESULT;
|
|
926
929
|
}
|
|
927
930
|
|
|
@@ -1197,6 +1200,7 @@ function convertTypeAnnotationType(annot, container, context) {
|
|
|
1197
1200
|
|
|
1198
1201
|
function convertTypeAnnotationTypeOrNull(annot, context) {
|
|
1199
1202
|
if (annot == null) {
|
|
1203
|
+
// $FlowFixMe[incompatible-return]
|
|
1200
1204
|
return EMPTY_TRANSLATION_RESULT;
|
|
1201
1205
|
}
|
|
1202
1206
|
|
|
@@ -1205,6 +1209,7 @@ function convertTypeAnnotationTypeOrNull(annot, context) {
|
|
|
1205
1209
|
|
|
1206
1210
|
function convertTypeParameterDeclarationOrNull(decl, context) {
|
|
1207
1211
|
if (decl == null) {
|
|
1212
|
+
// $FlowFixMe[incompatible-return]
|
|
1208
1213
|
return EMPTY_TRANSLATION_RESULT;
|
|
1209
1214
|
}
|
|
1210
1215
|
|
|
@@ -1213,6 +1218,7 @@ function convertTypeParameterDeclarationOrNull(decl, context) {
|
|
|
1213
1218
|
|
|
1214
1219
|
function convertTypeParameterInstantiationOrNull(inst, context) {
|
|
1215
1220
|
if (inst == null) {
|
|
1221
|
+
// $FlowFixMe[incompatible-return]
|
|
1216
1222
|
return EMPTY_TRANSLATION_RESULT;
|
|
1217
1223
|
}
|
|
1218
1224
|
|
|
@@ -199,7 +199,7 @@ interface ClassBase extends BaseNode {
|
|
|
199
199
|
* The generic type parameters passed to the superClass.
|
|
200
200
|
* This is `undefined` if there are no generic type parameters passed.
|
|
201
201
|
*/
|
|
202
|
-
+
|
|
202
|
+
+superTypeArguments?: TSTypeParameterInstantiation;
|
|
203
203
|
/**
|
|
204
204
|
* The generic type parameters declared for the class.
|
|
205
205
|
* This is `undefined` if there are no generic type parameters declared.
|
|
@@ -1572,7 +1572,7 @@ export interface TSFunctionType extends TSFunctionSignatureBase {
|
|
|
1572
1572
|
}
|
|
1573
1573
|
interface TSHeritageBase extends BaseNode {
|
|
1574
1574
|
+expression: Expression;
|
|
1575
|
-
+
|
|
1575
|
+
+typeArguments?: TSTypeParameterInstantiation;
|
|
1576
1576
|
}
|
|
1577
1577
|
export interface TSImportEqualsDeclaration extends BaseNode {
|
|
1578
1578
|
+type: 'TSImportEqualsDeclaration';
|
|
@@ -1928,7 +1928,7 @@ export interface TSTypeQuery extends BaseNode {
|
|
|
1928
1928
|
export interface TSTypeReference extends BaseNode {
|
|
1929
1929
|
+type: 'TSTypeReference';
|
|
1930
1930
|
+typeName: EntityName;
|
|
1931
|
-
+
|
|
1931
|
+
+typeArguments?: TSTypeParameterInstantiation;
|
|
1932
1932
|
}
|
|
1933
1933
|
export type TSUnaryExpression =
|
|
1934
1934
|
| AwaitExpression
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flow-api-translator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.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",
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@babel/code-frame": "^7.16.0",
|
|
13
|
-
"@typescript-eslint/parser": "
|
|
14
|
-
"@typescript-eslint/visitor-keys": "
|
|
13
|
+
"@typescript-eslint/parser": "8.38.0",
|
|
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.30.0",
|
|
17
|
+
"hermes-estree": "0.30.0",
|
|
18
|
+
"hermes-parser": "0.30.0",
|
|
19
|
+
"hermes-transform": "0.30.0",
|
|
20
20
|
"typescript": "5.3.2"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|