flow-api-translator 0.27.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.
- package/dist/flowDefToTSDef.js +30 -11
- package/dist/flowDefToTSDef.js.flow +33 -12
- package/dist/flowToFlowDef.js +7 -7
- package/dist/flowToFlowDef.js.flow +12 -3
- package/package.json +5 -5
package/dist/flowDefToTSDef.js
CHANGED
|
@@ -1957,6 +1957,20 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1957
1957
|
return unsupportedAnnotation(node, fullTypeName);
|
|
1958
1958
|
}
|
|
1959
1959
|
|
|
1960
|
+
case '$ArrayBufferView':
|
|
1961
|
+
{
|
|
1962
|
+
// `$ArrayBufferView` => `ArrayBufferView`
|
|
1963
|
+
return {
|
|
1964
|
+
type: 'TSTypeReference',
|
|
1965
|
+
loc: DUMMY_LOC,
|
|
1966
|
+
typeName: {
|
|
1967
|
+
type: 'Identifier',
|
|
1968
|
+
loc: DUMMY_LOC,
|
|
1969
|
+
name: 'ArrayBufferView'
|
|
1970
|
+
}
|
|
1971
|
+
};
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1960
1974
|
case '$ArrayLike':
|
|
1961
1975
|
{
|
|
1962
1976
|
// `$ArrayLike<T>` => `ArrayLike<T>`
|
|
@@ -2543,8 +2557,8 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2543
2557
|
}
|
|
2544
2558
|
};
|
|
2545
2559
|
}
|
|
2546
|
-
// React.ElementRef<typeof Component> -> React.
|
|
2547
|
-
// React$ElementRef<typeof Component> -> React.
|
|
2560
|
+
// React.ElementRef<typeof Component> -> React.ComponentRef<typeof Component>
|
|
2561
|
+
// React$ElementRef<typeof Component> -> React.ComponentRef<typeof Component>
|
|
2548
2562
|
|
|
2549
2563
|
case 'React$ElementRef':
|
|
2550
2564
|
case 'React.ElementRef':
|
|
@@ -2558,7 +2572,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2558
2572
|
right: {
|
|
2559
2573
|
type: 'Identifier',
|
|
2560
2574
|
loc: DUMMY_LOC,
|
|
2561
|
-
name: `
|
|
2575
|
+
name: `ComponentRef`
|
|
2562
2576
|
}
|
|
2563
2577
|
},
|
|
2564
2578
|
typeParameters: {
|
|
@@ -3211,8 +3225,8 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3211
3225
|
type T = { ...T1, ...T2, ...T3, b: string };
|
|
3212
3226
|
// becomes
|
|
3213
3227
|
type T =
|
|
3214
|
-
& Omit<T1, keyof
|
|
3215
|
-
& Omit<T2, keyof
|
|
3228
|
+
& Omit<T1, keyof T2 | keyof T3 | keyof { b: string }>
|
|
3229
|
+
& Omit<T2, keyof T3 | keyof { b: string }>
|
|
3216
3230
|
& Omit<T3, keyof { b: string }>
|
|
3217
3231
|
& { b: string };
|
|
3218
3232
|
```
|
|
@@ -3276,14 +3290,19 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3276
3290
|
type: 'TSTypeParameterInstantiation',
|
|
3277
3291
|
loc: DUMMY_LOC,
|
|
3278
3292
|
params: [currentType, {
|
|
3279
|
-
type: '
|
|
3293
|
+
type: 'TSUnionType',
|
|
3280
3294
|
loc: DUMMY_LOC,
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
type: 'TSUnionType',
|
|
3295
|
+
types: [...remainingTypes.map(t => ({
|
|
3296
|
+
type: 'TSTypeOperator',
|
|
3284
3297
|
loc: DUMMY_LOC,
|
|
3285
|
-
|
|
3286
|
-
|
|
3298
|
+
operator: 'keyof',
|
|
3299
|
+
typeAnnotation: t
|
|
3300
|
+
})), {
|
|
3301
|
+
type: 'TSTypeOperator',
|
|
3302
|
+
loc: DUMMY_LOC,
|
|
3303
|
+
operator: 'keyof',
|
|
3304
|
+
typeAnnotation: objectType
|
|
3305
|
+
}]
|
|
3287
3306
|
}]
|
|
3288
3307
|
}
|
|
3289
3308
|
});
|
|
@@ -2173,6 +2173,19 @@ const getTransforms = (
|
|
|
2173
2173
|
return unsupportedAnnotation(node, fullTypeName);
|
|
2174
2174
|
}
|
|
2175
2175
|
|
|
2176
|
+
case '$ArrayBufferView': {
|
|
2177
|
+
// `$ArrayBufferView` => `ArrayBufferView`
|
|
2178
|
+
return {
|
|
2179
|
+
type: 'TSTypeReference',
|
|
2180
|
+
loc: DUMMY_LOC,
|
|
2181
|
+
typeName: {
|
|
2182
|
+
type: 'Identifier',
|
|
2183
|
+
loc: DUMMY_LOC,
|
|
2184
|
+
name: 'ArrayBufferView',
|
|
2185
|
+
},
|
|
2186
|
+
};
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2176
2189
|
case '$ArrayLike': {
|
|
2177
2190
|
// `$ArrayLike<T>` => `ArrayLike<T>`
|
|
2178
2191
|
return {
|
|
@@ -2765,8 +2778,8 @@ const getTransforms = (
|
|
|
2765
2778
|
},
|
|
2766
2779
|
};
|
|
2767
2780
|
}
|
|
2768
|
-
// React.ElementRef<typeof Component> -> React.
|
|
2769
|
-
// React$ElementRef<typeof Component> -> React.
|
|
2781
|
+
// React.ElementRef<typeof Component> -> React.ComponentRef<typeof Component>
|
|
2782
|
+
// React$ElementRef<typeof Component> -> React.ComponentRef<typeof Component>
|
|
2770
2783
|
case 'React$ElementRef':
|
|
2771
2784
|
case 'React.ElementRef':
|
|
2772
2785
|
return {
|
|
@@ -2779,7 +2792,7 @@ const getTransforms = (
|
|
|
2779
2792
|
right: {
|
|
2780
2793
|
type: 'Identifier',
|
|
2781
2794
|
loc: DUMMY_LOC,
|
|
2782
|
-
name: `
|
|
2795
|
+
name: `ComponentRef`,
|
|
2783
2796
|
},
|
|
2784
2797
|
},
|
|
2785
2798
|
typeParameters: {
|
|
@@ -3495,8 +3508,8 @@ const getTransforms = (
|
|
|
3495
3508
|
type T = { ...T1, ...T2, ...T3, b: string };
|
|
3496
3509
|
// becomes
|
|
3497
3510
|
type T =
|
|
3498
|
-
& Omit<T1, keyof
|
|
3499
|
-
& Omit<T2, keyof
|
|
3511
|
+
& Omit<T1, keyof T2 | keyof T3 | keyof { b: string }>
|
|
3512
|
+
& Omit<T2, keyof T3 | keyof { b: string }>
|
|
3500
3513
|
& Omit<T3, keyof { b: string }>
|
|
3501
3514
|
& { b: string };
|
|
3502
3515
|
```
|
|
@@ -3577,14 +3590,22 @@ const getTransforms = (
|
|
|
3577
3590
|
params: [
|
|
3578
3591
|
currentType,
|
|
3579
3592
|
{
|
|
3580
|
-
type: '
|
|
3593
|
+
type: 'TSUnionType',
|
|
3581
3594
|
loc: DUMMY_LOC,
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3595
|
+
types: [
|
|
3596
|
+
...remainingTypes.map(t => ({
|
|
3597
|
+
type: 'TSTypeOperator',
|
|
3598
|
+
loc: DUMMY_LOC,
|
|
3599
|
+
operator: 'keyof',
|
|
3600
|
+
typeAnnotation: t,
|
|
3601
|
+
})),
|
|
3602
|
+
{
|
|
3603
|
+
type: 'TSTypeOperator',
|
|
3604
|
+
loc: DUMMY_LOC,
|
|
3605
|
+
operator: 'keyof',
|
|
3606
|
+
typeAnnotation: objectType,
|
|
3607
|
+
},
|
|
3608
|
+
],
|
|
3588
3609
|
},
|
|
3589
3610
|
],
|
|
3590
3611
|
},
|
package/dist/flowToFlowDef.js
CHANGED
|
@@ -1113,19 +1113,19 @@ function convertAFunction(func, context) {
|
|
|
1113
1113
|
}
|
|
1114
1114
|
|
|
1115
1115
|
function convertFunctionParameters(params, context) {
|
|
1116
|
-
return params.reduce(([resultParams, restParam, paramsDeps], param) => {
|
|
1116
|
+
return params.reduce(([resultParams, restParam, paramsDeps], param, index) => {
|
|
1117
1117
|
switch (param.type) {
|
|
1118
1118
|
case 'Identifier':
|
|
1119
1119
|
case 'ArrayPattern':
|
|
1120
1120
|
case 'ObjectPattern':
|
|
1121
1121
|
{
|
|
1122
|
-
const [resultParam, deps] = convertBindingNameToFunctionTypeParam(param, context);
|
|
1122
|
+
const [resultParam, deps] = convertBindingNameToFunctionTypeParam(param, context, index, false);
|
|
1123
1123
|
return [[...resultParams, resultParam], restParam, [...paramsDeps, ...deps]];
|
|
1124
1124
|
}
|
|
1125
1125
|
|
|
1126
1126
|
case 'AssignmentPattern':
|
|
1127
1127
|
{
|
|
1128
|
-
const [resultParam, deps] = convertBindingNameToFunctionTypeParam(param.left, context);
|
|
1128
|
+
const [resultParam, deps] = convertBindingNameToFunctionTypeParam(param.left, context, index, true);
|
|
1129
1129
|
return [[...resultParams, resultParam], restParam, [...paramsDeps, ...deps]];
|
|
1130
1130
|
}
|
|
1131
1131
|
|
|
@@ -1136,22 +1136,22 @@ function convertFunctionParameters(params, context) {
|
|
|
1136
1136
|
}
|
|
1137
1137
|
|
|
1138
1138
|
const [resultParam, deps] = convertBindingNameToFunctionTypeParam( // $FlowFixMe[incompatible-call] I dont think these other cases are possible
|
|
1139
|
-
param.argument, context);
|
|
1139
|
+
param.argument, context, index, false);
|
|
1140
1140
|
return [resultParams, resultParam, [...paramsDeps, ...deps]];
|
|
1141
1141
|
}
|
|
1142
1142
|
}
|
|
1143
1143
|
}, [[], null, []]);
|
|
1144
1144
|
}
|
|
1145
1145
|
|
|
1146
|
-
function convertBindingNameToFunctionTypeParam(pat, context) {
|
|
1147
|
-
const name = pat.type === 'Identifier' ? pat.name :
|
|
1146
|
+
function convertBindingNameToFunctionTypeParam(pat, context, index, isAssignment) {
|
|
1147
|
+
const name = pat.type === 'Identifier' ? pat.name : `$$PARAM_${index}$$`;
|
|
1148
1148
|
const [resultParamTypeAnnotation, paramDeps] = convertTypeAnnotation(pat.typeAnnotation, pat, context);
|
|
1149
1149
|
return [_hermesTransform.t.FunctionTypeParam({
|
|
1150
1150
|
name: name != null ? _hermesTransform.t.Identifier({
|
|
1151
1151
|
name
|
|
1152
1152
|
}) : null,
|
|
1153
1153
|
typeAnnotation: resultParamTypeAnnotation,
|
|
1154
|
-
optional: pat.type === 'Identifier' ? pat.optional : false
|
|
1154
|
+
optional: isAssignment || (pat.type === 'Identifier' ? pat.optional : false)
|
|
1155
1155
|
}), paramDeps];
|
|
1156
1156
|
}
|
|
1157
1157
|
|
|
@@ -1549,7 +1549,7 @@ function convertFunctionParameters(
|
|
|
1549
1549
|
context: TranslationContext,
|
|
1550
1550
|
): TranslatedFunctionParametersResults {
|
|
1551
1551
|
return params.reduce<TranslatedFunctionParametersResults>(
|
|
1552
|
-
([resultParams, restParam, paramsDeps], param) => {
|
|
1552
|
+
([resultParams, restParam, paramsDeps], param, index) => {
|
|
1553
1553
|
switch (param.type) {
|
|
1554
1554
|
case 'Identifier':
|
|
1555
1555
|
case 'ArrayPattern':
|
|
@@ -1557,6 +1557,8 @@ function convertFunctionParameters(
|
|
|
1557
1557
|
const [resultParam, deps] = convertBindingNameToFunctionTypeParam(
|
|
1558
1558
|
param,
|
|
1559
1559
|
context,
|
|
1560
|
+
index,
|
|
1561
|
+
false,
|
|
1560
1562
|
);
|
|
1561
1563
|
return [
|
|
1562
1564
|
[...resultParams, resultParam],
|
|
@@ -1568,6 +1570,8 @@ function convertFunctionParameters(
|
|
|
1568
1570
|
const [resultParam, deps] = convertBindingNameToFunctionTypeParam(
|
|
1569
1571
|
param.left,
|
|
1570
1572
|
context,
|
|
1573
|
+
index,
|
|
1574
|
+
true,
|
|
1571
1575
|
);
|
|
1572
1576
|
return [
|
|
1573
1577
|
[...resultParams, resultParam],
|
|
@@ -1587,6 +1591,8 @@ function convertFunctionParameters(
|
|
|
1587
1591
|
// $FlowFixMe[incompatible-call] I dont think these other cases are possible
|
|
1588
1592
|
param.argument,
|
|
1589
1593
|
context,
|
|
1594
|
+
index,
|
|
1595
|
+
false,
|
|
1590
1596
|
);
|
|
1591
1597
|
return [resultParams, resultParam, [...paramsDeps, ...deps]];
|
|
1592
1598
|
}
|
|
@@ -1599,8 +1605,10 @@ function convertFunctionParameters(
|
|
|
1599
1605
|
function convertBindingNameToFunctionTypeParam(
|
|
1600
1606
|
pat: BindingName,
|
|
1601
1607
|
context: TranslationContext,
|
|
1608
|
+
index: number,
|
|
1609
|
+
isAssignment: boolean,
|
|
1602
1610
|
): TranslatedResult<FunctionTypeParam> {
|
|
1603
|
-
const name = pat.type === 'Identifier' ? pat.name :
|
|
1611
|
+
const name = pat.type === 'Identifier' ? pat.name : `$$PARAM_${index}$$`;
|
|
1604
1612
|
const [resultParamTypeAnnotation, paramDeps] = convertTypeAnnotation(
|
|
1605
1613
|
pat.typeAnnotation,
|
|
1606
1614
|
pat,
|
|
@@ -1610,7 +1618,8 @@ function convertBindingNameToFunctionTypeParam(
|
|
|
1610
1618
|
t.FunctionTypeParam({
|
|
1611
1619
|
name: name != null ? t.Identifier({name}) : null,
|
|
1612
1620
|
typeAnnotation: resultParamTypeAnnotation,
|
|
1613
|
-
optional:
|
|
1621
|
+
optional:
|
|
1622
|
+
isAssignment || (pat.type === 'Identifier' ? pat.optional : false),
|
|
1614
1623
|
}),
|
|
1615
1624
|
paramDeps,
|
|
1616
1625
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flow-api-translator",
|
|
3
|
-
"version": "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.
|
|
17
|
-
"hermes-estree": "0.
|
|
18
|
-
"hermes-parser": "0.
|
|
19
|
-
"hermes-transform": "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": {
|