@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
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
NativeModuleEnumMembers,
|
|
21
21
|
} from '../CodegenSchema';
|
|
22
22
|
import type {ParserType} from './errors';
|
|
23
|
+
import type {TypeDeclarationMap} from './utils';
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* This is the main interface for Parsers of various languages.
|
|
@@ -152,4 +153,25 @@ export interface Parser {
|
|
|
152
153
|
* Calculates enum's members
|
|
153
154
|
*/
|
|
154
155
|
parseEnumMembers(typeAnnotation: $FlowFixMe): NativeModuleEnumMembers;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Given a node, it returns true if it is a module interface
|
|
159
|
+
*/
|
|
160
|
+
isModuleInterface(node: $FlowFixMe): boolean;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Given a typeAnnotation, it returns the annotated element.
|
|
164
|
+
* @paramater typeAnnotation: the annotation for a type.
|
|
165
|
+
* @paramater types: a map of type declarations.
|
|
166
|
+
* @returns: the annotated element.
|
|
167
|
+
*/
|
|
168
|
+
extractAnnotatedElement(
|
|
169
|
+
typeAnnotation: $FlowFixMe,
|
|
170
|
+
types: TypeDeclarationMap,
|
|
171
|
+
): $FlowFixMe;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Given the AST, returns the TypeDeclarationMap
|
|
175
|
+
*/
|
|
176
|
+
getTypes(ast: $FlowFixMe): TypeDeclarationMap;
|
|
155
177
|
}
|
|
@@ -150,4 +150,18 @@ export class MockedParser {
|
|
|
150
150
|
},
|
|
151
151
|
];
|
|
152
152
|
}
|
|
153
|
+
isModuleInterface(node) {
|
|
154
|
+
return (
|
|
155
|
+
node.type === 'InterfaceDeclaration' &&
|
|
156
|
+
node.extends.length === 1 &&
|
|
157
|
+
node.extends[0].type === 'InterfaceExtends' &&
|
|
158
|
+
node.extends[0].id.name === 'TurboModule'
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
extractAnnotatedElement(typeAnnotation, types) {
|
|
162
|
+
return types[typeAnnotation.typeParameters.params[0].id.name];
|
|
163
|
+
}
|
|
164
|
+
getTypes(ast) {
|
|
165
|
+
return {};
|
|
166
|
+
}
|
|
153
167
|
}
|
|
@@ -21,6 +21,7 @@ import type {
|
|
|
21
21
|
NativeModuleEnumMemberType,
|
|
22
22
|
NativeModuleEnumMembers,
|
|
23
23
|
} from '../CodegenSchema';
|
|
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');
|
|
@@ -159,4 +160,24 @@ export class MockedParser implements Parser {
|
|
|
159
160
|
},
|
|
160
161
|
];
|
|
161
162
|
}
|
|
163
|
+
|
|
164
|
+
isModuleInterface(node: $FlowFixMe): boolean {
|
|
165
|
+
return (
|
|
166
|
+
node.type === 'InterfaceDeclaration' &&
|
|
167
|
+
node.extends.length === 1 &&
|
|
168
|
+
node.extends[0].type === 'InterfaceExtends' &&
|
|
169
|
+
node.extends[0].id.name === 'TurboModule'
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
extractAnnotatedElement(
|
|
174
|
+
typeAnnotation: $FlowFixMe,
|
|
175
|
+
types: TypeDeclarationMap,
|
|
176
|
+
): $FlowFixMe {
|
|
177
|
+
return types[typeAnnotation.typeParameters.params[0].id.name];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
getTypes(ast: $FlowFixMe): TypeDeclarationMap {
|
|
181
|
+
return {};
|
|
182
|
+
}
|
|
162
183
|
}
|
|
@@ -369,7 +369,7 @@ function buildSchemaFromConfigType(
|
|
|
369
369
|
) {
|
|
370
370
|
switch (configType) {
|
|
371
371
|
case 'component': {
|
|
372
|
-
return wrapComponentSchema(buildComponentSchema(ast));
|
|
372
|
+
return wrapComponentSchema(buildComponentSchema(ast, parser));
|
|
373
373
|
}
|
|
374
374
|
case 'module': {
|
|
375
375
|
if (filename === undefined || filename === null) {
|
|
@@ -26,7 +26,7 @@ import type {
|
|
|
26
26
|
import type {Parser} from './parser';
|
|
27
27
|
import type {ParserType} from './errors';
|
|
28
28
|
import type {ParserErrorCapturer, TypeDeclarationMap} from './utils';
|
|
29
|
-
import type {ComponentSchemaBuilderConfig} from './
|
|
29
|
+
import type {ComponentSchemaBuilderConfig} from './schema.js';
|
|
30
30
|
|
|
31
31
|
const {
|
|
32
32
|
getConfigType,
|
|
@@ -345,7 +345,10 @@ function buildSchemaFromConfigType(
|
|
|
345
345
|
filename: ?string,
|
|
346
346
|
ast: $FlowFixMe,
|
|
347
347
|
wrapComponentSchema: (config: ComponentSchemaBuilderConfig) => SchemaType,
|
|
348
|
-
buildComponentSchema: (
|
|
348
|
+
buildComponentSchema: (
|
|
349
|
+
ast: $FlowFixMe,
|
|
350
|
+
parser: Parser,
|
|
351
|
+
) => ComponentSchemaBuilderConfig,
|
|
349
352
|
buildModuleSchema: (
|
|
350
353
|
hasteModuleName: string,
|
|
351
354
|
ast: $FlowFixMe,
|
|
@@ -356,7 +359,7 @@ function buildSchemaFromConfigType(
|
|
|
356
359
|
): SchemaType {
|
|
357
360
|
switch (configType) {
|
|
358
361
|
case 'component': {
|
|
359
|
-
return wrapComponentSchema(buildComponentSchema(ast));
|
|
362
|
+
return wrapComponentSchema(buildComponentSchema(ast, parser));
|
|
360
363
|
}
|
|
361
364
|
case 'module': {
|
|
362
365
|
if (filename === undefined || filename === null) {
|
|
@@ -398,7 +401,10 @@ function buildSchema(
|
|
|
398
401
|
contents: string,
|
|
399
402
|
filename: ?string,
|
|
400
403
|
wrapComponentSchema: (config: ComponentSchemaBuilderConfig) => SchemaType,
|
|
401
|
-
buildComponentSchema: (
|
|
404
|
+
buildComponentSchema: (
|
|
405
|
+
ast: $FlowFixMe,
|
|
406
|
+
parser: Parser,
|
|
407
|
+
) => ComponentSchemaBuilderConfig,
|
|
402
408
|
buildModuleSchema: (
|
|
403
409
|
hasteModuleName: string,
|
|
404
410
|
ast: $FlowFixMe,
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
-
* @flow strict
|
|
8
7
|
* @format
|
|
8
|
+
* @flow strict
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
@@ -18,7 +18,7 @@ import type {
|
|
|
18
18
|
ExtendsPropsShape,
|
|
19
19
|
SchemaType,
|
|
20
20
|
OptionsShape,
|
|
21
|
-
} from '
|
|
21
|
+
} from '../CodegenSchema.js';
|
|
22
22
|
|
|
23
23
|
export type ComponentSchemaBuilderConfig = $ReadOnly<{
|
|
24
24
|
filename: string,
|
|
@@ -72,21 +72,19 @@ 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
|
-
const _require4 = require('./
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const _require6 = require('./
|
|
87
|
-
|
|
88
|
-
const _require7 = require('./componentsUtils.js'),
|
|
89
|
-
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
|
+
categorizeProps = _require3.categorizeProps;
|
|
81
|
+
const _require4 = require('./options'),
|
|
82
|
+
getCommandOptions = _require4.getCommandOptions,
|
|
83
|
+
getOptions = _require4.getOptions;
|
|
84
|
+
const _require5 = require('./props'),
|
|
85
|
+
getProps = _require5.getProps;
|
|
86
|
+
const _require6 = require('./componentsUtils.js'),
|
|
87
|
+
getProperties = _require6.getProperties;
|
|
90
88
|
|
|
91
89
|
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
|
|
92
90
|
* LTI update could not be added via codemod */
|
|
@@ -231,16 +229,14 @@ function getCommandProperties(
|
|
|
231
229
|
// $FlowFixMe[unclear-type] TODO(T108222691): Use flow-types for @babel/parser
|
|
232
230
|
|
|
233
231
|
// $FlowFixMe[signature-verification-failure] TODO(T108222691): Use flow-types for @babel/parser
|
|
234
|
-
|
|
235
|
-
* LTI update could not be added via codemod */
|
|
236
|
-
function buildComponentSchema(ast) {
|
|
232
|
+
function buildComponentSchema(ast, parser) {
|
|
237
233
|
const _findComponentConfig = findComponentConfig(ast),
|
|
238
234
|
componentName = _findComponentConfig.componentName,
|
|
239
235
|
propsTypeName = _findComponentConfig.propsTypeName,
|
|
240
236
|
commandTypeName = _findComponentConfig.commandTypeName,
|
|
241
237
|
commandOptionsExpression = _findComponentConfig.commandOptionsExpression,
|
|
242
238
|
optionsExpression = _findComponentConfig.optionsExpression;
|
|
243
|
-
const types = getTypes(ast);
|
|
239
|
+
const types = parser.getTypes(ast);
|
|
244
240
|
const propProperties = getProperties(propsTypeName, types);
|
|
245
241
|
const commandOptions = getCommandOptions(commandOptionsExpression);
|
|
246
242
|
const commandProperties = getCommandProperties(
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
import type {ExtendsPropsShape} from '../../../CodegenSchema.js';
|
|
13
|
+
import type {Parser} from '../../parser';
|
|
13
14
|
import type {TypeDeclarationMap} from '../../utils';
|
|
14
15
|
import type {CommandOptions} from './options';
|
|
15
|
-
import type {ComponentSchemaBuilderConfig} from '
|
|
16
|
+
import type {ComponentSchemaBuilderConfig} from '../../schema.js';
|
|
16
17
|
|
|
17
|
-
const {getTypes} = require('../utils');
|
|
18
18
|
const {getCommands} = require('./commands');
|
|
19
19
|
const {getEvents} = require('./events');
|
|
20
20
|
const {categorizeProps} = require('./extends');
|
|
@@ -185,9 +185,10 @@ function getCommandProperties(
|
|
|
185
185
|
type PropsAST = Object;
|
|
186
186
|
|
|
187
187
|
// $FlowFixMe[signature-verification-failure] TODO(T108222691): Use flow-types for @babel/parser
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
188
|
+
function buildComponentSchema(
|
|
189
|
+
ast: $FlowFixMe,
|
|
190
|
+
parser: Parser,
|
|
191
|
+
): ComponentSchemaBuilderConfig {
|
|
191
192
|
const {
|
|
192
193
|
componentName,
|
|
193
194
|
propsTypeName,
|
|
@@ -196,7 +197,7 @@ function buildComponentSchema(ast): ComponentSchemaBuilderConfig {
|
|
|
196
197
|
optionsExpression,
|
|
197
198
|
} = findComponentConfig(ast);
|
|
198
199
|
|
|
199
|
-
const types = getTypes(ast);
|
|
200
|
+
const types = parser.getTypes(ast);
|
|
200
201
|
|
|
201
202
|
const propProperties = getProperties(propsTypeName, types);
|
|
202
203
|
const commandOptions = getCommandOptions(commandOptionsExpression);
|
|
@@ -149,8 +149,7 @@ const _require3 = require('../../utils'),
|
|
|
149
149
|
isModuleRegistryCall = _require3.isModuleRegistryCall,
|
|
150
150
|
verifyPlatforms = _require3.verifyPlatforms;
|
|
151
151
|
const _require4 = require('../utils'),
|
|
152
|
-
resolveTypeAnnotation = _require4.resolveTypeAnnotation
|
|
153
|
-
getTypes = _require4.getTypes;
|
|
152
|
+
resolveTypeAnnotation = _require4.resolveTypeAnnotation;
|
|
154
153
|
const _require5 = require('../../parsers-commons'),
|
|
155
154
|
parseObjectProperty = _require5.parseObjectProperty,
|
|
156
155
|
buildPropertySchema = _require5.buildPropertySchema;
|
|
@@ -178,9 +177,7 @@ const _require7 = require('../../parsers-primitives'),
|
|
|
178
177
|
const _require8 = require('../../errors'),
|
|
179
178
|
UnsupportedGenericParserError = _require8.UnsupportedGenericParserError,
|
|
180
179
|
UnsupportedTypeAnnotationParserError =
|
|
181
|
-
_require8.UnsupportedTypeAnnotationParserError
|
|
182
|
-
IncorrectModuleRegistryCallArgumentTypeParserError =
|
|
183
|
-
_require8.IncorrectModuleRegistryCallArgumentTypeParserError;
|
|
180
|
+
_require8.UnsupportedTypeAnnotationParserError;
|
|
184
181
|
const _require9 = require('../../error-utils'),
|
|
185
182
|
throwIfUntypedModule = _require9.throwIfUntypedModule,
|
|
186
183
|
throwIfUnusedModuleInterfaceParserError =
|
|
@@ -194,7 +191,12 @@ const _require9 = require('../../error-utils'),
|
|
|
194
191
|
throwIfMoreThanOneModuleInterfaceParserError =
|
|
195
192
|
_require9.throwIfMoreThanOneModuleInterfaceParserError,
|
|
196
193
|
throwIfIncorrectModuleRegistryCallTypeParameterParserError =
|
|
197
|
-
_require9.throwIfIncorrectModuleRegistryCallTypeParameterParserError
|
|
194
|
+
_require9.throwIfIncorrectModuleRegistryCallTypeParameterParserError,
|
|
195
|
+
throwIfIncorrectModuleRegistryCallArgument =
|
|
196
|
+
_require9.throwIfIncorrectModuleRegistryCallArgument,
|
|
197
|
+
throwIfPartialNotAnnotatingTypeParameter =
|
|
198
|
+
_require9.throwIfPartialNotAnnotatingTypeParameter,
|
|
199
|
+
throwIfPartialWithMoreParameter = _require9.throwIfPartialWithMoreParameter;
|
|
198
200
|
const language = 'TypeScript';
|
|
199
201
|
function translateObjectTypeAnnotation(
|
|
200
202
|
hasteModuleName,
|
|
@@ -361,18 +363,16 @@ function translateTypeAnnotation(
|
|
|
361
363
|
return emitGenericObject(nullable);
|
|
362
364
|
}
|
|
363
365
|
case 'Partial': {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
);
|
|
375
|
-
}
|
|
366
|
+
throwIfPartialWithMoreParameter(typeAnnotation);
|
|
367
|
+
const annotatedElement = parser.extractAnnotatedElement(
|
|
368
|
+
typeAnnotation,
|
|
369
|
+
types,
|
|
370
|
+
);
|
|
371
|
+
throwIfPartialNotAnnotatingTypeParameter(
|
|
372
|
+
typeAnnotation,
|
|
373
|
+
types,
|
|
374
|
+
parser,
|
|
375
|
+
);
|
|
376
376
|
const properties = annotatedElement.typeAnnotation.members.map(
|
|
377
377
|
member => {
|
|
378
378
|
return {
|
|
@@ -555,17 +555,6 @@ function translateTypeAnnotation(
|
|
|
555
555
|
}
|
|
556
556
|
}
|
|
557
557
|
}
|
|
558
|
-
function isModuleInterface(node) {
|
|
559
|
-
var _node$extends;
|
|
560
|
-
return (
|
|
561
|
-
node.type === 'TSInterfaceDeclaration' &&
|
|
562
|
-
((_node$extends = node.extends) === null || _node$extends === void 0
|
|
563
|
-
? void 0
|
|
564
|
-
: _node$extends.length) === 1 &&
|
|
565
|
-
node.extends[0].type === 'TSExpressionWithTypeArguments' &&
|
|
566
|
-
node.extends[0].expression.name === 'TurboModule'
|
|
567
|
-
);
|
|
568
|
-
}
|
|
569
558
|
function buildModuleSchema(
|
|
570
559
|
hasteModuleName,
|
|
571
560
|
/**
|
|
@@ -575,8 +564,10 @@ function buildModuleSchema(
|
|
|
575
564
|
tryParse,
|
|
576
565
|
parser,
|
|
577
566
|
) {
|
|
578
|
-
const types = getTypes(ast);
|
|
579
|
-
const moduleSpecs = Object.values(types).filter(
|
|
567
|
+
const types = parser.getTypes(ast);
|
|
568
|
+
const moduleSpecs = Object.values(types).filter(t =>
|
|
569
|
+
parser.isModuleInterface(t),
|
|
570
|
+
);
|
|
580
571
|
throwIfModuleInterfaceNotFound(
|
|
581
572
|
moduleSpecs.length,
|
|
582
573
|
hasteModuleName,
|
|
@@ -621,15 +612,11 @@ function buildModuleSchema(
|
|
|
621
612
|
methodName,
|
|
622
613
|
callExpression.arguments.length,
|
|
623
614
|
);
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
methodName,
|
|
630
|
-
type,
|
|
631
|
-
);
|
|
632
|
-
}
|
|
615
|
+
throwIfIncorrectModuleRegistryCallArgument(
|
|
616
|
+
hasteModuleName,
|
|
617
|
+
callExpression.arguments[0],
|
|
618
|
+
methodName,
|
|
619
|
+
);
|
|
633
620
|
const $moduleName = callExpression.arguments[0].value;
|
|
634
621
|
throwIfUntypedModule(
|
|
635
622
|
typeParameters,
|
|
@@ -31,7 +31,7 @@ const {flattenIntersectionType} = require('../parseTopLevelType');
|
|
|
31
31
|
const {flattenProperties} = require('../components/componentsUtils');
|
|
32
32
|
|
|
33
33
|
const {visit, isModuleRegistryCall, verifyPlatforms} = require('../../utils');
|
|
34
|
-
const {resolveTypeAnnotation
|
|
34
|
+
const {resolveTypeAnnotation} = require('../utils');
|
|
35
35
|
|
|
36
36
|
const {
|
|
37
37
|
parseObjectProperty,
|
|
@@ -63,7 +63,6 @@ const {
|
|
|
63
63
|
const {
|
|
64
64
|
UnsupportedGenericParserError,
|
|
65
65
|
UnsupportedTypeAnnotationParserError,
|
|
66
|
-
IncorrectModuleRegistryCallArgumentTypeParserError,
|
|
67
66
|
} = require('../../errors');
|
|
68
67
|
|
|
69
68
|
const {
|
|
@@ -75,6 +74,9 @@ const {
|
|
|
75
74
|
throwIfMoreThanOneModuleRegistryCalls,
|
|
76
75
|
throwIfMoreThanOneModuleInterfaceParserError,
|
|
77
76
|
throwIfIncorrectModuleRegistryCallTypeParameterParserError,
|
|
77
|
+
throwIfIncorrectModuleRegistryCallArgument,
|
|
78
|
+
throwIfPartialNotAnnotatingTypeParameter,
|
|
79
|
+
throwIfPartialWithMoreParameter,
|
|
78
80
|
} = require('../../error-utils');
|
|
79
81
|
|
|
80
82
|
const language = 'TypeScript';
|
|
@@ -243,20 +245,18 @@ function translateTypeAnnotation(
|
|
|
243
245
|
return emitGenericObject(nullable);
|
|
244
246
|
}
|
|
245
247
|
case 'Partial': {
|
|
246
|
-
|
|
247
|
-
throw new Error(
|
|
248
|
-
'Partials only support annotating exactly one parameter.',
|
|
249
|
-
);
|
|
250
|
-
}
|
|
248
|
+
throwIfPartialWithMoreParameter(typeAnnotation);
|
|
251
249
|
|
|
252
|
-
const annotatedElement =
|
|
253
|
-
|
|
250
|
+
const annotatedElement = parser.extractAnnotatedElement(
|
|
251
|
+
typeAnnotation,
|
|
252
|
+
types,
|
|
253
|
+
);
|
|
254
254
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
255
|
+
throwIfPartialNotAnnotatingTypeParameter(
|
|
256
|
+
typeAnnotation,
|
|
257
|
+
types,
|
|
258
|
+
parser,
|
|
259
|
+
);
|
|
260
260
|
|
|
261
261
|
const properties = annotatedElement.typeAnnotation.members.map(
|
|
262
262
|
member => {
|
|
@@ -436,15 +436,6 @@ function translateTypeAnnotation(
|
|
|
436
436
|
}
|
|
437
437
|
}
|
|
438
438
|
|
|
439
|
-
function isModuleInterface(node: $FlowFixMe) {
|
|
440
|
-
return (
|
|
441
|
-
node.type === 'TSInterfaceDeclaration' &&
|
|
442
|
-
node.extends?.length === 1 &&
|
|
443
|
-
node.extends[0].type === 'TSExpressionWithTypeArguments' &&
|
|
444
|
-
node.extends[0].expression.name === 'TurboModule'
|
|
445
|
-
);
|
|
446
|
-
}
|
|
447
|
-
|
|
448
439
|
function buildModuleSchema(
|
|
449
440
|
hasteModuleName: string,
|
|
450
441
|
/**
|
|
@@ -454,9 +445,9 @@ function buildModuleSchema(
|
|
|
454
445
|
tryParse: ParserErrorCapturer,
|
|
455
446
|
parser: Parser,
|
|
456
447
|
): NativeModuleSchema {
|
|
457
|
-
const types = getTypes(ast);
|
|
448
|
+
const types = parser.getTypes(ast);
|
|
458
449
|
const moduleSpecs = (Object.values(types): $ReadOnlyArray<$FlowFixMe>).filter(
|
|
459
|
-
isModuleInterface,
|
|
450
|
+
t => parser.isModuleInterface(t),
|
|
460
451
|
);
|
|
461
452
|
|
|
462
453
|
throwIfModuleInterfaceNotFound(
|
|
@@ -510,15 +501,11 @@ function buildModuleSchema(
|
|
|
510
501
|
callExpression.arguments.length,
|
|
511
502
|
);
|
|
512
503
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
methodName,
|
|
519
|
-
type,
|
|
520
|
-
);
|
|
521
|
-
}
|
|
504
|
+
throwIfIncorrectModuleRegistryCallArgument(
|
|
505
|
+
hasteModuleName,
|
|
506
|
+
callExpression.arguments[0],
|
|
507
|
+
methodName,
|
|
508
|
+
);
|
|
522
509
|
|
|
523
510
|
const $moduleName = callExpression.arguments[0].value;
|
|
524
511
|
|
|
@@ -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;
|
|
@@ -205,6 +205,50 @@ class TypeScriptParser {
|
|
|
205
205
|
};
|
|
206
206
|
});
|
|
207
207
|
}
|
|
208
|
+
isModuleInterface(node) {
|
|
209
|
+
var _node$extends;
|
|
210
|
+
return (
|
|
211
|
+
node.type === 'TSInterfaceDeclaration' &&
|
|
212
|
+
((_node$extends = node.extends) === null || _node$extends === void 0
|
|
213
|
+
? void 0
|
|
214
|
+
: _node$extends.length) === 1 &&
|
|
215
|
+
node.extends[0].type === 'TSExpressionWithTypeArguments' &&
|
|
216
|
+
node.extends[0].expression.name === 'TurboModule'
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
extractAnnotatedElement(typeAnnotation, types) {
|
|
220
|
+
return types[typeAnnotation.typeParameters.params[0].typeName.name];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* TODO(T108222691): Use flow-types for @babel/parser
|
|
225
|
+
*/
|
|
226
|
+
getTypes(ast) {
|
|
227
|
+
return ast.body.reduce((types, node) => {
|
|
228
|
+
switch (node.type) {
|
|
229
|
+
case 'ExportNamedDeclaration': {
|
|
230
|
+
if (node.declaration) {
|
|
231
|
+
switch (node.declaration.type) {
|
|
232
|
+
case 'TSTypeAliasDeclaration':
|
|
233
|
+
case 'TSInterfaceDeclaration':
|
|
234
|
+
case 'TSEnumDeclaration': {
|
|
235
|
+
types[node.declaration.id.name] = node.declaration;
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
case 'TSTypeAliasDeclaration':
|
|
243
|
+
case 'TSInterfaceDeclaration':
|
|
244
|
+
case 'TSEnumDeclaration': {
|
|
245
|
+
types[node.id.name] = node;
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return types;
|
|
250
|
+
}, {});
|
|
251
|
+
}
|
|
208
252
|
}
|
|
209
253
|
module.exports = {
|
|
210
254
|
TypeScriptParser,
|
|
@@ -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] Use flow-types for @babel/parser
|
|
26
27
|
const babelParser = require('@babel/parser');
|
|
@@ -28,7 +29,7 @@ const babelParser = require('@babel/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');
|
|
@@ -192,6 +193,52 @@ class TypeScriptParser implements Parser {
|
|
|
192
193
|
value: member.initializer?.value ?? member.id.name,
|
|
193
194
|
}));
|
|
194
195
|
}
|
|
196
|
+
|
|
197
|
+
isModuleInterface(node: $FlowFixMe): boolean {
|
|
198
|
+
return (
|
|
199
|
+
node.type === 'TSInterfaceDeclaration' &&
|
|
200
|
+
node.extends?.length === 1 &&
|
|
201
|
+
node.extends[0].type === 'TSExpressionWithTypeArguments' &&
|
|
202
|
+
node.extends[0].expression.name === 'TurboModule'
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
extractAnnotatedElement(
|
|
207
|
+
typeAnnotation: $FlowFixMe,
|
|
208
|
+
types: TypeDeclarationMap,
|
|
209
|
+
): $FlowFixMe {
|
|
210
|
+
return types[typeAnnotation.typeParameters.params[0].typeName.name];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* TODO(T108222691): Use flow-types for @babel/parser
|
|
215
|
+
*/
|
|
216
|
+
getTypes(ast: $FlowFixMe): TypeDeclarationMap {
|
|
217
|
+
return ast.body.reduce((types, node) => {
|
|
218
|
+
switch (node.type) {
|
|
219
|
+
case 'ExportNamedDeclaration': {
|
|
220
|
+
if (node.declaration) {
|
|
221
|
+
switch (node.declaration.type) {
|
|
222
|
+
case 'TSTypeAliasDeclaration':
|
|
223
|
+
case 'TSInterfaceDeclaration':
|
|
224
|
+
case 'TSEnumDeclaration': {
|
|
225
|
+
types[node.declaration.id.name] = node.declaration;
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
case 'TSTypeAliasDeclaration':
|
|
233
|
+
case 'TSInterfaceDeclaration':
|
|
234
|
+
case 'TSEnumDeclaration': {
|
|
235
|
+
types[node.id.name] = node;
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return types;
|
|
240
|
+
}, {});
|
|
241
|
+
}
|
|
195
242
|
}
|
|
196
243
|
module.exports = {
|
|
197
244
|
TypeScriptParser,
|
|
@@ -13,36 +13,6 @@
|
|
|
13
13
|
const _require = require('./parseTopLevelType'),
|
|
14
14
|
parseTopLevelType = _require.parseTopLevelType;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* TODO(T108222691): Use flow-types for @babel/parser
|
|
18
|
-
*/
|
|
19
|
-
function getTypes(ast) {
|
|
20
|
-
return ast.body.reduce((types, node) => {
|
|
21
|
-
switch (node.type) {
|
|
22
|
-
case 'ExportNamedDeclaration': {
|
|
23
|
-
if (node.declaration) {
|
|
24
|
-
switch (node.declaration.type) {
|
|
25
|
-
case 'TSTypeAliasDeclaration':
|
|
26
|
-
case 'TSInterfaceDeclaration':
|
|
27
|
-
case 'TSEnumDeclaration': {
|
|
28
|
-
types[node.declaration.id.name] = node.declaration;
|
|
29
|
-
break;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
case 'TSTypeAliasDeclaration':
|
|
36
|
-
case 'TSInterfaceDeclaration':
|
|
37
|
-
case 'TSEnumDeclaration': {
|
|
38
|
-
types[node.id.name] = node;
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return types;
|
|
43
|
-
}, {});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
16
|
// $FlowFixMe[unclear-type] Use flow-types for @babel/parser
|
|
47
17
|
|
|
48
18
|
const invariant = require('invariant');
|
|
@@ -117,5 +87,4 @@ function resolveTypeAnnotation(
|
|
|
117
87
|
}
|
|
118
88
|
module.exports = {
|
|
119
89
|
resolveTypeAnnotation,
|
|
120
|
-
getTypes,
|
|
121
90
|
};
|