@react-native/codegen 0.73.0 → 0.74.0-nightly-20231003-5dedf277c
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/cli/combine/combine-js-to-schema-cli.js +7 -1
- package/lib/cli/combine/combine-js-to-schema-cli.js.flow +7 -1
- package/lib/generators/components/CppHelpers.js +39 -2
- package/lib/generators/components/CppHelpers.js.flow +54 -5
- package/lib/generators/components/GenerateEventEmitterCpp.js +222 -28
- package/lib/generators/components/GenerateEventEmitterCpp.js.flow +221 -34
- package/lib/generators/components/GenerateEventEmitterH.js +77 -26
- package/lib/generators/components/GenerateEventEmitterH.js.flow +87 -30
- package/lib/generators/components/GeneratePropsH.js +2 -3
- package/lib/generators/components/GeneratePropsH.js.flow +2 -3
- 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 +1 -1
- package/lib/generators/modules/GenerateModuleCpp.js.flow +1 -1
- package/lib/generators/modules/GenerateModuleH.js +44 -39
- package/lib/generators/modules/GenerateModuleH.js.flow +51 -39
- package/lib/generators/modules/GenerateModuleJavaSpec.js +9 -7
- package/lib/generators/modules/GenerateModuleJavaSpec.js.flow +10 -6
- package/lib/generators/modules/GenerateModuleJniH.js +1 -1
- package/lib/generators/modules/GenerateModuleJniH.js.flow +1 -1
- package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js +11 -3
- package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js.flow +13 -3
- package/lib/parsers/error-utils.js +44 -0
- package/lib/parsers/error-utils.js.flow +59 -0
- package/lib/parsers/errors.js +3 -9
- package/lib/parsers/errors.js.flow +3 -9
- 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 +22 -33
- package/lib/parsers/flow/components/componentsUtils.js.flow +24 -45
- package/lib/parsers/flow/components/events.js +151 -128
- package/lib/parsers/flow/components/events.js.flow +161 -136
- package/lib/parsers/flow/components/index.js +13 -94
- package/lib/parsers/flow/components/index.js.flow +5 -102
- package/lib/parsers/flow/modules/index.js +24 -24
- package/lib/parsers/flow/modules/index.js.flow +6 -6
- package/lib/parsers/flow/parser.d.ts +9 -2
- package/lib/parsers/flow/parser.js +179 -18
- package/lib/parsers/flow/parser.js.flow +231 -7
- package/lib/parsers/flow/utils.js +0 -63
- package/lib/parsers/flow/utils.js.flow +1 -77
- package/lib/parsers/parser.js.flow +176 -3
- package/lib/parsers/parserMock.js +202 -4
- package/lib/parsers/parserMock.js.flow +253 -4
- package/lib/parsers/parsers-commons.js +268 -10
- package/lib/parsers/parsers-commons.js.flow +365 -12
- package/lib/parsers/parsers-primitives.js +95 -1
- package/lib/parsers/parsers-primitives.js.flow +136 -1
- 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 +49 -57
- package/lib/parsers/typescript/components/componentsUtils.js.flow +48 -66
- package/lib/parsers/typescript/components/events.js +136 -115
- package/lib/parsers/typescript/components/events.js.flow +148 -119
- 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 +14 -99
- package/lib/parsers/typescript/components/index.js.flow +6 -106
- package/lib/parsers/typescript/modules/index.js +28 -26
- package/lib/parsers/typescript/modules/index.js.flow +9 -8
- package/lib/parsers/typescript/parser.d.ts +9 -2
- package/lib/parsers/typescript/parser.js +208 -14
- package/lib/parsers/typescript/parser.js.flow +247 -8
- package/lib/parsers/utils.js.flow +6 -0
- package/package.json +27 -16
- 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
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ yarn add --dev @react-native/codegen
|
|
|
15
15
|
|
|
16
16
|
## Testing
|
|
17
17
|
|
|
18
|
-
To run the tests in this package, run the following commands from the
|
|
18
|
+
To run the tests in this package, run the following commands from the React Native root folder:
|
|
19
19
|
|
|
20
20
|
1. `yarn` to install the dependencies. You just need to run this once
|
|
21
|
-
2. `yarn jest react-native-codegen`.
|
|
21
|
+
2. `yarn jest packages/react-native-codegen`.
|
package/lib/CodegenSchema.d.ts
CHANGED
|
@@ -50,6 +50,10 @@ export interface ObjectTypeAnnotation<T> {
|
|
|
50
50
|
readonly baseTypes?: readonly string[] | undefined;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
export interface MixedTypeAnnotation {
|
|
54
|
+
readonly type: 'MixedTypeAnnotation';
|
|
55
|
+
}
|
|
56
|
+
|
|
53
57
|
export interface FunctionTypeAnnotation<P, R> {
|
|
54
58
|
readonly type: 'FunctionTypeAnnotation';
|
|
55
59
|
readonly params: readonly NamedShape<P>[];
|
|
@@ -74,6 +78,7 @@ export interface ComponentShape extends OptionsShape {
|
|
|
74
78
|
readonly events: readonly EventTypeShape[];
|
|
75
79
|
readonly props: readonly NamedShape<PropTypeAnnotation>[];
|
|
76
80
|
readonly commands: readonly NamedShape<CommandTypeAnnotation>[];
|
|
81
|
+
readonly deprecatedViewConfigName?: string | undefined;
|
|
77
82
|
}
|
|
78
83
|
|
|
79
84
|
export interface OptionsShape {
|
|
@@ -108,7 +113,11 @@ export type EventTypeAnnotation =
|
|
|
108
113
|
| FloatTypeAnnotation
|
|
109
114
|
| Int32TypeAnnotation
|
|
110
115
|
| StringEnumTypeAnnotation
|
|
111
|
-
| ObjectTypeAnnotation<EventTypeAnnotation
|
|
116
|
+
| ObjectTypeAnnotation<EventTypeAnnotation>
|
|
117
|
+
| {
|
|
118
|
+
readonly type: 'ArrayTypeAnnotation';
|
|
119
|
+
readonly elementType: EventTypeAnnotation
|
|
120
|
+
};
|
|
112
121
|
|
|
113
122
|
export type PropTypeAnnotation =
|
|
114
123
|
| {
|
|
@@ -168,7 +177,8 @@ export type PropTypeAnnotation =
|
|
|
168
177
|
readonly type: 'ArrayTypeAnnotation';
|
|
169
178
|
readonly elementType: ObjectTypeAnnotation<PropTypeAnnotation>;
|
|
170
179
|
};
|
|
171
|
-
}
|
|
180
|
+
}
|
|
181
|
+
| MixedTypeAnnotation;
|
|
172
182
|
|
|
173
183
|
export interface ReservedPropTypeAnnotation {
|
|
174
184
|
readonly type: 'ReservedPropTypeAnnotation';
|
|
@@ -263,7 +273,7 @@ export interface NativeModuleBooleanTypeAnnotation {
|
|
|
263
273
|
|
|
264
274
|
export type NativeModuleEnumMembers = readonly {
|
|
265
275
|
readonly name: string;
|
|
266
|
-
readonly value: string;
|
|
276
|
+
readonly value: string | number;
|
|
267
277
|
}[];
|
|
268
278
|
|
|
269
279
|
export type NativeModuleEnumMemberType =
|
|
@@ -285,6 +295,7 @@ export interface NativeModuleEnumDeclarationWithMembers {
|
|
|
285
295
|
|
|
286
296
|
export interface NativeModuleGenericObjectTypeAnnotation {
|
|
287
297
|
readonly type: 'GenericObjectTypeAnnotation';
|
|
298
|
+
readonly dictionaryValueType?: Nullable<NativeModuleTypeAnnotation> | undefined;
|
|
288
299
|
}
|
|
289
300
|
|
|
290
301
|
export interface NativeModuleTypeAliasTypeAnnotation {
|
|
@@ -343,6 +354,6 @@ export type NativeModuleTypeAnnotation =
|
|
|
343
354
|
export type NativeModuleParamOnlyTypeAnnotation = NativeModuleFunctionTypeAnnotation;
|
|
344
355
|
|
|
345
356
|
export type NativeModuleReturnOnlyTypeAnnotation =
|
|
357
|
+
| NativeModuleFunctionTypeAnnotation
|
|
346
358
|
| NativeModulePromiseTypeAnnotation
|
|
347
359
|
| VoidTypeAnnotation;
|
|
348
|
-
|
|
@@ -126,8 +126,34 @@ export type EventTypeAnnotation =
|
|
|
126
126
|
| DoubleTypeAnnotation
|
|
127
127
|
| FloatTypeAnnotation
|
|
128
128
|
| Int32TypeAnnotation
|
|
129
|
+
| MixedTypeAnnotation
|
|
129
130
|
| StringEnumTypeAnnotation
|
|
130
|
-
| ObjectTypeAnnotation<EventTypeAnnotation
|
|
131
|
+
| ObjectTypeAnnotation<EventTypeAnnotation>
|
|
132
|
+
| $ReadOnly<{
|
|
133
|
+
type: 'ArrayTypeAnnotation',
|
|
134
|
+
elementType: EventTypeAnnotation,
|
|
135
|
+
}>;
|
|
136
|
+
|
|
137
|
+
export type ArrayTypeAnnotation = $ReadOnly<{
|
|
138
|
+
type: 'ArrayTypeAnnotation',
|
|
139
|
+
elementType:
|
|
140
|
+
| BooleanTypeAnnotation
|
|
141
|
+
| StringTypeAnnotation
|
|
142
|
+
| DoubleTypeAnnotation
|
|
143
|
+
| FloatTypeAnnotation
|
|
144
|
+
| Int32TypeAnnotation
|
|
145
|
+
| $ReadOnly<{
|
|
146
|
+
type: 'StringEnumTypeAnnotation',
|
|
147
|
+
default: string,
|
|
148
|
+
options: $ReadOnlyArray<string>,
|
|
149
|
+
}>
|
|
150
|
+
| ObjectTypeAnnotation<PropTypeAnnotation>
|
|
151
|
+
| ReservedPropTypeAnnotation
|
|
152
|
+
| $ReadOnly<{
|
|
153
|
+
type: 'ArrayTypeAnnotation',
|
|
154
|
+
elementType: ObjectTypeAnnotation<PropTypeAnnotation>,
|
|
155
|
+
}>,
|
|
156
|
+
}>;
|
|
131
157
|
|
|
132
158
|
export type PropTypeAnnotation =
|
|
133
159
|
| $ReadOnly<{
|
|
@@ -162,26 +188,7 @@ export type PropTypeAnnotation =
|
|
|
162
188
|
}>
|
|
163
189
|
| ReservedPropTypeAnnotation
|
|
164
190
|
| ObjectTypeAnnotation<PropTypeAnnotation>
|
|
165
|
-
|
|
|
166
|
-
type: 'ArrayTypeAnnotation',
|
|
167
|
-
elementType:
|
|
168
|
-
| BooleanTypeAnnotation
|
|
169
|
-
| StringTypeAnnotation
|
|
170
|
-
| DoubleTypeAnnotation
|
|
171
|
-
| FloatTypeAnnotation
|
|
172
|
-
| Int32TypeAnnotation
|
|
173
|
-
| $ReadOnly<{
|
|
174
|
-
type: 'StringEnumTypeAnnotation',
|
|
175
|
-
default: string,
|
|
176
|
-
options: $ReadOnlyArray<string>,
|
|
177
|
-
}>
|
|
178
|
-
| ObjectTypeAnnotation<PropTypeAnnotation>
|
|
179
|
-
| ReservedPropTypeAnnotation
|
|
180
|
-
| $ReadOnly<{
|
|
181
|
-
type: 'ArrayTypeAnnotation',
|
|
182
|
-
elementType: ObjectTypeAnnotation<PropTypeAnnotation>,
|
|
183
|
-
}>,
|
|
184
|
-
}>
|
|
191
|
+
| ArrayTypeAnnotation
|
|
185
192
|
| MixedTypeAnnotation;
|
|
186
193
|
|
|
187
194
|
export type ReservedPropTypeAnnotation = $ReadOnly<{
|
|
@@ -323,6 +330,11 @@ export type NativeModuleEnumDeclarationWithMembers = {
|
|
|
323
330
|
|
|
324
331
|
export type NativeModuleGenericObjectTypeAnnotation = $ReadOnly<{
|
|
325
332
|
type: 'GenericObjectTypeAnnotation',
|
|
333
|
+
|
|
334
|
+
// a dictionary type is codegen as "Object"
|
|
335
|
+
// but we know all its members are in the same type
|
|
336
|
+
// when it happens, the following field is non-null
|
|
337
|
+
dictionaryValueType?: Nullable<NativeModuleTypeAnnotation>,
|
|
326
338
|
}>;
|
|
327
339
|
|
|
328
340
|
export type NativeModuleTypeAliasTypeAnnotation = $ReadOnly<{
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
const combine = require('./combine-js-to-schema');
|
|
15
15
|
const fs = require('fs');
|
|
16
16
|
const glob = require('glob');
|
|
17
|
+
const path = require('path');
|
|
17
18
|
const _require = require('./combine-utils'),
|
|
18
19
|
parseArgs = _require.parseArgs,
|
|
19
20
|
filterJSFile = _require.filterJSFile;
|
|
@@ -24,9 +25,14 @@ const _parseArgs = parseArgs(process.argv),
|
|
|
24
25
|
const allFiles = [];
|
|
25
26
|
fileList.forEach(file => {
|
|
26
27
|
if (fs.lstatSync(file).isDirectory()) {
|
|
28
|
+
const filePattern = path.sep === '\\' ? file.replace(/\\/g, '/') : file;
|
|
27
29
|
const dirFiles = glob
|
|
28
|
-
.sync(`${
|
|
30
|
+
.sync(`${filePattern}/**/*.{js,ts,tsx}`, {
|
|
29
31
|
nodir: true,
|
|
32
|
+
// TODO: This will remove the need of slash substitution above for Windows,
|
|
33
|
+
// but it requires glob@v9+; with the package currenlty relying on
|
|
34
|
+
// glob@7.1.1; and flow-typed repo not having definitions for glob@9+.
|
|
35
|
+
// windowsPathsNoEscape: true,
|
|
30
36
|
})
|
|
31
37
|
.filter(element => filterJSFile(element, platform));
|
|
32
38
|
allFiles.push(...dirFiles);
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
const combine = require('./combine-js-to-schema');
|
|
15
15
|
const fs = require('fs');
|
|
16
16
|
const glob = require('glob');
|
|
17
|
+
const path = require('path');
|
|
17
18
|
const {parseArgs, filterJSFile} = require('./combine-utils');
|
|
18
19
|
|
|
19
20
|
const {platform, outfile, fileList} = parseArgs(process.argv);
|
|
@@ -21,9 +22,14 @@ const {platform, outfile, fileList} = parseArgs(process.argv);
|
|
|
21
22
|
const allFiles = [];
|
|
22
23
|
fileList.forEach(file => {
|
|
23
24
|
if (fs.lstatSync(file).isDirectory()) {
|
|
25
|
+
const filePattern = path.sep === '\\' ? file.replace(/\\/g, '/') : file;
|
|
24
26
|
const dirFiles = glob
|
|
25
|
-
.sync(`${
|
|
27
|
+
.sync(`${filePattern}/**/*.{js,ts,tsx}`, {
|
|
26
28
|
nodir: true,
|
|
29
|
+
// TODO: This will remove the need of slash substitution above for Windows,
|
|
30
|
+
// but it requires glob@v9+; with the package currenlty relying on
|
|
31
|
+
// glob@7.1.1; and flow-typed repo not having definitions for glob@9+.
|
|
32
|
+
// windowsPathsNoEscape: true,
|
|
27
33
|
})
|
|
28
34
|
.filter(element => filterJSFile(element, platform));
|
|
29
35
|
allFiles.push(...dirFiles);
|
|
@@ -28,11 +28,45 @@ function getCppTypeForAnnotation(type) {
|
|
|
28
28
|
return 'double';
|
|
29
29
|
case 'FloatTypeAnnotation':
|
|
30
30
|
return 'Float';
|
|
31
|
+
case 'MixedTypeAnnotation':
|
|
32
|
+
return 'folly::dynamic';
|
|
31
33
|
default:
|
|
32
34
|
type;
|
|
33
35
|
throw new Error(`Received invalid typeAnnotation ${type}`);
|
|
34
36
|
}
|
|
35
37
|
}
|
|
38
|
+
function getCppArrayTypeForAnnotation(typeElement, structParts) {
|
|
39
|
+
switch (typeElement.type) {
|
|
40
|
+
case 'BooleanTypeAnnotation':
|
|
41
|
+
case 'StringTypeAnnotation':
|
|
42
|
+
case 'DoubleTypeAnnotation':
|
|
43
|
+
case 'FloatTypeAnnotation':
|
|
44
|
+
case 'Int32TypeAnnotation':
|
|
45
|
+
case 'MixedTypeAnnotation':
|
|
46
|
+
return `std::vector<${getCppTypeForAnnotation(typeElement.type)}>`;
|
|
47
|
+
case 'StringEnumTypeAnnotation':
|
|
48
|
+
case 'ObjectTypeAnnotation':
|
|
49
|
+
if (!structParts) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`Trying to generate the event emitter for an Array of ${typeElement.type} without informations to generate the generic type`,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
return `std::vector<${generateEventStructName(structParts)}>`;
|
|
55
|
+
case 'ArrayTypeAnnotation':
|
|
56
|
+
return `std::vector<${getCppArrayTypeForAnnotation(
|
|
57
|
+
typeElement.elementType,
|
|
58
|
+
structParts,
|
|
59
|
+
)}>`;
|
|
60
|
+
default:
|
|
61
|
+
throw new Error(
|
|
62
|
+
`Can't determine array type with typeElement: ${JSON.stringify(
|
|
63
|
+
typeElement,
|
|
64
|
+
null,
|
|
65
|
+
2,
|
|
66
|
+
)}`,
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
36
70
|
function getImports(properties) {
|
|
37
71
|
const imports = new Set();
|
|
38
72
|
function addImportsForNativeName(name) {
|
|
@@ -67,6 +101,9 @@ function getImports(properties) {
|
|
|
67
101
|
) {
|
|
68
102
|
addImportsForNativeName(typeAnnotation.elementType.name);
|
|
69
103
|
}
|
|
104
|
+
if (typeAnnotation.type === 'MixedTypeAnnotation') {
|
|
105
|
+
imports.add('#include <folly/dynamic.h>');
|
|
106
|
+
}
|
|
70
107
|
if (typeAnnotation.type === 'ObjectTypeAnnotation') {
|
|
71
108
|
const objectImports = getImports(typeAnnotation.properties);
|
|
72
109
|
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
@@ -76,8 +113,7 @@ function getImports(properties) {
|
|
|
76
113
|
return imports;
|
|
77
114
|
}
|
|
78
115
|
function generateEventStructName(parts = []) {
|
|
79
|
-
|
|
80
|
-
return `${additional}`;
|
|
116
|
+
return parts.map(toSafeCppString).join('');
|
|
81
117
|
}
|
|
82
118
|
function generateStructName(componentName, parts = []) {
|
|
83
119
|
const additional = parts.map(toSafeCppString).join('');
|
|
@@ -174,6 +210,7 @@ function convertDefaultTypeToString(componentName, prop) {
|
|
|
174
210
|
}
|
|
175
211
|
module.exports = {
|
|
176
212
|
convertDefaultTypeToString,
|
|
213
|
+
getCppArrayTypeForAnnotation,
|
|
177
214
|
getCppTypeForAnnotation,
|
|
178
215
|
getEnumMaskName,
|
|
179
216
|
getImports,
|
|
@@ -9,7 +9,11 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
|
-
import type {
|
|
12
|
+
import type {
|
|
13
|
+
EventTypeAnnotation,
|
|
14
|
+
NamedShape,
|
|
15
|
+
PropTypeAnnotation,
|
|
16
|
+
} from '../../CodegenSchema';
|
|
13
17
|
|
|
14
18
|
const {getEnumName, toSafeCppString} = require('../Utils');
|
|
15
19
|
|
|
@@ -23,7 +27,8 @@ function getCppTypeForAnnotation(
|
|
|
23
27
|
| 'StringTypeAnnotation'
|
|
24
28
|
| 'Int32TypeAnnotation'
|
|
25
29
|
| 'DoubleTypeAnnotation'
|
|
26
|
-
| 'FloatTypeAnnotation'
|
|
30
|
+
| 'FloatTypeAnnotation'
|
|
31
|
+
| 'MixedTypeAnnotation',
|
|
27
32
|
): string {
|
|
28
33
|
switch (type) {
|
|
29
34
|
case 'BooleanTypeAnnotation':
|
|
@@ -36,14 +41,54 @@ function getCppTypeForAnnotation(
|
|
|
36
41
|
return 'double';
|
|
37
42
|
case 'FloatTypeAnnotation':
|
|
38
43
|
return 'Float';
|
|
44
|
+
case 'MixedTypeAnnotation':
|
|
45
|
+
return 'folly::dynamic';
|
|
39
46
|
default:
|
|
40
47
|
(type: empty);
|
|
41
48
|
throw new Error(`Received invalid typeAnnotation ${type}`);
|
|
42
49
|
}
|
|
43
50
|
}
|
|
44
51
|
|
|
52
|
+
function getCppArrayTypeForAnnotation(
|
|
53
|
+
typeElement: EventTypeAnnotation,
|
|
54
|
+
structParts?: string[],
|
|
55
|
+
): string {
|
|
56
|
+
switch (typeElement.type) {
|
|
57
|
+
case 'BooleanTypeAnnotation':
|
|
58
|
+
case 'StringTypeAnnotation':
|
|
59
|
+
case 'DoubleTypeAnnotation':
|
|
60
|
+
case 'FloatTypeAnnotation':
|
|
61
|
+
case 'Int32TypeAnnotation':
|
|
62
|
+
case 'MixedTypeAnnotation':
|
|
63
|
+
return `std::vector<${getCppTypeForAnnotation(typeElement.type)}>`;
|
|
64
|
+
case 'StringEnumTypeAnnotation':
|
|
65
|
+
case 'ObjectTypeAnnotation':
|
|
66
|
+
if (!structParts) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
`Trying to generate the event emitter for an Array of ${typeElement.type} without informations to generate the generic type`,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return `std::vector<${generateEventStructName(structParts)}>`;
|
|
72
|
+
case 'ArrayTypeAnnotation':
|
|
73
|
+
return `std::vector<${getCppArrayTypeForAnnotation(
|
|
74
|
+
typeElement.elementType,
|
|
75
|
+
structParts,
|
|
76
|
+
)}>`;
|
|
77
|
+
default:
|
|
78
|
+
throw new Error(
|
|
79
|
+
`Can't determine array type with typeElement: ${JSON.stringify(
|
|
80
|
+
typeElement,
|
|
81
|
+
null,
|
|
82
|
+
2,
|
|
83
|
+
)}`,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
45
88
|
function getImports(
|
|
46
|
-
properties:
|
|
89
|
+
properties:
|
|
90
|
+
| $ReadOnlyArray<NamedShape<PropTypeAnnotation>>
|
|
91
|
+
| $ReadOnlyArray<NamedShape<EventTypeAnnotation>>,
|
|
47
92
|
): Set<string> {
|
|
48
93
|
const imports: Set<string> = new Set();
|
|
49
94
|
|
|
@@ -91,6 +136,10 @@ function getImports(
|
|
|
91
136
|
addImportsForNativeName(typeAnnotation.elementType.name);
|
|
92
137
|
}
|
|
93
138
|
|
|
139
|
+
if (typeAnnotation.type === 'MixedTypeAnnotation') {
|
|
140
|
+
imports.add('#include <folly/dynamic.h>');
|
|
141
|
+
}
|
|
142
|
+
|
|
94
143
|
if (typeAnnotation.type === 'ObjectTypeAnnotation') {
|
|
95
144
|
const objectImports = getImports(typeAnnotation.properties);
|
|
96
145
|
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
@@ -102,8 +151,7 @@ function getImports(
|
|
|
102
151
|
}
|
|
103
152
|
|
|
104
153
|
function generateEventStructName(parts: $ReadOnlyArray<string> = []): string {
|
|
105
|
-
|
|
106
|
-
return `${additional}`;
|
|
154
|
+
return parts.map(toSafeCppString).join('');
|
|
107
155
|
}
|
|
108
156
|
|
|
109
157
|
function generateStructName(
|
|
@@ -210,6 +258,7 @@ function convertDefaultTypeToString(
|
|
|
210
258
|
|
|
211
259
|
module.exports = {
|
|
212
260
|
convertDefaultTypeToString,
|
|
261
|
+
getCppArrayTypeForAnnotation,
|
|
213
262
|
getCppTypeForAnnotation,
|
|
214
263
|
getEnumMaskName,
|
|
215
264
|
getImports,
|