@react-native-windows/codegen 0.0.0-canary.13 → 0.0.0-canary.130

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.
Files changed (61) hide show
  1. package/CHANGELOG.md +1125 -16
  2. package/README.md +1 -1
  3. package/bin.js +0 -0
  4. package/lib-commonjs/Cli.d.ts +7 -0
  5. package/lib-commonjs/Cli.js +103 -0
  6. package/lib-commonjs/Cli.js.map +1 -0
  7. package/lib-commonjs/generators/AliasGen.d.ts +12 -0
  8. package/lib-commonjs/generators/AliasGen.js +115 -0
  9. package/lib-commonjs/generators/AliasGen.js.map +1 -0
  10. package/lib-commonjs/generators/AliasManaging.d.ts +15 -0
  11. package/lib-commonjs/generators/AliasManaging.js +49 -0
  12. package/lib-commonjs/generators/AliasManaging.js.map +1 -0
  13. package/lib-commonjs/generators/GenerateComponentWindows.d.ts +13 -0
  14. package/lib-commonjs/generators/GenerateComponentWindows.js +469 -0
  15. package/lib-commonjs/generators/GenerateComponentWindows.js.map +1 -0
  16. package/lib-commonjs/generators/GenerateNM2.d.ts +15 -0
  17. package/lib-commonjs/generators/GenerateNM2.js +145 -0
  18. package/lib-commonjs/generators/GenerateNM2.js.map +1 -0
  19. package/lib-commonjs/generators/GenerateTypeScript.d.ts +11 -0
  20. package/lib-commonjs/generators/GenerateTypeScript.js +166 -0
  21. package/lib-commonjs/generators/GenerateTypeScript.js.map +1 -0
  22. package/lib-commonjs/generators/ObjectTypes.d.ts +13 -0
  23. package/lib-commonjs/generators/ObjectTypes.js +81 -0
  24. package/lib-commonjs/generators/ObjectTypes.js.map +1 -0
  25. package/lib-commonjs/generators/ParamTypes.d.ts +13 -0
  26. package/lib-commonjs/generators/ParamTypes.js +183 -0
  27. package/lib-commonjs/generators/ParamTypes.js.map +1 -0
  28. package/lib-commonjs/generators/PropObjectTypes.d.ts +18 -0
  29. package/lib-commonjs/generators/PropObjectTypes.js +208 -0
  30. package/lib-commonjs/generators/PropObjectTypes.js.map +1 -0
  31. package/lib-commonjs/generators/ReturnTypes.d.ts +10 -0
  32. package/lib-commonjs/generators/ReturnTypes.js +29 -0
  33. package/lib-commonjs/generators/ReturnTypes.js.map +1 -0
  34. package/lib-commonjs/generators/ValidateConstants.d.ts +8 -0
  35. package/lib-commonjs/generators/ValidateConstants.js +38 -0
  36. package/lib-commonjs/generators/ValidateConstants.js.map +1 -0
  37. package/lib-commonjs/generators/ValidateMethods.d.ts +14 -0
  38. package/lib-commonjs/generators/ValidateMethods.js +112 -0
  39. package/lib-commonjs/generators/ValidateMethods.js.map +1 -0
  40. package/lib-commonjs/index.d.ts +39 -0
  41. package/lib-commonjs/index.js +227 -0
  42. package/lib-commonjs/index.js.map +1 -0
  43. package/package.json +39 -21
  44. package/src/Cli.ts +69 -232
  45. package/src/generators/AliasGen.ts +195 -0
  46. package/src/generators/AliasManaging.ts +75 -0
  47. package/src/generators/GenerateComponentWindows.ts +616 -0
  48. package/src/generators/GenerateNM2.ts +128 -131
  49. package/src/generators/GenerateTypeScript.ts +250 -0
  50. package/src/generators/ObjectTypes.ts +95 -37
  51. package/src/generators/ParamTypes.ts +309 -53
  52. package/src/generators/PropObjectTypes.ts +223 -0
  53. package/src/generators/ReturnTypes.ts +38 -40
  54. package/src/generators/ValidateConstants.ts +50 -0
  55. package/src/generators/ValidateMethods.ts +270 -0
  56. package/src/index.ts +415 -0
  57. package/.eslintrc.js +0 -4
  58. package/.vscode/launch.json +0 -23
  59. package/CHANGELOG.json +0 -726
  60. package/jest.config.js +0 -1
  61. package/tsconfig.json +0 -5
@@ -6,31 +6,71 @@
6
6
 
7
7
  'use strict';
8
8
 
9
- import {
9
+ import type {
10
+ NativeModuleEnumDeclaration,
10
11
  NativeModuleBaseTypeAnnotation,
11
- NativeModuleObjectTypeAnnotation,
12
- NamedShape,
12
+ NativeModuleUnionTypeAnnotation,
13
+ NativeModuleStringTypeAnnotation,
14
+ NativeModuleFunctionTypeAnnotation,
15
+ NativeModuleStringLiteralTypeAnnotation,
16
+ StringLiteralUnionTypeAnnotation,
17
+ UnsafeAnyTypeAnnotation,
13
18
  Nullable,
14
- } from 'react-native-tscodegen';
19
+ } from '@react-native/codegen/lib/CodegenSchema';
20
+ import {
21
+ AliasMap,
22
+ getAliasCppName,
23
+ getAnonymousAliasCppName,
24
+ } from './AliasManaging';
15
25
 
16
- let preferredModuleName: string = '';
26
+ export type CppStringTypes = 'std::string' | 'std::wstring';
17
27
 
18
- export function setPreferredModuleName(moduleName: string): void {
19
- preferredModuleName = moduleName;
28
+ export interface CppCodegenOptions {
29
+ cppStringType: CppStringTypes;
20
30
  }
21
31
 
22
- export function getAliasCppName(typeName: string): string {
23
- return `${preferredModuleName}Spec_${typeName}`;
32
+ function translateUnionReturnType(
33
+ type: NativeModuleEnumDeclaration | NativeModuleUnionTypeAnnotation,
34
+ options: CppCodegenOptions,
35
+ ): string {
36
+ const memberType = type.memberType;
37
+ switch (type.memberType) {
38
+ case 'StringTypeAnnotation':
39
+ return options.cppStringType;
40
+ case 'NumberTypeAnnotation':
41
+ return 'double';
42
+ case 'ObjectTypeAnnotation':
43
+ return '::React::JSValue';
44
+ default:
45
+ throw new Error(
46
+ `Unknown enum/union member type in translateReturnType: ${memberType}`,
47
+ );
48
+ }
24
49
  }
25
50
 
26
- function translateField(
27
- type: Nullable<NativeModuleBaseTypeAnnotation>,
51
+ // eslint-disable-next-line complexity
52
+ export function translateFieldOrReturnType(
53
+ type:
54
+ | Nullable<
55
+ | NativeModuleBaseTypeAnnotation
56
+ | NativeModuleStringTypeAnnotation
57
+ | NativeModuleFunctionTypeAnnotation
58
+ | NativeModuleStringLiteralTypeAnnotation
59
+ | StringLiteralUnionTypeAnnotation
60
+ >
61
+ | UnsafeAnyTypeAnnotation,
62
+ aliases: AliasMap,
63
+ baseAliasName: string,
64
+ callerName: 'translateField' | 'translateReturnType',
65
+ options: CppCodegenOptions,
28
66
  ): string {
29
67
  // avoid: Property 'type' does not exist on type 'never'
30
68
  const returnType = type.type;
31
69
  switch (type.type) {
32
70
  case 'StringTypeAnnotation':
33
- return 'std::string';
71
+ case 'StringLiteralTypeAnnotation':
72
+ case 'StringLiteralUnionTypeAnnotation':
73
+ return options.cppStringType;
34
74
  case 'NumberTypeAnnotation':
35
75
  case 'FloatTypeAnnotation':
36
76
  case 'DoubleTypeAnnotation':
@@ -40,46 +80,64 @@ function translateField(
40
80
  case 'BooleanTypeAnnotation':
41
81
  return 'bool';
42
82
  case 'ArrayTypeAnnotation':
43
- // TODO: type.elementType
44
- return 'React::JSValueArray';
83
+ if (type.elementType.type !== 'AnyTypeAnnotation') {
84
+ return `std::vector<${translateFieldOrReturnType(
85
+ type.elementType,
86
+ aliases,
87
+ `${baseAliasName}_element`,
88
+ callerName,
89
+ options,
90
+ )}>`;
91
+ } else {
92
+ return `::React::JSValueArray`;
93
+ }
45
94
  case 'GenericObjectTypeAnnotation':
46
- return 'React::JSValue';
95
+ return '::React::JSValue';
47
96
  case 'ObjectTypeAnnotation':
48
- // TODO: we have more information here, and could create a more specific type
49
- return 'React::JSValueObject';
97
+ return getAnonymousAliasCppName(aliases, baseAliasName, type);
50
98
  case 'ReservedTypeAnnotation': {
51
99
  // avoid: Property 'name' does not exist on type 'never'
52
100
  const name = type.name;
53
101
  // (#6597)
54
102
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
55
103
  if (name !== 'RootTag')
56
- throw new Error(
57
- `Unknown reserved function: ${name} in translateReturnType`,
58
- );
104
+ throw new Error(`Unknown reserved function: ${name} in ${callerName}`);
59
105
  return 'double';
60
106
  }
61
107
  case 'TypeAliasTypeAnnotation':
62
108
  return getAliasCppName(type.name);
63
109
  case 'NullableTypeAnnotation':
64
- return `std::optional<${translateField(type.typeAnnotation)}>`;
110
+ return `std::optional<${translateFieldOrReturnType(
111
+ type.typeAnnotation,
112
+ aliases,
113
+ baseAliasName,
114
+ callerName,
115
+ options,
116
+ )}>`;
117
+ case 'FunctionTypeAnnotation':
118
+ case 'MixedTypeAnnotation':
119
+ return '';
120
+ case 'EnumDeclaration':
121
+ case 'UnionTypeAnnotation':
122
+ return translateUnionReturnType(type, options);
123
+ case 'AnyTypeAnnotation':
124
+ return '::React::JSValue?';
65
125
  default:
66
- throw new Error(`Unhandled type in translateReturnType: ${returnType}`);
126
+ throw new Error(`Unhandled type in ${callerName}: ${returnType}`);
67
127
  }
68
128
  }
69
129
 
70
- export function translateObjectBody(
71
- type: NativeModuleObjectTypeAnnotation,
72
- prefix: string,
73
- ) {
74
- return type.properties
75
- .map((prop: NamedShape<Nullable<NativeModuleBaseTypeAnnotation>>) => {
76
- let propType = prop.typeAnnotation;
77
- if (prop.optional && propType.type !== 'NullableTypeAnnotation') {
78
- propType = {type: 'NullableTypeAnnotation', typeAnnotation: propType};
79
- }
80
- const first = `${prefix}REACT_FIELD(${prop.name})`;
81
- const second = `${prefix}${translateField(propType)} ${prop.name};`;
82
- return `${first}\n${second}`;
83
- })
84
- .join('\n');
130
+ export function translateField(
131
+ type: Nullable<NativeModuleBaseTypeAnnotation>,
132
+ aliases: AliasMap,
133
+ baseAliasName: string,
134
+ options: CppCodegenOptions,
135
+ ): string {
136
+ return translateFieldOrReturnType(
137
+ type,
138
+ aliases,
139
+ baseAliasName,
140
+ 'translateField',
141
+ options,
142
+ );
85
143
  }
@@ -6,12 +6,25 @@
6
6
 
7
7
  'use strict';
8
8
 
9
- import {
9
+ import type {
10
10
  NamedShape,
11
+ NativeModuleArrayTypeAnnotation,
12
+ NativeModuleBaseTypeAnnotation,
13
+ NativeModuleEventEmitterBaseTypeAnnotation,
14
+ NativeModuleEventEmitterTypeAnnotation,
15
+ NativeModuleEnumDeclaration,
16
+ NativeModuleFunctionTypeAnnotation,
11
17
  NativeModuleParamTypeAnnotation,
18
+ NativeModuleUnionTypeAnnotation,
19
+ UnsafeAnyTypeAnnotation,
12
20
  Nullable,
13
- } from 'react-native-tscodegen';
14
- import {getAliasCppName} from './ObjectTypes';
21
+ } from '@react-native/codegen/lib/CodegenSchema';
22
+ import {
23
+ AliasMap,
24
+ getAliasCppName,
25
+ getAnonymousAliasCppName,
26
+ } from './AliasManaging';
27
+ import type {CppCodegenOptions} from './ObjectTypes';
15
28
 
16
29
  type NativeModuleParamShape = NamedShape<
17
30
  Nullable<NativeModuleParamTypeAnnotation>
@@ -30,15 +43,156 @@ function decorateType(type: string, target: ParamTarget): string {
30
43
  }
31
44
  }
32
45
 
46
+ function translateUnionReturnType(
47
+ type: NativeModuleEnumDeclaration | NativeModuleUnionTypeAnnotation,
48
+ target: ParamTarget,
49
+ options: CppCodegenOptions,
50
+ ): string {
51
+ const memberType = type.memberType;
52
+ switch (type.memberType) {
53
+ case 'StringTypeAnnotation':
54
+ return options.cppStringType;
55
+ case 'NumberTypeAnnotation':
56
+ return 'double';
57
+ case 'ObjectTypeAnnotation':
58
+ return decorateType('::React::JSValue', target);
59
+ default:
60
+ throw new Error(
61
+ `Unknown enum/union member type in translateReturnType: ${memberType}`,
62
+ );
63
+ }
64
+ }
65
+
66
+ function translateFunction(
67
+ param: NativeModuleFunctionTypeAnnotation,
68
+ aliases: AliasMap,
69
+ baseAliasName: string,
70
+ target: ParamTarget,
71
+ options: CppCodegenOptions,
72
+ ): string {
73
+ // TODO: type.returnTypeAnnotation
74
+ switch (target) {
75
+ case 'spec':
76
+ return `Callback<${param.params
77
+ .map((p: NativeModuleParamShape) =>
78
+ translateSpecFunctionParam(
79
+ p,
80
+ aliases,
81
+ `${baseAliasName}_${p.name}`,
82
+ options,
83
+ ),
84
+ )
85
+ .join(', ')}>`;
86
+ case 'template':
87
+ return `std::function<void(${param.params
88
+ .map((p: NativeModuleParamShape) =>
89
+ translateCallbackParam(
90
+ p,
91
+ aliases,
92
+ `${baseAliasName}_${p.name}`,
93
+ options,
94
+ ),
95
+ )
96
+ .join(', ')})>`;
97
+ default:
98
+ return `std::function<void(${param.params
99
+ .map((p: NativeModuleParamShape) =>
100
+ translateCallbackParam(
101
+ p,
102
+ aliases,
103
+ `${baseAliasName}_${p.name}`,
104
+ options,
105
+ ),
106
+ )
107
+ .join(', ')})> const &`;
108
+ }
109
+ }
110
+
111
+ function translateArray(
112
+ param: NativeModuleArrayTypeAnnotation<
113
+ Nullable<NativeModuleBaseTypeAnnotation>
114
+ >,
115
+ aliases: AliasMap,
116
+ baseAliasName: string,
117
+ target: ParamTarget,
118
+ options: CppCodegenOptions,
119
+ ): string {
120
+ if (param.elementType.type !== 'AnyTypeAnnotation') {
121
+ switch (target) {
122
+ case 'spec':
123
+ case 'template':
124
+ return `std::vector<${translateNullableParamType(
125
+ param.elementType,
126
+ aliases,
127
+ `${baseAliasName}_element`,
128
+ 'template',
129
+ 'template',
130
+ options,
131
+ )}>`;
132
+ default:
133
+ return `std::vector<${translateNullableParamType(
134
+ param.elementType,
135
+ aliases,
136
+ `${baseAliasName}_element`,
137
+ 'template',
138
+ 'template',
139
+ options,
140
+ )}> const &`;
141
+ }
142
+ } else {
143
+ return decorateType('::React::JSValueArray', target);
144
+ }
145
+ }
146
+
147
+ // Hopefully eventually NativeModuleEventEmitterTypeAnnotation will align better with NativeModuleParamTypeAnnotation
148
+ // and this method can be merged / replaced with translateArray
149
+ function translateEventEmitterArray(
150
+ param: {
151
+ readonly type: 'ArrayTypeAnnotation';
152
+ readonly elementType:
153
+ | NativeModuleEventEmitterBaseTypeAnnotation
154
+ | {type: string};
155
+ },
156
+ aliases: AliasMap,
157
+ baseAliasName: string,
158
+ target: ParamTarget,
159
+ options: CppCodegenOptions,
160
+ ): string {
161
+ switch (target) {
162
+ case 'spec':
163
+ case 'template':
164
+ return `std::vector<${translateEventEmitterParam(
165
+ param.elementType as NativeModuleEventEmitterBaseTypeAnnotation,
166
+ aliases,
167
+ `${baseAliasName}_element`,
168
+ 'template',
169
+ options,
170
+ )}>`;
171
+ default:
172
+ return `std::vector<${translateEventEmitterParam(
173
+ param.elementType as NativeModuleEventEmitterBaseTypeAnnotation,
174
+ aliases,
175
+ `${baseAliasName}_element`,
176
+ 'template',
177
+ options,
178
+ )}> const &`;
179
+ }
180
+ }
181
+
33
182
  function translateParam(
34
- param: NativeModuleParamTypeAnnotation,
183
+ param: NativeModuleParamTypeAnnotation | UnsafeAnyTypeAnnotation,
184
+ aliases: AliasMap,
185
+ baseAliasName: string,
35
186
  target: ParamTarget,
187
+ options: CppCodegenOptions,
36
188
  ): string {
37
189
  // avoid: Property 'type' does not exist on type 'never'
38
190
  const paramType = param.type;
39
191
  switch (param.type) {
40
192
  case 'StringTypeAnnotation':
41
- return 'std::string';
193
+ case 'StringLiteralTypeAnnotation':
194
+ case 'StringLiteralUnionTypeAnnotation':
195
+ return options.cppStringType;
42
196
  case 'NumberTypeAnnotation':
43
197
  case 'FloatTypeAnnotation':
44
198
  case 'DoubleTypeAnnotation':
@@ -47,31 +201,17 @@ function translateParam(
47
201
  return 'int';
48
202
  case 'BooleanTypeAnnotation':
49
203
  return 'bool';
50
- case 'FunctionTypeAnnotation': {
51
- // TODO: type.returnTypeAnnotation
52
- switch (target) {
53
- case 'spec':
54
- return `Callback<${param.params
55
- .map(translateSpecFunctionParam)
56
- .join(', ')}>`;
57
- case 'template':
58
- return `std::function<void(${param.params
59
- .map(translateCallbackParam)
60
- .join(', ')})>`;
61
- default:
62
- return `std::function<void(${param.params
63
- .map(translateCallbackParam)
64
- .join(', ')})> const &`;
65
- }
66
- }
204
+ case 'FunctionTypeAnnotation':
205
+ return translateFunction(param, aliases, baseAliasName, target, options);
67
206
  case 'ArrayTypeAnnotation':
68
- // TODO: type.elementType
69
- return decorateType('React::JSValueArray', target);
207
+ return translateArray(param, aliases, baseAliasName, target, options);
70
208
  case 'GenericObjectTypeAnnotation':
71
- return decorateType('React::JSValue', target);
209
+ return decorateType('::React::JSValue', target);
72
210
  case 'ObjectTypeAnnotation':
73
- // TODO: we have more information here, and could create a more specific type
74
- return decorateType('React::JSValueObject', target);
211
+ return decorateType(
212
+ getAnonymousAliasCppName(aliases, baseAliasName, param),
213
+ target,
214
+ );
75
215
  case 'ReservedTypeAnnotation': {
76
216
  // avoid: Property 'name' does not exist on type 'never'
77
217
  const name = param.name;
@@ -83,59 +223,175 @@ function translateParam(
83
223
  }
84
224
  case 'TypeAliasTypeAnnotation':
85
225
  return decorateType(getAliasCppName(param.name), target);
226
+ case 'MixedTypeAnnotation':
227
+ return '';
228
+ case 'EnumDeclaration':
229
+ case 'UnionTypeAnnotation':
230
+ return translateUnionReturnType(param, target, options);
231
+ case 'AnyTypeAnnotation':
232
+ return decorateType('::React::JSValue', target);
86
233
  default:
87
234
  throw new Error(`Unhandled type in translateParam: ${paramType}`);
88
235
  }
89
236
  }
90
237
 
91
- function translateSpecFunctionParam(param: NativeModuleParamShape): string {
92
- switch (param.typeAnnotation.type) {
93
- case 'NullableTypeAnnotation':
94
- return `std::optional<${translateParam(
95
- param.typeAnnotation.typeAnnotation,
96
- 'spec',
97
- )}>`;
238
+ // Hopefully eventually NativeModuleEventEmitterTypeAnnotation will align better with NativeModuleParamTypeAnnotation
239
+ // and this method can be merged / replaced with translateParam
240
+ function translateEventEmitterParam(
241
+ param: NativeModuleEventEmitterTypeAnnotation,
242
+ aliases: AliasMap,
243
+ baseAliasName: string,
244
+ target: ParamTarget,
245
+ options: CppCodegenOptions,
246
+ ): string {
247
+ // avoid: Property 'type' does not exist on type 'never'
248
+ const paramType = param.type;
249
+ switch (param.type) {
250
+ case 'StringTypeAnnotation':
251
+ return options.cppStringType;
252
+ case 'NumberTypeAnnotation':
253
+ case 'FloatTypeAnnotation':
254
+ case 'DoubleTypeAnnotation':
255
+ return 'double';
256
+ case 'Int32TypeAnnotation':
257
+ return 'int';
258
+ case 'BooleanTypeAnnotation':
259
+ return 'bool';
260
+ case 'ArrayTypeAnnotation':
261
+ return translateEventEmitterArray(
262
+ param,
263
+ aliases,
264
+ baseAliasName,
265
+ target,
266
+ options,
267
+ );
268
+ case 'TypeAliasTypeAnnotation':
269
+ return decorateType(getAliasCppName(param.name), target);
270
+ case 'VoidTypeAnnotation':
271
+ return 'void';
98
272
  default:
99
- return translateParam(param.typeAnnotation, 'spec');
273
+ throw new Error(`Unhandled type in translateParam: ${paramType}`);
100
274
  }
101
275
  }
102
276
 
103
- function translateCallbackParam(param: NativeModuleParamShape): string {
104
- switch (param.typeAnnotation.type) {
277
+ function translateNullableParamType(
278
+ paramType:
279
+ | Nullable<NativeModuleParamTypeAnnotation>
280
+ | UnsafeAnyTypeAnnotation,
281
+ aliases: AliasMap,
282
+ baseAliasName: string,
283
+ nullableTarget: ParamTarget,
284
+ target: ParamTarget,
285
+ options: CppCodegenOptions,
286
+ ): string {
287
+ switch (paramType.type) {
105
288
  case 'NullableTypeAnnotation':
106
289
  return `std::optional<${translateParam(
107
- param.typeAnnotation.typeAnnotation,
108
- 'template',
290
+ paramType.typeAnnotation,
291
+ aliases,
292
+ baseAliasName,
293
+ nullableTarget,
294
+ options,
109
295
  )}>`;
110
296
  default:
111
- return translateParam(param.typeAnnotation, 'callback-arg');
297
+ return translateParam(paramType, aliases, baseAliasName, target, options);
112
298
  }
113
299
  }
114
300
 
115
- function translateFunctionParam(param: NativeModuleParamShape): string {
116
- switch (param.typeAnnotation.type) {
117
- case 'NullableTypeAnnotation':
118
- return `std::optional<${translateParam(
119
- param.typeAnnotation.typeAnnotation,
120
- 'template',
121
- )}>`;
122
- default:
123
- return translateParam(param.typeAnnotation, 'method-arg');
124
- }
301
+ function translateSpecFunctionParam(
302
+ param: NativeModuleParamShape,
303
+ aliases: AliasMap,
304
+ baseAliasName: string,
305
+ options: CppCodegenOptions,
306
+ ): string {
307
+ return translateNullableParamType(
308
+ param.typeAnnotation,
309
+ aliases,
310
+ baseAliasName,
311
+ 'spec',
312
+ 'spec',
313
+ options,
314
+ );
315
+ }
316
+
317
+ function translateCallbackParam(
318
+ param: NativeModuleParamShape,
319
+ aliases: AliasMap,
320
+ baseAliasName: string,
321
+ options: CppCodegenOptions,
322
+ ): string {
323
+ return translateNullableParamType(
324
+ param.typeAnnotation,
325
+ aliases,
326
+ baseAliasName,
327
+ 'template',
328
+ 'callback-arg',
329
+ options,
330
+ );
331
+ }
332
+
333
+ function translateFunctionParam(
334
+ param: NativeModuleParamShape,
335
+ aliases: AliasMap,
336
+ baseAliasName: string,
337
+ options: CppCodegenOptions,
338
+ ): string {
339
+ return translateNullableParamType(
340
+ param.typeAnnotation,
341
+ aliases,
342
+ baseAliasName,
343
+ 'template',
344
+ 'method-arg',
345
+ options,
346
+ );
125
347
  }
126
348
 
127
349
  export function translateSpecArgs(
128
350
  params: ReadonlyArray<NativeModuleParamShape>,
351
+ aliases: AliasMap,
352
+ baseAliasName: string,
353
+ options: CppCodegenOptions,
129
354
  ) {
130
355
  return params.map(param => {
131
- const translatedParam = translateSpecFunctionParam(param);
356
+ const translatedParam = translateSpecFunctionParam(
357
+ param,
358
+ aliases,
359
+ `${baseAliasName}_${param.name}`,
360
+ options,
361
+ );
132
362
  return `${translatedParam}`;
133
363
  });
134
364
  }
135
365
 
136
- export function translateArgs(params: ReadonlyArray<NativeModuleParamShape>) {
366
+ export function translateEventEmitterArgs(
367
+ params: NativeModuleEventEmitterTypeAnnotation,
368
+ aliases: AliasMap,
369
+ baseAliasName: string,
370
+ options: CppCodegenOptions,
371
+ ) {
372
+ const translatedParam = translateEventEmitterParam(
373
+ params,
374
+ aliases,
375
+ baseAliasName,
376
+ 'spec',
377
+ options,
378
+ );
379
+ return `${translatedParam}`;
380
+ }
381
+
382
+ export function translateArgs(
383
+ params: ReadonlyArray<NativeModuleParamShape>,
384
+ aliases: AliasMap,
385
+ baseAliasName: string,
386
+ options: CppCodegenOptions,
387
+ ) {
137
388
  return params.map(param => {
138
- const translatedParam = translateFunctionParam(param);
389
+ const translatedParam = translateFunctionParam(
390
+ param,
391
+ aliases,
392
+ `${baseAliasName}_${param.name}`,
393
+ options,
394
+ );
139
395
  return `${translatedParam} ${param.name}`;
140
396
  });
141
397
  }