@react-native/codegen 0.72.5 → 0.73.0-nightly-20230605-5062553c6
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/README.md +2 -2
- package/lib/CodegenSchema.d.ts +15 -4
- package/lib/CodegenSchema.js.flow +33 -21
- package/lib/generators/components/CppHelpers.js +39 -2
- package/lib/generators/components/CppHelpers.js.flow +54 -5
- package/lib/generators/components/GenerateEventEmitterCpp.js +238 -55
- package/lib/generators/components/GenerateEventEmitterCpp.js.flow +233 -55
- package/lib/generators/components/GenerateEventEmitterH.js +77 -28
- package/lib/generators/components/GenerateEventEmitterH.js.flow +87 -32
- package/lib/generators/components/GeneratePropsH.js +1 -2
- package/lib/generators/components/GeneratePropsH.js.flow +1 -2
- package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js +0 -1
- package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js.flow +3 -5
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js +4 -0
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js.flow +4 -0
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js +2 -0
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js.flow +2 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js +114 -1
- package/lib/generators/components/__test_fixtures__/fixtures.js.flow +114 -1
- package/lib/generators/modules/GenerateModuleCpp.js +3 -3
- package/lib/generators/modules/GenerateModuleCpp.js.flow +3 -3
- package/lib/generators/modules/GenerateModuleJavaSpec.js +1 -2
- package/lib/generators/modules/GenerateModuleJavaSpec.js.flow +1 -2
- package/lib/parsers/error-utils.js +44 -0
- package/lib/parsers/error-utils.js.flow +59 -0
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +51 -0
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +51 -0
- package/lib/parsers/flow/components/componentsUtils.js +12 -19
- package/lib/parsers/flow/components/componentsUtils.js.flow +16 -27
- package/lib/parsers/flow/components/events.js +157 -83
- package/lib/parsers/flow/components/events.js.flow +158 -82
- package/lib/parsers/flow/components/index.js +10 -129
- package/lib/parsers/flow/components/index.js.flow +10 -150
- package/lib/parsers/flow/modules/index.js +39 -49
- package/lib/parsers/flow/modules/index.js.flow +22 -31
- package/lib/parsers/flow/parser.d.ts +9 -2
- package/lib/parsers/flow/parser.js +177 -16
- package/lib/parsers/flow/parser.js.flow +220 -6
- package/lib/parsers/flow/utils.js +0 -63
- package/lib/parsers/flow/utils.js.flow +1 -77
- package/lib/parsers/parser.js.flow +143 -1
- package/lib/parsers/parserMock.js +175 -2
- package/lib/parsers/parserMock.js.flow +227 -2
- package/lib/parsers/parsers-commons.js +169 -9
- package/lib/parsers/parsers-commons.js.flow +233 -12
- package/lib/parsers/parsers-primitives.js +94 -35
- package/lib/parsers/parsers-primitives.js.flow +124 -35
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +51 -0
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +51 -0
- package/lib/parsers/typescript/components/componentsUtils.js +44 -46
- package/lib/parsers/typescript/components/componentsUtils.js.flow +44 -51
- package/lib/parsers/typescript/components/events.js +142 -72
- package/lib/parsers/typescript/components/events.js.flow +149 -73
- package/lib/parsers/typescript/components/extends.js +2 -49
- package/lib/parsers/typescript/components/extends.js.flow +1 -55
- package/lib/parsers/typescript/components/index.js +11 -134
- package/lib/parsers/typescript/components/index.js.flow +11 -156
- package/lib/parsers/typescript/modules/index.js +43 -51
- package/lib/parsers/typescript/modules/index.js.flow +25 -32
- package/lib/parsers/typescript/parser.d.ts +9 -2
- package/lib/parsers/typescript/parser.js +224 -7
- package/lib/parsers/typescript/parser.js.flow +262 -6
- package/lib/parsers/utils.js.flow +6 -0
- package/package.json +16 -5
- package/lib/parsers/flow/components/extends.js +0 -52
- package/lib/parsers/flow/components/extends.js.flow +0 -66
- package/lib/parsers/flow/components/props.js +0 -47
- package/lib/parsers/flow/components/props.js.flow +0 -60
- package/lib/parsers/typescript/components/props.js +0 -39
- package/lib/parsers/typescript/components/props.js.flow +0 -48
- package/lib/parsers/typescript/utils.js +0 -90
- package/lib/parsers/typescript/utils.js.flow +0 -104
|
@@ -9,147 +9,18 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
|
-
import type {ExtendsPropsShape} from '../../../CodegenSchema.js';
|
|
13
12
|
import type {Parser} from '../../parser';
|
|
14
|
-
import type {TypeDeclarationMap} from '../../utils';
|
|
15
|
-
import type {CommandOptions} from '../../parsers-commons';
|
|
16
13
|
import type {ComponentSchemaBuilderConfig} from '../../schema.js';
|
|
17
14
|
|
|
18
15
|
const {getCommands} = require('./commands');
|
|
19
16
|
const {getEvents} = require('./events');
|
|
20
17
|
const {categorizeProps} = require('./extends');
|
|
21
|
-
const {getProps} = require('./props');
|
|
22
|
-
const {getProperties} = require('./componentsUtils.js');
|
|
23
|
-
const {throwIfMoreThanOneCodegenNativecommands} = require('../../error-utils');
|
|
24
18
|
const {
|
|
25
|
-
createComponentConfig,
|
|
26
|
-
findNativeComponentType,
|
|
27
|
-
getCommandOptions,
|
|
28
19
|
getOptions,
|
|
20
|
+
findComponentConfig,
|
|
21
|
+
getCommandProperties,
|
|
29
22
|
} = require('../../parsers-commons');
|
|
30
23
|
|
|
31
|
-
// $FlowFixMe[signature-verification-failure] TODO(T108222691): Use flow-types for @babel/parser
|
|
32
|
-
function findComponentConfig(ast: $FlowFixMe, parser: Parser) {
|
|
33
|
-
const foundConfigs: Array<{[string]: string}> = [];
|
|
34
|
-
|
|
35
|
-
const defaultExports = ast.body.filter(
|
|
36
|
-
node => node.type === 'ExportDefaultDeclaration',
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
defaultExports.forEach(statement =>
|
|
40
|
-
findNativeComponentType(statement, foundConfigs, parser),
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
if (foundConfigs.length === 0) {
|
|
44
|
-
throw new Error('Could not find component config for native component');
|
|
45
|
-
}
|
|
46
|
-
if (foundConfigs.length > 1) {
|
|
47
|
-
throw new Error('Only one component is supported per file');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const foundConfig = foundConfigs[0];
|
|
51
|
-
|
|
52
|
-
const namedExports = ast.body.filter(
|
|
53
|
-
node => node.type === 'ExportNamedDeclaration',
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
const commandsTypeNames = namedExports
|
|
57
|
-
.map(statement => {
|
|
58
|
-
let callExpression;
|
|
59
|
-
let calleeName;
|
|
60
|
-
try {
|
|
61
|
-
callExpression = statement.declaration.declarations[0].init;
|
|
62
|
-
calleeName = callExpression.callee.name;
|
|
63
|
-
} catch (e) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (calleeName !== 'codegenNativeCommands') {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// const statement.declaration.declarations[0].init
|
|
72
|
-
if (callExpression.arguments.length !== 1) {
|
|
73
|
-
throw new Error(
|
|
74
|
-
'codegenNativeCommands must be passed options including the supported commands',
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const typeArgumentParam = callExpression.typeParameters.params[0];
|
|
79
|
-
|
|
80
|
-
if (typeArgumentParam.type !== 'TSTypeReference') {
|
|
81
|
-
throw new Error(
|
|
82
|
-
"codegenNativeCommands doesn't support inline definitions. Specify a file local type alias",
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
commandTypeName: typeArgumentParam.typeName.name,
|
|
88
|
-
commandOptionsExpression: callExpression.arguments[0],
|
|
89
|
-
};
|
|
90
|
-
})
|
|
91
|
-
.filter(Boolean);
|
|
92
|
-
|
|
93
|
-
throwIfMoreThanOneCodegenNativecommands(commandsTypeNames);
|
|
94
|
-
|
|
95
|
-
return createComponentConfig(foundConfig, commandsTypeNames);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function getCommandProperties(
|
|
99
|
-
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
|
|
100
|
-
* LTI update could not be added via codemod */
|
|
101
|
-
commandTypeName,
|
|
102
|
-
types: TypeDeclarationMap,
|
|
103
|
-
commandOptions: ?CommandOptions,
|
|
104
|
-
) {
|
|
105
|
-
if (commandTypeName == null) {
|
|
106
|
-
return [];
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const typeAlias = types[commandTypeName];
|
|
110
|
-
|
|
111
|
-
if (typeAlias.type !== 'TSInterfaceDeclaration') {
|
|
112
|
-
throw new Error(
|
|
113
|
-
`The type argument for codegenNativeCommands must be an interface, received ${typeAlias.type}`,
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
let properties;
|
|
118
|
-
try {
|
|
119
|
-
properties = typeAlias.body.body;
|
|
120
|
-
} catch (e) {
|
|
121
|
-
throw new Error(
|
|
122
|
-
`Failed to find type definition for "${commandTypeName}", please check that you have a valid codegen typescript file`,
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const typeScriptPropertyNames = properties
|
|
127
|
-
.map(property => property && property.key && property.key.name)
|
|
128
|
-
.filter(Boolean);
|
|
129
|
-
|
|
130
|
-
if (commandOptions == null || commandOptions.supportedCommands == null) {
|
|
131
|
-
throw new Error(
|
|
132
|
-
'codegenNativeCommands must be given an options object with supportedCommands array',
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (
|
|
137
|
-
commandOptions.supportedCommands.length !==
|
|
138
|
-
typeScriptPropertyNames.length ||
|
|
139
|
-
!commandOptions.supportedCommands.every(supportedCommand =>
|
|
140
|
-
typeScriptPropertyNames.includes(supportedCommand),
|
|
141
|
-
)
|
|
142
|
-
) {
|
|
143
|
-
throw new Error(
|
|
144
|
-
`codegenNativeCommands expected the same supportedCommands specified in the ${commandTypeName} interface: ${typeScriptPropertyNames.join(
|
|
145
|
-
', ',
|
|
146
|
-
)}`,
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return properties;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
24
|
// $FlowFixMe[unclear-type] TODO(T108222691): Use flow-types for @babel/parser
|
|
154
25
|
type PropsAST = Object;
|
|
155
26
|
|
|
@@ -158,39 +29,23 @@ function buildComponentSchema(
|
|
|
158
29
|
ast: $FlowFixMe,
|
|
159
30
|
parser: Parser,
|
|
160
31
|
): ComponentSchemaBuilderConfig {
|
|
161
|
-
const {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
commandOptionsExpression,
|
|
166
|
-
optionsExpression,
|
|
167
|
-
} = findComponentConfig(ast, parser);
|
|
32
|
+
const {componentName, propsTypeName, optionsExpression} = findComponentConfig(
|
|
33
|
+
ast,
|
|
34
|
+
parser,
|
|
35
|
+
);
|
|
168
36
|
|
|
169
37
|
const types = parser.getTypes(ast);
|
|
170
38
|
|
|
171
|
-
const propProperties = getProperties(propsTypeName, types);
|
|
172
|
-
const commandOptions = getCommandOptions(commandOptionsExpression);
|
|
39
|
+
const propProperties = parser.getProperties(propsTypeName, types);
|
|
173
40
|
|
|
174
|
-
const commandProperties = getCommandProperties(
|
|
175
|
-
commandTypeName,
|
|
176
|
-
types,
|
|
177
|
-
commandOptions,
|
|
178
|
-
);
|
|
41
|
+
const commandProperties = getCommandProperties(ast, parser);
|
|
179
42
|
|
|
180
43
|
const options = getOptions(optionsExpression);
|
|
181
44
|
|
|
182
|
-
const extendsProps: Array<ExtendsPropsShape> = [];
|
|
183
|
-
const componentPropAsts: Array<PropsAST> = [];
|
|
184
45
|
const componentEventAsts: Array<PropsAST> = [];
|
|
185
|
-
categorizeProps(
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
extendsProps,
|
|
189
|
-
componentPropAsts,
|
|
190
|
-
componentEventAsts,
|
|
191
|
-
);
|
|
192
|
-
const props = getProps(componentPropAsts, types);
|
|
193
|
-
const events = getEvents(componentEventAsts, types);
|
|
46
|
+
categorizeProps(propProperties, types, componentEventAsts);
|
|
47
|
+
const {props, extendsProps} = parser.getProps(propProperties, types);
|
|
48
|
+
const events = getEvents(componentEventAsts, types, parser);
|
|
194
49
|
const commands = getCommands(commandProperties, types);
|
|
195
50
|
|
|
196
51
|
return {
|
|
@@ -14,30 +14,23 @@ const _require = require('../parseTopLevelType'),
|
|
|
14
14
|
flattenIntersectionType = _require.flattenIntersectionType;
|
|
15
15
|
const _require2 = require('../components/componentsUtils'),
|
|
16
16
|
flattenProperties = _require2.flattenProperties;
|
|
17
|
-
const _require3 = require('
|
|
18
|
-
|
|
19
|
-
const _require4 = require('../../parsers-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
emitUnion = _require5.emitUnion,
|
|
33
|
-
emitCommonTypes = _require5.emitCommonTypes,
|
|
34
|
-
typeAliasResolution = _require5.typeAliasResolution,
|
|
35
|
-
typeEnumResolution = _require5.typeEnumResolution,
|
|
36
|
-
translateArrayTypeAnnotation = _require5.translateArrayTypeAnnotation;
|
|
37
|
-
const _require6 = require('../../errors'),
|
|
38
|
-
UnsupportedGenericParserError = _require6.UnsupportedGenericParserError,
|
|
17
|
+
const _require3 = require('../../parsers-commons'),
|
|
18
|
+
parseObjectProperty = _require3.parseObjectProperty;
|
|
19
|
+
const _require4 = require('../../parsers-primitives'),
|
|
20
|
+
emitArrayType = _require4.emitArrayType,
|
|
21
|
+
emitFunction = _require4.emitFunction,
|
|
22
|
+
emitDictionary = _require4.emitDictionary,
|
|
23
|
+
emitPromise = _require4.emitPromise,
|
|
24
|
+
emitRootTag = _require4.emitRootTag,
|
|
25
|
+
emitUnion = _require4.emitUnion,
|
|
26
|
+
emitCommonTypes = _require4.emitCommonTypes,
|
|
27
|
+
typeAliasResolution = _require4.typeAliasResolution,
|
|
28
|
+
typeEnumResolution = _require4.typeEnumResolution,
|
|
29
|
+
translateArrayTypeAnnotation = _require4.translateArrayTypeAnnotation;
|
|
30
|
+
const _require5 = require('../../errors'),
|
|
31
|
+
UnsupportedGenericParserError = _require5.UnsupportedGenericParserError,
|
|
39
32
|
UnsupportedTypeAnnotationParserError =
|
|
40
|
-
|
|
33
|
+
_require5.UnsupportedTypeAnnotationParserError;
|
|
41
34
|
function translateObjectTypeAnnotation(
|
|
42
35
|
hasteModuleName,
|
|
43
36
|
/**
|
|
@@ -173,13 +166,16 @@ function translateTypeAnnotation(
|
|
|
173
166
|
cxxOnly,
|
|
174
167
|
parser,
|
|
175
168
|
) {
|
|
176
|
-
const
|
|
169
|
+
const _parser$getResolvedTy = parser.getResolvedTypeAnnotation(
|
|
177
170
|
typeScriptTypeAnnotation,
|
|
178
171
|
types,
|
|
172
|
+
parser,
|
|
179
173
|
),
|
|
180
|
-
nullable =
|
|
181
|
-
typeAnnotation =
|
|
182
|
-
typeResolutionStatus =
|
|
174
|
+
nullable = _parser$getResolvedTy.nullable,
|
|
175
|
+
typeAnnotation = _parser$getResolvedTy.typeAnnotation,
|
|
176
|
+
typeResolutionStatus = _parser$getResolvedTy.typeResolutionStatus;
|
|
177
|
+
const resolveTypeaAnnotationFn = parser.getResolveTypeAnnotationFN();
|
|
178
|
+
resolveTypeaAnnotationFn(typeScriptTypeAnnotation, types, parser);
|
|
183
179
|
switch (typeAnnotation.type) {
|
|
184
180
|
case 'TSArrayType': {
|
|
185
181
|
return translateArrayTypeAnnotation(
|
|
@@ -264,7 +260,7 @@ function translateTypeAnnotation(
|
|
|
264
260
|
return translateObjectTypeAnnotation(
|
|
265
261
|
hasteModuleName,
|
|
266
262
|
nullable,
|
|
267
|
-
flattenProperties([typeAnnotation], types),
|
|
263
|
+
flattenProperties([typeAnnotation], types, parser),
|
|
268
264
|
typeResolutionStatus,
|
|
269
265
|
baseTypes,
|
|
270
266
|
types,
|
|
@@ -282,6 +278,7 @@ function translateTypeAnnotation(
|
|
|
282
278
|
flattenProperties(
|
|
283
279
|
flattenIntersectionType(typeAnnotation, types),
|
|
284
280
|
types,
|
|
281
|
+
parser,
|
|
285
282
|
),
|
|
286
283
|
typeResolutionStatus,
|
|
287
284
|
[],
|
|
@@ -303,7 +300,7 @@ function translateTypeAnnotation(
|
|
|
303
300
|
// check the property type to prevent developers from using unsupported types
|
|
304
301
|
// the return value from `translateTypeAnnotation` is unused
|
|
305
302
|
const propertyType = indexSignatures[0].typeAnnotation;
|
|
306
|
-
translateTypeAnnotation(
|
|
303
|
+
const valueType = translateTypeAnnotation(
|
|
307
304
|
hasteModuleName,
|
|
308
305
|
propertyType,
|
|
309
306
|
types,
|
|
@@ -314,7 +311,7 @@ function translateTypeAnnotation(
|
|
|
314
311
|
parser,
|
|
315
312
|
);
|
|
316
313
|
// no need to do further checking
|
|
317
|
-
return
|
|
314
|
+
return emitDictionary(nullable, valueType);
|
|
318
315
|
}
|
|
319
316
|
}
|
|
320
317
|
return translateObjectTypeAnnotation(
|
|
@@ -341,18 +338,6 @@ function translateTypeAnnotation(
|
|
|
341
338
|
parser,
|
|
342
339
|
);
|
|
343
340
|
}
|
|
344
|
-
case 'TSBooleanKeyword': {
|
|
345
|
-
return emitBoolean(nullable);
|
|
346
|
-
}
|
|
347
|
-
case 'TSNumberKeyword': {
|
|
348
|
-
return emitNumber(nullable);
|
|
349
|
-
}
|
|
350
|
-
case 'TSVoidKeyword': {
|
|
351
|
-
return emitVoid(nullable);
|
|
352
|
-
}
|
|
353
|
-
case 'TSStringKeyword': {
|
|
354
|
-
return emitString(nullable);
|
|
355
|
-
}
|
|
356
341
|
case 'TSFunctionType': {
|
|
357
342
|
return emitFunction(
|
|
358
343
|
nullable,
|
|
@@ -370,19 +355,26 @@ function translateTypeAnnotation(
|
|
|
370
355
|
case 'TSUnionType': {
|
|
371
356
|
return emitUnion(nullable, hasteModuleName, typeAnnotation, parser);
|
|
372
357
|
}
|
|
373
|
-
case 'TSUnknownKeyword': {
|
|
374
|
-
if (cxxOnly) {
|
|
375
|
-
return emitMixed(nullable);
|
|
376
|
-
}
|
|
377
|
-
// Fallthrough
|
|
378
|
-
}
|
|
379
|
-
|
|
380
358
|
default: {
|
|
381
|
-
|
|
359
|
+
const commonType = emitCommonTypes(
|
|
382
360
|
hasteModuleName,
|
|
361
|
+
types,
|
|
383
362
|
typeAnnotation,
|
|
384
|
-
|
|
363
|
+
aliasMap,
|
|
364
|
+
enumMap,
|
|
365
|
+
tryParse,
|
|
366
|
+
cxxOnly,
|
|
367
|
+
nullable,
|
|
368
|
+
parser,
|
|
385
369
|
);
|
|
370
|
+
if (!commonType) {
|
|
371
|
+
throw new UnsupportedTypeAnnotationParserError(
|
|
372
|
+
hasteModuleName,
|
|
373
|
+
typeAnnotation,
|
|
374
|
+
parser.language(),
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
return commonType;
|
|
386
378
|
}
|
|
387
379
|
}
|
|
388
380
|
}
|
|
@@ -28,21 +28,14 @@ import type {
|
|
|
28
28
|
const {flattenIntersectionType} = require('../parseTopLevelType');
|
|
29
29
|
const {flattenProperties} = require('../components/componentsUtils');
|
|
30
30
|
|
|
31
|
-
const {resolveTypeAnnotation} = require('../utils');
|
|
32
|
-
|
|
33
31
|
const {parseObjectProperty} = require('../../parsers-commons');
|
|
34
32
|
|
|
35
33
|
const {
|
|
36
34
|
emitArrayType,
|
|
37
|
-
emitBoolean,
|
|
38
35
|
emitFunction,
|
|
39
|
-
|
|
40
|
-
emitGenericObject,
|
|
36
|
+
emitDictionary,
|
|
41
37
|
emitPromise,
|
|
42
38
|
emitRootTag,
|
|
43
|
-
emitVoid,
|
|
44
|
-
emitString,
|
|
45
|
-
emitMixed,
|
|
46
39
|
emitUnion,
|
|
47
40
|
emitCommonTypes,
|
|
48
41
|
typeAliasResolution,
|
|
@@ -195,7 +188,9 @@ function translateTypeAnnotation(
|
|
|
195
188
|
parser: Parser,
|
|
196
189
|
): Nullable<NativeModuleTypeAnnotation> {
|
|
197
190
|
const {nullable, typeAnnotation, typeResolutionStatus} =
|
|
198
|
-
|
|
191
|
+
parser.getResolvedTypeAnnotation(typeScriptTypeAnnotation, types, parser);
|
|
192
|
+
const resolveTypeaAnnotationFn = parser.getResolveTypeAnnotationFN();
|
|
193
|
+
resolveTypeaAnnotationFn(typeScriptTypeAnnotation, types, parser);
|
|
199
194
|
|
|
200
195
|
switch (typeAnnotation.type) {
|
|
201
196
|
case 'TSArrayType': {
|
|
@@ -275,7 +270,7 @@ function translateTypeAnnotation(
|
|
|
275
270
|
return translateObjectTypeAnnotation(
|
|
276
271
|
hasteModuleName,
|
|
277
272
|
nullable,
|
|
278
|
-
flattenProperties([typeAnnotation], types),
|
|
273
|
+
flattenProperties([typeAnnotation], types, parser),
|
|
279
274
|
typeResolutionStatus,
|
|
280
275
|
baseTypes,
|
|
281
276
|
types,
|
|
@@ -293,6 +288,7 @@ function translateTypeAnnotation(
|
|
|
293
288
|
flattenProperties(
|
|
294
289
|
flattenIntersectionType(typeAnnotation, types),
|
|
295
290
|
types,
|
|
291
|
+
parser,
|
|
296
292
|
),
|
|
297
293
|
typeResolutionStatus,
|
|
298
294
|
[],
|
|
@@ -314,7 +310,7 @@ function translateTypeAnnotation(
|
|
|
314
310
|
// check the property type to prevent developers from using unsupported types
|
|
315
311
|
// the return value from `translateTypeAnnotation` is unused
|
|
316
312
|
const propertyType = indexSignatures[0].typeAnnotation;
|
|
317
|
-
translateTypeAnnotation(
|
|
313
|
+
const valueType = translateTypeAnnotation(
|
|
318
314
|
hasteModuleName,
|
|
319
315
|
propertyType,
|
|
320
316
|
types,
|
|
@@ -325,7 +321,7 @@ function translateTypeAnnotation(
|
|
|
325
321
|
parser,
|
|
326
322
|
);
|
|
327
323
|
// no need to do further checking
|
|
328
|
-
return
|
|
324
|
+
return emitDictionary(nullable, valueType);
|
|
329
325
|
}
|
|
330
326
|
}
|
|
331
327
|
|
|
@@ -353,18 +349,6 @@ function translateTypeAnnotation(
|
|
|
353
349
|
parser,
|
|
354
350
|
);
|
|
355
351
|
}
|
|
356
|
-
case 'TSBooleanKeyword': {
|
|
357
|
-
return emitBoolean(nullable);
|
|
358
|
-
}
|
|
359
|
-
case 'TSNumberKeyword': {
|
|
360
|
-
return emitNumber(nullable);
|
|
361
|
-
}
|
|
362
|
-
case 'TSVoidKeyword': {
|
|
363
|
-
return emitVoid(nullable);
|
|
364
|
-
}
|
|
365
|
-
case 'TSStringKeyword': {
|
|
366
|
-
return emitString(nullable);
|
|
367
|
-
}
|
|
368
352
|
case 'TSFunctionType': {
|
|
369
353
|
return emitFunction(
|
|
370
354
|
nullable,
|
|
@@ -382,18 +366,27 @@ function translateTypeAnnotation(
|
|
|
382
366
|
case 'TSUnionType': {
|
|
383
367
|
return emitUnion(nullable, hasteModuleName, typeAnnotation, parser);
|
|
384
368
|
}
|
|
385
|
-
case 'TSUnknownKeyword': {
|
|
386
|
-
if (cxxOnly) {
|
|
387
|
-
return emitMixed(nullable);
|
|
388
|
-
}
|
|
389
|
-
// Fallthrough
|
|
390
|
-
}
|
|
391
369
|
default: {
|
|
392
|
-
|
|
370
|
+
const commonType = emitCommonTypes(
|
|
393
371
|
hasteModuleName,
|
|
372
|
+
types,
|
|
394
373
|
typeAnnotation,
|
|
395
|
-
|
|
374
|
+
aliasMap,
|
|
375
|
+
enumMap,
|
|
376
|
+
tryParse,
|
|
377
|
+
cxxOnly,
|
|
378
|
+
nullable,
|
|
379
|
+
parser,
|
|
396
380
|
);
|
|
381
|
+
|
|
382
|
+
if (!commonType) {
|
|
383
|
+
throw new UnsupportedTypeAnnotationParserError(
|
|
384
|
+
hasteModuleName,
|
|
385
|
+
typeAnnotation,
|
|
386
|
+
parser.language(),
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
return commonType;
|
|
397
390
|
}
|
|
398
391
|
}
|
|
399
392
|
}
|
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type {Parser} from '../parser';
|
|
8
|
+
import type { Parser } from '../parser';
|
|
9
|
+
import type { SchemaType } from '../../CodegenSchema';
|
|
10
|
+
import type { ParserType } from '../errors';
|
|
9
11
|
|
|
10
|
-
export declare class TypeScriptParser implements Parser{
|
|
12
|
+
export declare class TypeScriptParser implements Parser {
|
|
13
|
+
language(): ParserType;
|
|
14
|
+
parseFile(filename: string): SchemaType;
|
|
15
|
+
parseString(contents: string, filename?: string): SchemaType;
|
|
16
|
+
parseModuleFixture(filename: string): SchemaType;
|
|
17
|
+
}
|