@react-native/codegen 0.72.2 → 0.72.3
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/parsers/error-utils.js +41 -0
- package/lib/parsers/error-utils.js.flow +45 -0
- package/lib/parsers/flow/components/index.js +16 -20
- package/lib/parsers/flow/components/index.js.flow +7 -6
- package/lib/parsers/flow/modules/index.js +26 -36
- package/lib/parsers/flow/modules/index.js.flow +21 -34
- package/lib/parsers/flow/parser.js +52 -1
- package/lib/parsers/flow/parser.js.flow +58 -1
- package/lib/parsers/flow/utils.js +0 -38
- package/lib/parsers/flow/utils.js.flow +0 -38
- package/lib/parsers/parser.js.flow +22 -0
- package/lib/parsers/parserMock.js +14 -0
- package/lib/parsers/parserMock.js.flow +21 -0
- package/lib/parsers/parsers-commons.js +1 -1
- package/lib/parsers/parsers-commons.js.flow +10 -4
- package/lib/parsers/{flow/components/schema.js.flow → schema.js.flow} +2 -2
- package/lib/parsers/typescript/components/index.js +15 -19
- package/lib/parsers/typescript/components/index.js.flow +7 -6
- package/lib/parsers/typescript/modules/index.js +27 -40
- package/lib/parsers/typescript/modules/index.js.flow +21 -34
- package/lib/parsers/typescript/parser.js +45 -1
- package/lib/parsers/typescript/parser.js.flow +48 -1
- package/lib/parsers/typescript/utils.js +0 -31
- package/lib/parsers/typescript/utils.js.flow +0 -31
- package/package.json +1 -1
- package/lib/parsers/flow/components/schema.js +0 -106
- package/lib/parsers/typescript/components/schema.js.flow +0 -62
- /package/lib/parsers/{typescript/components/schema.js → schema.js} +0 -0
|
@@ -24,6 +24,8 @@ const _require = require('./errors'),
|
|
|
24
24
|
_require.IncorrectModuleRegistryCallArityParserError,
|
|
25
25
|
IncorrectModuleRegistryCallTypeParameterParserError =
|
|
26
26
|
_require.IncorrectModuleRegistryCallTypeParameterParserError,
|
|
27
|
+
IncorrectModuleRegistryCallArgumentTypeParserError =
|
|
28
|
+
_require.IncorrectModuleRegistryCallArgumentTypeParserError,
|
|
27
29
|
UnsupportedObjectPropertyValueTypeAnnotationParserError =
|
|
28
30
|
_require.UnsupportedObjectPropertyValueTypeAnnotationParserError,
|
|
29
31
|
UntypedModuleRegistryCallParserError =
|
|
@@ -249,6 +251,42 @@ function throwIfArrayElementTypeAnnotationIsUnsupported(
|
|
|
249
251
|
);
|
|
250
252
|
}
|
|
251
253
|
}
|
|
254
|
+
function throwIfIncorrectModuleRegistryCallArgument(
|
|
255
|
+
nativeModuleName,
|
|
256
|
+
callExpressionArg,
|
|
257
|
+
methodName,
|
|
258
|
+
) {
|
|
259
|
+
if (
|
|
260
|
+
callExpressionArg.type !== 'StringLiteral' &&
|
|
261
|
+
callExpressionArg.type !== 'Literal'
|
|
262
|
+
) {
|
|
263
|
+
const type = callExpressionArg.type;
|
|
264
|
+
throw new IncorrectModuleRegistryCallArgumentTypeParserError(
|
|
265
|
+
nativeModuleName,
|
|
266
|
+
callExpressionArg,
|
|
267
|
+
methodName,
|
|
268
|
+
type,
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function throwIfPartialNotAnnotatingTypeParameter(
|
|
273
|
+
typeAnnotation,
|
|
274
|
+
types,
|
|
275
|
+
parser,
|
|
276
|
+
) {
|
|
277
|
+
const annotatedElement = parser.extractAnnotatedElement(
|
|
278
|
+
typeAnnotation,
|
|
279
|
+
types,
|
|
280
|
+
);
|
|
281
|
+
if (!annotatedElement) {
|
|
282
|
+
throw new Error('Partials only support annotating a type parameter.');
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
function throwIfPartialWithMoreParameter(typeAnnotation) {
|
|
286
|
+
if (typeAnnotation.typeParameters.params.length !== 1) {
|
|
287
|
+
throw new Error('Partials only support annotating exactly one parameter.');
|
|
288
|
+
}
|
|
289
|
+
}
|
|
252
290
|
module.exports = {
|
|
253
291
|
throwIfModuleInterfaceIsMisnamed,
|
|
254
292
|
throwIfUnsupportedFunctionReturnTypeAnnotationParserError,
|
|
@@ -263,4 +301,7 @@ module.exports = {
|
|
|
263
301
|
throwIfMoreThanOneModuleInterfaceParserError,
|
|
264
302
|
throwIfUnsupportedFunctionParamTypeAnnotationParserError,
|
|
265
303
|
throwIfArrayElementTypeAnnotationIsUnsupported,
|
|
304
|
+
throwIfIncorrectModuleRegistryCallArgument,
|
|
305
|
+
throwIfPartialNotAnnotatingTypeParameter,
|
|
306
|
+
throwIfPartialWithMoreParameter,
|
|
266
307
|
};
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import type {NativeModuleTypeAnnotation} from '../CodegenSchema';
|
|
14
14
|
import type {ParserType} from './errors';
|
|
15
15
|
import type {Parser} from './parser';
|
|
16
|
+
import type {TypeDeclarationMap} from '../parsers/utils';
|
|
16
17
|
|
|
17
18
|
const {
|
|
18
19
|
MisnamedModuleInterfaceParserError,
|
|
@@ -22,6 +23,7 @@ const {
|
|
|
22
23
|
UnusedModuleInterfaceParserError,
|
|
23
24
|
IncorrectModuleRegistryCallArityParserError,
|
|
24
25
|
IncorrectModuleRegistryCallTypeParameterParserError,
|
|
26
|
+
IncorrectModuleRegistryCallArgumentTypeParserError,
|
|
25
27
|
UnsupportedObjectPropertyValueTypeAnnotationParserError,
|
|
26
28
|
UntypedModuleRegistryCallParserError,
|
|
27
29
|
UnsupportedModulePropertyParserError,
|
|
@@ -260,6 +262,46 @@ function throwIfArrayElementTypeAnnotationIsUnsupported(
|
|
|
260
262
|
}
|
|
261
263
|
}
|
|
262
264
|
|
|
265
|
+
function throwIfIncorrectModuleRegistryCallArgument(
|
|
266
|
+
nativeModuleName: string,
|
|
267
|
+
callExpressionArg: $FlowFixMe,
|
|
268
|
+
methodName: string,
|
|
269
|
+
) {
|
|
270
|
+
if (
|
|
271
|
+
callExpressionArg.type !== 'StringLiteral' &&
|
|
272
|
+
callExpressionArg.type !== 'Literal'
|
|
273
|
+
) {
|
|
274
|
+
const {type} = callExpressionArg;
|
|
275
|
+
throw new IncorrectModuleRegistryCallArgumentTypeParserError(
|
|
276
|
+
nativeModuleName,
|
|
277
|
+
callExpressionArg,
|
|
278
|
+
methodName,
|
|
279
|
+
type,
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function throwIfPartialNotAnnotatingTypeParameter(
|
|
285
|
+
typeAnnotation: $FlowFixMe,
|
|
286
|
+
types: TypeDeclarationMap,
|
|
287
|
+
parser: Parser,
|
|
288
|
+
) {
|
|
289
|
+
const annotatedElement = parser.extractAnnotatedElement(
|
|
290
|
+
typeAnnotation,
|
|
291
|
+
types,
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
if (!annotatedElement) {
|
|
295
|
+
throw new Error('Partials only support annotating a type parameter.');
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function throwIfPartialWithMoreParameter(typeAnnotation: $FlowFixMe) {
|
|
300
|
+
if (typeAnnotation.typeParameters.params.length !== 1) {
|
|
301
|
+
throw new Error('Partials only support annotating exactly one parameter.');
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
263
305
|
module.exports = {
|
|
264
306
|
throwIfModuleInterfaceIsMisnamed,
|
|
265
307
|
throwIfUnsupportedFunctionReturnTypeAnnotationParserError,
|
|
@@ -274,4 +316,7 @@ module.exports = {
|
|
|
274
316
|
throwIfMoreThanOneModuleInterfaceParserError,
|
|
275
317
|
throwIfUnsupportedFunctionParamTypeAnnotationParserError,
|
|
276
318
|
throwIfArrayElementTypeAnnotationIsUnsupported,
|
|
319
|
+
throwIfIncorrectModuleRegistryCallArgument,
|
|
320
|
+
throwIfPartialNotAnnotatingTypeParameter,
|
|
321
|
+
throwIfPartialWithMoreParameter,
|
|
277
322
|
};
|
|
@@ -72,22 +72,20 @@ function _toPrimitive(input, hint) {
|
|
|
72
72
|
}
|
|
73
73
|
return (hint === 'string' ? String : Number)(input);
|
|
74
74
|
}
|
|
75
|
-
const _require = require('
|
|
76
|
-
|
|
77
|
-
const _require2 = require('./
|
|
78
|
-
|
|
79
|
-
const _require3 = require('./
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const _require6 = require('./
|
|
88
|
-
|
|
89
|
-
const _require7 = require('./componentsUtils.js'),
|
|
90
|
-
getProperties = _require7.getProperties;
|
|
75
|
+
const _require = require('./commands'),
|
|
76
|
+
getCommands = _require.getCommands;
|
|
77
|
+
const _require2 = require('./events'),
|
|
78
|
+
getEvents = _require2.getEvents;
|
|
79
|
+
const _require3 = require('./extends'),
|
|
80
|
+
getExtendsProps = _require3.getExtendsProps,
|
|
81
|
+
removeKnownExtends = _require3.removeKnownExtends;
|
|
82
|
+
const _require4 = require('./options'),
|
|
83
|
+
getCommandOptions = _require4.getCommandOptions,
|
|
84
|
+
getOptions = _require4.getOptions;
|
|
85
|
+
const _require5 = require('./props'),
|
|
86
|
+
getProps = _require5.getProps;
|
|
87
|
+
const _require6 = require('./componentsUtils.js'),
|
|
88
|
+
getProperties = _require6.getProperties;
|
|
91
89
|
|
|
92
90
|
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
|
|
93
91
|
* LTI update could not be added via codemod */
|
|
@@ -229,16 +227,14 @@ function getCommandProperties(
|
|
|
229
227
|
}
|
|
230
228
|
|
|
231
229
|
// $FlowFixMe[signature-verification-failure] there's no flowtype for AST
|
|
232
|
-
|
|
233
|
-
* LTI update could not be added via codemod */
|
|
234
|
-
function buildComponentSchema(ast) {
|
|
230
|
+
function buildComponentSchema(ast, parser) {
|
|
235
231
|
const _findComponentConfig = findComponentConfig(ast),
|
|
236
232
|
componentName = _findComponentConfig.componentName,
|
|
237
233
|
propsTypeName = _findComponentConfig.propsTypeName,
|
|
238
234
|
commandTypeName = _findComponentConfig.commandTypeName,
|
|
239
235
|
commandOptionsExpression = _findComponentConfig.commandOptionsExpression,
|
|
240
236
|
optionsExpression = _findComponentConfig.optionsExpression;
|
|
241
|
-
const types = getTypes(ast);
|
|
237
|
+
const types = parser.getTypes(ast);
|
|
242
238
|
const propProperties = getProperties(propsTypeName, types);
|
|
243
239
|
const commandOptions = getCommandOptions(commandOptionsExpression);
|
|
244
240
|
const commandProperties = getCommandProperties(
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
|
+
import type {Parser} from '../../parser';
|
|
12
13
|
import type {TypeDeclarationMap} from '../../utils';
|
|
13
14
|
import type {CommandOptions} from './options';
|
|
14
|
-
import type {ComponentSchemaBuilderConfig} from '
|
|
15
|
+
import type {ComponentSchemaBuilderConfig} from '../../schema.js';
|
|
15
16
|
|
|
16
|
-
const {getTypes} = require('../utils');
|
|
17
17
|
const {getCommands} = require('./commands');
|
|
18
18
|
const {getEvents} = require('./events');
|
|
19
19
|
const {getExtendsProps, removeKnownExtends} = require('./extends');
|
|
@@ -180,9 +180,10 @@ function getCommandProperties(
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
// $FlowFixMe[signature-verification-failure] there's no flowtype for AST
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
183
|
+
function buildComponentSchema(
|
|
184
|
+
ast: $FlowFixMe,
|
|
185
|
+
parser: Parser,
|
|
186
|
+
): ComponentSchemaBuilderConfig {
|
|
186
187
|
const {
|
|
187
188
|
componentName,
|
|
188
189
|
propsTypeName,
|
|
@@ -191,7 +192,7 @@ function buildComponentSchema(ast): ComponentSchemaBuilderConfig {
|
|
|
191
192
|
optionsExpression,
|
|
192
193
|
} = findComponentConfig(ast);
|
|
193
194
|
|
|
194
|
-
const types = getTypes(ast);
|
|
195
|
+
const types = parser.getTypes(ast);
|
|
195
196
|
|
|
196
197
|
const propProperties = getProperties(propsTypeName, types);
|
|
197
198
|
const commandOptions = getCommandOptions(commandOptionsExpression);
|
|
@@ -145,8 +145,7 @@ const _require = require('../../utils'),
|
|
|
145
145
|
isModuleRegistryCall = _require.isModuleRegistryCall,
|
|
146
146
|
verifyPlatforms = _require.verifyPlatforms;
|
|
147
147
|
const _require2 = require('../utils'),
|
|
148
|
-
resolveTypeAnnotation = _require2.resolveTypeAnnotation
|
|
149
|
-
getTypes = _require2.getTypes;
|
|
148
|
+
resolveTypeAnnotation = _require2.resolveTypeAnnotation;
|
|
150
149
|
const _require3 = require('../../parsers-commons'),
|
|
151
150
|
unwrapNullable = _require3.unwrapNullable,
|
|
152
151
|
wrapNullable = _require3.wrapNullable,
|
|
@@ -176,8 +175,6 @@ const _require4 = require('../../parsers-primitives'),
|
|
|
176
175
|
const _require5 = require('../../errors'),
|
|
177
176
|
UnsupportedTypeAnnotationParserError =
|
|
178
177
|
_require5.UnsupportedTypeAnnotationParserError,
|
|
179
|
-
IncorrectModuleRegistryCallArgumentTypeParserError =
|
|
180
|
-
_require5.IncorrectModuleRegistryCallArgumentTypeParserError,
|
|
181
178
|
UnsupportedGenericParserError = _require5.UnsupportedGenericParserError;
|
|
182
179
|
const _require6 = require('../../error-utils'),
|
|
183
180
|
throwIfModuleInterfaceNotFound = _require6.throwIfModuleInterfaceNotFound,
|
|
@@ -190,9 +187,14 @@ const _require6 = require('../../error-utils'),
|
|
|
190
187
|
_require6.throwIfMoreThanOneModuleRegistryCalls,
|
|
191
188
|
throwIfIncorrectModuleRegistryCallTypeParameterParserError =
|
|
192
189
|
_require6.throwIfIncorrectModuleRegistryCallTypeParameterParserError,
|
|
190
|
+
throwIfIncorrectModuleRegistryCallArgument =
|
|
191
|
+
_require6.throwIfIncorrectModuleRegistryCallArgument,
|
|
193
192
|
throwIfUntypedModule = _require6.throwIfUntypedModule,
|
|
194
193
|
throwIfMoreThanOneModuleInterfaceParserError =
|
|
195
|
-
_require6.throwIfMoreThanOneModuleInterfaceParserError
|
|
194
|
+
_require6.throwIfMoreThanOneModuleInterfaceParserError,
|
|
195
|
+
throwIfPartialNotAnnotatingTypeParameter =
|
|
196
|
+
_require6.throwIfPartialNotAnnotatingTypeParameter,
|
|
197
|
+
throwIfPartialWithMoreParameter = _require6.throwIfPartialWithMoreParameter;
|
|
196
198
|
const language = 'Flow';
|
|
197
199
|
function translateTypeAnnotation(
|
|
198
200
|
hasteModuleName,
|
|
@@ -288,18 +290,16 @@ function translateTypeAnnotation(
|
|
|
288
290
|
return emitGenericObject(nullable);
|
|
289
291
|
}
|
|
290
292
|
case '$Partial': {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
);
|
|
302
|
-
}
|
|
293
|
+
throwIfPartialWithMoreParameter(typeAnnotation);
|
|
294
|
+
const annotatedElement = parser.extractAnnotatedElement(
|
|
295
|
+
typeAnnotation,
|
|
296
|
+
types,
|
|
297
|
+
);
|
|
298
|
+
throwIfPartialNotAnnotatingTypeParameter(
|
|
299
|
+
typeAnnotation,
|
|
300
|
+
types,
|
|
301
|
+
parser,
|
|
302
|
+
);
|
|
303
303
|
const properties = annotatedElement.right.properties.map(prop => {
|
|
304
304
|
return {
|
|
305
305
|
name: prop.key.name,
|
|
@@ -444,14 +444,6 @@ function translateTypeAnnotation(
|
|
|
444
444
|
}
|
|
445
445
|
}
|
|
446
446
|
}
|
|
447
|
-
function isModuleInterface(node) {
|
|
448
|
-
return (
|
|
449
|
-
node.type === 'InterfaceDeclaration' &&
|
|
450
|
-
node.extends.length === 1 &&
|
|
451
|
-
node.extends[0].type === 'InterfaceExtends' &&
|
|
452
|
-
node.extends[0].id.name === 'TurboModule'
|
|
453
|
-
);
|
|
454
|
-
}
|
|
455
447
|
function buildModuleSchema(
|
|
456
448
|
hasteModuleName,
|
|
457
449
|
/**
|
|
@@ -461,8 +453,10 @@ function buildModuleSchema(
|
|
|
461
453
|
tryParse,
|
|
462
454
|
parser,
|
|
463
455
|
) {
|
|
464
|
-
const types = getTypes(ast);
|
|
465
|
-
const moduleSpecs = Object.values(types).filter(
|
|
456
|
+
const types = parser.getTypes(ast);
|
|
457
|
+
const moduleSpecs = Object.values(types).filter(t =>
|
|
458
|
+
parser.isModuleInterface(t),
|
|
459
|
+
);
|
|
466
460
|
throwIfModuleInterfaceNotFound(
|
|
467
461
|
moduleSpecs.length,
|
|
468
462
|
hasteModuleName,
|
|
@@ -507,15 +501,11 @@ function buildModuleSchema(
|
|
|
507
501
|
methodName,
|
|
508
502
|
callExpression.arguments.length,
|
|
509
503
|
);
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
methodName,
|
|
516
|
-
type,
|
|
517
|
-
);
|
|
518
|
-
}
|
|
504
|
+
throwIfIncorrectModuleRegistryCallArgument(
|
|
505
|
+
hasteModuleName,
|
|
506
|
+
callExpression.arguments[0],
|
|
507
|
+
methodName,
|
|
508
|
+
);
|
|
519
509
|
const $moduleName = callExpression.arguments[0].value;
|
|
520
510
|
throwIfUntypedModule(
|
|
521
511
|
typeArguments,
|
|
@@ -25,7 +25,7 @@ import type {Parser} from '../../parser';
|
|
|
25
25
|
import type {ParserErrorCapturer, TypeDeclarationMap} from '../../utils';
|
|
26
26
|
|
|
27
27
|
const {visit, isModuleRegistryCall, verifyPlatforms} = require('../../utils');
|
|
28
|
-
const {resolveTypeAnnotation
|
|
28
|
+
const {resolveTypeAnnotation} = require('../utils');
|
|
29
29
|
const {
|
|
30
30
|
unwrapNullable,
|
|
31
31
|
wrapNullable,
|
|
@@ -56,7 +56,6 @@ const {
|
|
|
56
56
|
|
|
57
57
|
const {
|
|
58
58
|
UnsupportedTypeAnnotationParserError,
|
|
59
|
-
IncorrectModuleRegistryCallArgumentTypeParserError,
|
|
60
59
|
UnsupportedGenericParserError,
|
|
61
60
|
} = require('../../errors');
|
|
62
61
|
|
|
@@ -67,8 +66,11 @@ const {
|
|
|
67
66
|
throwIfWrongNumberOfCallExpressionArgs,
|
|
68
67
|
throwIfMoreThanOneModuleRegistryCalls,
|
|
69
68
|
throwIfIncorrectModuleRegistryCallTypeParameterParserError,
|
|
69
|
+
throwIfIncorrectModuleRegistryCallArgument,
|
|
70
70
|
throwIfUntypedModule,
|
|
71
71
|
throwIfMoreThanOneModuleInterfaceParserError,
|
|
72
|
+
throwIfPartialNotAnnotatingTypeParameter,
|
|
73
|
+
throwIfPartialWithMoreParameter,
|
|
72
74
|
} = require('../../error-utils');
|
|
73
75
|
|
|
74
76
|
const language = 'Flow';
|
|
@@ -162,20 +164,18 @@ function translateTypeAnnotation(
|
|
|
162
164
|
return emitGenericObject(nullable);
|
|
163
165
|
}
|
|
164
166
|
case '$Partial': {
|
|
165
|
-
|
|
166
|
-
throw new Error(
|
|
167
|
-
'Partials only support annotating exactly one parameter.',
|
|
168
|
-
);
|
|
169
|
-
}
|
|
167
|
+
throwIfPartialWithMoreParameter(typeAnnotation);
|
|
170
168
|
|
|
171
|
-
const annotatedElement =
|
|
172
|
-
|
|
169
|
+
const annotatedElement = parser.extractAnnotatedElement(
|
|
170
|
+
typeAnnotation,
|
|
171
|
+
types,
|
|
172
|
+
);
|
|
173
173
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
174
|
+
throwIfPartialNotAnnotatingTypeParameter(
|
|
175
|
+
typeAnnotation,
|
|
176
|
+
types,
|
|
177
|
+
parser,
|
|
178
|
+
);
|
|
179
179
|
|
|
180
180
|
const properties = annotatedElement.right.properties.map(prop => {
|
|
181
181
|
return {
|
|
@@ -330,15 +330,6 @@ function translateTypeAnnotation(
|
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
332
|
|
|
333
|
-
function isModuleInterface(node: $FlowFixMe) {
|
|
334
|
-
return (
|
|
335
|
-
node.type === 'InterfaceDeclaration' &&
|
|
336
|
-
node.extends.length === 1 &&
|
|
337
|
-
node.extends[0].type === 'InterfaceExtends' &&
|
|
338
|
-
node.extends[0].id.name === 'TurboModule'
|
|
339
|
-
);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
333
|
function buildModuleSchema(
|
|
343
334
|
hasteModuleName: string,
|
|
344
335
|
/**
|
|
@@ -348,9 +339,9 @@ function buildModuleSchema(
|
|
|
348
339
|
tryParse: ParserErrorCapturer,
|
|
349
340
|
parser: Parser,
|
|
350
341
|
): NativeModuleSchema {
|
|
351
|
-
const types = getTypes(ast);
|
|
342
|
+
const types = parser.getTypes(ast);
|
|
352
343
|
const moduleSpecs = (Object.values(types): $ReadOnlyArray<$FlowFixMe>).filter(
|
|
353
|
-
isModuleInterface,
|
|
344
|
+
t => parser.isModuleInterface(t),
|
|
354
345
|
);
|
|
355
346
|
|
|
356
347
|
throwIfModuleInterfaceNotFound(
|
|
@@ -404,15 +395,11 @@ function buildModuleSchema(
|
|
|
404
395
|
callExpression.arguments.length,
|
|
405
396
|
);
|
|
406
397
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
methodName,
|
|
413
|
-
type,
|
|
414
|
-
);
|
|
415
|
-
}
|
|
398
|
+
throwIfIncorrectModuleRegistryCallArgument(
|
|
399
|
+
hasteModuleName,
|
|
400
|
+
callExpression.arguments[0],
|
|
401
|
+
methodName,
|
|
402
|
+
);
|
|
416
403
|
|
|
417
404
|
const $moduleName = callExpression.arguments[0].value;
|
|
418
405
|
|
|
@@ -46,7 +46,7 @@ const _require2 = require('./Visitor'),
|
|
|
46
46
|
Visitor = _require2.Visitor;
|
|
47
47
|
const _require3 = require('./components'),
|
|
48
48
|
buildComponentSchema = _require3.buildComponentSchema;
|
|
49
|
-
const _require4 = require('
|
|
49
|
+
const _require4 = require('../schema.js'),
|
|
50
50
|
wrapComponentSchema = _require4.wrapComponentSchema;
|
|
51
51
|
const _require5 = require('./modules'),
|
|
52
52
|
buildModuleSchema = _require5.buildModuleSchema;
|
|
@@ -193,6 +193,57 @@ class FlowParser {
|
|
|
193
193
|
};
|
|
194
194
|
});
|
|
195
195
|
}
|
|
196
|
+
isModuleInterface(node) {
|
|
197
|
+
return (
|
|
198
|
+
node.type === 'InterfaceDeclaration' &&
|
|
199
|
+
node.extends.length === 1 &&
|
|
200
|
+
node.extends[0].type === 'InterfaceExtends' &&
|
|
201
|
+
node.extends[0].id.name === 'TurboModule'
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
extractAnnotatedElement(typeAnnotation, types) {
|
|
205
|
+
return types[typeAnnotation.typeParameters.params[0].id.name];
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* This FlowFixMe is supposed to refer to an InterfaceDeclaration or TypeAlias
|
|
210
|
+
* declaration type. Unfortunately, we don't have those types, because flow-parser
|
|
211
|
+
* generates them, and flow-parser is not type-safe. In the future, we should find
|
|
212
|
+
* a way to get these types from our flow parser library.
|
|
213
|
+
*
|
|
214
|
+
* TODO(T71778680): Flow type AST Nodes
|
|
215
|
+
*/
|
|
216
|
+
|
|
217
|
+
getTypes(ast) {
|
|
218
|
+
return ast.body.reduce((types, node) => {
|
|
219
|
+
if (
|
|
220
|
+
node.type === 'ExportNamedDeclaration' &&
|
|
221
|
+
node.exportKind === 'type'
|
|
222
|
+
) {
|
|
223
|
+
if (
|
|
224
|
+
node.declaration != null &&
|
|
225
|
+
(node.declaration.type === 'TypeAlias' ||
|
|
226
|
+
node.declaration.type === 'InterfaceDeclaration')
|
|
227
|
+
) {
|
|
228
|
+
types[node.declaration.id.name] = node.declaration;
|
|
229
|
+
}
|
|
230
|
+
} else if (
|
|
231
|
+
node.type === 'ExportNamedDeclaration' &&
|
|
232
|
+
node.exportKind === 'value' &&
|
|
233
|
+
node.declaration &&
|
|
234
|
+
node.declaration.type === 'EnumDeclaration'
|
|
235
|
+
) {
|
|
236
|
+
types[node.declaration.id.name] = node.declaration;
|
|
237
|
+
} else if (
|
|
238
|
+
node.type === 'TypeAlias' ||
|
|
239
|
+
node.type === 'InterfaceDeclaration' ||
|
|
240
|
+
node.type === 'EnumDeclaration'
|
|
241
|
+
) {
|
|
242
|
+
types[node.id.name] = node;
|
|
243
|
+
}
|
|
244
|
+
return types;
|
|
245
|
+
}, {});
|
|
246
|
+
}
|
|
196
247
|
}
|
|
197
248
|
module.exports = {
|
|
198
249
|
FlowParser,
|
|
@@ -21,6 +21,7 @@ import type {
|
|
|
21
21
|
} from '../../CodegenSchema';
|
|
22
22
|
import type {ParserType} from '../errors';
|
|
23
23
|
import type {Parser} from '../parser';
|
|
24
|
+
import type {TypeDeclarationMap} from '../utils';
|
|
24
25
|
|
|
25
26
|
// $FlowFixMe[untyped-import] there's no flowtype flow-parser
|
|
26
27
|
const flowParser = require('flow-parser');
|
|
@@ -28,7 +29,7 @@ const flowParser = require('flow-parser');
|
|
|
28
29
|
const {buildSchema} = require('../parsers-commons');
|
|
29
30
|
const {Visitor} = require('./Visitor');
|
|
30
31
|
const {buildComponentSchema} = require('./components');
|
|
31
|
-
const {wrapComponentSchema} = require('
|
|
32
|
+
const {wrapComponentSchema} = require('../schema.js');
|
|
32
33
|
const {buildModuleSchema} = require('./modules');
|
|
33
34
|
|
|
34
35
|
const fs = require('fs');
|
|
@@ -196,6 +197,62 @@ class FlowParser implements Parser {
|
|
|
196
197
|
value: member.init?.value ?? member.id.name,
|
|
197
198
|
}));
|
|
198
199
|
}
|
|
200
|
+
|
|
201
|
+
isModuleInterface(node: $FlowFixMe): boolean {
|
|
202
|
+
return (
|
|
203
|
+
node.type === 'InterfaceDeclaration' &&
|
|
204
|
+
node.extends.length === 1 &&
|
|
205
|
+
node.extends[0].type === 'InterfaceExtends' &&
|
|
206
|
+
node.extends[0].id.name === 'TurboModule'
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
extractAnnotatedElement(
|
|
211
|
+
typeAnnotation: $FlowFixMe,
|
|
212
|
+
types: TypeDeclarationMap,
|
|
213
|
+
): $FlowFixMe {
|
|
214
|
+
return types[typeAnnotation.typeParameters.params[0].id.name];
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* This FlowFixMe is supposed to refer to an InterfaceDeclaration or TypeAlias
|
|
219
|
+
* declaration type. Unfortunately, we don't have those types, because flow-parser
|
|
220
|
+
* generates them, and flow-parser is not type-safe. In the future, we should find
|
|
221
|
+
* a way to get these types from our flow parser library.
|
|
222
|
+
*
|
|
223
|
+
* TODO(T71778680): Flow type AST Nodes
|
|
224
|
+
*/
|
|
225
|
+
|
|
226
|
+
getTypes(ast: $FlowFixMe): TypeDeclarationMap {
|
|
227
|
+
return ast.body.reduce((types, node) => {
|
|
228
|
+
if (
|
|
229
|
+
node.type === 'ExportNamedDeclaration' &&
|
|
230
|
+
node.exportKind === 'type'
|
|
231
|
+
) {
|
|
232
|
+
if (
|
|
233
|
+
node.declaration != null &&
|
|
234
|
+
(node.declaration.type === 'TypeAlias' ||
|
|
235
|
+
node.declaration.type === 'InterfaceDeclaration')
|
|
236
|
+
) {
|
|
237
|
+
types[node.declaration.id.name] = node.declaration;
|
|
238
|
+
}
|
|
239
|
+
} else if (
|
|
240
|
+
node.type === 'ExportNamedDeclaration' &&
|
|
241
|
+
node.exportKind === 'value' &&
|
|
242
|
+
node.declaration &&
|
|
243
|
+
node.declaration.type === 'EnumDeclaration'
|
|
244
|
+
) {
|
|
245
|
+
types[node.declaration.id.name] = node.declaration;
|
|
246
|
+
} else if (
|
|
247
|
+
node.type === 'TypeAlias' ||
|
|
248
|
+
node.type === 'InterfaceDeclaration' ||
|
|
249
|
+
node.type === 'EnumDeclaration'
|
|
250
|
+
) {
|
|
251
|
+
types[node.id.name] = node;
|
|
252
|
+
}
|
|
253
|
+
return types;
|
|
254
|
+
}, {});
|
|
255
|
+
}
|
|
199
256
|
}
|
|
200
257
|
|
|
201
258
|
module.exports = {
|
|
@@ -10,43 +10,6 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
/**
|
|
14
|
-
* This FlowFixMe is supposed to refer to an InterfaceDeclaration or TypeAlias
|
|
15
|
-
* declaration type. Unfortunately, we don't have those types, because flow-parser
|
|
16
|
-
* generates them, and flow-parser is not type-safe. In the future, we should find
|
|
17
|
-
* a way to get these types from our flow parser library.
|
|
18
|
-
*
|
|
19
|
-
* TODO(T71778680): Flow type AST Nodes
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
function getTypes(ast) {
|
|
23
|
-
return ast.body.reduce((types, node) => {
|
|
24
|
-
if (node.type === 'ExportNamedDeclaration' && node.exportKind === 'type') {
|
|
25
|
-
if (
|
|
26
|
-
node.declaration != null &&
|
|
27
|
-
(node.declaration.type === 'TypeAlias' ||
|
|
28
|
-
node.declaration.type === 'InterfaceDeclaration')
|
|
29
|
-
) {
|
|
30
|
-
types[node.declaration.id.name] = node.declaration;
|
|
31
|
-
}
|
|
32
|
-
} else if (
|
|
33
|
-
node.type === 'ExportNamedDeclaration' &&
|
|
34
|
-
node.exportKind === 'value' &&
|
|
35
|
-
node.declaration &&
|
|
36
|
-
node.declaration.type === 'EnumDeclaration'
|
|
37
|
-
) {
|
|
38
|
-
types[node.declaration.id.name] = node.declaration;
|
|
39
|
-
} else if (
|
|
40
|
-
node.type === 'TypeAlias' ||
|
|
41
|
-
node.type === 'InterfaceDeclaration' ||
|
|
42
|
-
node.type === 'EnumDeclaration'
|
|
43
|
-
) {
|
|
44
|
-
types[node.id.name] = node;
|
|
45
|
-
}
|
|
46
|
-
return types;
|
|
47
|
-
}, {});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
13
|
// $FlowFixMe[unclear-type] there's no flowtype for ASTs
|
|
51
14
|
|
|
52
15
|
const invariant = require('invariant');
|
|
@@ -118,5 +81,4 @@ function getValueFromTypes(value, types) {
|
|
|
118
81
|
module.exports = {
|
|
119
82
|
getValueFromTypes,
|
|
120
83
|
resolveTypeAnnotation,
|
|
121
|
-
getTypes,
|
|
122
84
|
};
|
|
@@ -12,43 +12,6 @@
|
|
|
12
12
|
|
|
13
13
|
import type {TypeResolutionStatus, TypeDeclarationMap} from '../utils';
|
|
14
14
|
|
|
15
|
-
/**
|
|
16
|
-
* This FlowFixMe is supposed to refer to an InterfaceDeclaration or TypeAlias
|
|
17
|
-
* declaration type. Unfortunately, we don't have those types, because flow-parser
|
|
18
|
-
* generates them, and flow-parser is not type-safe. In the future, we should find
|
|
19
|
-
* a way to get these types from our flow parser library.
|
|
20
|
-
*
|
|
21
|
-
* TODO(T71778680): Flow type AST Nodes
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
function getTypes(ast: $FlowFixMe): TypeDeclarationMap {
|
|
25
|
-
return ast.body.reduce((types, node) => {
|
|
26
|
-
if (node.type === 'ExportNamedDeclaration' && node.exportKind === 'type') {
|
|
27
|
-
if (
|
|
28
|
-
node.declaration != null &&
|
|
29
|
-
(node.declaration.type === 'TypeAlias' ||
|
|
30
|
-
node.declaration.type === 'InterfaceDeclaration')
|
|
31
|
-
) {
|
|
32
|
-
types[node.declaration.id.name] = node.declaration;
|
|
33
|
-
}
|
|
34
|
-
} else if (
|
|
35
|
-
node.type === 'ExportNamedDeclaration' &&
|
|
36
|
-
node.exportKind === 'value' &&
|
|
37
|
-
node.declaration &&
|
|
38
|
-
node.declaration.type === 'EnumDeclaration'
|
|
39
|
-
) {
|
|
40
|
-
types[node.declaration.id.name] = node.declaration;
|
|
41
|
-
} else if (
|
|
42
|
-
node.type === 'TypeAlias' ||
|
|
43
|
-
node.type === 'InterfaceDeclaration' ||
|
|
44
|
-
node.type === 'EnumDeclaration'
|
|
45
|
-
) {
|
|
46
|
-
types[node.id.name] = node;
|
|
47
|
-
}
|
|
48
|
-
return types;
|
|
49
|
-
}, {});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
15
|
// $FlowFixMe[unclear-type] there's no flowtype for ASTs
|
|
53
16
|
export type ASTNode = Object;
|
|
54
17
|
|
|
@@ -134,5 +97,4 @@ function getValueFromTypes(value: ASTNode, types: TypeDeclarationMap): ASTNode {
|
|
|
134
97
|
module.exports = {
|
|
135
98
|
getValueFromTypes,
|
|
136
99
|
resolveTypeAnnotation,
|
|
137
|
-
getTypes,
|
|
138
100
|
};
|