flow-api-translator 0.10.1 → 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.
@@ -647,7 +647,8 @@ function convertVariableDeclaration(stmt, context) {
647
647
  typeAnnotation: resultTypeAnnotation
648
648
  }),
649
649
  optional: false
650
- })
650
+ }),
651
+ kind: stmt.kind
651
652
  }), annotDeps];
652
653
  }
653
654
 
@@ -826,6 +826,7 @@ function convertVariableDeclaration(
826
826
  }),
827
827
  optional: false,
828
828
  }),
829
+ kind: stmt.kind,
829
830
  }),
830
831
  annotDeps,
831
832
  ];
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, code, { ...prettierOptions
60
+ tsAST, mutatedCode, { ...prettierOptions
59
61
  }, _visitorKeys.visitorKeys);
60
62
  }
61
63
 
@@ -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
- code,
56
+ mutatedCode,
55
57
  {
56
58
  ...prettierOptions,
57
59
  },
@@ -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: process.env.NODE_ENV !== 'test',
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
- ): Error {
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
- ): Error {
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: process.env.NODE_ENV !== 'test',
98
+ highlightCode,
98
99
  message: message,
99
100
  });
100
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flow-api-translator",
3
- "version": "0.10.1",
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",