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
package/dist/TSDefToFlowDef.js
CHANGED
|
@@ -4,21 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.TSDefToFlowDef = TSDefToFlowDef;
|
|
7
|
-
|
|
8
|
-
var FlowESTree = _interopRequireWildcard(require("hermes-estree"));
|
|
9
|
-
|
|
7
|
+
var FlowESTree = _interopRequireWildcard(require("flow-estree"));
|
|
10
8
|
var TSESTree = _interopRequireWildcard(require("./utils/ts-estree-ast-types"));
|
|
11
|
-
|
|
12
|
-
var _hermesTransform = require("hermes-transform");
|
|
13
|
-
|
|
9
|
+
var _flowTransform = require("flow-transform");
|
|
14
10
|
var _ErrorUtils = require("./utils/ErrorUtils");
|
|
15
|
-
|
|
16
11
|
var _os = require("os");
|
|
17
|
-
|
|
18
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
-
|
|
20
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
-
|
|
12
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
22
13
|
const DUMMY_LOC = null;
|
|
23
14
|
const DUMMY_RANGE = [0, 0];
|
|
24
15
|
const DUMMY_PARENT = null;
|
|
@@ -27,18 +18,17 @@ const DUMMY_COMMON = {
|
|
|
27
18
|
range: DUMMY_RANGE,
|
|
28
19
|
parent: DUMMY_PARENT
|
|
29
20
|
};
|
|
30
|
-
|
|
31
21
|
function constructFlowNode(node) {
|
|
32
|
-
return {
|
|
22
|
+
return {
|
|
23
|
+
...node,
|
|
33
24
|
...DUMMY_COMMON
|
|
34
25
|
};
|
|
35
26
|
}
|
|
36
|
-
|
|
37
|
-
const makeCommentOwnLine = _hermesTransform.makeCommentOwnLine;
|
|
38
|
-
|
|
27
|
+
const makeCommentOwnLine = _flowTransform.makeCommentOwnLine;
|
|
39
28
|
function TSDefToFlowDef(originalCode, ast, opts) {
|
|
40
29
|
const flowBody = [];
|
|
41
|
-
const flowProgram = {
|
|
30
|
+
const flowProgram = {
|
|
31
|
+
...DUMMY_COMMON,
|
|
42
32
|
type: 'Program',
|
|
43
33
|
body: flowBody,
|
|
44
34
|
comments: [],
|
|
@@ -49,41 +39,32 @@ function TSDefToFlowDef(originalCode, ast, opts) {
|
|
|
49
39
|
docblock: null
|
|
50
40
|
};
|
|
51
41
|
const [transform, code] = getTransforms(originalCode, opts);
|
|
52
|
-
|
|
53
42
|
for (const node of ast.body) {
|
|
54
43
|
const result = transform.AllStatement(node);
|
|
55
44
|
flowBody.push(...(Array.isArray(result) ? result : [result]));
|
|
56
45
|
}
|
|
57
|
-
|
|
58
46
|
return [flowProgram, code];
|
|
59
47
|
}
|
|
60
|
-
|
|
61
48
|
const getTransforms = (originalCode, opts) => {
|
|
62
49
|
let code = originalCode;
|
|
63
|
-
|
|
64
50
|
function translationError(node, message) {
|
|
65
51
|
return (0, _ErrorUtils.translationError)(node, message, {
|
|
66
52
|
code
|
|
67
53
|
});
|
|
68
54
|
}
|
|
69
|
-
|
|
70
55
|
function unexpectedTranslationError(node, message) {
|
|
71
56
|
return (0, _ErrorUtils.unexpectedTranslationError)(node, message, {
|
|
72
57
|
code
|
|
73
58
|
});
|
|
74
59
|
}
|
|
75
|
-
|
|
76
60
|
function unsupportedFeatureMessage(thing) {
|
|
77
61
|
return `Unsupported feature: Translating "${thing}" is currently not supported.`;
|
|
78
62
|
}
|
|
79
|
-
|
|
80
63
|
function buildCodeFrameForComment(node, message) {
|
|
81
64
|
return (0, _ErrorUtils.buildCodeFrame)(node, message, code, false);
|
|
82
65
|
}
|
|
83
|
-
|
|
84
66
|
function addErrorComment(node, message) {
|
|
85
67
|
var _node$comments;
|
|
86
|
-
|
|
87
68
|
const comment = {
|
|
88
69
|
type: 'Block',
|
|
89
70
|
loc: DUMMY_LOC,
|
|
@@ -95,31 +76,29 @@ const getTransforms = (originalCode, opts) => {
|
|
|
95
76
|
(_node$comments = node.comments) != null ? _node$comments : node.comments = [];
|
|
96
77
|
node.comments.push(comment);
|
|
97
78
|
}
|
|
98
|
-
|
|
99
79
|
function unsupportedAnnotation(node, thing) {
|
|
100
80
|
const message = unsupportedFeatureMessage(thing);
|
|
101
|
-
|
|
102
81
|
if (opts.recoverFromErrors) {
|
|
103
82
|
const codeFrame = buildCodeFrameForComment(node, message);
|
|
104
|
-
const newNode = {
|
|
83
|
+
const newNode = {
|
|
84
|
+
...DUMMY_COMMON,
|
|
105
85
|
type: 'AnyTypeAnnotation'
|
|
106
86
|
};
|
|
107
87
|
addErrorComment(newNode, codeFrame);
|
|
108
88
|
return newNode;
|
|
109
89
|
}
|
|
110
|
-
|
|
111
90
|
throw translationError(node, message);
|
|
112
91
|
}
|
|
113
|
-
|
|
114
92
|
function unsupportedDeclaration(node, thing, id, typeParameters = null) {
|
|
115
93
|
const message = unsupportedFeatureMessage(thing);
|
|
116
|
-
|
|
117
94
|
if (opts.recoverFromErrors) {
|
|
118
95
|
const codeFrame = buildCodeFrameForComment(node, message);
|
|
119
|
-
const newNode = {
|
|
96
|
+
const newNode = {
|
|
97
|
+
...DUMMY_COMMON,
|
|
120
98
|
type: 'TypeAlias',
|
|
121
99
|
id: Transform.Identifier(id, false),
|
|
122
|
-
right: {
|
|
100
|
+
right: {
|
|
101
|
+
...DUMMY_COMMON,
|
|
123
102
|
type: 'AnyTypeAnnotation'
|
|
124
103
|
},
|
|
125
104
|
typeParameters: Transform.TSTypeParameterDeclarationOpt(typeParameters)
|
|
@@ -127,10 +106,8 @@ const getTransforms = (originalCode, opts) => {
|
|
|
127
106
|
addErrorComment(newNode, codeFrame);
|
|
128
107
|
return newNode;
|
|
129
108
|
}
|
|
130
|
-
|
|
131
109
|
throw translationError(node, message);
|
|
132
110
|
}
|
|
133
|
-
|
|
134
111
|
class Transform {
|
|
135
112
|
static BlockStatement(node) {
|
|
136
113
|
return constructFlowNode({
|
|
@@ -138,7 +115,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
138
115
|
body: node.body.flatMap(node => Transform.Statement(node))
|
|
139
116
|
});
|
|
140
117
|
}
|
|
141
|
-
|
|
142
118
|
static ClassDeclarationWithName(node) {
|
|
143
119
|
return constructFlowNode({
|
|
144
120
|
type: 'DeclareClass',
|
|
@@ -150,35 +126,27 @@ const getTransforms = (originalCode, opts) => {
|
|
|
150
126
|
body: Transform.ClassDeclarationBody(node.body)
|
|
151
127
|
});
|
|
152
128
|
}
|
|
153
|
-
|
|
154
129
|
static ClassDeclarationBody({
|
|
155
130
|
body
|
|
156
131
|
}) {
|
|
157
132
|
const properties = [];
|
|
158
133
|
const indexers = [];
|
|
159
|
-
|
|
160
134
|
for (const classItem of body) {
|
|
161
135
|
switch (classItem.type) {
|
|
162
136
|
case 'StaticBlock':
|
|
163
137
|
break;
|
|
164
|
-
|
|
165
138
|
case 'TSIndexSignature':
|
|
166
139
|
break;
|
|
167
|
-
|
|
168
140
|
case 'TSAbstractPropertyDefinition':
|
|
169
141
|
case 'PropertyDefinition':
|
|
170
142
|
Transform._translateIntoObjectProp(classItem, properties, indexers);
|
|
171
|
-
|
|
172
143
|
break;
|
|
173
|
-
|
|
174
144
|
case 'MethodDefinition':
|
|
175
145
|
case 'TSAbstractMethodDefinition':
|
|
176
146
|
Transform._translateIntoObjectMethod(classItem, properties);
|
|
177
|
-
|
|
178
147
|
break;
|
|
179
148
|
}
|
|
180
149
|
}
|
|
181
|
-
|
|
182
150
|
return constructFlowNode({
|
|
183
151
|
type: 'ObjectTypeAnnotation',
|
|
184
152
|
properties,
|
|
@@ -189,47 +157,38 @@ const getTransforms = (originalCode, opts) => {
|
|
|
189
157
|
inexact: false
|
|
190
158
|
});
|
|
191
159
|
}
|
|
192
|
-
|
|
193
160
|
static ClassDeclarationSuperClass(superClass, superTypeArguments) {
|
|
194
161
|
if (superClass == null) {
|
|
195
162
|
return [];
|
|
196
163
|
}
|
|
197
|
-
|
|
198
164
|
const id = Transform._expressionToIdOrQualifiedTypeId(superClass, 'superClass');
|
|
199
|
-
|
|
200
165
|
return [constructFlowNode({
|
|
201
166
|
type: 'InterfaceExtends',
|
|
202
167
|
id,
|
|
203
168
|
typeParameters: Transform.TSTypeParameterInstantiationOpt(superTypeArguments)
|
|
204
169
|
})];
|
|
205
170
|
}
|
|
206
|
-
|
|
207
171
|
static ClassImplements(node) {
|
|
208
172
|
if (node.expression.type !== 'Identifier') {
|
|
209
173
|
throw unexpectedTranslationError(node, 'Expected expression to be an Identifier');
|
|
210
174
|
}
|
|
211
|
-
|
|
212
175
|
return constructFlowNode({
|
|
213
176
|
type: 'ClassImplements',
|
|
214
177
|
id: Transform.Identifier(node.expression),
|
|
215
178
|
typeParameters: Transform.TSTypeParameterInstantiationOpt(node.typeArguments)
|
|
216
179
|
});
|
|
217
180
|
}
|
|
218
|
-
|
|
219
181
|
static DebuggerStatement() {
|
|
220
182
|
return constructFlowNode({
|
|
221
183
|
type: 'DebuggerStatement'
|
|
222
184
|
});
|
|
223
185
|
}
|
|
224
|
-
|
|
225
186
|
static EntityNameToTypeIdentifier(node) {
|
|
226
187
|
switch (node.type) {
|
|
227
188
|
case 'Identifier':
|
|
228
189
|
return Transform.Identifier(node);
|
|
229
|
-
|
|
230
190
|
case 'TSQualifiedName':
|
|
231
191
|
return Transform.TSQualifiedNameToQualifiedTypeIdentifier(node);
|
|
232
|
-
|
|
233
192
|
case 'ThisExpression':
|
|
234
193
|
return constructFlowNode({
|
|
235
194
|
type: 'Identifier',
|
|
@@ -239,15 +198,12 @@ const getTransforms = (originalCode, opts) => {
|
|
|
239
198
|
});
|
|
240
199
|
}
|
|
241
200
|
}
|
|
242
|
-
|
|
243
201
|
static EntityNameToTypeofIdentifier(node) {
|
|
244
202
|
switch (node.type) {
|
|
245
203
|
case 'Identifier':
|
|
246
204
|
return Transform.Identifier(node);
|
|
247
|
-
|
|
248
205
|
case 'TSQualifiedName':
|
|
249
206
|
return Transform.TSQualifiedNameToQualifiedTypeofIdentifier(node);
|
|
250
|
-
|
|
251
207
|
case 'ThisExpression':
|
|
252
208
|
return constructFlowNode({
|
|
253
209
|
type: 'Identifier',
|
|
@@ -257,7 +213,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
257
213
|
});
|
|
258
214
|
}
|
|
259
215
|
}
|
|
260
|
-
|
|
261
216
|
static ExportAllDeclaration(node) {
|
|
262
217
|
return constructFlowNode({
|
|
263
218
|
type: 'ExportAllDeclaration',
|
|
@@ -272,34 +227,27 @@ const getTransforms = (originalCode, opts) => {
|
|
|
272
227
|
exported: node.exported != null ? Transform.Identifier(node.exported) : null
|
|
273
228
|
});
|
|
274
229
|
}
|
|
275
|
-
|
|
276
230
|
static ExportDefaultDeclaration(node) {
|
|
277
231
|
let declaration;
|
|
278
|
-
|
|
279
232
|
switch (node.declaration.type) {
|
|
280
233
|
case 'ClassDeclaration':
|
|
281
234
|
declaration = Transform.ClassDeclarationWithName(node.declaration);
|
|
282
235
|
break;
|
|
283
|
-
|
|
284
236
|
case 'FunctionDeclaration':
|
|
285
237
|
declaration = Transform.FunctionDeclarationWithName(node.declaration);
|
|
286
238
|
break;
|
|
287
|
-
|
|
288
239
|
case 'TSDeclareFunction':
|
|
289
240
|
declaration = Transform.TSDeclareFunction(node.declaration);
|
|
290
241
|
break;
|
|
291
|
-
|
|
292
242
|
case 'Identifier':
|
|
293
243
|
declaration = constructFlowNode({
|
|
294
244
|
type: 'TypeofTypeAnnotation',
|
|
295
245
|
argument: Transform.Identifier(node.declaration)
|
|
296
246
|
});
|
|
297
247
|
break;
|
|
298
|
-
|
|
299
248
|
default:
|
|
300
249
|
throw translationError(node.declaration, `Unsupported export declaration: ${node.declaration.type}`);
|
|
301
250
|
}
|
|
302
|
-
|
|
303
251
|
return constructFlowNode({
|
|
304
252
|
type: 'DeclareExportDeclaration',
|
|
305
253
|
declaration,
|
|
@@ -308,7 +256,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
308
256
|
specifiers: []
|
|
309
257
|
});
|
|
310
258
|
}
|
|
311
|
-
|
|
312
259
|
static ExportNamedDeclaration(node) {
|
|
313
260
|
if (node.declaration == null) {
|
|
314
261
|
const source = node.source == null ? null : constructFlowNode({
|
|
@@ -330,7 +277,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
330
277
|
specifiers
|
|
331
278
|
});
|
|
332
279
|
}
|
|
333
|
-
|
|
334
280
|
switch (node.declaration.type) {
|
|
335
281
|
case 'ClassDeclaration':
|
|
336
282
|
return constructFlowNode({
|
|
@@ -340,7 +286,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
340
286
|
source: null,
|
|
341
287
|
specifiers: []
|
|
342
288
|
});
|
|
343
|
-
|
|
344
289
|
case 'FunctionDeclaration':
|
|
345
290
|
return constructFlowNode({
|
|
346
291
|
type: 'DeclareExportDeclaration',
|
|
@@ -349,7 +294,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
349
294
|
source: null,
|
|
350
295
|
specifiers: []
|
|
351
296
|
});
|
|
352
|
-
|
|
353
297
|
case 'TSDeclareFunction':
|
|
354
298
|
return constructFlowNode({
|
|
355
299
|
type: 'DeclareExportDeclaration',
|
|
@@ -358,18 +302,14 @@ const getTransforms = (originalCode, opts) => {
|
|
|
358
302
|
source: null,
|
|
359
303
|
specifiers: []
|
|
360
304
|
});
|
|
361
|
-
|
|
362
305
|
case 'TSEnumDeclaration':
|
|
363
306
|
throw translationError(node.declaration, `Unsupported export declaration: ${node.declaration.type}`);
|
|
364
|
-
|
|
365
307
|
case 'TSModuleDeclaration':
|
|
366
308
|
{
|
|
367
309
|
const decl = Transform.TSModuleDeclaration(node.declaration);
|
|
368
|
-
|
|
369
310
|
if (decl.id.type !== 'Identifier') {
|
|
370
311
|
throw translationError(decl.id, `Unsupported module declaration id`);
|
|
371
312
|
}
|
|
372
|
-
|
|
373
313
|
return [decl, constructFlowNode({
|
|
374
314
|
type: 'ExportNamedDeclaration',
|
|
375
315
|
declaration: null,
|
|
@@ -382,7 +322,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
382
322
|
})]
|
|
383
323
|
})];
|
|
384
324
|
}
|
|
385
|
-
|
|
386
325
|
case 'TSInterfaceDeclaration':
|
|
387
326
|
{
|
|
388
327
|
const decl = Transform.TSInterfaceDeclaration(node.declaration);
|
|
@@ -400,7 +339,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
400
339
|
specifiers: []
|
|
401
340
|
});
|
|
402
341
|
}
|
|
403
|
-
|
|
404
342
|
case 'TSTypeAliasDeclaration':
|
|
405
343
|
{
|
|
406
344
|
const decl = Transform.TSTypeAliasDeclaration(node.declaration);
|
|
@@ -412,7 +350,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
412
350
|
specifiers: []
|
|
413
351
|
});
|
|
414
352
|
}
|
|
415
|
-
|
|
416
353
|
case 'VariableDeclaration':
|
|
417
354
|
{
|
|
418
355
|
return Transform.VariableDeclaration(node.declaration).map(declaration => constructFlowNode({
|
|
@@ -425,16 +362,13 @@ const getTransforms = (originalCode, opts) => {
|
|
|
425
362
|
}
|
|
426
363
|
}
|
|
427
364
|
}
|
|
428
|
-
|
|
429
365
|
static FunctionDeclarationWithName(node) {
|
|
430
366
|
var _node$returnType;
|
|
431
|
-
|
|
432
367
|
const {
|
|
433
368
|
thisParam,
|
|
434
369
|
restParam,
|
|
435
370
|
params
|
|
436
371
|
} = Transform._partitionAndTranslateTSFunctionParams(node.params);
|
|
437
|
-
|
|
438
372
|
const fnAnnot = constructFlowNode({
|
|
439
373
|
type: 'FunctionTypeAnnotation',
|
|
440
374
|
typeParameters: Transform.TSTypeParameterDeclarationOpt(node.typeParameters),
|
|
@@ -445,19 +379,21 @@ const getTransforms = (originalCode, opts) => {
|
|
|
445
379
|
});
|
|
446
380
|
return constructFlowNode({
|
|
447
381
|
type: 'DeclareFunction',
|
|
448
|
-
id: {
|
|
382
|
+
id: {
|
|
383
|
+
...DUMMY_COMMON,
|
|
449
384
|
type: 'Identifier',
|
|
450
385
|
name: node.id.name,
|
|
451
|
-
typeAnnotation: {
|
|
386
|
+
typeAnnotation: {
|
|
387
|
+
...DUMMY_COMMON,
|
|
452
388
|
type: 'TypeAnnotation',
|
|
453
389
|
typeAnnotation: fnAnnot
|
|
454
390
|
},
|
|
455
391
|
optional: false
|
|
456
392
|
},
|
|
393
|
+
implicitDeclare: false,
|
|
457
394
|
predicate: null
|
|
458
395
|
});
|
|
459
396
|
}
|
|
460
|
-
|
|
461
397
|
static Identifier(node, optional) {
|
|
462
398
|
return constructFlowNode({
|
|
463
399
|
type: 'Identifier',
|
|
@@ -466,24 +402,20 @@ const getTransforms = (originalCode, opts) => {
|
|
|
466
402
|
optional: Boolean(optional != null ? optional : node.optional)
|
|
467
403
|
});
|
|
468
404
|
}
|
|
469
|
-
|
|
470
405
|
static ImportDeclaration(node) {
|
|
471
406
|
const specifiers = node.specifiers.map(specifier => {
|
|
472
407
|
var _specifier$importKind;
|
|
473
|
-
|
|
474
408
|
switch (specifier.type) {
|
|
475
409
|
case 'ImportNamespaceSpecifier':
|
|
476
410
|
return constructFlowNode({
|
|
477
411
|
type: 'ImportNamespaceSpecifier',
|
|
478
412
|
local: Transform.Identifier(specifier.local)
|
|
479
413
|
});
|
|
480
|
-
|
|
481
414
|
case 'ImportDefaultSpecifier':
|
|
482
415
|
return constructFlowNode({
|
|
483
416
|
type: 'ImportDefaultSpecifier',
|
|
484
417
|
local: Transform.Identifier(specifier.local)
|
|
485
418
|
});
|
|
486
|
-
|
|
487
419
|
case 'ImportSpecifier':
|
|
488
420
|
return constructFlowNode({
|
|
489
421
|
type: 'ImportSpecifier',
|
|
@@ -506,21 +438,17 @@ const getTransforms = (originalCode, opts) => {
|
|
|
506
438
|
specifiers
|
|
507
439
|
});
|
|
508
440
|
}
|
|
509
|
-
|
|
510
441
|
static LabeledStatement(node) {
|
|
511
442
|
const body = Transform.Statement(node.body);
|
|
512
|
-
|
|
513
443
|
if (Array.isArray(body)) {
|
|
514
444
|
throw translationError(node.body, 'Unexpected array of statements');
|
|
515
445
|
}
|
|
516
|
-
|
|
517
446
|
return constructFlowNode({
|
|
518
447
|
type: 'LabeledStatement',
|
|
519
448
|
label: Transform.Identifier(node.label),
|
|
520
449
|
body
|
|
521
450
|
});
|
|
522
451
|
}
|
|
523
|
-
|
|
524
452
|
static Literal(node) {
|
|
525
453
|
if (typeof node.value === 'number') {
|
|
526
454
|
return constructFlowNode({
|
|
@@ -570,10 +498,8 @@ const getTransforms = (originalCode, opts) => {
|
|
|
570
498
|
throw translationError(node, `Unsupported literal type ${typeof node.value}`);
|
|
571
499
|
}
|
|
572
500
|
}
|
|
573
|
-
|
|
574
501
|
static LiteralType(node) {
|
|
575
502
|
const literal = Transform.Literal(node);
|
|
576
|
-
|
|
577
503
|
switch (literal.literalType) {
|
|
578
504
|
case 'boolean':
|
|
579
505
|
return constructFlowNode({
|
|
@@ -581,21 +507,18 @@ const getTransforms = (originalCode, opts) => {
|
|
|
581
507
|
value: literal.value,
|
|
582
508
|
raw: literal.raw
|
|
583
509
|
});
|
|
584
|
-
|
|
585
510
|
case 'numeric':
|
|
586
511
|
return constructFlowNode({
|
|
587
512
|
type: 'NumberLiteralTypeAnnotation',
|
|
588
513
|
value: literal.value,
|
|
589
514
|
raw: literal.raw
|
|
590
515
|
});
|
|
591
|
-
|
|
592
516
|
case 'string':
|
|
593
517
|
return constructFlowNode({
|
|
594
518
|
type: 'StringLiteralTypeAnnotation',
|
|
595
519
|
value: literal.value,
|
|
596
520
|
raw: literal.raw
|
|
597
521
|
});
|
|
598
|
-
|
|
599
522
|
case 'bigint':
|
|
600
523
|
return constructFlowNode({
|
|
601
524
|
type: 'BigIntLiteralTypeAnnotation',
|
|
@@ -603,85 +526,61 @@ const getTransforms = (originalCode, opts) => {
|
|
|
603
526
|
bigint: literal.bigint,
|
|
604
527
|
raw: literal.raw
|
|
605
528
|
});
|
|
606
|
-
|
|
607
529
|
case 'null':
|
|
608
530
|
return constructFlowNode({
|
|
609
531
|
type: 'NullLiteralTypeAnnotation',
|
|
610
532
|
value: literal.value,
|
|
611
533
|
raw: literal.raw
|
|
612
534
|
});
|
|
613
|
-
|
|
614
535
|
case 'regexp':
|
|
615
536
|
return unsupportedAnnotation(node, 'regexp literal type');
|
|
616
|
-
|
|
617
537
|
default:
|
|
618
538
|
literal;
|
|
619
539
|
throw 'unreachable';
|
|
620
540
|
}
|
|
621
541
|
}
|
|
622
|
-
|
|
623
542
|
static AllStatement(node) {
|
|
624
543
|
switch (node.type) {
|
|
625
544
|
case 'BlockStatement':
|
|
626
545
|
return Transform.BlockStatement(node);
|
|
627
|
-
|
|
628
546
|
case 'ClassDeclaration':
|
|
629
547
|
return Transform.ClassDeclarationWithName(node);
|
|
630
|
-
|
|
631
548
|
case 'DebuggerStatement':
|
|
632
549
|
return Transform.DebuggerStatement();
|
|
633
|
-
|
|
634
550
|
case 'ExportAllDeclaration':
|
|
635
551
|
return Transform.ExportAllDeclaration(node);
|
|
636
|
-
|
|
637
552
|
case 'ExportDefaultDeclaration':
|
|
638
553
|
return Transform.ExportDefaultDeclaration(node);
|
|
639
|
-
|
|
640
554
|
case 'ExportNamedDeclaration':
|
|
641
555
|
return Transform.ExportNamedDeclaration(node);
|
|
642
|
-
|
|
643
556
|
case 'FunctionDeclaration':
|
|
644
557
|
return Transform.FunctionDeclarationWithName(node);
|
|
645
|
-
|
|
646
558
|
case 'ImportDeclaration':
|
|
647
559
|
return Transform.ImportDeclaration(node);
|
|
648
|
-
|
|
649
560
|
case 'LabeledStatement':
|
|
650
561
|
return Transform.LabeledStatement(node);
|
|
651
|
-
|
|
652
562
|
case 'TSDeclareFunction':
|
|
653
563
|
return Transform.TSDeclareFunction(node);
|
|
654
|
-
|
|
655
564
|
case 'TSEnumDeclaration':
|
|
656
565
|
return Transform.TSEnumDeclaration(node);
|
|
657
|
-
|
|
658
566
|
case 'TSExportAssignment':
|
|
659
567
|
return Transform.TSExportAssignment(node);
|
|
660
|
-
|
|
661
568
|
case 'TSImportEqualsDeclaration':
|
|
662
569
|
return Transform.TSImportEqualsDeclaration(node);
|
|
663
|
-
|
|
664
570
|
case 'TSInterfaceDeclaration':
|
|
665
571
|
return Transform.TSInterfaceDeclaration(node);
|
|
666
|
-
|
|
667
572
|
case 'TSModuleDeclaration':
|
|
668
573
|
return Transform.TSModuleDeclaration(node);
|
|
669
|
-
|
|
670
574
|
case 'TSNamespaceExportDeclaration':
|
|
671
575
|
return [];
|
|
672
|
-
|
|
673
576
|
case 'TSTypeAliasDeclaration':
|
|
674
577
|
return Transform.TSTypeAliasDeclaration(node);
|
|
675
|
-
|
|
676
578
|
case 'VariableDeclaration':
|
|
677
579
|
return Transform.VariableDeclaration(node);
|
|
678
|
-
|
|
679
580
|
case 'ExpressionStatement':
|
|
680
581
|
throw translationError(node, 'Unsupported expression statement');
|
|
681
|
-
|
|
682
582
|
case 'WithStatement':
|
|
683
583
|
throw translationError(node, 'Unsupported with statement');
|
|
684
|
-
|
|
685
584
|
case 'BreakStatement':
|
|
686
585
|
case 'ContinueStatement':
|
|
687
586
|
case 'DoWhileStatement':
|
|
@@ -697,36 +596,30 @@ const getTransforms = (originalCode, opts) => {
|
|
|
697
596
|
throw translationError(node, 'Unsupported control flow statement');
|
|
698
597
|
}
|
|
699
598
|
}
|
|
700
|
-
|
|
701
599
|
static Statement(node) {
|
|
702
600
|
return Transform.AllStatement(node);
|
|
703
601
|
}
|
|
704
|
-
|
|
705
602
|
static TSAnyType() {
|
|
706
603
|
return constructFlowNode({
|
|
707
604
|
type: 'AnyTypeAnnotation'
|
|
708
605
|
});
|
|
709
606
|
}
|
|
710
|
-
|
|
711
607
|
static TSArrayType(node) {
|
|
712
608
|
return constructFlowNode({
|
|
713
609
|
type: 'ArrayTypeAnnotation',
|
|
714
610
|
elementType: Transform.TSTypeAnnotation(node.elementType)
|
|
715
611
|
});
|
|
716
612
|
}
|
|
717
|
-
|
|
718
613
|
static TSBigIntType() {
|
|
719
614
|
return constructFlowNode({
|
|
720
615
|
type: 'BigIntTypeAnnotation'
|
|
721
616
|
});
|
|
722
617
|
}
|
|
723
|
-
|
|
724
618
|
static TSBooleanType() {
|
|
725
619
|
return constructFlowNode({
|
|
726
620
|
type: 'BooleanTypeAnnotation'
|
|
727
621
|
});
|
|
728
622
|
}
|
|
729
|
-
|
|
730
623
|
static TSConditionalType(node) {
|
|
731
624
|
return constructFlowNode({
|
|
732
625
|
type: 'ConditionalTypeAnnotation',
|
|
@@ -736,26 +629,20 @@ const getTransforms = (originalCode, opts) => {
|
|
|
736
629
|
falseType: Transform.TSTypeAnnotation(node.falseType)
|
|
737
630
|
});
|
|
738
631
|
}
|
|
739
|
-
|
|
740
632
|
static TSConstructorType(node) {
|
|
741
633
|
return unsupportedAnnotation(node, 'constructor types');
|
|
742
634
|
}
|
|
743
|
-
|
|
744
635
|
static TSDeclareFunction(node) {
|
|
745
636
|
var _node$returnType2;
|
|
746
|
-
|
|
747
637
|
if (node.id == null) {
|
|
748
638
|
throw translationError(node, 'Missing function name');
|
|
749
639
|
}
|
|
750
|
-
|
|
751
640
|
const name = node.id.name;
|
|
752
|
-
|
|
753
641
|
const {
|
|
754
642
|
thisParam,
|
|
755
643
|
restParam,
|
|
756
644
|
params
|
|
757
645
|
} = Transform._partitionAndTranslateTSFunctionParams(node.params);
|
|
758
|
-
|
|
759
646
|
const fnAnnot = constructFlowNode({
|
|
760
647
|
type: 'FunctionTypeAnnotation',
|
|
761
648
|
typeParameters: Transform.TSTypeParameterDeclarationOpt(node.typeParameters),
|
|
@@ -766,26 +653,26 @@ const getTransforms = (originalCode, opts) => {
|
|
|
766
653
|
});
|
|
767
654
|
return constructFlowNode({
|
|
768
655
|
type: 'DeclareFunction',
|
|
769
|
-
id: {
|
|
656
|
+
id: {
|
|
657
|
+
...DUMMY_COMMON,
|
|
770
658
|
type: 'Identifier',
|
|
771
659
|
name,
|
|
772
|
-
typeAnnotation: {
|
|
660
|
+
typeAnnotation: {
|
|
661
|
+
...DUMMY_COMMON,
|
|
773
662
|
type: 'TypeAnnotation',
|
|
774
663
|
typeAnnotation: fnAnnot
|
|
775
664
|
},
|
|
776
665
|
optional: false
|
|
777
666
|
},
|
|
667
|
+
implicitDeclare: false,
|
|
778
668
|
predicate: null
|
|
779
669
|
});
|
|
780
670
|
}
|
|
781
|
-
|
|
782
671
|
static TSEnumDeclaration(node) {
|
|
783
672
|
return unsupportedDeclaration(node, 'enums', node.id);
|
|
784
673
|
}
|
|
785
|
-
|
|
786
674
|
static TSExportAssignment(node) {
|
|
787
675
|
let typeAnnotation;
|
|
788
|
-
|
|
789
676
|
if (node.expression.type === 'Identifier') {
|
|
790
677
|
typeAnnotation = constructFlowNode({
|
|
791
678
|
type: 'TypeofTypeAnnotation',
|
|
@@ -796,7 +683,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
796
683
|
} else {
|
|
797
684
|
throw translationError(node, `Unsupported export assignment expression ${node.expression.type}`);
|
|
798
685
|
}
|
|
799
|
-
|
|
800
686
|
return constructFlowNode({
|
|
801
687
|
type: 'DeclareModuleExports',
|
|
802
688
|
typeAnnotation: constructFlowNode({
|
|
@@ -805,16 +691,13 @@ const getTransforms = (originalCode, opts) => {
|
|
|
805
691
|
})
|
|
806
692
|
});
|
|
807
693
|
}
|
|
808
|
-
|
|
809
694
|
static TSFunctionType(node, allowMissingReturn = false) {
|
|
810
695
|
var _node$returnType3;
|
|
811
|
-
|
|
812
696
|
const {
|
|
813
697
|
thisParam,
|
|
814
698
|
restParam,
|
|
815
699
|
params
|
|
816
700
|
} = Transform._partitionAndTranslateTSFunctionParams(node.params);
|
|
817
|
-
|
|
818
701
|
return constructFlowNode({
|
|
819
702
|
type: 'FunctionTypeAnnotation',
|
|
820
703
|
typeParameters: Transform.TSTypeParameterDeclarationOpt(node.typeParameters),
|
|
@@ -826,16 +709,13 @@ const getTransforms = (originalCode, opts) => {
|
|
|
826
709
|
this: thisParam
|
|
827
710
|
});
|
|
828
711
|
}
|
|
829
|
-
|
|
830
712
|
static _partitionAndTranslateTSFunctionParams(tsParams) {
|
|
831
713
|
const params = [...tsParams];
|
|
832
714
|
const firstParam = params[0];
|
|
833
715
|
let thisParam = null;
|
|
834
716
|
let restParam = null;
|
|
835
|
-
|
|
836
717
|
if (firstParam != null && firstParam.type === 'Identifier' && firstParam.name === 'this') {
|
|
837
718
|
var _firstParam$typeAnnot;
|
|
838
|
-
|
|
839
719
|
thisParam = constructFlowNode({
|
|
840
720
|
type: 'FunctionTypeParam',
|
|
841
721
|
name: constructFlowNode({
|
|
@@ -849,12 +729,9 @@ const getTransforms = (originalCode, opts) => {
|
|
|
849
729
|
});
|
|
850
730
|
params.shift();
|
|
851
731
|
}
|
|
852
|
-
|
|
853
732
|
const lastParam = params[params.length - 1];
|
|
854
|
-
|
|
855
733
|
if (lastParam != null && lastParam.type === 'RestElement') {
|
|
856
734
|
var _lastParam$typeAnnota;
|
|
857
|
-
|
|
858
735
|
restParam = constructFlowNode({
|
|
859
736
|
type: 'FunctionTypeParam',
|
|
860
737
|
name: constructFlowNode({
|
|
@@ -868,14 +745,12 @@ const getTransforms = (originalCode, opts) => {
|
|
|
868
745
|
});
|
|
869
746
|
params.pop();
|
|
870
747
|
}
|
|
871
|
-
|
|
872
748
|
return {
|
|
873
749
|
thisParam,
|
|
874
750
|
restParam,
|
|
875
751
|
params: params.map((param, i) => {
|
|
876
752
|
if (param.type === 'Identifier') {
|
|
877
753
|
var _param$typeAnnotation;
|
|
878
|
-
|
|
879
754
|
return constructFlowNode({
|
|
880
755
|
type: 'FunctionTypeParam',
|
|
881
756
|
name: constructFlowNode({
|
|
@@ -889,7 +764,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
889
764
|
});
|
|
890
765
|
} else if (param.type === 'ArrayPattern' || param.type === 'ObjectPattern') {
|
|
891
766
|
var _param$typeAnnotation2;
|
|
892
|
-
|
|
893
767
|
return constructFlowNode({
|
|
894
768
|
type: 'FunctionTypeParam',
|
|
895
769
|
name: constructFlowNode({
|
|
@@ -907,20 +781,16 @@ const getTransforms = (originalCode, opts) => {
|
|
|
907
781
|
})
|
|
908
782
|
};
|
|
909
783
|
}
|
|
910
|
-
|
|
911
784
|
static TSImportType(node) {
|
|
912
785
|
var _node$argument;
|
|
913
|
-
|
|
914
786
|
const source = (_node$argument = node.argument) != null ? _node$argument : node.source == null ? null : {
|
|
915
787
|
type: 'TSLiteralType',
|
|
916
788
|
loc: node.source.loc,
|
|
917
789
|
literal: node.source
|
|
918
790
|
};
|
|
919
|
-
|
|
920
791
|
if (source == null) {
|
|
921
792
|
return unsupportedAnnotation(node, 'import types without a source');
|
|
922
793
|
}
|
|
923
|
-
|
|
924
794
|
let base = constructFlowNode({
|
|
925
795
|
type: 'GenericTypeAnnotation',
|
|
926
796
|
id: constructFlowNode({
|
|
@@ -934,25 +804,19 @@ const getTransforms = (originalCode, opts) => {
|
|
|
934
804
|
params: [Transform.TSTypeAnnotation(source)]
|
|
935
805
|
})
|
|
936
806
|
});
|
|
937
|
-
|
|
938
807
|
if (node.typeArguments != null) {
|
|
939
808
|
return unsupportedAnnotation(node, 'import types with type arguments');
|
|
940
809
|
}
|
|
941
|
-
|
|
942
810
|
if (node.qualifier == null) {
|
|
943
811
|
return base;
|
|
944
812
|
}
|
|
945
|
-
|
|
946
813
|
let qualifier = Transform.EntityNameToTypeIdentifier(node.qualifier);
|
|
947
814
|
const namesRev = [];
|
|
948
|
-
|
|
949
815
|
while (qualifier.type !== 'Identifier') {
|
|
950
816
|
namesRev.push(qualifier.id.name);
|
|
951
817
|
qualifier = qualifier.qualification;
|
|
952
818
|
}
|
|
953
|
-
|
|
954
819
|
namesRev.push(qualifier.name);
|
|
955
|
-
|
|
956
820
|
while (namesRev.length > 0) {
|
|
957
821
|
const name = namesRev.pop();
|
|
958
822
|
base = constructFlowNode({
|
|
@@ -965,17 +829,13 @@ const getTransforms = (originalCode, opts) => {
|
|
|
965
829
|
})
|
|
966
830
|
});
|
|
967
831
|
}
|
|
968
|
-
|
|
969
832
|
return base;
|
|
970
833
|
}
|
|
971
|
-
|
|
972
834
|
static TSImportEqualsDeclaration(node) {
|
|
973
835
|
if (node.moduleReference.type === 'ThisExpression' || node.moduleReference.type === 'TSQualifiedName') {
|
|
974
836
|
return unsupportedDeclaration(node, 'import equals declaration with weird module reference', node.id);
|
|
975
837
|
}
|
|
976
|
-
|
|
977
838
|
let moduleName;
|
|
978
|
-
|
|
979
839
|
if (node.moduleReference.type === 'TSExternalModuleReference') {
|
|
980
840
|
if (node.moduleReference.expression.type === 'Literal') {
|
|
981
841
|
moduleName = String(node.moduleReference.expression.value);
|
|
@@ -985,7 +845,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
985
845
|
} else {
|
|
986
846
|
moduleName = node.moduleReference.name;
|
|
987
847
|
}
|
|
988
|
-
|
|
989
848
|
return constructFlowNode({
|
|
990
849
|
type: 'VariableDeclaration',
|
|
991
850
|
kind: 'const',
|
|
@@ -1017,7 +876,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1017
876
|
})]
|
|
1018
877
|
});
|
|
1019
878
|
}
|
|
1020
|
-
|
|
1021
879
|
static TSIndexedAccessType(node) {
|
|
1022
880
|
return constructFlowNode({
|
|
1023
881
|
type: 'IndexedAccessType',
|
|
@@ -1025,14 +883,12 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1025
883
|
indexType: Transform.TSTypeAnnotation(node.indexType)
|
|
1026
884
|
});
|
|
1027
885
|
}
|
|
1028
|
-
|
|
1029
886
|
static TSInferType(node) {
|
|
1030
887
|
return constructFlowNode({
|
|
1031
888
|
type: 'InferTypeAnnotation',
|
|
1032
889
|
typeParameter: Transform.TSTypeParameter(node.typeParameter)
|
|
1033
890
|
});
|
|
1034
891
|
}
|
|
1035
|
-
|
|
1036
892
|
static TSInterfaceDeclaration(node) {
|
|
1037
893
|
const body = Transform.TSTypeLiteralOrInterfaceBody(node.body);
|
|
1038
894
|
body.inexact = false;
|
|
@@ -1044,7 +900,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1044
900
|
extends: (node.extends || []).map(e => Transform.TSInterfaceHeritage(e))
|
|
1045
901
|
});
|
|
1046
902
|
}
|
|
1047
|
-
|
|
1048
903
|
static TSInterfaceHeritage(node) {
|
|
1049
904
|
return constructFlowNode({
|
|
1050
905
|
type: 'InterfaceExtends',
|
|
@@ -1052,7 +907,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1052
907
|
typeParameters: Transform.TSTypeParameterInstantiationOpt(node.typeArguments)
|
|
1053
908
|
});
|
|
1054
909
|
}
|
|
1055
|
-
|
|
1056
910
|
static _expressionToIdOrQualifiedTypeId(node, kind) {
|
|
1057
911
|
if (node.type === 'Identifier') {
|
|
1058
912
|
return Transform.Identifier(node);
|
|
@@ -1067,33 +921,26 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1067
921
|
throw unexpectedTranslationError(node, `Expected ${kind} to be an Identifier or Member`);
|
|
1068
922
|
}
|
|
1069
923
|
}
|
|
1070
|
-
|
|
1071
924
|
static TSIntersectionType(node) {
|
|
1072
925
|
return constructFlowNode({
|
|
1073
926
|
type: 'IntersectionTypeAnnotation',
|
|
1074
927
|
types: node.types.map(node => Transform.TSTypeAnnotation(node))
|
|
1075
928
|
});
|
|
1076
929
|
}
|
|
1077
|
-
|
|
1078
930
|
static TSLiteralType(node) {
|
|
1079
931
|
switch (node.literal.type) {
|
|
1080
932
|
case 'TemplateLiteral':
|
|
1081
933
|
return unsupportedAnnotation(node, 'template literals');
|
|
1082
|
-
|
|
1083
934
|
case 'Literal':
|
|
1084
935
|
return Transform.LiteralType(node.literal);
|
|
1085
|
-
|
|
1086
936
|
case 'UnaryExpression':
|
|
1087
937
|
return unsupportedAnnotation(node, 'UnaryExpression literal type');
|
|
1088
|
-
|
|
1089
938
|
case 'UpdateExpression':
|
|
1090
939
|
return unsupportedAnnotation(node, 'UpdateExpression literal type');
|
|
1091
940
|
}
|
|
1092
941
|
}
|
|
1093
|
-
|
|
1094
942
|
static TSMappedType(node) {
|
|
1095
943
|
var _keyTparam$bound;
|
|
1096
|
-
|
|
1097
944
|
const keyTparam = Transform.TSTypeParameter(node.typeParameter);
|
|
1098
945
|
const sourceType = (_keyTparam$bound = keyTparam.bound) == null ? void 0 : _keyTparam$bound.typeAnnotation;
|
|
1099
946
|
keyTparam.bound = null;
|
|
@@ -1118,10 +965,8 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1118
965
|
inexact: false
|
|
1119
966
|
});
|
|
1120
967
|
}
|
|
1121
|
-
|
|
1122
968
|
static TSModuleDeclaration(node) {
|
|
1123
969
|
var _node$global;
|
|
1124
|
-
|
|
1125
970
|
const body = node.body == null ? constructFlowNode({
|
|
1126
971
|
type: 'BlockStatement',
|
|
1127
972
|
body: []
|
|
@@ -1131,7 +976,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1131
976
|
type: 'BlockStatement',
|
|
1132
977
|
body: node.body.body.flatMap(s => Transform.Statement(s))
|
|
1133
978
|
});
|
|
1134
|
-
|
|
1135
979
|
if (node.id.type === 'Literal') {
|
|
1136
980
|
return constructFlowNode({
|
|
1137
981
|
type: 'DeclareModule',
|
|
@@ -1139,22 +983,21 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1139
983
|
body
|
|
1140
984
|
});
|
|
1141
985
|
}
|
|
1142
|
-
|
|
1143
986
|
if ((_node$global = node.global) != null ? _node$global : false) {
|
|
1144
987
|
return unsupportedDeclaration(node, 'global declaration', node.id);
|
|
1145
988
|
}
|
|
1146
|
-
|
|
1147
989
|
return constructFlowNode({
|
|
1148
990
|
type: 'DeclareNamespace',
|
|
991
|
+
global: false,
|
|
1149
992
|
id: Transform.Identifier(node.id),
|
|
1150
|
-
body
|
|
993
|
+
body,
|
|
994
|
+
implicitDeclare: false,
|
|
995
|
+
keyword: 'namespace'
|
|
1151
996
|
});
|
|
1152
997
|
}
|
|
1153
|
-
|
|
1154
998
|
static TSNamedTupleMember(node) {
|
|
1155
999
|
let optional = false;
|
|
1156
1000
|
let elementType;
|
|
1157
|
-
|
|
1158
1001
|
if (node.elementType.type === 'TSRestType') {
|
|
1159
1002
|
const child = node.elementType;
|
|
1160
1003
|
return constructFlowNode({
|
|
@@ -1170,7 +1013,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1170
1013
|
} else {
|
|
1171
1014
|
elementType = Transform.TSTypeAnnotation(node.elementType);
|
|
1172
1015
|
}
|
|
1173
|
-
|
|
1174
1016
|
return constructFlowNode({
|
|
1175
1017
|
type: 'TupleTypeLabeledElement',
|
|
1176
1018
|
label: Transform.Identifier(node.label),
|
|
@@ -1179,25 +1021,21 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1179
1021
|
variance: null
|
|
1180
1022
|
});
|
|
1181
1023
|
}
|
|
1182
|
-
|
|
1183
1024
|
static TSNeverType() {
|
|
1184
1025
|
return constructFlowNode({
|
|
1185
1026
|
type: 'EmptyTypeAnnotation'
|
|
1186
1027
|
});
|
|
1187
1028
|
}
|
|
1188
|
-
|
|
1189
1029
|
static TSNullType() {
|
|
1190
1030
|
return constructFlowNode({
|
|
1191
1031
|
type: 'NullLiteralTypeAnnotation'
|
|
1192
1032
|
});
|
|
1193
1033
|
}
|
|
1194
|
-
|
|
1195
1034
|
static TSNumberType() {
|
|
1196
1035
|
return constructFlowNode({
|
|
1197
1036
|
type: 'NumberTypeAnnotation'
|
|
1198
1037
|
});
|
|
1199
1038
|
}
|
|
1200
|
-
|
|
1201
1039
|
static TSObjectType() {
|
|
1202
1040
|
return constructFlowNode({
|
|
1203
1041
|
type: 'InterfaceTypeAnnotation',
|
|
@@ -1213,7 +1051,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1213
1051
|
extends: []
|
|
1214
1052
|
});
|
|
1215
1053
|
}
|
|
1216
|
-
|
|
1217
1054
|
static TSQualifiedNameToQualifiedTypeIdentifier(node) {
|
|
1218
1055
|
return constructFlowNode({
|
|
1219
1056
|
type: 'QualifiedTypeIdentifier',
|
|
@@ -1221,7 +1058,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1221
1058
|
id: Transform.Identifier(node.right)
|
|
1222
1059
|
});
|
|
1223
1060
|
}
|
|
1224
|
-
|
|
1225
1061
|
static TSQualifiedNameToQualifiedTypeofIdentifier(node) {
|
|
1226
1062
|
return constructFlowNode({
|
|
1227
1063
|
type: 'QualifiedTypeofIdentifier',
|
|
@@ -1229,23 +1065,19 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1229
1065
|
id: Transform.Identifier(node.right)
|
|
1230
1066
|
});
|
|
1231
1067
|
}
|
|
1232
|
-
|
|
1233
1068
|
static TSStringType() {
|
|
1234
1069
|
return constructFlowNode({
|
|
1235
1070
|
type: 'StringTypeAnnotation'
|
|
1236
1071
|
});
|
|
1237
1072
|
}
|
|
1238
|
-
|
|
1239
1073
|
static TSSymbolType() {
|
|
1240
1074
|
return constructFlowNode({
|
|
1241
1075
|
type: 'SymbolTypeAnnotation'
|
|
1242
1076
|
});
|
|
1243
1077
|
}
|
|
1244
|
-
|
|
1245
1078
|
static TSTemplateLiteralType(node) {
|
|
1246
1079
|
return unsupportedAnnotation(node, 'constructor types');
|
|
1247
1080
|
}
|
|
1248
|
-
|
|
1249
1081
|
static TSThisType(_node) {
|
|
1250
1082
|
return constructFlowNode({
|
|
1251
1083
|
type: 'GenericTypeAnnotation',
|
|
@@ -1258,7 +1090,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1258
1090
|
typeParameters: null
|
|
1259
1091
|
});
|
|
1260
1092
|
}
|
|
1261
|
-
|
|
1262
1093
|
static TSTupleType(node) {
|
|
1263
1094
|
return constructFlowNode({
|
|
1264
1095
|
type: 'TupleTypeAnnotation',
|
|
@@ -1266,7 +1097,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1266
1097
|
inexact: false
|
|
1267
1098
|
});
|
|
1268
1099
|
}
|
|
1269
|
-
|
|
1270
1100
|
static TSTypeAliasDeclaration(node) {
|
|
1271
1101
|
return constructFlowNode({
|
|
1272
1102
|
type: 'TypeAlias',
|
|
@@ -1275,14 +1105,12 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1275
1105
|
right: Transform.TSTypeAnnotation(node.typeAnnotation)
|
|
1276
1106
|
});
|
|
1277
1107
|
}
|
|
1278
|
-
|
|
1279
1108
|
static TSTypeAnnotation(node) {
|
|
1280
1109
|
switch (node.type) {
|
|
1281
1110
|
case 'TSOptionalType':
|
|
1282
1111
|
case 'TSQualifiedName':
|
|
1283
1112
|
case 'TSRestType':
|
|
1284
1113
|
return unsupportedAnnotation(node, 'unexpected toplevel ' + node.type);
|
|
1285
|
-
|
|
1286
1114
|
case 'TSAbstractKeyword':
|
|
1287
1115
|
case 'TSAsyncKeyword':
|
|
1288
1116
|
case 'TSDeclareKeyword':
|
|
@@ -1293,140 +1121,100 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1293
1121
|
case 'TSReadonlyKeyword':
|
|
1294
1122
|
case 'TSStaticKeyword':
|
|
1295
1123
|
return unsupportedAnnotation(node, 'wat keyword ' + node.type);
|
|
1296
|
-
|
|
1297
1124
|
case 'TSAnyKeyword':
|
|
1298
1125
|
return Transform.TSAnyType();
|
|
1299
|
-
|
|
1300
1126
|
case 'TSArrayType':
|
|
1301
1127
|
return Transform.TSArrayType(node);
|
|
1302
|
-
|
|
1303
1128
|
case 'TSBigIntKeyword':
|
|
1304
1129
|
return Transform.TSBigIntType();
|
|
1305
|
-
|
|
1306
1130
|
case 'TSBooleanKeyword':
|
|
1307
1131
|
return Transform.TSBooleanType();
|
|
1308
|
-
|
|
1309
1132
|
case 'TSConditionalType':
|
|
1310
1133
|
return Transform.TSConditionalType(node);
|
|
1311
|
-
|
|
1312
1134
|
case 'TSConstructorType':
|
|
1313
1135
|
return Transform.TSConstructorType(node);
|
|
1314
|
-
|
|
1315
1136
|
case 'TSFunctionType':
|
|
1316
1137
|
return Transform.TSFunctionType(node);
|
|
1317
|
-
|
|
1318
1138
|
case 'TSImportType':
|
|
1319
1139
|
return Transform.TSImportType(node);
|
|
1320
|
-
|
|
1321
1140
|
case 'TSIndexedAccessType':
|
|
1322
1141
|
return Transform.TSIndexedAccessType(node);
|
|
1323
|
-
|
|
1324
1142
|
case 'TSInferType':
|
|
1325
1143
|
return Transform.TSInferType(node);
|
|
1326
|
-
|
|
1327
1144
|
case 'TSIntersectionType':
|
|
1328
1145
|
return Transform.TSIntersectionType(node);
|
|
1329
|
-
|
|
1330
1146
|
case 'TSIntrinsicKeyword':
|
|
1331
1147
|
return unsupportedAnnotation(node, 'intrinsic keyword');
|
|
1332
|
-
|
|
1333
1148
|
case 'TSLiteralType':
|
|
1334
1149
|
return Transform.TSLiteralType(node);
|
|
1335
|
-
|
|
1336
1150
|
case 'TSMappedType':
|
|
1337
1151
|
return Transform.TSMappedType(node);
|
|
1338
|
-
|
|
1339
1152
|
case 'TSNamedTupleMember':
|
|
1340
1153
|
return Transform.TSNamedTupleMember(node);
|
|
1341
|
-
|
|
1342
1154
|
case 'TSNeverKeyword':
|
|
1343
1155
|
return Transform.TSNeverType();
|
|
1344
|
-
|
|
1345
1156
|
case 'TSNullKeyword':
|
|
1346
1157
|
return Transform.TSNullType();
|
|
1347
|
-
|
|
1348
1158
|
case 'TSNumberKeyword':
|
|
1349
1159
|
return Transform.TSNumberType();
|
|
1350
|
-
|
|
1351
1160
|
case 'TSObjectKeyword':
|
|
1352
1161
|
return Transform.TSObjectType();
|
|
1353
|
-
|
|
1354
1162
|
case 'TSStringKeyword':
|
|
1355
1163
|
return Transform.TSStringType();
|
|
1356
|
-
|
|
1357
1164
|
case 'TSSymbolKeyword':
|
|
1358
1165
|
return Transform.TSSymbolType();
|
|
1359
|
-
|
|
1360
1166
|
case 'TSTemplateLiteralType':
|
|
1361
1167
|
return Transform.TSTemplateLiteralType(node);
|
|
1362
|
-
|
|
1363
1168
|
case 'TSThisType':
|
|
1364
1169
|
return Transform.TSThisType(node);
|
|
1365
|
-
|
|
1366
1170
|
case 'TSTupleType':
|
|
1367
1171
|
return Transform.TSTupleType(node);
|
|
1368
|
-
|
|
1369
1172
|
case 'TSTypeLiteral':
|
|
1370
1173
|
return Transform.TSTypeLiteralOrInterfaceBody(node);
|
|
1371
|
-
|
|
1372
1174
|
case 'TSTypeOperator':
|
|
1373
1175
|
return Transform.TSTypeOperator(node);
|
|
1374
|
-
|
|
1375
1176
|
case 'TSTypePredicate':
|
|
1376
1177
|
return Transform.TSTypePredicate(node);
|
|
1377
|
-
|
|
1378
1178
|
case 'TSTypeQuery':
|
|
1379
1179
|
return Transform.TSTypeQuery(node);
|
|
1380
|
-
|
|
1381
1180
|
case 'TSTypeReference':
|
|
1382
1181
|
return Transform.TSTypeReference(node);
|
|
1383
|
-
|
|
1384
1182
|
case 'TSUndefinedKeyword':
|
|
1385
1183
|
case 'TSVoidKeyword':
|
|
1386
1184
|
return Transform.TSUndefinedOrVoidType();
|
|
1387
|
-
|
|
1388
1185
|
case 'TSUnionType':
|
|
1389
1186
|
return Transform.TSUnionType(node);
|
|
1390
|
-
|
|
1391
1187
|
case 'TSUnknownKeyword':
|
|
1392
1188
|
return Transform.TSUnknownType();
|
|
1393
1189
|
}
|
|
1394
1190
|
}
|
|
1395
|
-
|
|
1396
1191
|
static TSTypeAnnotationOpt(node) {
|
|
1397
1192
|
return node == null ? constructFlowNode({
|
|
1398
1193
|
type: 'AnyTypeAnnotation'
|
|
1399
1194
|
}) : Transform.TSTypeAnnotation(node);
|
|
1400
1195
|
}
|
|
1401
|
-
|
|
1402
1196
|
static TSTypeAnnotationNode(node) {
|
|
1403
1197
|
return constructFlowNode({
|
|
1404
1198
|
type: 'TypeAnnotation',
|
|
1405
1199
|
typeAnnotation: Transform.TSTypeAnnotation(node.typeAnnotation)
|
|
1406
1200
|
});
|
|
1407
1201
|
}
|
|
1408
|
-
|
|
1409
1202
|
static TSTypeLiteralOrInterfaceBody(node) {
|
|
1410
1203
|
const properties = [];
|
|
1411
1204
|
const indexers = [];
|
|
1412
1205
|
const callProperties = [];
|
|
1413
|
-
|
|
1414
1206
|
for (const prop of node.type === 'TSTypeLiteral' ? node.members : node.body) {
|
|
1415
1207
|
switch (prop.type) {
|
|
1416
1208
|
case 'TSPropertySignature':
|
|
1417
1209
|
{
|
|
1418
1210
|
Transform._translateIntoObjectProp(prop, properties, indexers);
|
|
1419
|
-
|
|
1420
1211
|
break;
|
|
1421
1212
|
}
|
|
1422
|
-
|
|
1423
1213
|
case 'TSMethodSignature':
|
|
1424
1214
|
{
|
|
1425
1215
|
Transform._translateIntoObjectMethod(prop, properties);
|
|
1426
|
-
|
|
1427
1216
|
break;
|
|
1428
1217
|
}
|
|
1429
|
-
|
|
1430
1218
|
case 'TSCallSignatureDeclaration':
|
|
1431
1219
|
callProperties.push(constructFlowNode({
|
|
1432
1220
|
type: 'ObjectTypeCallProperty',
|
|
@@ -1444,11 +1232,9 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1444
1232
|
})
|
|
1445
1233
|
}));
|
|
1446
1234
|
break;
|
|
1447
|
-
|
|
1448
1235
|
case 'TSIndexSignature':
|
|
1449
1236
|
{
|
|
1450
1237
|
var _prop$typeAnnotation;
|
|
1451
|
-
|
|
1452
1238
|
const variance = Boolean(prop.readonly) ? constructFlowNode({
|
|
1453
1239
|
type: 'Variance',
|
|
1454
1240
|
kind: 'plus'
|
|
@@ -1469,7 +1255,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1469
1255
|
}));
|
|
1470
1256
|
break;
|
|
1471
1257
|
}
|
|
1472
|
-
|
|
1473
1258
|
case 'TSConstructSignatureDeclaration':
|
|
1474
1259
|
properties.push(constructFlowNode({
|
|
1475
1260
|
type: 'ObjectTypeProperty',
|
|
@@ -1496,7 +1281,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1496
1281
|
break;
|
|
1497
1282
|
}
|
|
1498
1283
|
}
|
|
1499
|
-
|
|
1500
1284
|
return constructFlowNode({
|
|
1501
1285
|
type: 'ObjectTypeAnnotation',
|
|
1502
1286
|
properties,
|
|
@@ -1507,16 +1291,13 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1507
1291
|
inexact: true
|
|
1508
1292
|
});
|
|
1509
1293
|
}
|
|
1510
|
-
|
|
1511
1294
|
static _translateIntoObjectProp(prop, properties, indexers) {
|
|
1512
1295
|
const variance = Boolean(prop.readonly) ? constructFlowNode({
|
|
1513
1296
|
type: 'Variance',
|
|
1514
1297
|
kind: 'plus'
|
|
1515
1298
|
}) : null;
|
|
1516
|
-
|
|
1517
1299
|
if (prop.computed === false) {
|
|
1518
1300
|
var _prop$typeAnnotation2;
|
|
1519
|
-
|
|
1520
1301
|
const key = prop.key;
|
|
1521
1302
|
properties.push(constructFlowNode({
|
|
1522
1303
|
type: 'ObjectTypeProperty',
|
|
@@ -1539,7 +1320,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1539
1320
|
}));
|
|
1540
1321
|
} else {
|
|
1541
1322
|
var _prop$typeAnnotation3;
|
|
1542
|
-
|
|
1543
1323
|
indexers.push(constructFlowNode({
|
|
1544
1324
|
type: 'ObjectTypeIndexer',
|
|
1545
1325
|
kind: 'init',
|
|
@@ -1556,12 +1336,10 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1556
1336
|
}));
|
|
1557
1337
|
}
|
|
1558
1338
|
}
|
|
1559
|
-
|
|
1560
1339
|
static _translateIntoObjectMethod(prop, properties) {
|
|
1561
1340
|
if (prop.computed === true) {
|
|
1562
1341
|
throw translationError(prop, 'computed method signature');
|
|
1563
1342
|
}
|
|
1564
|
-
|
|
1565
1343
|
const originalKey = prop.key;
|
|
1566
1344
|
const key = originalKey.type === 'Identifier' ? Transform.Identifier(originalKey, false) : originalKey.type === 'PrivateIdentifier' ? constructFlowNode({
|
|
1567
1345
|
type: 'PrivateIdentifier',
|
|
@@ -1579,7 +1357,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1579
1357
|
returnType: prop.type === 'MethodDefinition' || prop.type === 'TSAbstractMethodDefinition' ? prop.value.returnType : prop.returnType,
|
|
1580
1358
|
typeParameters: prop.typeParameters
|
|
1581
1359
|
}, true);
|
|
1582
|
-
|
|
1583
1360
|
if (prop.kind === 'method' || prop.kind === 'constructor') {
|
|
1584
1361
|
properties.push(constructFlowNode({
|
|
1585
1362
|
type: 'ObjectTypeProperty',
|
|
@@ -1606,22 +1383,18 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1606
1383
|
}));
|
|
1607
1384
|
}
|
|
1608
1385
|
}
|
|
1609
|
-
|
|
1610
1386
|
static TSTypeOperator(node) {
|
|
1611
1387
|
switch (node.operator) {
|
|
1612
1388
|
case 'unique':
|
|
1613
1389
|
return unsupportedAnnotation(node, 'unique operator');
|
|
1614
|
-
|
|
1615
1390
|
case 'keyof':
|
|
1616
1391
|
return constructFlowNode({
|
|
1617
1392
|
type: 'KeyofTypeAnnotation',
|
|
1618
1393
|
argument: Transform.TSTypeAnnotationOpt(node.typeAnnotation)
|
|
1619
1394
|
});
|
|
1620
|
-
|
|
1621
1395
|
case 'readonly':
|
|
1622
1396
|
{
|
|
1623
1397
|
const child = node.typeAnnotation;
|
|
1624
|
-
|
|
1625
1398
|
switch (child == null ? void 0 : child.type) {
|
|
1626
1399
|
case 'TSArrayType':
|
|
1627
1400
|
return constructFlowNode({
|
|
@@ -1637,7 +1410,6 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1637
1410
|
params: [Transform.TSTypeAnnotation(child.elementType)]
|
|
1638
1411
|
})
|
|
1639
1412
|
});
|
|
1640
|
-
|
|
1641
1413
|
case 'TSTupleType':
|
|
1642
1414
|
return constructFlowNode({
|
|
1643
1415
|
type: 'GenericTypeAnnotation',
|
|
@@ -1652,14 +1424,12 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1652
1424
|
params: [Transform.TSTypeAnnotation(child)]
|
|
1653
1425
|
})
|
|
1654
1426
|
});
|
|
1655
|
-
|
|
1656
1427
|
default:
|
|
1657
1428
|
return unsupportedAnnotation(node, 'readonly operator with inner type: ' + ((child == null ? void 0 : child.type) || 'null'));
|
|
1658
1429
|
}
|
|
1659
1430
|
}
|
|
1660
1431
|
}
|
|
1661
1432
|
}
|
|
1662
|
-
|
|
1663
1433
|
static TSTypeParameter(node) {
|
|
1664
1434
|
return constructFlowNode({
|
|
1665
1435
|
type: 'TypeParameter',
|
|
@@ -1677,29 +1447,24 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1677
1447
|
})
|
|
1678
1448
|
});
|
|
1679
1449
|
}
|
|
1680
|
-
|
|
1681
1450
|
static TSTypeParameterDeclaration(node) {
|
|
1682
1451
|
return constructFlowNode({
|
|
1683
1452
|
type: 'TypeParameterDeclaration',
|
|
1684
1453
|
params: node.params.map(node => Transform.TSTypeParameter(node))
|
|
1685
1454
|
});
|
|
1686
1455
|
}
|
|
1687
|
-
|
|
1688
1456
|
static TSTypeParameterDeclarationOpt(node) {
|
|
1689
1457
|
return node != null ? Transform.TSTypeParameterDeclaration(node) : null;
|
|
1690
1458
|
}
|
|
1691
|
-
|
|
1692
1459
|
static TSTypeParameterInstantiation(node) {
|
|
1693
1460
|
return constructFlowNode({
|
|
1694
1461
|
type: 'TypeParameterInstantiation',
|
|
1695
1462
|
params: node.params.map(node => Transform.TSTypeAnnotation(node))
|
|
1696
1463
|
});
|
|
1697
1464
|
}
|
|
1698
|
-
|
|
1699
1465
|
static TSTypeParameterInstantiationOpt(node) {
|
|
1700
1466
|
return node != null ? Transform.TSTypeParameterInstantiation(node) : null;
|
|
1701
1467
|
}
|
|
1702
|
-
|
|
1703
1468
|
static TSTypePredicate(node) {
|
|
1704
1469
|
return constructFlowNode({
|
|
1705
1470
|
type: 'TypePredicate',
|
|
@@ -1713,25 +1478,20 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1713
1478
|
typeAnnotation: node.typeAnnotation == null ? null : Transform.TSTypeAnnotation(node.typeAnnotation.typeAnnotation)
|
|
1714
1479
|
});
|
|
1715
1480
|
}
|
|
1716
|
-
|
|
1717
1481
|
static TSTypeQuery(node) {
|
|
1718
1482
|
var _Transform$TSTypePara;
|
|
1719
|
-
|
|
1720
1483
|
if (node.exprName.type === 'TSImportType') {
|
|
1721
1484
|
if (node.typeArguments != null) {
|
|
1722
1485
|
return unsupportedAnnotation(node, 'type query imports with type arguments');
|
|
1723
1486
|
}
|
|
1724
|
-
|
|
1725
1487
|
return Transform.TSImportType(node.exprName);
|
|
1726
1488
|
}
|
|
1727
|
-
|
|
1728
1489
|
return constructFlowNode({
|
|
1729
1490
|
type: 'TypeofTypeAnnotation',
|
|
1730
1491
|
argument: Transform.EntityNameToTypeofIdentifier(node.exprName),
|
|
1731
1492
|
typeArguments: (_Transform$TSTypePara = Transform.TSTypeParameterInstantiationOpt(node.typeArguments)) != null ? _Transform$TSTypePara : undefined
|
|
1732
1493
|
});
|
|
1733
1494
|
}
|
|
1734
|
-
|
|
1735
1495
|
static TSTypeReference(node) {
|
|
1736
1496
|
return constructFlowNode({
|
|
1737
1497
|
type: 'GenericTypeAnnotation',
|
|
@@ -1739,34 +1499,28 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1739
1499
|
typeParameters: Transform.TSTypeParameterInstantiationOpt(node.typeArguments)
|
|
1740
1500
|
});
|
|
1741
1501
|
}
|
|
1742
|
-
|
|
1743
1502
|
static TSUndefinedOrVoidType() {
|
|
1744
1503
|
return constructFlowNode({
|
|
1745
1504
|
type: 'VoidTypeAnnotation'
|
|
1746
1505
|
});
|
|
1747
1506
|
}
|
|
1748
|
-
|
|
1749
1507
|
static TSUnionType(node) {
|
|
1750
1508
|
return constructFlowNode({
|
|
1751
1509
|
type: 'UnionTypeAnnotation',
|
|
1752
1510
|
types: node.types.map(node => Transform.TSTypeAnnotation(node))
|
|
1753
1511
|
});
|
|
1754
1512
|
}
|
|
1755
|
-
|
|
1756
1513
|
static TSUnknownType() {
|
|
1757
1514
|
return constructFlowNode({
|
|
1758
1515
|
type: 'MixedTypeAnnotation'
|
|
1759
1516
|
});
|
|
1760
1517
|
}
|
|
1761
|
-
|
|
1762
1518
|
static VariableDeclaration(node) {
|
|
1763
1519
|
return node.declarations.map(decl => {
|
|
1764
1520
|
if (decl.id.type !== 'Identifier') {
|
|
1765
1521
|
throw translationError(decl.id, 'Non-identifier variable declaration');
|
|
1766
1522
|
}
|
|
1767
|
-
|
|
1768
1523
|
const id = Transform.Identifier(decl.id);
|
|
1769
|
-
|
|
1770
1524
|
if (id.typeAnnotation == null) {
|
|
1771
1525
|
id.typeAnnotation = constructFlowNode({
|
|
1772
1526
|
type: 'TypeAnnotation',
|
|
@@ -1775,16 +1529,18 @@ const getTransforms = (originalCode, opts) => {
|
|
|
1775
1529
|
})
|
|
1776
1530
|
});
|
|
1777
1531
|
}
|
|
1778
|
-
|
|
1779
1532
|
return constructFlowNode({
|
|
1780
1533
|
type: 'DeclareVariable',
|
|
1781
|
-
|
|
1782
|
-
|
|
1534
|
+
declarations: [constructFlowNode({
|
|
1535
|
+
type: 'VariableDeclarator',
|
|
1536
|
+
id,
|
|
1537
|
+
init: null
|
|
1538
|
+
})],
|
|
1539
|
+
kind: node.kind,
|
|
1540
|
+
implicitDeclare: false
|
|
1783
1541
|
});
|
|
1784
1542
|
});
|
|
1785
1543
|
}
|
|
1786
|
-
|
|
1787
1544
|
}
|
|
1788
|
-
|
|
1789
1545
|
return [Transform, code];
|
|
1790
1546
|
};
|