flow-api-translator 0.37.0 → 0.328.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 +35 -279
- package/dist/TSDefToFlowDef.js.flow +16 -4
- package/dist/flowDefToTSDef.js +51 -377
- package/dist/flowDefToTSDef.js.flow +93 -12
- package/dist/flowImportTo.js +5 -16
- package/dist/flowImportTo.js.flow +3 -3
- package/dist/flowToFlowDef.js +134 -359
- package/dist/flowToFlowDef.js.flow +18 -12
- package/dist/flowToJS.js +3 -10
- package/dist/flowToJS.js.flow +5 -5
- package/dist/index.js +12 -28
- package/dist/index.js.flow +1 -1
- package/dist/src/TSDefToFlowDef.js +35 -279
- package/dist/src/flowDefToTSDef.js +51 -377
- package/dist/src/flowImportTo.js +5 -16
- package/dist/src/flowToFlowDef.js +134 -359
- package/dist/src/flowToJS.js +3 -10
- package/dist/src/index.js +12 -28
- package/dist/src/utils/DocblockUtils.js +4 -4
- package/dist/src/utils/ErrorUtils.js +3 -18
- package/dist/src/utils/FlowAnalyze.js +5 -16
- package/dist/src/utils/TSNodeUtils.js +28 -13
- package/dist/src/utils/TranslationUtils.js +0 -4
- package/dist/utils/DocblockUtils.js +4 -4
- package/dist/utils/DocblockUtils.js.flow +1 -1
- package/dist/utils/ErrorUtils.js +3 -18
- package/dist/utils/ErrorUtils.js.flow +3 -3
- package/dist/utils/FlowAnalyze.js +5 -16
- package/dist/utils/FlowAnalyze.js.flow +3 -3
- package/dist/utils/TSNodeUtils.js +28 -13
- package/dist/utils/TSNodeUtils.js.flow +35 -1
- package/dist/utils/TranslationUtils.js +0 -4
- package/dist/utils/TranslationUtils.js.flow +2 -2
- package/package.json +9 -9
|
@@ -64,22 +64,22 @@ import type {
|
|
|
64
64
|
TypeParameterDeclaration,
|
|
65
65
|
TypeParameterInstantiation,
|
|
66
66
|
VariableDeclaration,
|
|
67
|
-
} from '
|
|
68
|
-
import type {ScopeManager} from '
|
|
69
|
-
import type {DetachedNode} from '
|
|
67
|
+
} from 'flow-estree';
|
|
68
|
+
import type {ScopeManager} from 'flow-eslint';
|
|
69
|
+
import type {DetachedNode} from 'flow-transform';
|
|
70
70
|
import type {
|
|
71
71
|
Dep,
|
|
72
72
|
TranslationContext,
|
|
73
73
|
TranslationOptions,
|
|
74
74
|
} from './utils/TranslationUtils';
|
|
75
75
|
|
|
76
|
-
import {t} from '
|
|
76
|
+
import {t} from 'flow-transform';
|
|
77
77
|
import {
|
|
78
78
|
analyzeFunctionReturn,
|
|
79
79
|
analyzeTypeDependencies,
|
|
80
80
|
} from './utils/FlowAnalyze';
|
|
81
81
|
import {createTranslationContext} from './utils/TranslationUtils';
|
|
82
|
-
import {asDetachedNode} from '
|
|
82
|
+
import {asDetachedNode} from 'flow-transform';
|
|
83
83
|
import {translationError, flowFixMeOrError} from './utils/ErrorUtils';
|
|
84
84
|
import {
|
|
85
85
|
isExpression,
|
|
@@ -87,7 +87,7 @@ import {
|
|
|
87
87
|
isNumericLiteral,
|
|
88
88
|
isIdentifier,
|
|
89
89
|
isMemberExpressionWithNonComputedProperty,
|
|
90
|
-
} from '
|
|
90
|
+
} from 'flow-estree';
|
|
91
91
|
|
|
92
92
|
const EMPTY_TRANSLATION_RESULT: TranslatedResultOrNull<empty> = [null, []];
|
|
93
93
|
|
|
@@ -930,14 +930,20 @@ function convertVariableDeclaration(
|
|
|
930
930
|
|
|
931
931
|
return [
|
|
932
932
|
t.DeclareVariable({
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
933
|
+
declarations: [
|
|
934
|
+
t.VariableDeclarator({
|
|
935
|
+
id: t.Identifier({
|
|
936
|
+
name: id.name,
|
|
937
|
+
typeAnnotation: t.TypeAnnotation({
|
|
938
|
+
typeAnnotation: resultTypeAnnotation,
|
|
939
|
+
}),
|
|
940
|
+
optional: false,
|
|
941
|
+
}),
|
|
942
|
+
init: null,
|
|
937
943
|
}),
|
|
938
|
-
|
|
939
|
-
}),
|
|
944
|
+
],
|
|
940
945
|
kind: stmt.kind,
|
|
946
|
+
implicitDeclare: false,
|
|
941
947
|
}),
|
|
942
948
|
annotDeps,
|
|
943
949
|
];
|
package/dist/flowToJS.js
CHANGED
|
@@ -4,27 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.flowToJS = flowToJS;
|
|
7
|
-
|
|
8
|
-
var _hermesParser = require("hermes-parser");
|
|
9
|
-
|
|
7
|
+
var _flowParser = require("flow-parser");
|
|
10
8
|
var _DocblockUtils = require("./utils/DocblockUtils");
|
|
11
|
-
|
|
12
9
|
const {
|
|
13
10
|
nodeWith
|
|
14
|
-
} =
|
|
15
|
-
|
|
11
|
+
} = _flowParser.astNodeMutationHelpers;
|
|
16
12
|
function stripAtFlow(ast, _options) {
|
|
17
13
|
const docblock = ast.docblock;
|
|
18
|
-
|
|
19
14
|
if (docblock == null) {
|
|
20
15
|
return ast;
|
|
21
16
|
}
|
|
22
|
-
|
|
23
17
|
return nodeWith(ast, {
|
|
24
18
|
docblock: (0, _DocblockUtils.removeAtFlowFromDocblock)(docblock)
|
|
25
19
|
});
|
|
26
20
|
}
|
|
27
|
-
|
|
28
21
|
function flowToJS(sourceAST, _code, _scopeManager) {
|
|
29
|
-
return [
|
|
22
|
+
return [_flowParser.Transforms.transformComponentSyntax, _flowParser.Transforms.stripFlowTypes, stripAtFlow].reduce((ast, transform) => transform(ast, {}), sourceAST);
|
|
30
23
|
}
|
package/dist/flowToJS.js.flow
CHANGED
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
import type {ScopeManager} from '
|
|
14
|
-
import type {Program} from '
|
|
15
|
-
import type {ParserOptions} from '
|
|
13
|
+
import type {ScopeManager} from 'flow-eslint';
|
|
14
|
+
import type {Program} from 'flow-estree';
|
|
15
|
+
import type {ParserOptions} from 'flow-parser';
|
|
16
16
|
|
|
17
|
-
import {Transforms} from '
|
|
18
|
-
import {astNodeMutationHelpers} from '
|
|
17
|
+
import {Transforms} from 'flow-parser';
|
|
18
|
+
import {astNodeMutationHelpers} from 'flow-parser';
|
|
19
19
|
import {removeAtFlowFromDocblock} from './utils/DocblockUtils';
|
|
20
20
|
|
|
21
21
|
const {nodeWith} = astNodeMutationHelpers;
|
package/dist/index.js
CHANGED
|
@@ -9,85 +9,69 @@ exports.translateFlowToFlowDef = translateFlowToFlowDef;
|
|
|
9
9
|
exports.translateFlowToJS = translateFlowToJS;
|
|
10
10
|
exports.translateFlowToTSDef = translateFlowToTSDef;
|
|
11
11
|
exports.unstable_translateTSDefToFlowDef = unstable_translateTSDefToFlowDef;
|
|
12
|
-
|
|
13
|
-
var _hermesTransform = require("hermes-transform");
|
|
14
|
-
|
|
12
|
+
var _flowTransform = require("flow-transform");
|
|
15
13
|
var _parser = require("@typescript-eslint/parser");
|
|
16
|
-
|
|
17
14
|
var _visitorKeys = require("@typescript-eslint/visitor-keys");
|
|
18
|
-
|
|
19
15
|
var _flowToFlowDef = _interopRequireDefault(require("./flowToFlowDef"));
|
|
20
|
-
|
|
21
16
|
var _flowDefToTSDef = require("./flowDefToTSDef");
|
|
22
|
-
|
|
23
17
|
var _flowToJS = require("./flowToJS");
|
|
24
|
-
|
|
25
18
|
var _flowImportTo = require("./flowImportTo");
|
|
26
|
-
|
|
27
19
|
var _TSDefToFlowDef = require("./TSDefToFlowDef");
|
|
28
|
-
|
|
29
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
30
|
-
|
|
20
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
31
21
|
async function translateFlowToFlowDef(code, prettierOptions = {}, opts) {
|
|
32
22
|
const {
|
|
33
23
|
ast,
|
|
34
24
|
scopeManager
|
|
35
|
-
} = await (0,
|
|
25
|
+
} = await (0, _flowTransform.parse)(code);
|
|
36
26
|
const [flowDefAst, mutatedCode] = (0, _flowToFlowDef.default)(ast, code, scopeManager, {
|
|
37
27
|
recoverFromErrors: true,
|
|
38
28
|
mungeUnderscores: opts == null ? void 0 : opts.mungeUnderscores
|
|
39
29
|
});
|
|
40
|
-
return (0,
|
|
30
|
+
return (0, _flowTransform.print)(flowDefAst, mutatedCode, prettierOptions);
|
|
41
31
|
}
|
|
42
|
-
|
|
43
32
|
async function translateFlowToTSDef(code, prettierOptions = {}) {
|
|
44
33
|
const flowDefCode = await translateFlowToFlowDef(code, prettierOptions);
|
|
45
34
|
return translateFlowDefToTSDef(flowDefCode, prettierOptions);
|
|
46
35
|
}
|
|
47
|
-
|
|
48
36
|
async function translateFlowDefToTSDef(code, prettierOptions = {}) {
|
|
49
37
|
const {
|
|
50
38
|
ast,
|
|
51
39
|
scopeManager
|
|
52
|
-
} = await (0,
|
|
40
|
+
} = await (0, _flowTransform.parse)(code);
|
|
53
41
|
const [tsAST, mutatedCode] = (0, _flowDefToTSDef.flowDefToTSDef)(code, ast, scopeManager, {
|
|
54
42
|
recoverFromErrors: true
|
|
55
43
|
});
|
|
56
|
-
return (0,
|
|
44
|
+
return (0, _flowTransform.print)(tsAST, mutatedCode, {
|
|
45
|
+
...prettierOptions
|
|
57
46
|
}, _visitorKeys.visitorKeys);
|
|
58
47
|
}
|
|
59
|
-
|
|
60
48
|
async function translateFlowToJS(code, prettierOptions = {}) {
|
|
61
49
|
const {
|
|
62
50
|
ast,
|
|
63
51
|
scopeManager
|
|
64
|
-
} = await (0,
|
|
52
|
+
} = await (0, _flowTransform.parse)(code);
|
|
65
53
|
const jsAST = (0, _flowToJS.flowToJS)(ast, code, scopeManager);
|
|
66
|
-
return (0,
|
|
54
|
+
return (0, _flowTransform.print)(jsAST, code, prettierOptions);
|
|
67
55
|
}
|
|
68
|
-
|
|
69
56
|
async function unstable_translateTSDefToFlowDef(code, prettierOptions = {}) {
|
|
70
57
|
const ast = (0, _parser.parse)(code, {
|
|
71
58
|
loc: true,
|
|
72
59
|
range: true,
|
|
73
60
|
sourceType: 'module'
|
|
74
61
|
});
|
|
75
|
-
|
|
76
62
|
if (ast == null) {
|
|
77
63
|
throw `Failed to parse ${code} with @typescript-eslint/parser`;
|
|
78
64
|
}
|
|
79
|
-
|
|
80
65
|
const [flowAST, mutatedCode] = (0, _TSDefToFlowDef.TSDefToFlowDef)(code, ast, {
|
|
81
66
|
recoverFromErrors: false
|
|
82
67
|
});
|
|
83
|
-
return (0,
|
|
68
|
+
return (0, _flowTransform.print)(flowAST, mutatedCode, prettierOptions);
|
|
84
69
|
}
|
|
85
|
-
|
|
86
70
|
async function translateFlowImportsTo(code, prettierOptions = {}, opts) {
|
|
87
71
|
const {
|
|
88
72
|
ast,
|
|
89
73
|
scopeManager
|
|
90
|
-
} = await (0,
|
|
74
|
+
} = await (0, _flowTransform.parse)(code);
|
|
91
75
|
const jsAST = (0, _flowImportTo.flowImportTo)(ast, code, scopeManager, opts);
|
|
92
|
-
return (0,
|
|
76
|
+
return (0, _flowTransform.print)(jsAST, code, prettierOptions);
|
|
93
77
|
}
|
package/dist/index.js.flow
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import type {MapperOptions} from './flowImportTo';
|
|
14
14
|
|
|
15
|
-
import {parse, print} from '
|
|
15
|
+
import {parse, print} from 'flow-transform';
|
|
16
16
|
import {parse as parseTS} from '@typescript-eslint/parser';
|
|
17
17
|
import {visitorKeys as tsVisitorKeys} from '@typescript-eslint/visitor-keys';
|
|
18
18
|
import flowToFlowDef from './flowToFlowDef';
|