@react-native-windows/codegen 0.72.0 → 0.72.2

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 (33) hide show
  1. package/CHANGELOG.md +22 -5
  2. package/lib-commonjs/Cli.js +18 -0
  3. package/lib-commonjs/Cli.js.map +1 -1
  4. package/lib-commonjs/generators/AliasGen.d.ts +2 -1
  5. package/lib-commonjs/generators/AliasGen.js +33 -17
  6. package/lib-commonjs/generators/AliasGen.js.map +1 -1
  7. package/lib-commonjs/generators/GenerateNM2.d.ts +5 -2
  8. package/lib-commonjs/generators/GenerateNM2.js +68 -20
  9. package/lib-commonjs/generators/GenerateNM2.js.map +1 -1
  10. package/lib-commonjs/generators/ObjectTypes.d.ts +6 -2
  11. package/lib-commonjs/generators/ObjectTypes.js +9 -9
  12. package/lib-commonjs/generators/ObjectTypes.js.map +1 -1
  13. package/lib-commonjs/generators/ParamTypes.d.ts +3 -2
  14. package/lib-commonjs/generators/ParamTypes.js +27 -27
  15. package/lib-commonjs/generators/ParamTypes.js.map +1 -1
  16. package/lib-commonjs/generators/ReturnTypes.d.ts +3 -2
  17. package/lib-commonjs/generators/ReturnTypes.js +7 -7
  18. package/lib-commonjs/generators/ReturnTypes.js.map +1 -1
  19. package/lib-commonjs/generators/ValidateMethods.d.ts +2 -1
  20. package/lib-commonjs/generators/ValidateMethods.js +15 -15
  21. package/lib-commonjs/generators/ValidateMethods.js.map +1 -1
  22. package/lib-commonjs/index.d.ts +11 -13
  23. package/lib-commonjs/index.js +8 -4
  24. package/lib-commonjs/index.js.map +1 -1
  25. package/package.json +1 -1
  26. package/src/Cli.ts +24 -2
  27. package/src/generators/AliasGen.ts +61 -17
  28. package/src/generators/GenerateNM2.ts +86 -17
  29. package/src/generators/ObjectTypes.ts +15 -3
  30. package/src/generators/ParamTypes.ts +43 -9
  31. package/src/generators/ReturnTypes.ts +18 -3
  32. package/src/generators/ValidateMethods.ts +32 -4
  33. package/src/index.ts +23 -14
package/src/Cli.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import yargs from 'yargs';
9
- import {runCodeGen} from './index';
9
+ import {CodeGenOptions, runCodeGen} from './index';
10
10
 
11
11
  const argv = yargs.options({
12
12
  file: {
@@ -58,6 +58,17 @@ const argv = yargs.options({
58
58
  required: true,
59
59
  describe: 'Used for part of the path generated within the codegen dir',
60
60
  },
61
+ cppStringType: {
62
+ choices: ['std::string', 'std::wstring'],
63
+ describe:
64
+ 'C++ string type in generated code, should be "std::string" or "std::wstring"',
65
+ default: 'std::string',
66
+ },
67
+ separateDataTypes: {
68
+ type: 'boolean',
69
+ describe: 'generate data types in a separate file',
70
+ default: false,
71
+ },
61
72
  }).argv;
62
73
 
63
74
  if ((argv.file && argv.files) || (!argv.file && !argv.files)) {
@@ -65,7 +76,18 @@ if ((argv.file && argv.files) || (!argv.file && !argv.files)) {
65
76
  process.exit(1);
66
77
  }
67
78
 
68
- const changesNecessary = runCodeGen(argv);
79
+ if (
80
+ argv.cppStringType !== 'std::string' &&
81
+ argv.cppStringType !== 'std::wstring'
82
+ ) {
83
+ console.error('cppStringType should be "std::string" or "std::wstring".');
84
+ process.exit(1);
85
+ }
86
+
87
+ // type casting is necessary here because
88
+ // cppStringType does not become union of string literals
89
+ // until yargs.options get improved in the future
90
+ const changesNecessary = runCodeGen(<CodeGenOptions>argv);
69
91
 
70
92
  if (argv.test && changesNecessary) {
71
93
  console.error(
@@ -13,13 +13,14 @@ import type {
13
13
  Nullable,
14
14
  } from '@react-native/codegen/lib/CodegenSchema';
15
15
  import {AliasMap, getAliasCppName} from './AliasManaging';
16
- import {translateField} from './ObjectTypes';
16
+ import {CppCodegenOptions, translateField} from './ObjectTypes';
17
17
 
18
- function translateObjectBody(
18
+ function translateObjectMembersDefinition(
19
19
  type: NativeModuleObjectTypeAnnotation,
20
20
  aliases: AliasMap,
21
21
  baseAliasName: string,
22
22
  prefix: string,
23
+ options: CppCodegenOptions,
23
24
  ) {
24
25
  return type.properties
25
26
  .map((prop: NamedShape<Nullable<NativeModuleBaseTypeAnnotation>>) => {
@@ -27,13 +28,24 @@ function translateObjectBody(
27
28
  if (prop.optional && propType.type !== 'NullableTypeAnnotation') {
28
29
  propType = {type: 'NullableTypeAnnotation', typeAnnotation: propType};
29
30
  }
30
- const first = `${prefix}REACT_FIELD(${prop.name})`;
31
- const second = `${prefix}${translateField(
31
+ return `${prefix}${translateField(
32
32
  propType,
33
33
  aliases,
34
34
  `${baseAliasName}_${prop.name}`,
35
+ options,
35
36
  )} ${prop.name};`;
36
- return `${first}\n${second}`;
37
+ })
38
+ .join('\n');
39
+ }
40
+
41
+ function translateObjectMembersReflection(
42
+ type: NativeModuleObjectTypeAnnotation,
43
+ aliasCppName: string,
44
+ prefix: string,
45
+ ) {
46
+ return type.properties
47
+ .map((prop: NamedShape<Nullable<NativeModuleBaseTypeAnnotation>>) => {
48
+ return `${prefix}{L"${prop.name}", &${aliasCppName}::${prop.name}},`;
37
49
  })
38
50
  .join('\n');
39
51
  }
@@ -48,28 +60,50 @@ export function createAliasMap(nativeModuleAliases: {
48
60
  return aliases;
49
61
  }
50
62
 
63
+ interface AliasCode {
64
+ definition: string;
65
+ reflection: string;
66
+ }
67
+
51
68
  interface AliasCodeMap {
52
- [name: string]: string;
69
+ [name: string]: AliasCode;
53
70
  }
54
71
 
55
72
  function generateSingleAlias(
56
73
  aliases: AliasMap,
57
74
  aliasName: string,
58
75
  aliasCode: AliasCodeMap,
76
+ options: CppCodegenOptions,
59
77
  ): void {
78
+ const aliasCppName = getAliasCppName(aliasName);
60
79
  const aliasType = <NativeModuleObjectTypeAnnotation>aliases.types[aliasName];
61
- aliasCode[aliasName] = `
62
- REACT_STRUCT(${getAliasCppName(aliasName)})
63
- struct ${getAliasCppName(aliasName)} {
64
- ${translateObjectBody(aliasType, aliases, aliasName, ' ')}
80
+ const definition = `
81
+ struct ${aliasCppName} {
82
+ ${translateObjectMembersDefinition(
83
+ aliasType,
84
+ aliases,
85
+ aliasName,
86
+ ' ',
87
+ options,
88
+ )}
65
89
  };
66
90
  `;
91
+ const reflection = `
92
+ inline winrt::Microsoft::ReactNative::FieldMap GetStructInfo(${aliasCppName}*) noexcept {
93
+ winrt::Microsoft::ReactNative::FieldMap fieldMap {
94
+ ${translateObjectMembersReflection(aliasType, aliasCppName, ' ')}
95
+ };
96
+ return fieldMap;
97
+ }
98
+ `;
99
+ aliasCode[aliasName] = {definition, reflection};
67
100
  }
68
101
 
69
102
  function generateNestedAliasesInCorrectOrder(
70
103
  aliases: AliasMap,
71
104
  aliasCode: AliasCodeMap,
72
105
  aliasOrder: string[],
106
+ options: CppCodegenOptions,
73
107
  ): void {
74
108
  // retrieve and clean all ungenerated aliases
75
109
  const jobs = aliases.jobs;
@@ -80,26 +114,36 @@ function generateNestedAliasesInCorrectOrder(
80
114
  // generate a new struct and all fields will be examined
81
115
  // new anonymous objects could be found
82
116
  // they will be stored in aliases.jobs
83
- generateSingleAlias(aliases, aliasName, aliasCode);
117
+ generateSingleAlias(aliases, aliasName, aliasCode, options);
84
118
  // nested C++ structs must be put before the current C++ struct
85
119
  // as they will be used in the current C++ struct
86
120
  // the order will be perfectly and easily ensured by doing this recursively
87
- generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder);
121
+ generateNestedAliasesInCorrectOrder(
122
+ aliases,
123
+ aliasCode,
124
+ aliasOrder,
125
+ options,
126
+ );
88
127
  // all referenced C++ structs are generated
89
128
  // put the current one following them
90
129
  aliasOrder.push(aliasName);
91
130
  }
92
131
  }
93
132
 
94
- export function generateAliases(aliases: AliasMap): string {
133
+ export function generateAliases(
134
+ aliases: AliasMap,
135
+ options: CppCodegenOptions,
136
+ ): [string, string] {
95
137
  const aliasCode: AliasCodeMap = {};
96
138
  const aliasOrder: string[] = [];
97
- generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder);
139
+ generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder, options);
98
140
 
99
141
  // aliasOrder now has the correct order of C++ struct code
100
- let traversedAliasedStructs = '';
142
+ let customTypes = '';
143
+ let customReflection = '';
101
144
  for (const aliasName of aliasOrder) {
102
- traversedAliasedStructs = `${traversedAliasedStructs}${aliasCode[aliasName]}`;
145
+ customTypes = `${customTypes}${aliasCode[aliasName].definition}`;
146
+ customReflection = `${customReflection}${aliasCode[aliasName].reflection}`;
103
147
  }
104
- return traversedAliasedStructs;
148
+ return [customTypes, customReflection];
105
149
  }
@@ -11,24 +11,22 @@ import {AliasMap, setPreferredModuleName} from './AliasManaging';
11
11
  import {createAliasMap, generateAliases} from './AliasGen';
12
12
  import {generateValidateConstants} from './ValidateConstants';
13
13
  import {generateValidateMethods} from './ValidateMethods';
14
+ import type {CppStringTypes} from './ObjectTypes';
15
+
16
+ export type {CppStringTypes} from './ObjectTypes';
14
17
 
15
18
  type FilesOutput = Map<string, string>;
16
19
 
17
- const moduleTemplate = `
18
- /*
20
+ const headerTemplate = `/*
19
21
  * This file is auto-generated from a NativeModule spec file in js.
20
22
  *
21
23
  * This is a C++ Spec class that should be used with MakeTurboModuleProvider to register native modules
22
24
  * in a way that also verifies at compile time that the native module matches the interface required
23
25
  * by the TurboModule JS spec.
24
26
  */
25
- #pragma once
26
-
27
- #include "NativeModules.h"
28
- #include <tuple>
27
+ #pragma once`;
29
28
 
30
- namespace ::_NAMESPACE_:: {
31
- ::_MODULE_ALIASED_STRUCTS_::
29
+ const specTemplate = `::_MODULE_CUSTPM_TYPES_REFLECTION_::
32
30
  struct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {
33
31
  ::_MODULE_MEMBERS_TUPLES_::
34
32
 
@@ -37,7 +35,44 @@ struct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {
37
35
  ::_MODULE_MEMBERS_CHECKS_::
38
36
 
39
37
  ::_MODULE_MEMBERS_ERRORS_::
40
- }
38
+ }`;
39
+
40
+ const typeOnlyTemplate = `
41
+ ${headerTemplate}
42
+
43
+ #include <string>
44
+ #include <optional>
45
+ #include <functional>
46
+ #include <vector>
47
+
48
+ namespace ::_NAMESPACE_:: {
49
+ ::_MODULE_CUSTPM_TYPES_::
50
+ } // namespace ::_NAMESPACE_::
51
+ `;
52
+
53
+ const moduleOnlyTemplate = `
54
+ ${headerTemplate}
55
+
56
+ ::_TYPE_DEFINITION_INCLUDE_::
57
+ #include <NativeModules.h>
58
+ #include <tuple>
59
+
60
+ namespace ::_NAMESPACE_:: {
61
+ ${specTemplate}
62
+ };
63
+
64
+ } // namespace ::_NAMESPACE_::
65
+ `;
66
+
67
+ const allInOneTemplate = `
68
+ ${headerTemplate}
69
+
70
+ #include <NativeModules.h>
71
+ #include <tuple>
72
+
73
+ namespace ::_NAMESPACE_:: {
74
+ ::_MODULE_CUSTPM_TYPES_::
75
+ ${specTemplate}
41
76
  };
42
77
 
43
78
  } // namespace ::_NAMESPACE_::
@@ -46,9 +81,13 @@ struct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {
46
81
  export function createNM2Generator({
47
82
  methodOnly,
48
83
  namespace,
84
+ cppStringType,
85
+ separateDataTypes,
49
86
  }: {
50
87
  methodOnly: boolean;
51
88
  namespace: string;
89
+ cppStringType: CppStringTypes;
90
+ separateDataTypes: boolean;
52
91
  }) {
53
92
  return (
54
93
  _libraryName: string,
@@ -74,7 +113,9 @@ export function createNM2Generator({
74
113
  const aliases: AliasMap = createAliasMap(nativeModule.aliasMap);
75
114
 
76
115
  // prepare methods
77
- const methods = generateValidateMethods(nativeModule, aliases);
116
+ const methods = generateValidateMethods(nativeModule, aliases, {
117
+ cppStringType,
118
+ });
78
119
  let tuples = `
79
120
  static constexpr auto methods = std::tuple{
80
121
  ${methods[0]}
@@ -98,18 +139,46 @@ ${errors}`;
98
139
  }
99
140
 
100
141
  // generate code for structs
101
- const traversedAliasedStructs = generateAliases(aliases);
142
+ const [customTypes, customReflection] = generateAliases(aliases, {
143
+ cppStringType,
144
+ });
145
+
146
+ const customTypesExist = customTypes !== '';
102
147
 
103
- files.set(
104
- `Native${preferredModuleName}Spec.g.h`,
105
- moduleTemplate
106
- .replace(/::_MODULE_ALIASED_STRUCTS_::/g, traversedAliasedStructs)
148
+ const replaceContent = function (template: string): string {
149
+ return template
150
+ .replace(/::_MODULE_CUSTPM_TYPES_::/g, customTypes)
151
+ .replace(/::_MODULE_CUSTPM_TYPES_REFLECTION_::/g, customReflection)
107
152
  .replace(/::_MODULE_MEMBERS_TUPLES_::/g, tuples.substring(1))
108
153
  .replace(/::_MODULE_MEMBERS_CHECKS_::/g, checks.substring(1))
109
154
  .replace(/::_MODULE_MEMBERS_ERRORS_::/g, errors)
110
155
  .replace(/::_MODULE_NAME_::/g, preferredModuleName)
111
- .replace(/::_NAMESPACE_::/g, namespace),
112
- );
156
+ .replace(
157
+ /::_TYPE_DEFINITION_INCLUDE_::/g,
158
+ customTypesExist
159
+ ? `// #include "Native${preferredModuleName}DataTypes.g.h" before this file to use the generated type definition`
160
+ : '',
161
+ )
162
+ .replace(/::_NAMESPACE_::/g, namespace);
163
+ };
164
+
165
+ if (separateDataTypes) {
166
+ if (customTypesExist) {
167
+ files.set(
168
+ `Native${preferredModuleName}DataTypes.g.h`,
169
+ replaceContent(typeOnlyTemplate),
170
+ );
171
+ }
172
+ files.set(
173
+ `Native${preferredModuleName}Spec.g.h`,
174
+ replaceContent(moduleOnlyTemplate),
175
+ );
176
+ } else {
177
+ files.set(
178
+ `Native${preferredModuleName}Spec.g.h`,
179
+ replaceContent(allInOneTemplate),
180
+ );
181
+ }
113
182
  }
114
183
  }
115
184
 
@@ -18,13 +18,20 @@ import {
18
18
  getAnonymousAliasCppName,
19
19
  } from './AliasManaging';
20
20
 
21
+ export type CppStringTypes = 'std::string' | 'std::wstring';
22
+
23
+ export interface CppCodegenOptions {
24
+ cppStringType: CppStringTypes;
25
+ }
26
+
21
27
  function translateUnionReturnType(
22
28
  type: NativeModuleEnumDeclaration | NativeModuleUnionTypeAnnotation,
29
+ options: CppCodegenOptions,
23
30
  ): string {
24
31
  const memberType = type.memberType;
25
32
  switch (type.memberType) {
26
33
  case 'StringTypeAnnotation':
27
- return 'std::string';
34
+ return options.cppStringType;
28
35
  case 'NumberTypeAnnotation':
29
36
  return 'double';
30
37
  case 'ObjectTypeAnnotation':
@@ -41,12 +48,13 @@ export function translateFieldOrReturnType(
41
48
  aliases: AliasMap,
42
49
  baseAliasName: string,
43
50
  callerName: 'translateField' | 'translateReturnType',
51
+ options: CppCodegenOptions,
44
52
  ): string {
45
53
  // avoid: Property 'type' does not exist on type 'never'
46
54
  const returnType = type.type;
47
55
  switch (type.type) {
48
56
  case 'StringTypeAnnotation':
49
- return 'std::string';
57
+ return options.cppStringType;
50
58
  case 'NumberTypeAnnotation':
51
59
  case 'FloatTypeAnnotation':
52
60
  case 'DoubleTypeAnnotation':
@@ -62,6 +70,7 @@ export function translateFieldOrReturnType(
62
70
  aliases,
63
71
  `${baseAliasName}_element`,
64
72
  callerName,
73
+ options,
65
74
  )}>`;
66
75
  } else {
67
76
  return `::React::JSValueArray`;
@@ -87,10 +96,11 @@ export function translateFieldOrReturnType(
87
96
  aliases,
88
97
  baseAliasName,
89
98
  callerName,
99
+ options,
90
100
  )}>`;
91
101
  case 'EnumDeclaration':
92
102
  case 'UnionTypeAnnotation':
93
- return translateUnionReturnType(type);
103
+ return translateUnionReturnType(type, options);
94
104
  default:
95
105
  throw new Error(`Unhandled type in ${callerName}: ${returnType}`);
96
106
  }
@@ -100,11 +110,13 @@ export function translateField(
100
110
  type: Nullable<NativeModuleBaseTypeAnnotation>,
101
111
  aliases: AliasMap,
102
112
  baseAliasName: string,
113
+ options: CppCodegenOptions,
103
114
  ): string {
104
115
  return translateFieldOrReturnType(
105
116
  type,
106
117
  aliases,
107
118
  baseAliasName,
108
119
  'translateField',
120
+ options,
109
121
  );
110
122
  }
@@ -21,6 +21,7 @@ import {
21
21
  getAliasCppName,
22
22
  getAnonymousAliasCppName,
23
23
  } from './AliasManaging';
24
+ import type {CppCodegenOptions} from './ObjectTypes';
24
25
 
25
26
  type NativeModuleParamShape = NamedShape<
26
27
  Nullable<NativeModuleParamTypeAnnotation>
@@ -42,11 +43,12 @@ function decorateType(type: string, target: ParamTarget): string {
42
43
  function translateUnionReturnType(
43
44
  type: NativeModuleEnumDeclaration | NativeModuleUnionTypeAnnotation,
44
45
  target: ParamTarget,
46
+ options: CppCodegenOptions,
45
47
  ): string {
46
48
  const memberType = type.memberType;
47
49
  switch (type.memberType) {
48
50
  case 'StringTypeAnnotation':
49
- return 'std::string';
51
+ return options.cppStringType;
50
52
  case 'NumberTypeAnnotation':
51
53
  return 'double';
52
54
  case 'ObjectTypeAnnotation':
@@ -63,25 +65,41 @@ function translateFunction(
63
65
  aliases: AliasMap,
64
66
  baseAliasName: string,
65
67
  target: ParamTarget,
68
+ options: CppCodegenOptions,
66
69
  ): string {
67
70
  // TODO: type.returnTypeAnnotation
68
71
  switch (target) {
69
72
  case 'spec':
70
73
  return `Callback<${param.params
71
74
  .map((p: NativeModuleParamShape) =>
72
- translateSpecFunctionParam(p, aliases, `${baseAliasName}_${p.name}`),
75
+ translateSpecFunctionParam(
76
+ p,
77
+ aliases,
78
+ `${baseAliasName}_${p.name}`,
79
+ options,
80
+ ),
73
81
  )
74
82
  .join(', ')}>`;
75
83
  case 'template':
76
84
  return `std::function<void(${param.params
77
85
  .map((p: NativeModuleParamShape) =>
78
- translateCallbackParam(p, aliases, `${baseAliasName}_${p.name}`),
86
+ translateCallbackParam(
87
+ p,
88
+ aliases,
89
+ `${baseAliasName}_${p.name}`,
90
+ options,
91
+ ),
79
92
  )
80
93
  .join(', ')})>`;
81
94
  default:
82
95
  return `std::function<void(${param.params
83
96
  .map((p: NativeModuleParamShape) =>
84
- translateCallbackParam(p, aliases, `${baseAliasName}_${p.name}`),
97
+ translateCallbackParam(
98
+ p,
99
+ aliases,
100
+ `${baseAliasName}_${p.name}`,
101
+ options,
102
+ ),
85
103
  )
86
104
  .join(', ')})> const &`;
87
105
  }
@@ -94,6 +112,7 @@ function translateArray(
94
112
  aliases: AliasMap,
95
113
  baseAliasName: string,
96
114
  target: ParamTarget,
115
+ options: CppCodegenOptions,
97
116
  ): string {
98
117
  if (param.elementType) {
99
118
  switch (target) {
@@ -105,6 +124,7 @@ function translateArray(
105
124
  `${baseAliasName}_element`,
106
125
  'template',
107
126
  'template',
127
+ options,
108
128
  )}>`;
109
129
  default:
110
130
  return `std::vector<${translateNullableParamType(
@@ -113,6 +133,7 @@ function translateArray(
113
133
  `${baseAliasName}_element`,
114
134
  'template',
115
135
  'template',
136
+ options,
116
137
  )}> const &`;
117
138
  }
118
139
  } else {
@@ -125,12 +146,13 @@ function translateParam(
125
146
  aliases: AliasMap,
126
147
  baseAliasName: string,
127
148
  target: ParamTarget,
149
+ options: CppCodegenOptions,
128
150
  ): string {
129
151
  // avoid: Property 'type' does not exist on type 'never'
130
152
  const paramType = param.type;
131
153
  switch (param.type) {
132
154
  case 'StringTypeAnnotation':
133
- return 'std::string';
155
+ return options.cppStringType;
134
156
  case 'NumberTypeAnnotation':
135
157
  case 'FloatTypeAnnotation':
136
158
  case 'DoubleTypeAnnotation':
@@ -140,9 +162,9 @@ function translateParam(
140
162
  case 'BooleanTypeAnnotation':
141
163
  return 'bool';
142
164
  case 'FunctionTypeAnnotation':
143
- return translateFunction(param, aliases, baseAliasName, target);
165
+ return translateFunction(param, aliases, baseAliasName, target, options);
144
166
  case 'ArrayTypeAnnotation':
145
- return translateArray(param, aliases, baseAliasName, target);
167
+ return translateArray(param, aliases, baseAliasName, target, options);
146
168
  case 'GenericObjectTypeAnnotation':
147
169
  return decorateType('::React::JSValue', target);
148
170
  case 'ObjectTypeAnnotation':
@@ -163,7 +185,7 @@ function translateParam(
163
185
  return decorateType(getAliasCppName(param.name), target);
164
186
  case 'EnumDeclaration':
165
187
  case 'UnionTypeAnnotation':
166
- return translateUnionReturnType(param, target);
188
+ return translateUnionReturnType(param, target, options);
167
189
  default:
168
190
  throw new Error(`Unhandled type in translateParam: ${paramType}`);
169
191
  }
@@ -175,6 +197,7 @@ function translateNullableParamType(
175
197
  baseAliasName: string,
176
198
  nullableTarget: ParamTarget,
177
199
  target: ParamTarget,
200
+ options: CppCodegenOptions,
178
201
  ): string {
179
202
  switch (paramType.type) {
180
203
  case 'NullableTypeAnnotation':
@@ -183,9 +206,10 @@ function translateNullableParamType(
183
206
  aliases,
184
207
  baseAliasName,
185
208
  nullableTarget,
209
+ options,
186
210
  )}>`;
187
211
  default:
188
- return translateParam(paramType, aliases, baseAliasName, target);
212
+ return translateParam(paramType, aliases, baseAliasName, target, options);
189
213
  }
190
214
  }
191
215
 
@@ -193,6 +217,7 @@ function translateSpecFunctionParam(
193
217
  param: NativeModuleParamShape,
194
218
  aliases: AliasMap,
195
219
  baseAliasName: string,
220
+ options: CppCodegenOptions,
196
221
  ): string {
197
222
  return translateNullableParamType(
198
223
  param.typeAnnotation,
@@ -200,6 +225,7 @@ function translateSpecFunctionParam(
200
225
  baseAliasName,
201
226
  'spec',
202
227
  'spec',
228
+ options,
203
229
  );
204
230
  }
205
231
 
@@ -207,6 +233,7 @@ function translateCallbackParam(
207
233
  param: NativeModuleParamShape,
208
234
  aliases: AliasMap,
209
235
  baseAliasName: string,
236
+ options: CppCodegenOptions,
210
237
  ): string {
211
238
  return translateNullableParamType(
212
239
  param.typeAnnotation,
@@ -214,6 +241,7 @@ function translateCallbackParam(
214
241
  baseAliasName,
215
242
  'template',
216
243
  'callback-arg',
244
+ options,
217
245
  );
218
246
  }
219
247
 
@@ -221,6 +249,7 @@ function translateFunctionParam(
221
249
  param: NativeModuleParamShape,
222
250
  aliases: AliasMap,
223
251
  baseAliasName: string,
252
+ options: CppCodegenOptions,
224
253
  ): string {
225
254
  return translateNullableParamType(
226
255
  param.typeAnnotation,
@@ -228,6 +257,7 @@ function translateFunctionParam(
228
257
  baseAliasName,
229
258
  'template',
230
259
  'method-arg',
260
+ options,
231
261
  );
232
262
  }
233
263
 
@@ -235,12 +265,14 @@ export function translateSpecArgs(
235
265
  params: ReadonlyArray<NativeModuleParamShape>,
236
266
  aliases: AliasMap,
237
267
  baseAliasName: string,
268
+ options: CppCodegenOptions,
238
269
  ) {
239
270
  return params.map(param => {
240
271
  const translatedParam = translateSpecFunctionParam(
241
272
  param,
242
273
  aliases,
243
274
  `${baseAliasName}_${param.name}`,
275
+ options,
244
276
  );
245
277
  return `${translatedParam}`;
246
278
  });
@@ -250,12 +282,14 @@ export function translateArgs(
250
282
  params: ReadonlyArray<NativeModuleParamShape>,
251
283
  aliases: AliasMap,
252
284
  baseAliasName: string,
285
+ options: CppCodegenOptions,
253
286
  ) {
254
287
  return params.map(param => {
255
288
  const translatedParam = translateFunctionParam(
256
289
  param,
257
290
  aliases,
258
291
  `${baseAliasName}_${param.name}`,
292
+ options,
259
293
  );
260
294
  return `${translatedParam} ${param.name}`;
261
295
  });
@@ -11,12 +11,13 @@ import type {
11
11
  Nullable,
12
12
  } from '@react-native/codegen/lib/CodegenSchema';
13
13
  import {AliasMap} from './AliasManaging';
14
- import {translateFieldOrReturnType} from './ObjectTypes';
14
+ import {CppCodegenOptions, translateFieldOrReturnType} from './ObjectTypes';
15
15
 
16
16
  function translateReturnType(
17
17
  type: Nullable<NativeModuleReturnTypeAnnotation>,
18
18
  aliases: AliasMap,
19
19
  baseAliasName: string,
20
+ options: CppCodegenOptions,
20
21
  ): string {
21
22
  switch (type.type) {
22
23
  case 'VoidTypeAnnotation':
@@ -27,6 +28,7 @@ function translateReturnType(
27
28
  type.typeAnnotation,
28
29
  aliases,
29
30
  baseAliasName,
31
+ options,
30
32
  )}>`;
31
33
  default:
32
34
  return translateFieldOrReturnType(
@@ -34,6 +36,7 @@ function translateReturnType(
34
36
  aliases,
35
37
  baseAliasName,
36
38
  'translateReturnType',
39
+ options,
37
40
  );
38
41
  }
39
42
  }
@@ -42,14 +45,26 @@ export function translateSpecReturnType(
42
45
  type: Nullable<NativeModuleReturnTypeAnnotation>,
43
46
  aliases: AliasMap,
44
47
  baseAliasName: string,
48
+ options: CppCodegenOptions,
45
49
  ) {
46
- return translateReturnType(type, aliases, `${baseAliasName}_returnType`);
50
+ return translateReturnType(
51
+ type,
52
+ aliases,
53
+ `${baseAliasName}_returnType`,
54
+ options,
55
+ );
47
56
  }
48
57
 
49
58
  export function translateImplReturnType(
50
59
  type: Nullable<NativeModuleReturnTypeAnnotation>,
51
60
  aliases: AliasMap,
52
61
  baseAliasName: string,
62
+ options: CppCodegenOptions,
53
63
  ) {
54
- return translateReturnType(type, aliases, `${baseAliasName}_returnType`);
64
+ return translateReturnType(
65
+ type,
66
+ aliases,
67
+ `${baseAliasName}_returnType`,
68
+ options,
69
+ );
55
70
  }