flow-api-translator 0.331.0 → 0.332.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/README.md +17 -0
- package/dist/TSDefToFlowDef.js +17 -7
- package/dist/TSDefToFlowDef.js.flow +18 -2
- package/dist/flowDefToTSDef.js +293 -80
- package/dist/flowDefToTSDef.js.flow +441 -123
- package/dist/flowToFlowDef.js +121 -2
- package/dist/flowToFlowDef.js.flow +244 -2
- package/dist/index.js +7 -6
- package/dist/index.js.flow +16 -4
- package/dist/src/TSDefToFlowDef.js +17 -7
- package/dist/src/flowDefToTSDef.js +293 -80
- package/dist/src/flowToFlowDef.js +121 -2
- package/dist/src/index.js +7 -6
- package/dist/src/utils/TSNodeUtils.js +20 -0
- package/dist/utils/TSNodeUtils.js +20 -0
- package/dist/utils/TSNodeUtils.js.flow +46 -1
- package/dist/utils/TranslationUtils.js.flow +16 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -29,6 +29,23 @@ await fs.writeFile('output/myFile.d.ts', translate.translateFlowToTSDef(sourceFi
|
|
|
29
29
|
await fs.writeFile('output/myFile.js', translate.translateFlowToJS(sourceFile, prettierConfig));
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
+
By default, documentation remains attached to the declaration it originally
|
|
33
|
+
described. To associate that documentation with a generated default-export
|
|
34
|
+
symbol, pass `defaultExportDocPlacement` to either definition translator:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
await fs.writeFile(
|
|
38
|
+
'output/myFile.d.ts',
|
|
39
|
+
translate.translateFlowToTSDef(sourceFile, prettierConfig, {
|
|
40
|
+
defaultExportDocPlacement: 'export',
|
|
41
|
+
}),
|
|
42
|
+
);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The supported placements are `declaration` (the default), `export`, and `both`.
|
|
46
|
+
`both` retains the documentation on the original declaration as well as
|
|
47
|
+
attaching it to the default export.
|
|
48
|
+
|
|
32
49
|
### Flow (with Haste modules) -> TS Lib
|
|
33
50
|
|
|
34
51
|
Haste module paths are commonly used with Flow libraries. TypeScript does not support this so they needs to be converted back to relative paths first:
|
package/dist/TSDefToFlowDef.js
CHANGED
|
@@ -264,11 +264,15 @@ const getTransforms = (originalCode, opts) => {
|
|
|
264
264
|
value: node.source.value,
|
|
265
265
|
raw: node.source.raw
|
|
266
266
|
});
|
|
267
|
-
const specifiers = node.specifiers.map(specifier =>
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
267
|
+
const specifiers = node.specifiers.map(specifier => {
|
|
268
|
+
var _specifier$exportKind;
|
|
269
|
+
return constructFlowNode({
|
|
270
|
+
type: 'ExportSpecifier',
|
|
271
|
+
local: Transform.Identifier(specifier.local),
|
|
272
|
+
exported: Transform.Identifier(specifier.exported),
|
|
273
|
+
exportKind: (_specifier$exportKind = specifier.exportKind) != null ? _specifier$exportKind : 'value'
|
|
274
|
+
});
|
|
275
|
+
});
|
|
272
276
|
return constructFlowNode({
|
|
273
277
|
type: 'DeclareExportDeclaration',
|
|
274
278
|
declaration: null,
|
|
@@ -318,7 +322,8 @@ const getTransforms = (originalCode, opts) => {
|
|
|
318
322
|
specifiers: [constructFlowNode({
|
|
319
323
|
type: 'ExportSpecifier',
|
|
320
324
|
local: decl.id,
|
|
321
|
-
exported: decl.id
|
|
325
|
+
exported: decl.id,
|
|
326
|
+
exportKind: 'value'
|
|
322
327
|
})]
|
|
323
328
|
})];
|
|
324
329
|
}
|
|
@@ -814,6 +819,9 @@ const getTransforms = (originalCode, opts) => {
|
|
|
814
819
|
const namesRev = [];
|
|
815
820
|
while (qualifier.type !== 'Identifier') {
|
|
816
821
|
namesRev.push(qualifier.id.name);
|
|
822
|
+
if (qualifier.qualification.type === 'ImportType') {
|
|
823
|
+
return unsupportedAnnotation(node, 'nested import types in import type qualifiers');
|
|
824
|
+
}
|
|
817
825
|
qualifier = qualifier.qualification;
|
|
818
826
|
}
|
|
819
827
|
namesRev.push(qualifier.name);
|
|
@@ -949,10 +957,12 @@ const getTransforms = (originalCode, opts) => {
|
|
|
949
957
|
keyTparam,
|
|
950
958
|
propType: Transform.TSTypeAnnotationOpt(node.typeAnnotation),
|
|
951
959
|
sourceType,
|
|
952
|
-
|
|
960
|
+
nameType: node.nameType == null ? null : Transform.TSTypeAnnotation(node.nameType),
|
|
961
|
+
variance: node.readonly != null && node.readonly !== false ? constructFlowNode({
|
|
953
962
|
type: 'Variance',
|
|
954
963
|
kind: 'plus'
|
|
955
964
|
}) : null,
|
|
965
|
+
varianceOp: node.readonly === '+' ? '+' : node.readonly === '-' ? '-' : null,
|
|
956
966
|
optional: node.optional === '+' ? 'PlusOptional' : node.optional === '-' ? 'MinusOptional' : Boolean(node.optional) ? 'Optional' : null
|
|
957
967
|
});
|
|
958
968
|
return constructFlowNode({
|
|
@@ -391,6 +391,7 @@ const getTransforms = (originalCode: string, opts: TranslationOptions) => {
|
|
|
391
391
|
type: 'ExportSpecifier',
|
|
392
392
|
local: Transform.Identifier(specifier.local),
|
|
393
393
|
exported: Transform.Identifier(specifier.exported),
|
|
394
|
+
exportKind: specifier.exportKind ?? 'value',
|
|
394
395
|
}),
|
|
395
396
|
);
|
|
396
397
|
return constructFlowNode<FlowESTree.DeclareExportDeclarationNamedWithSpecifiers>(
|
|
@@ -465,6 +466,7 @@ const getTransforms = (originalCode: string, opts: TranslationOptions) => {
|
|
|
465
466
|
type: 'ExportSpecifier',
|
|
466
467
|
local: decl.id,
|
|
467
468
|
exported: decl.id,
|
|
469
|
+
exportKind: 'value',
|
|
468
470
|
}),
|
|
469
471
|
],
|
|
470
472
|
}),
|
|
@@ -1063,10 +1065,18 @@ const getTransforms = (originalCode: string, opts: TranslationOptions) => {
|
|
|
1063
1065
|
if (node.qualifier == null) {
|
|
1064
1066
|
return base;
|
|
1065
1067
|
}
|
|
1066
|
-
let qualifier
|
|
1068
|
+
let qualifier:
|
|
1069
|
+
FlowESTree.Identifier | FlowESTree.QualifiedTypeIdentifier =
|
|
1070
|
+
Transform.EntityNameToTypeIdentifier(node.qualifier);
|
|
1067
1071
|
const namesRev: Array<string> = [];
|
|
1068
1072
|
while (qualifier.type !== 'Identifier') {
|
|
1069
1073
|
namesRev.push(qualifier.id.name);
|
|
1074
|
+
if (qualifier.qualification.type === 'ImportType') {
|
|
1075
|
+
return unsupportedAnnotation(
|
|
1076
|
+
node,
|
|
1077
|
+
'nested import types in import type qualifiers',
|
|
1078
|
+
);
|
|
1079
|
+
}
|
|
1070
1080
|
qualifier = qualifier.qualification;
|
|
1071
1081
|
}
|
|
1072
1082
|
namesRev.push(qualifier.name);
|
|
@@ -1267,13 +1277,19 @@ const getTransforms = (originalCode: string, opts: TranslationOptions) => {
|
|
|
1267
1277
|
keyTparam,
|
|
1268
1278
|
propType: Transform.TSTypeAnnotationOpt(node.typeAnnotation),
|
|
1269
1279
|
sourceType,
|
|
1280
|
+
nameType:
|
|
1281
|
+
node.nameType == null
|
|
1282
|
+
? null
|
|
1283
|
+
: Transform.TSTypeAnnotation(node.nameType),
|
|
1270
1284
|
variance:
|
|
1271
|
-
node.readonly
|
|
1285
|
+
node.readonly != null && node.readonly !== false
|
|
1272
1286
|
? constructFlowNode<FlowESTree.Variance>({
|
|
1273
1287
|
type: 'Variance',
|
|
1274
1288
|
kind: 'plus',
|
|
1275
1289
|
})
|
|
1276
1290
|
: null,
|
|
1291
|
+
varianceOp:
|
|
1292
|
+
node.readonly === '+' ? '+' : node.readonly === '-' ? '-' : null,
|
|
1277
1293
|
optional:
|
|
1278
1294
|
node.optional === '+'
|
|
1279
1295
|
? 'PlusOptional'
|