flow-api-translator 0.28.0 → 0.29.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.flow +7 -3
- package/dist/flowDefToTSDef.js +17 -10
- package/dist/flowDefToTSDef.js.flow +50 -41
- package/dist/flowToFlowDef.js +8 -8
- package/dist/flowToFlowDef.js.flow +47 -35
- package/dist/src/TSDefToFlowDef.js +1807 -0
- package/dist/src/flowDefToTSDef.js +3853 -0
- package/dist/src/flowImportTo.js +73 -0
- package/dist/src/flowToFlowDef.js +1220 -0
- package/dist/src/flowToJS.js +39 -0
- package/dist/src/index.js +114 -0
- package/dist/src/utils/DocblockUtils.js +33 -0
- package/dist/src/utils/ErrorUtils.js +103 -0
- package/dist/src/utils/FlowAnalyze.js +55 -0
- package/dist/src/utils/TranslationUtils.js +42 -0
- package/dist/src/utils/ts-estree-ast-types.js +30 -0
- package/dist/utils/ts-estree-ast-types.js.flow +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, "__esModule", {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
exports.flowImportTo = flowImportTo;
|
|
16
|
+
|
|
17
|
+
var _hermesParser = require("hermes-parser");
|
|
18
|
+
|
|
19
|
+
function flowImportTo(ast, _code, _scopeManager, opts) {
|
|
20
|
+
function mapSource(source) {
|
|
21
|
+
const resultValue = opts.sourceMapper({
|
|
22
|
+
module: source.value
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
if (resultValue === source.value) {
|
|
26
|
+
return source;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return _hermesParser.SimpleTransform.nodeWith(source, {
|
|
30
|
+
value: resultValue,
|
|
31
|
+
raw: `"${resultValue}"`
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const result = _hermesParser.SimpleTransform.transform(ast, {
|
|
36
|
+
transform(node) {
|
|
37
|
+
switch (node.type) {
|
|
38
|
+
case 'ImportDeclaration':
|
|
39
|
+
{
|
|
40
|
+
return _hermesParser.SimpleTransform.nodeWith(node, {
|
|
41
|
+
source: mapSource(node.source)
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
case 'DeclareExportAllDeclaration':
|
|
46
|
+
case 'ExportAllDeclaration':
|
|
47
|
+
case 'DeclareExportDeclaration':
|
|
48
|
+
case 'ExportNamedDeclaration':
|
|
49
|
+
{
|
|
50
|
+
if (node.source != null) {
|
|
51
|
+
return _hermesParser.SimpleTransform.nodeWith(node, {
|
|
52
|
+
source: mapSource(node.source)
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return node;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
default:
|
|
60
|
+
{
|
|
61
|
+
return node;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
if (result == null || result.type !== 'Program') {
|
|
69
|
+
throw new Error('flowImportTo: Unexpected transform result.');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return result;
|
|
73
|
+
}
|