flow-api-translator 0.10.0 → 0.11.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 +1052 -617
- package/dist/flowDefToTSDef.js.flow +1128 -612
- package/dist/flowToFlowDef.js +2 -1
- package/dist/flowToFlowDef.js.flow +1 -0
- package/dist/index.js +4 -2
- package/dist/index.js.flow +4 -2
- package/dist/utils/ErrorUtils.js +3 -2
- package/dist/utils/ErrorUtils.js.flow +5 -4
- package/dist/utils/ts-estree-ast-types.js.flow +1 -1
- package/package.json +5 -4
package/dist/flowToFlowDef.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -53,9 +53,11 @@ function translateFlowDefToTSDef(code, prettierOptions = {}) {
|
|
|
53
53
|
ast,
|
|
54
54
|
scopeManager
|
|
55
55
|
} = (0, _hermesTransform.parse)(code);
|
|
56
|
-
const tsAST = (0, _flowDefToTSDef.flowDefToTSDef)(code, ast, scopeManager
|
|
56
|
+
const [tsAST, mutatedCode] = (0, _flowDefToTSDef.flowDefToTSDef)(code, ast, scopeManager, {
|
|
57
|
+
recoverFromErrors: true
|
|
58
|
+
});
|
|
57
59
|
return (0, _hermesTransform.print)( // $FlowExpectedError[incompatible-call] - this is fine as we're providing the visitor keys
|
|
58
|
-
tsAST,
|
|
60
|
+
tsAST, mutatedCode, { ...prettierOptions
|
|
59
61
|
}, _visitorKeys.visitorKeys);
|
|
60
62
|
}
|
|
61
63
|
|
package/dist/index.js.flow
CHANGED
|
@@ -46,12 +46,14 @@ export function translateFlowDefToTSDef(
|
|
|
46
46
|
prettierOptions: {...} = {},
|
|
47
47
|
): string {
|
|
48
48
|
const {ast, scopeManager} = parse(code);
|
|
49
|
-
const tsAST = flowDefToTSDef(code, ast, scopeManager
|
|
49
|
+
const [tsAST, mutatedCode] = flowDefToTSDef(code, ast, scopeManager, {
|
|
50
|
+
recoverFromErrors: true,
|
|
51
|
+
});
|
|
50
52
|
|
|
51
53
|
return print(
|
|
52
54
|
// $FlowExpectedError[incompatible-call] - this is fine as we're providing the visitor keys
|
|
53
55
|
tsAST,
|
|
54
|
-
|
|
56
|
+
mutatedCode,
|
|
55
57
|
{
|
|
56
58
|
...prettierOptions,
|
|
57
59
|
},
|
package/dist/utils/ErrorUtils.js
CHANGED
|
@@ -13,6 +13,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
13
13
|
value: true
|
|
14
14
|
});
|
|
15
15
|
exports.UnexpectedTranslationError = exports.ExpectedTranslationError = void 0;
|
|
16
|
+
exports.buildCodeFrame = buildCodeFrame;
|
|
16
17
|
exports.flowFixMeOrError = flowFixMeOrError;
|
|
17
18
|
exports.translationError = translationError;
|
|
18
19
|
exports.unexpectedTranslationError = unexpectedTranslationError;
|
|
@@ -81,7 +82,7 @@ function unexpectedTranslationError(node, message, context) {
|
|
|
81
82
|
return new UnexpectedTranslationError(node, message, context);
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
function buildCodeFrame(node, message, code) {
|
|
85
|
+
function buildCodeFrame(node, message, code, highlightCode = process.env.NODE_ENV !== 'test') {
|
|
85
86
|
// babel uses 1-indexed columns
|
|
86
87
|
const locForBabel = {
|
|
87
88
|
start: {
|
|
@@ -96,7 +97,7 @@ function buildCodeFrame(node, message, code) {
|
|
|
96
97
|
return (0, _codeFrame.codeFrameColumns)(code, locForBabel, {
|
|
97
98
|
linesAbove: 0,
|
|
98
99
|
linesBelow: 0,
|
|
99
|
-
highlightCode
|
|
100
|
+
highlightCode,
|
|
100
101
|
message: message
|
|
101
102
|
});
|
|
102
103
|
}
|
|
@@ -60,7 +60,7 @@ export function translationError(
|
|
|
60
60
|
node: ObjectWithLoc,
|
|
61
61
|
message: string,
|
|
62
62
|
context: $ReadOnly<{code: string, ...}>,
|
|
63
|
-
):
|
|
63
|
+
): ExpectedTranslationError {
|
|
64
64
|
return new ExpectedTranslationError(node, message, context);
|
|
65
65
|
}
|
|
66
66
|
|
|
@@ -71,14 +71,15 @@ export function unexpectedTranslationError(
|
|
|
71
71
|
node: ObjectWithLoc,
|
|
72
72
|
message: string,
|
|
73
73
|
context: $ReadOnly<{code: string, ...}>,
|
|
74
|
-
):
|
|
74
|
+
): UnexpectedTranslationError {
|
|
75
75
|
return new UnexpectedTranslationError(node, message, context);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
function buildCodeFrame(
|
|
78
|
+
export function buildCodeFrame(
|
|
79
79
|
node: ObjectWithLoc,
|
|
80
80
|
message: string,
|
|
81
81
|
code: string,
|
|
82
|
+
highlightCode: boolean = process.env.NODE_ENV !== 'test',
|
|
82
83
|
): string {
|
|
83
84
|
// babel uses 1-indexed columns
|
|
84
85
|
const locForBabel = {
|
|
@@ -94,7 +95,7 @@ function buildCodeFrame(
|
|
|
94
95
|
return codeFrameColumns(code, locForBabel, {
|
|
95
96
|
linesAbove: 0,
|
|
96
97
|
linesBelow: 0,
|
|
97
|
-
highlightCode
|
|
98
|
+
highlightCode,
|
|
98
99
|
message: message,
|
|
99
100
|
});
|
|
100
101
|
}
|
|
@@ -650,7 +650,7 @@ export interface ImportSpecifier extends BaseNode {
|
|
|
650
650
|
+type: 'ImportSpecifier';
|
|
651
651
|
+local: Identifier;
|
|
652
652
|
+imported: Identifier;
|
|
653
|
-
+importKind: ImportKind;
|
|
653
|
+
+importKind: ?ImportKind;
|
|
654
654
|
}
|
|
655
655
|
export type IterationStatement =
|
|
656
656
|
| DoWhileStatement
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flow-api-translator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.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",
|
|
@@ -12,9 +12,10 @@
|
|
|
12
12
|
"@babel/code-frame": "^7.16.0",
|
|
13
13
|
"@typescript-eslint/visitor-keys": "^5.42.0",
|
|
14
14
|
"flow-enums-runtime": "^0.0.6",
|
|
15
|
-
"hermes-
|
|
16
|
-
"hermes-
|
|
17
|
-
"hermes-
|
|
15
|
+
"hermes-eslint": "0.10.1",
|
|
16
|
+
"hermes-estree": "0.10.1",
|
|
17
|
+
"hermes-parser": "0.10.1",
|
|
18
|
+
"hermes-transform": "0.10.1"
|
|
18
19
|
},
|
|
19
20
|
"peerDependencies": {
|
|
20
21
|
"prettier": "^2.7.1"
|