@react-native/codegen 0.72.3 → 0.72.4
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/lib/CodegenSchema.d.ts +10 -10
- package/lib/CodegenSchema.js.flow +6 -1
- package/lib/SchemaValidator.d.ts +1 -1
- package/lib/generators/RNCodegen.d.ts +98 -0
- package/lib/generators/RNCodegen.js +33 -4
- package/lib/generators/RNCodegen.js.flow +35 -4
- package/lib/generators/components/ComponentsGeneratorUtils.js +2 -0
- package/lib/generators/components/ComponentsGeneratorUtils.js.flow +2 -0
- package/lib/generators/components/CppHelpers.js +2 -0
- package/lib/generators/components/CppHelpers.js.flow +2 -0
- package/lib/generators/components/GeneratePropsH.js +2 -0
- package/lib/generators/components/GeneratePropsH.js.flow +2 -0
- package/lib/generators/components/GeneratePropsJavaDelegate.js +2 -0
- package/lib/generators/components/GeneratePropsJavaDelegate.js.flow +2 -0
- package/lib/generators/components/GeneratePropsJavaInterface.js +2 -0
- package/lib/generators/components/GeneratePropsJavaInterface.js.flow +2 -0
- package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js.flow +3 -1
- package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js +5 -0
- package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js.flow +6 -0
- package/lib/generators/components/GenerateViewConfigJs.js +1 -0
- package/lib/generators/components/GenerateViewConfigJs.js.flow +1 -0
- package/lib/generators/components/JavaHelpers.js +7 -0
- package/lib/generators/components/JavaHelpers.js.flow +8 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js +29 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js.flow +30 -0
- package/lib/parsers/error-utils.js +9 -15
- package/lib/parsers/error-utils.js.flow +12 -15
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +5 -1
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +5 -1
- package/lib/parsers/flow/components/componentsUtils.js +4 -0
- package/lib/parsers/flow/components/componentsUtils.js.flow +4 -0
- package/lib/parsers/flow/components/index.js +18 -113
- package/lib/parsers/flow/components/index.js.flow +15 -46
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js +4 -4
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js.flow +4 -4
- package/lib/parsers/flow/modules/index.js +41 -307
- package/lib/parsers/flow/modules/index.js.flow +18 -233
- package/lib/parsers/flow/parser.js +68 -12
- package/lib/parsers/flow/parser.js.flow +67 -3
- package/lib/parsers/parser.d.ts +2 -2
- package/lib/parsers/parser.js.flow +65 -3
- package/lib/parsers/parserMock.js +44 -0
- package/lib/parsers/parserMock.js.flow +52 -1
- package/lib/parsers/parsers-commons.js +361 -4
- package/lib/parsers/parsers-commons.js.flow +341 -4
- package/lib/parsers/parsers-primitives.js +119 -3
- package/lib/parsers/parsers-primitives.js.flow +128 -3
- package/lib/parsers/schema/index.d.ts +1 -1
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +5 -1
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +5 -1
- package/lib/parsers/typescript/components/componentsUtils.js +8 -0
- package/lib/parsers/typescript/components/componentsUtils.js.flow +8 -0
- package/lib/parsers/typescript/components/index.js +20 -115
- package/lib/parsers/typescript/components/index.js.flow +17 -48
- package/lib/parsers/typescript/modules/index.js +103 -421
- package/lib/parsers/typescript/modules/index.js.flow +84 -285
- package/lib/parsers/typescript/parser.js +69 -12
- package/lib/parsers/typescript/parser.js.flow +68 -3
- package/lib/parsers/utils.js +4 -0
- package/lib/parsers/utils.js.flow +3 -0
- package/package.json +1 -1
- package/lib/parsers/flow/Visitor.js +0 -37
- package/lib/parsers/flow/Visitor.js.flow +0 -41
- package/lib/parsers/flow/components/options.js +0 -72
- package/lib/parsers/flow/components/options.js.flow +0 -87
- package/lib/parsers/typescript/Visitor.js +0 -42
- package/lib/parsers/typescript/Visitor.js.flow +0 -47
- package/lib/parsers/typescript/components/options.js +0 -72
- package/lib/parsers/typescript/components/options.js.flow +0 -87
|
@@ -10,68 +10,6 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
function ownKeys(object, enumerableOnly) {
|
|
14
|
-
var keys = Object.keys(object);
|
|
15
|
-
if (Object.getOwnPropertySymbols) {
|
|
16
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
17
|
-
enumerableOnly &&
|
|
18
|
-
(symbols = symbols.filter(function (sym) {
|
|
19
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
20
|
-
})),
|
|
21
|
-
keys.push.apply(keys, symbols);
|
|
22
|
-
}
|
|
23
|
-
return keys;
|
|
24
|
-
}
|
|
25
|
-
function _objectSpread(target) {
|
|
26
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
27
|
-
var source = null != arguments[i] ? arguments[i] : {};
|
|
28
|
-
i % 2
|
|
29
|
-
? ownKeys(Object(source), !0).forEach(function (key) {
|
|
30
|
-
_defineProperty(target, key, source[key]);
|
|
31
|
-
})
|
|
32
|
-
: Object.getOwnPropertyDescriptors
|
|
33
|
-
? Object.defineProperties(
|
|
34
|
-
target,
|
|
35
|
-
Object.getOwnPropertyDescriptors(source),
|
|
36
|
-
)
|
|
37
|
-
: ownKeys(Object(source)).forEach(function (key) {
|
|
38
|
-
Object.defineProperty(
|
|
39
|
-
target,
|
|
40
|
-
key,
|
|
41
|
-
Object.getOwnPropertyDescriptor(source, key),
|
|
42
|
-
);
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
return target;
|
|
46
|
-
}
|
|
47
|
-
function _defineProperty(obj, key, value) {
|
|
48
|
-
key = _toPropertyKey(key);
|
|
49
|
-
if (key in obj) {
|
|
50
|
-
Object.defineProperty(obj, key, {
|
|
51
|
-
value: value,
|
|
52
|
-
enumerable: true,
|
|
53
|
-
configurable: true,
|
|
54
|
-
writable: true,
|
|
55
|
-
});
|
|
56
|
-
} else {
|
|
57
|
-
obj[key] = value;
|
|
58
|
-
}
|
|
59
|
-
return obj;
|
|
60
|
-
}
|
|
61
|
-
function _toPropertyKey(arg) {
|
|
62
|
-
var key = _toPrimitive(arg, 'string');
|
|
63
|
-
return typeof key === 'symbol' ? key : String(key);
|
|
64
|
-
}
|
|
65
|
-
function _toPrimitive(input, hint) {
|
|
66
|
-
if (typeof input !== 'object' || input === null) return input;
|
|
67
|
-
var prim = input[Symbol.toPrimitive];
|
|
68
|
-
if (prim !== undefined) {
|
|
69
|
-
var res = prim.call(input, hint || 'default');
|
|
70
|
-
if (typeof res !== 'object') return res;
|
|
71
|
-
throw new TypeError('@@toPrimitive must return a primitive value.');
|
|
72
|
-
}
|
|
73
|
-
return (hint === 'string' ? String : Number)(input);
|
|
74
|
-
}
|
|
75
13
|
function _slicedToArray(arr, i) {
|
|
76
14
|
return (
|
|
77
15
|
_arrayWithHoles(arr) ||
|
|
@@ -140,62 +78,33 @@ function _iterableToArrayLimit(arr, i) {
|
|
|
140
78
|
function _arrayWithHoles(arr) {
|
|
141
79
|
if (Array.isArray(arr)) return arr;
|
|
142
80
|
}
|
|
143
|
-
const _require = require('
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
resolveTypeAnnotation = _require2.resolveTypeAnnotation;
|
|
149
|
-
const _require3 = require('../../parsers-commons'),
|
|
150
|
-
unwrapNullable = _require3.unwrapNullable,
|
|
151
|
-
wrapNullable = _require3.wrapNullable,
|
|
81
|
+
const _require = require('../utils'),
|
|
82
|
+
resolveTypeAnnotation = _require.resolveTypeAnnotation;
|
|
83
|
+
const _require2 = require('../../parsers-commons'),
|
|
84
|
+
unwrapNullable = _require2.unwrapNullable,
|
|
85
|
+
wrapNullable = _require2.wrapNullable,
|
|
152
86
|
assertGenericTypeAnnotationHasExactlyOneTypeParameter =
|
|
153
|
-
|
|
154
|
-
parseObjectProperty =
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
emitMixed = _require4.emitMixed,
|
|
172
|
-
emitUnion = _require4.emitUnion,
|
|
173
|
-
typeAliasResolution = _require4.typeAliasResolution,
|
|
174
|
-
typeEnumResolution = _require4.typeEnumResolution;
|
|
175
|
-
const _require5 = require('../../errors'),
|
|
87
|
+
_require2.assertGenericTypeAnnotationHasExactlyOneTypeParameter,
|
|
88
|
+
parseObjectProperty = _require2.parseObjectProperty;
|
|
89
|
+
const _require3 = require('../../parsers-primitives'),
|
|
90
|
+
emitArrayType = _require3.emitArrayType,
|
|
91
|
+
emitBoolean = _require3.emitBoolean,
|
|
92
|
+
emitFunction = _require3.emitFunction,
|
|
93
|
+
emitNumber = _require3.emitNumber,
|
|
94
|
+
emitGenericObject = _require3.emitGenericObject,
|
|
95
|
+
emitPromise = _require3.emitPromise,
|
|
96
|
+
emitRootTag = _require3.emitRootTag,
|
|
97
|
+
emitVoid = _require3.emitVoid,
|
|
98
|
+
emitString = _require3.emitString,
|
|
99
|
+
emitMixed = _require3.emitMixed,
|
|
100
|
+
emitUnion = _require3.emitUnion,
|
|
101
|
+
emitCommonTypes = _require3.emitCommonTypes,
|
|
102
|
+
typeAliasResolution = _require3.typeAliasResolution,
|
|
103
|
+
typeEnumResolution = _require3.typeEnumResolution;
|
|
104
|
+
const _require4 = require('../../errors'),
|
|
176
105
|
UnsupportedTypeAnnotationParserError =
|
|
177
|
-
|
|
178
|
-
UnsupportedGenericParserError =
|
|
179
|
-
const _require6 = require('../../error-utils'),
|
|
180
|
-
throwIfModuleInterfaceNotFound = _require6.throwIfModuleInterfaceNotFound,
|
|
181
|
-
throwIfModuleInterfaceIsMisnamed = _require6.throwIfModuleInterfaceIsMisnamed,
|
|
182
|
-
throwIfUnusedModuleInterfaceParserError =
|
|
183
|
-
_require6.throwIfUnusedModuleInterfaceParserError,
|
|
184
|
-
throwIfWrongNumberOfCallExpressionArgs =
|
|
185
|
-
_require6.throwIfWrongNumberOfCallExpressionArgs,
|
|
186
|
-
throwIfMoreThanOneModuleRegistryCalls =
|
|
187
|
-
_require6.throwIfMoreThanOneModuleRegistryCalls,
|
|
188
|
-
throwIfIncorrectModuleRegistryCallTypeParameterParserError =
|
|
189
|
-
_require6.throwIfIncorrectModuleRegistryCallTypeParameterParserError,
|
|
190
|
-
throwIfIncorrectModuleRegistryCallArgument =
|
|
191
|
-
_require6.throwIfIncorrectModuleRegistryCallArgument,
|
|
192
|
-
throwIfUntypedModule = _require6.throwIfUntypedModule,
|
|
193
|
-
throwIfMoreThanOneModuleInterfaceParserError =
|
|
194
|
-
_require6.throwIfMoreThanOneModuleInterfaceParserError,
|
|
195
|
-
throwIfPartialNotAnnotatingTypeParameter =
|
|
196
|
-
_require6.throwIfPartialNotAnnotatingTypeParameter,
|
|
197
|
-
throwIfPartialWithMoreParameter = _require6.throwIfPartialWithMoreParameter;
|
|
198
|
-
const language = 'Flow';
|
|
106
|
+
_require4.UnsupportedTypeAnnotationParserError,
|
|
107
|
+
UnsupportedGenericParserError = _require4.UnsupportedGenericParserError;
|
|
199
108
|
function translateTypeAnnotation(
|
|
200
109
|
hasteModuleName,
|
|
201
110
|
/**
|
|
@@ -273,57 +182,26 @@ function translateTypeAnnotation(
|
|
|
273
182
|
isParamNullable = _unwrapNullable2[1];
|
|
274
183
|
return wrapNullable(nullable || isParamNullable, paramType);
|
|
275
184
|
}
|
|
276
|
-
case 'Stringish': {
|
|
277
|
-
return emitStringish(nullable);
|
|
278
|
-
}
|
|
279
|
-
case 'Int32': {
|
|
280
|
-
return emitInt32(nullable);
|
|
281
|
-
}
|
|
282
|
-
case 'Double': {
|
|
283
|
-
return emitDouble(nullable);
|
|
284
|
-
}
|
|
285
|
-
case 'Float': {
|
|
286
|
-
return emitFloat(nullable);
|
|
287
|
-
}
|
|
288
|
-
case 'UnsafeObject':
|
|
289
|
-
case 'Object': {
|
|
290
|
-
return emitGenericObject(nullable);
|
|
291
|
-
}
|
|
292
|
-
case '$Partial': {
|
|
293
|
-
throwIfPartialWithMoreParameter(typeAnnotation);
|
|
294
|
-
const annotatedElement = parser.extractAnnotatedElement(
|
|
295
|
-
typeAnnotation,
|
|
296
|
-
types,
|
|
297
|
-
);
|
|
298
|
-
throwIfPartialNotAnnotatingTypeParameter(
|
|
299
|
-
typeAnnotation,
|
|
300
|
-
types,
|
|
301
|
-
parser,
|
|
302
|
-
);
|
|
303
|
-
const properties = annotatedElement.right.properties.map(prop => {
|
|
304
|
-
return {
|
|
305
|
-
name: prop.key.name,
|
|
306
|
-
optional: true,
|
|
307
|
-
typeAnnotation: translateTypeAnnotation(
|
|
308
|
-
hasteModuleName,
|
|
309
|
-
prop.value,
|
|
310
|
-
types,
|
|
311
|
-
aliasMap,
|
|
312
|
-
enumMap,
|
|
313
|
-
tryParse,
|
|
314
|
-
cxxOnly,
|
|
315
|
-
parser,
|
|
316
|
-
),
|
|
317
|
-
};
|
|
318
|
-
});
|
|
319
|
-
return emitObject(nullable, properties);
|
|
320
|
-
}
|
|
321
185
|
default: {
|
|
322
|
-
|
|
186
|
+
const commonType = emitCommonTypes(
|
|
323
187
|
hasteModuleName,
|
|
188
|
+
types,
|
|
324
189
|
typeAnnotation,
|
|
190
|
+
aliasMap,
|
|
191
|
+
enumMap,
|
|
192
|
+
tryParse,
|
|
193
|
+
cxxOnly,
|
|
194
|
+
nullable,
|
|
325
195
|
parser,
|
|
326
196
|
);
|
|
197
|
+
if (!commonType) {
|
|
198
|
+
throw new UnsupportedGenericParserError(
|
|
199
|
+
hasteModuleName,
|
|
200
|
+
typeAnnotation,
|
|
201
|
+
parser,
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
return commonType;
|
|
327
205
|
}
|
|
328
206
|
}
|
|
329
207
|
}
|
|
@@ -430,7 +308,6 @@ function translateTypeAnnotation(
|
|
|
430
308
|
typeResolutionStatus,
|
|
431
309
|
nullable,
|
|
432
310
|
hasteModuleName,
|
|
433
|
-
language,
|
|
434
311
|
enumMap,
|
|
435
312
|
parser,
|
|
436
313
|
);
|
|
@@ -439,154 +316,11 @@ function translateTypeAnnotation(
|
|
|
439
316
|
throw new UnsupportedTypeAnnotationParserError(
|
|
440
317
|
hasteModuleName,
|
|
441
318
|
typeAnnotation,
|
|
442
|
-
language,
|
|
319
|
+
parser.language(),
|
|
443
320
|
);
|
|
444
321
|
}
|
|
445
322
|
}
|
|
446
323
|
}
|
|
447
|
-
function buildModuleSchema(
|
|
448
|
-
hasteModuleName,
|
|
449
|
-
/**
|
|
450
|
-
* TODO(T71778680): Flow-type this node.
|
|
451
|
-
*/
|
|
452
|
-
ast,
|
|
453
|
-
tryParse,
|
|
454
|
-
parser,
|
|
455
|
-
) {
|
|
456
|
-
const types = parser.getTypes(ast);
|
|
457
|
-
const moduleSpecs = Object.values(types).filter(t =>
|
|
458
|
-
parser.isModuleInterface(t),
|
|
459
|
-
);
|
|
460
|
-
throwIfModuleInterfaceNotFound(
|
|
461
|
-
moduleSpecs.length,
|
|
462
|
-
hasteModuleName,
|
|
463
|
-
ast,
|
|
464
|
-
language,
|
|
465
|
-
);
|
|
466
|
-
throwIfMoreThanOneModuleInterfaceParserError(
|
|
467
|
-
hasteModuleName,
|
|
468
|
-
moduleSpecs,
|
|
469
|
-
language,
|
|
470
|
-
);
|
|
471
|
-
const _moduleSpecs = _slicedToArray(moduleSpecs, 1),
|
|
472
|
-
moduleSpec = _moduleSpecs[0];
|
|
473
|
-
throwIfModuleInterfaceIsMisnamed(hasteModuleName, moduleSpec.id, language);
|
|
474
|
-
|
|
475
|
-
// Parse Module Name
|
|
476
|
-
const moduleName = (() => {
|
|
477
|
-
const callExpressions = [];
|
|
478
|
-
visit(ast, {
|
|
479
|
-
CallExpression(node) {
|
|
480
|
-
if (isModuleRegistryCall(node)) {
|
|
481
|
-
callExpressions.push(node);
|
|
482
|
-
}
|
|
483
|
-
},
|
|
484
|
-
});
|
|
485
|
-
throwIfUnusedModuleInterfaceParserError(
|
|
486
|
-
hasteModuleName,
|
|
487
|
-
moduleSpec,
|
|
488
|
-
callExpressions,
|
|
489
|
-
);
|
|
490
|
-
throwIfMoreThanOneModuleRegistryCalls(
|
|
491
|
-
hasteModuleName,
|
|
492
|
-
callExpressions,
|
|
493
|
-
callExpressions.length,
|
|
494
|
-
);
|
|
495
|
-
const callExpression = callExpressions[0];
|
|
496
|
-
const typeArguments = callExpression.typeArguments;
|
|
497
|
-
const methodName = callExpression.callee.property.name;
|
|
498
|
-
throwIfWrongNumberOfCallExpressionArgs(
|
|
499
|
-
hasteModuleName,
|
|
500
|
-
callExpression,
|
|
501
|
-
methodName,
|
|
502
|
-
callExpression.arguments.length,
|
|
503
|
-
);
|
|
504
|
-
throwIfIncorrectModuleRegistryCallArgument(
|
|
505
|
-
hasteModuleName,
|
|
506
|
-
callExpression.arguments[0],
|
|
507
|
-
methodName,
|
|
508
|
-
);
|
|
509
|
-
const $moduleName = callExpression.arguments[0].value;
|
|
510
|
-
throwIfUntypedModule(
|
|
511
|
-
typeArguments,
|
|
512
|
-
hasteModuleName,
|
|
513
|
-
callExpression,
|
|
514
|
-
methodName,
|
|
515
|
-
$moduleName,
|
|
516
|
-
);
|
|
517
|
-
throwIfIncorrectModuleRegistryCallTypeParameterParserError(
|
|
518
|
-
hasteModuleName,
|
|
519
|
-
typeArguments,
|
|
520
|
-
methodName,
|
|
521
|
-
$moduleName,
|
|
522
|
-
parser,
|
|
523
|
-
);
|
|
524
|
-
return $moduleName;
|
|
525
|
-
})();
|
|
526
|
-
|
|
527
|
-
// Some module names use platform suffix to indicate platform-exclusive modules.
|
|
528
|
-
// Eventually this should be made explicit in the Flow type itself.
|
|
529
|
-
// Also check the hasteModuleName for platform suffix.
|
|
530
|
-
// Note: this shape is consistent with ComponentSchema.
|
|
531
|
-
const _verifyPlatforms = verifyPlatforms(hasteModuleName, moduleName),
|
|
532
|
-
cxxOnly = _verifyPlatforms.cxxOnly,
|
|
533
|
-
excludedPlatforms = _verifyPlatforms.excludedPlatforms;
|
|
534
|
-
|
|
535
|
-
// $FlowFixMe[missing-type-arg]
|
|
536
|
-
return moduleSpec.body.properties
|
|
537
|
-
.filter(property => property.type === 'ObjectTypeProperty')
|
|
538
|
-
.map(property => {
|
|
539
|
-
const aliasMap = {};
|
|
540
|
-
const enumMap = {};
|
|
541
|
-
return tryParse(() => ({
|
|
542
|
-
aliasMap: aliasMap,
|
|
543
|
-
enumMap: enumMap,
|
|
544
|
-
propertyShape: buildPropertySchema(
|
|
545
|
-
hasteModuleName,
|
|
546
|
-
property,
|
|
547
|
-
types,
|
|
548
|
-
aliasMap,
|
|
549
|
-
enumMap,
|
|
550
|
-
tryParse,
|
|
551
|
-
cxxOnly,
|
|
552
|
-
resolveTypeAnnotation,
|
|
553
|
-
translateTypeAnnotation,
|
|
554
|
-
parser,
|
|
555
|
-
),
|
|
556
|
-
}));
|
|
557
|
-
})
|
|
558
|
-
.filter(Boolean)
|
|
559
|
-
.reduce(
|
|
560
|
-
(moduleSchema, {aliasMap, enumMap, propertyShape}) => ({
|
|
561
|
-
type: 'NativeModule',
|
|
562
|
-
aliasMap: _objectSpread(
|
|
563
|
-
_objectSpread({}, moduleSchema.aliasMap),
|
|
564
|
-
aliasMap,
|
|
565
|
-
),
|
|
566
|
-
enumMap: _objectSpread(
|
|
567
|
-
_objectSpread({}, moduleSchema.enumMap),
|
|
568
|
-
enumMap,
|
|
569
|
-
),
|
|
570
|
-
spec: {
|
|
571
|
-
properties: [...moduleSchema.spec.properties, propertyShape],
|
|
572
|
-
},
|
|
573
|
-
moduleName: moduleSchema.moduleName,
|
|
574
|
-
excludedPlatforms: moduleSchema.excludedPlatforms,
|
|
575
|
-
}),
|
|
576
|
-
{
|
|
577
|
-
type: 'NativeModule',
|
|
578
|
-
aliasMap: {},
|
|
579
|
-
enumMap: {},
|
|
580
|
-
spec: {
|
|
581
|
-
properties: [],
|
|
582
|
-
},
|
|
583
|
-
moduleName,
|
|
584
|
-
excludedPlatforms:
|
|
585
|
-
excludedPlatforms.length !== 0 ? [...excludedPlatforms] : undefined,
|
|
586
|
-
},
|
|
587
|
-
);
|
|
588
|
-
}
|
|
589
324
|
module.exports = {
|
|
590
|
-
buildModuleSchema,
|
|
591
325
|
flowTranslateTypeAnnotation: translateTypeAnnotation,
|
|
592
326
|
};
|
|
@@ -16,40 +16,32 @@ import type {
|
|
|
16
16
|
NativeModuleEnumMap,
|
|
17
17
|
NativeModuleBaseTypeAnnotation,
|
|
18
18
|
NativeModuleTypeAnnotation,
|
|
19
|
-
NativeModulePropertyShape,
|
|
20
|
-
NativeModuleSchema,
|
|
21
19
|
Nullable,
|
|
22
20
|
} from '../../../CodegenSchema';
|
|
23
21
|
|
|
24
22
|
import type {Parser} from '../../parser';
|
|
25
23
|
import type {ParserErrorCapturer, TypeDeclarationMap} from '../../utils';
|
|
26
24
|
|
|
27
|
-
const {visit, isModuleRegistryCall, verifyPlatforms} = require('../../utils');
|
|
28
25
|
const {resolveTypeAnnotation} = require('../utils');
|
|
29
26
|
const {
|
|
30
27
|
unwrapNullable,
|
|
31
28
|
wrapNullable,
|
|
32
29
|
assertGenericTypeAnnotationHasExactlyOneTypeParameter,
|
|
33
30
|
parseObjectProperty,
|
|
34
|
-
buildPropertySchema,
|
|
35
31
|
} = require('../../parsers-commons');
|
|
36
32
|
const {
|
|
37
33
|
emitArrayType,
|
|
38
34
|
emitBoolean,
|
|
39
|
-
emitDouble,
|
|
40
|
-
emitFloat,
|
|
41
35
|
emitFunction,
|
|
42
36
|
emitNumber,
|
|
43
|
-
emitInt32,
|
|
44
37
|
emitGenericObject,
|
|
45
|
-
emitObject,
|
|
46
38
|
emitPromise,
|
|
47
39
|
emitRootTag,
|
|
48
40
|
emitVoid,
|
|
49
41
|
emitString,
|
|
50
|
-
emitStringish,
|
|
51
42
|
emitMixed,
|
|
52
43
|
emitUnion,
|
|
44
|
+
emitCommonTypes,
|
|
53
45
|
typeAliasResolution,
|
|
54
46
|
typeEnumResolution,
|
|
55
47
|
} = require('../../parsers-primitives');
|
|
@@ -59,22 +51,6 @@ const {
|
|
|
59
51
|
UnsupportedGenericParserError,
|
|
60
52
|
} = require('../../errors');
|
|
61
53
|
|
|
62
|
-
const {
|
|
63
|
-
throwIfModuleInterfaceNotFound,
|
|
64
|
-
throwIfModuleInterfaceIsMisnamed,
|
|
65
|
-
throwIfUnusedModuleInterfaceParserError,
|
|
66
|
-
throwIfWrongNumberOfCallExpressionArgs,
|
|
67
|
-
throwIfMoreThanOneModuleRegistryCalls,
|
|
68
|
-
throwIfIncorrectModuleRegistryCallTypeParameterParserError,
|
|
69
|
-
throwIfIncorrectModuleRegistryCallArgument,
|
|
70
|
-
throwIfUntypedModule,
|
|
71
|
-
throwIfMoreThanOneModuleInterfaceParserError,
|
|
72
|
-
throwIfPartialNotAnnotatingTypeParameter,
|
|
73
|
-
throwIfPartialWithMoreParameter,
|
|
74
|
-
} = require('../../error-utils');
|
|
75
|
-
|
|
76
|
-
const language = 'Flow';
|
|
77
|
-
|
|
78
54
|
function translateTypeAnnotation(
|
|
79
55
|
hasteModuleName: string,
|
|
80
56
|
/**
|
|
@@ -147,61 +123,27 @@ function translateTypeAnnotation(
|
|
|
147
123
|
|
|
148
124
|
return wrapNullable(nullable || isParamNullable, paramType);
|
|
149
125
|
}
|
|
150
|
-
case 'Stringish': {
|
|
151
|
-
return emitStringish(nullable);
|
|
152
|
-
}
|
|
153
|
-
case 'Int32': {
|
|
154
|
-
return emitInt32(nullable);
|
|
155
|
-
}
|
|
156
|
-
case 'Double': {
|
|
157
|
-
return emitDouble(nullable);
|
|
158
|
-
}
|
|
159
|
-
case 'Float': {
|
|
160
|
-
return emitFloat(nullable);
|
|
161
|
-
}
|
|
162
|
-
case 'UnsafeObject':
|
|
163
|
-
case 'Object': {
|
|
164
|
-
return emitGenericObject(nullable);
|
|
165
|
-
}
|
|
166
|
-
case '$Partial': {
|
|
167
|
-
throwIfPartialWithMoreParameter(typeAnnotation);
|
|
168
|
-
|
|
169
|
-
const annotatedElement = parser.extractAnnotatedElement(
|
|
170
|
-
typeAnnotation,
|
|
171
|
-
types,
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
throwIfPartialNotAnnotatingTypeParameter(
|
|
175
|
-
typeAnnotation,
|
|
176
|
-
types,
|
|
177
|
-
parser,
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
const properties = annotatedElement.right.properties.map(prop => {
|
|
181
|
-
return {
|
|
182
|
-
name: prop.key.name,
|
|
183
|
-
optional: true,
|
|
184
|
-
typeAnnotation: translateTypeAnnotation(
|
|
185
|
-
hasteModuleName,
|
|
186
|
-
prop.value,
|
|
187
|
-
types,
|
|
188
|
-
aliasMap,
|
|
189
|
-
enumMap,
|
|
190
|
-
tryParse,
|
|
191
|
-
cxxOnly,
|
|
192
|
-
parser,
|
|
193
|
-
),
|
|
194
|
-
};
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
return emitObject(nullable, properties);
|
|
198
|
-
}
|
|
199
126
|
default: {
|
|
200
|
-
|
|
127
|
+
const commonType = emitCommonTypes(
|
|
201
128
|
hasteModuleName,
|
|
129
|
+
types,
|
|
202
130
|
typeAnnotation,
|
|
131
|
+
aliasMap,
|
|
132
|
+
enumMap,
|
|
133
|
+
tryParse,
|
|
134
|
+
cxxOnly,
|
|
135
|
+
nullable,
|
|
203
136
|
parser,
|
|
204
137
|
);
|
|
138
|
+
|
|
139
|
+
if (!commonType) {
|
|
140
|
+
throw new UnsupportedGenericParserError(
|
|
141
|
+
hasteModuleName,
|
|
142
|
+
typeAnnotation,
|
|
143
|
+
parser,
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
return commonType;
|
|
205
147
|
}
|
|
206
148
|
}
|
|
207
149
|
}
|
|
@@ -315,7 +257,6 @@ function translateTypeAnnotation(
|
|
|
315
257
|
typeResolutionStatus,
|
|
316
258
|
nullable,
|
|
317
259
|
hasteModuleName,
|
|
318
|
-
language,
|
|
319
260
|
enumMap,
|
|
320
261
|
parser,
|
|
321
262
|
);
|
|
@@ -324,168 +265,12 @@ function translateTypeAnnotation(
|
|
|
324
265
|
throw new UnsupportedTypeAnnotationParserError(
|
|
325
266
|
hasteModuleName,
|
|
326
267
|
typeAnnotation,
|
|
327
|
-
language,
|
|
268
|
+
parser.language(),
|
|
328
269
|
);
|
|
329
270
|
}
|
|
330
271
|
}
|
|
331
272
|
}
|
|
332
273
|
|
|
333
|
-
function buildModuleSchema(
|
|
334
|
-
hasteModuleName: string,
|
|
335
|
-
/**
|
|
336
|
-
* TODO(T71778680): Flow-type this node.
|
|
337
|
-
*/
|
|
338
|
-
ast: $FlowFixMe,
|
|
339
|
-
tryParse: ParserErrorCapturer,
|
|
340
|
-
parser: Parser,
|
|
341
|
-
): NativeModuleSchema {
|
|
342
|
-
const types = parser.getTypes(ast);
|
|
343
|
-
const moduleSpecs = (Object.values(types): $ReadOnlyArray<$FlowFixMe>).filter(
|
|
344
|
-
t => parser.isModuleInterface(t),
|
|
345
|
-
);
|
|
346
|
-
|
|
347
|
-
throwIfModuleInterfaceNotFound(
|
|
348
|
-
moduleSpecs.length,
|
|
349
|
-
hasteModuleName,
|
|
350
|
-
ast,
|
|
351
|
-
language,
|
|
352
|
-
);
|
|
353
|
-
|
|
354
|
-
throwIfMoreThanOneModuleInterfaceParserError(
|
|
355
|
-
hasteModuleName,
|
|
356
|
-
moduleSpecs,
|
|
357
|
-
language,
|
|
358
|
-
);
|
|
359
|
-
|
|
360
|
-
const [moduleSpec] = moduleSpecs;
|
|
361
|
-
|
|
362
|
-
throwIfModuleInterfaceIsMisnamed(hasteModuleName, moduleSpec.id, language);
|
|
363
|
-
|
|
364
|
-
// Parse Module Name
|
|
365
|
-
const moduleName = ((): string => {
|
|
366
|
-
const callExpressions = [];
|
|
367
|
-
visit(ast, {
|
|
368
|
-
CallExpression(node) {
|
|
369
|
-
if (isModuleRegistryCall(node)) {
|
|
370
|
-
callExpressions.push(node);
|
|
371
|
-
}
|
|
372
|
-
},
|
|
373
|
-
});
|
|
374
|
-
|
|
375
|
-
throwIfUnusedModuleInterfaceParserError(
|
|
376
|
-
hasteModuleName,
|
|
377
|
-
moduleSpec,
|
|
378
|
-
callExpressions,
|
|
379
|
-
);
|
|
380
|
-
|
|
381
|
-
throwIfMoreThanOneModuleRegistryCalls(
|
|
382
|
-
hasteModuleName,
|
|
383
|
-
callExpressions,
|
|
384
|
-
callExpressions.length,
|
|
385
|
-
);
|
|
386
|
-
|
|
387
|
-
const [callExpression] = callExpressions;
|
|
388
|
-
const {typeArguments} = callExpression;
|
|
389
|
-
const methodName = callExpression.callee.property.name;
|
|
390
|
-
|
|
391
|
-
throwIfWrongNumberOfCallExpressionArgs(
|
|
392
|
-
hasteModuleName,
|
|
393
|
-
callExpression,
|
|
394
|
-
methodName,
|
|
395
|
-
callExpression.arguments.length,
|
|
396
|
-
);
|
|
397
|
-
|
|
398
|
-
throwIfIncorrectModuleRegistryCallArgument(
|
|
399
|
-
hasteModuleName,
|
|
400
|
-
callExpression.arguments[0],
|
|
401
|
-
methodName,
|
|
402
|
-
);
|
|
403
|
-
|
|
404
|
-
const $moduleName = callExpression.arguments[0].value;
|
|
405
|
-
|
|
406
|
-
throwIfUntypedModule(
|
|
407
|
-
typeArguments,
|
|
408
|
-
hasteModuleName,
|
|
409
|
-
callExpression,
|
|
410
|
-
methodName,
|
|
411
|
-
$moduleName,
|
|
412
|
-
);
|
|
413
|
-
|
|
414
|
-
throwIfIncorrectModuleRegistryCallTypeParameterParserError(
|
|
415
|
-
hasteModuleName,
|
|
416
|
-
typeArguments,
|
|
417
|
-
methodName,
|
|
418
|
-
$moduleName,
|
|
419
|
-
parser,
|
|
420
|
-
);
|
|
421
|
-
|
|
422
|
-
return $moduleName;
|
|
423
|
-
})();
|
|
424
|
-
|
|
425
|
-
// Some module names use platform suffix to indicate platform-exclusive modules.
|
|
426
|
-
// Eventually this should be made explicit in the Flow type itself.
|
|
427
|
-
// Also check the hasteModuleName for platform suffix.
|
|
428
|
-
// Note: this shape is consistent with ComponentSchema.
|
|
429
|
-
const {cxxOnly, excludedPlatforms} = verifyPlatforms(
|
|
430
|
-
hasteModuleName,
|
|
431
|
-
moduleName,
|
|
432
|
-
);
|
|
433
|
-
|
|
434
|
-
// $FlowFixMe[missing-type-arg]
|
|
435
|
-
return (moduleSpec.body.properties: $ReadOnlyArray<$FlowFixMe>)
|
|
436
|
-
.filter(property => property.type === 'ObjectTypeProperty')
|
|
437
|
-
.map<?{
|
|
438
|
-
aliasMap: NativeModuleAliasMap,
|
|
439
|
-
enumMap: NativeModuleEnumMap,
|
|
440
|
-
propertyShape: NativeModulePropertyShape,
|
|
441
|
-
}>(property => {
|
|
442
|
-
const aliasMap: {...NativeModuleAliasMap} = {};
|
|
443
|
-
const enumMap: {...NativeModuleEnumMap} = {};
|
|
444
|
-
return tryParse(() => ({
|
|
445
|
-
aliasMap: aliasMap,
|
|
446
|
-
enumMap: enumMap,
|
|
447
|
-
propertyShape: buildPropertySchema(
|
|
448
|
-
hasteModuleName,
|
|
449
|
-
property,
|
|
450
|
-
types,
|
|
451
|
-
aliasMap,
|
|
452
|
-
enumMap,
|
|
453
|
-
tryParse,
|
|
454
|
-
cxxOnly,
|
|
455
|
-
resolveTypeAnnotation,
|
|
456
|
-
translateTypeAnnotation,
|
|
457
|
-
parser,
|
|
458
|
-
),
|
|
459
|
-
}));
|
|
460
|
-
})
|
|
461
|
-
.filter(Boolean)
|
|
462
|
-
.reduce(
|
|
463
|
-
(
|
|
464
|
-
moduleSchema: NativeModuleSchema,
|
|
465
|
-
{aliasMap, enumMap, propertyShape},
|
|
466
|
-
) => ({
|
|
467
|
-
type: 'NativeModule',
|
|
468
|
-
aliasMap: {...moduleSchema.aliasMap, ...aliasMap},
|
|
469
|
-
enumMap: {...moduleSchema.enumMap, ...enumMap},
|
|
470
|
-
spec: {
|
|
471
|
-
properties: [...moduleSchema.spec.properties, propertyShape],
|
|
472
|
-
},
|
|
473
|
-
moduleName: moduleSchema.moduleName,
|
|
474
|
-
excludedPlatforms: moduleSchema.excludedPlatforms,
|
|
475
|
-
}),
|
|
476
|
-
{
|
|
477
|
-
type: 'NativeModule',
|
|
478
|
-
aliasMap: {},
|
|
479
|
-
enumMap: {},
|
|
480
|
-
spec: {properties: []},
|
|
481
|
-
moduleName,
|
|
482
|
-
excludedPlatforms:
|
|
483
|
-
excludedPlatforms.length !== 0 ? [...excludedPlatforms] : undefined,
|
|
484
|
-
},
|
|
485
|
-
);
|
|
486
|
-
}
|
|
487
|
-
|
|
488
274
|
module.exports = {
|
|
489
|
-
buildModuleSchema,
|
|
490
275
|
flowTranslateTypeAnnotation: translateTypeAnnotation,
|
|
491
276
|
};
|