@react-native-windows/codegen 0.74.2 → 0.75.0

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/CHANGELOG.md CHANGED
@@ -1,43 +1,175 @@
1
1
  # Change Log - @react-native-windows/codegen
2
2
 
3
- This log was last generated on Mon, 19 Aug 2024 19:09:34 GMT and should not be manually modified.
3
+ This log was last generated on Mon, 19 Aug 2024 20:18:09 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## 0.74.2
7
+ ## 0.75.0
8
8
 
9
- Mon, 19 Aug 2024 19:09:34 GMT
9
+ Mon, 19 Aug 2024 20:18:09 GMT
10
10
 
11
11
  ### Patches
12
12
 
13
- - Promote 0.74 to legacy (tatianakapos@microsoft.com)
14
- - Bump @react-native-windows/fs to v0.74.1
13
+ - Promote 0.75 to latest (tatianakapos@microsoft.com)
14
+ - Bump @react-native-windows/fs to v0.75.0
15
15
 
16
- ## 0.74.1
16
+ ## 0.75.0-preview.1
17
17
 
18
- Mon, 01 Jul 2024 15:16:24 GMT
18
+ Mon, 15 Jul 2024 16:52:21 GMT
19
19
 
20
- ### Patches
20
+ ### Changes
21
+
22
+ - Promote 0.75 to preview (tatianakapos@microsoft.com)
23
+ - Bump @react-native-windows/fs to v0.75.0-preview.1
24
+
25
+ ## 0.0.0-canary.96
26
+
27
+ Fri, 21 Jun 2024 05:17:50 GMT
28
+
29
+ ### Changes
21
30
 
22
31
  - SFI: Component Governance fixes 6/19/24 (jthysell@microsoft.com)
23
32
 
24
- ## 0.74.0
33
+ ## 0.0.0-canary.95
25
34
 
26
- Sat, 27 Apr 2024 21:16:06 GMT
35
+ Wed, 12 Jun 2024 05:16:24 GMT
27
36
 
28
- ### Patches
37
+ ### Changes
38
+
39
+ - Bump @react-native-windows/fs to v0.0.0-canary.52
40
+ - Bump @rnw-scripts/eslint-config to v1.2.23
41
+ - Bump @rnw-scripts/just-task to v2.3.40
42
+
43
+ ## 0.0.0-canary.94
44
+
45
+ Sat, 08 Jun 2024 05:17:57 GMT
46
+
47
+ ### Changes
48
+
49
+ - Bump @react-native-windows/fs to v0.0.0-canary.51
50
+ - Bump @rnw-scripts/eslint-config to v1.2.22
51
+ - Bump @rnw-scripts/just-task to v2.3.39
52
+
53
+ ## 0.0.0-canary.93
54
+
55
+ Wed, 05 Jun 2024 05:18:11 GMT
56
+
57
+ ### Changes
58
+
59
+ - Bump @react-native-windows/fs to v0.0.0-canary.50
60
+ - Bump @rnw-scripts/just-task to v2.3.38
61
+
62
+ ## 0.0.0-canary.92
63
+
64
+ Tue, 04 Jun 2024 05:18:35 GMT
65
+
66
+ ### Changes
67
+
68
+ - Bump @react-native-windows/fs to v0.0.0-canary.49
69
+ - Bump @rnw-scripts/eslint-config to v1.2.21
70
+ - Bump @rnw-scripts/just-task to v2.3.37
71
+
72
+ ## 0.0.0-canary.91
73
+
74
+ Sat, 01 Jun 2024 05:21:31 GMT
75
+
76
+ ### Changes
77
+
78
+ - Bump @react-native-windows/fs to v0.0.0-canary.48
79
+ - Bump @rnw-scripts/eslint-config to v1.2.20
80
+ - Bump @rnw-scripts/just-task to v2.3.36
81
+
82
+ ## 0.0.0-canary.90
83
+
84
+ Thu, 30 May 2024 05:18:25 GMT
85
+
86
+ ### Changes
87
+
88
+ - RN Integration 05/11 (1422161+marlenecota@users.noreply.github.com)
89
+ - Bump @react-native-windows/fs to v0.0.0-canary.47
90
+ - Bump @rnw-scripts/eslint-config to v1.2.19
91
+ - Bump @rnw-scripts/just-task to v2.3.35
92
+
93
+ ## 0.0.0-canary.89
94
+
95
+ Thu, 23 May 2024 05:17:50 GMT
96
+
97
+ ### Changes
98
+
99
+ - Bump @react-native-windows/fs to v0.0.0-canary.46
100
+ - Bump @rnw-scripts/eslint-config to v1.2.18
101
+ - Bump @rnw-scripts/just-task to v2.3.34
102
+
103
+ ## 0.0.0-canary.88
104
+
105
+ Wed, 22 May 2024 05:18:18 GMT
106
+
107
+ ### Changes
108
+
109
+ - Bump @react-native-windows/fs to v0.0.0-canary.45
110
+ - Bump @rnw-scripts/eslint-config to v1.2.17
111
+ - Bump @rnw-scripts/just-task to v2.3.33
112
+
113
+ ## 0.0.0-canary.87
114
+
115
+ Wed, 15 May 2024 05:14:54 GMT
116
+
117
+ ### Changes
118
+
119
+ - Bump @react-native-windows/fs to v0.0.0-canary.44
120
+ - Bump @rnw-scripts/eslint-config to v1.2.16
121
+ - Bump @rnw-scripts/just-task to v2.3.32
122
+
123
+ ## 0.0.0-canary.86
124
+
125
+ Sat, 11 May 2024 05:18:30 GMT
126
+
127
+ ### Changes
128
+
129
+ - Bump @react-native-windows/fs to v0.0.0-canary.43
130
+ - Bump @rnw-scripts/eslint-config to v1.2.15
131
+ - Bump @rnw-scripts/just-task to v2.3.31
132
+
133
+ ## 0.0.0-canary.85
134
+
135
+ Thu, 09 May 2024 05:18:44 GMT
136
+
137
+ ### Changes
138
+
139
+ - Bump @react-native-windows/fs to v0.0.0-canary.42
140
+ - Bump @rnw-scripts/eslint-config to v1.2.14
141
+ - Bump @rnw-scripts/just-task to v2.3.30
142
+
143
+ ## 0.0.0-canary.84
144
+
145
+ Thu, 25 Apr 2024 20:12:42 GMT
146
+
147
+ ### Changes
148
+
149
+ - Fix bad version bump (30809111+acoates-ms@users.noreply.github.com)
150
+ - Bump @react-native-windows/fs to v0.0.0-canary.41
151
+ - Bump @rnw-scripts/eslint-config to v1.2.13
152
+ - Bump @rnw-scripts/just-task to v2.3.29
153
+
154
+ ## 0.0.0-canary.83
155
+
156
+ Wed, 10 Apr 2024 05:18:19 GMT
157
+
158
+ ### Changes
29
159
 
30
- - Promote 0.74 to latest (tatianakapos@microsoft.com)
31
- - Bump @react-native-windows/fs to v0.74.0
160
+ - Bump @react-native-windows/fs to v0.0.0-canary.40
161
+ - Bump @rnw-scripts/eslint-config to v1.2.11
162
+ - Bump @rnw-scripts/just-task to v2.3.27
32
163
 
33
- ## 0.74.0-preview.1
164
+ ## 0.0.0-canary.82
34
165
 
35
- Mon, 08 Apr 2024 15:16:48 GMT
166
+ Sat, 30 Mar 2024 05:18:04 GMT
36
167
 
37
168
  ### Changes
38
169
 
39
- - Promote 0.74 to preview (tatianakapos@microsoft.com)
40
- - Bump @react-native-windows/fs to v0.74.0-preview.1
170
+ - Bump @react-native-windows/fs to v0.0.0-canary.39
171
+ - Bump @rnw-scripts/eslint-config to v1.2.10
172
+ - Bump @rnw-scripts/just-task to v2.3.26
41
173
 
42
174
  ## 0.0.0-canary.81
43
175
 
@@ -34,9 +34,32 @@ function createAliasMap(nativeModuleAliases) {
34
34
  return aliases;
35
35
  }
36
36
  exports.createAliasMap = createAliasMap;
37
- function generateSingleAlias(aliases, aliasName, aliasCode, options) {
37
+ function getArrayTypeName(type) {
38
+ var _a;
39
+ if (type.type === 'ArrayTypeAnnotation' && ((_a = type.elementType) === null || _a === void 0 ? void 0 : _a.type) === 'TypeAliasTypeAnnotation') {
40
+ return type.elementType.name;
41
+ }
42
+ return '';
43
+ }
44
+ function checkTypes(aliases, type, aliasOrder) {
45
+ for (const prop of type.properties) {
46
+ const propType = prop.typeAnnotation;
47
+ let propName = '';
48
+ if (propType.type === 'TypeAliasTypeAnnotation') {
49
+ propName = propType.name;
50
+ }
51
+ if (propType.type === 'ArrayTypeAnnotation') {
52
+ propName = getArrayTypeName(propType);
53
+ }
54
+ if (propName !== '' && !aliasOrder.includes(prop.name) && !aliases.jobs.includes(propName)) {
55
+ aliases.jobs.push(propName);
56
+ }
57
+ }
58
+ }
59
+ function generateSingleAlias(aliases, aliasName, aliasCode, options, aliasOrder) {
38
60
  const aliasCppName = (0, AliasManaging_1.getAliasCppName)(aliasName);
39
61
  const aliasType = aliases.types[aliasName];
62
+ checkTypes(aliases, aliasType, aliasOrder);
40
63
  const definition = `
41
64
  struct ${aliasCppName} {
42
65
  ${translateObjectMembersDefinition(aliasType, aliases, aliasName, ' ', options)}
@@ -61,14 +84,16 @@ function generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder, opt
61
84
  // generate a new struct and all fields will be examined
62
85
  // new anonymous objects could be found
63
86
  // they will be stored in aliases.jobs
64
- generateSingleAlias(aliases, aliasName, aliasCode, options);
87
+ generateSingleAlias(aliases, aliasName, aliasCode, options, aliasOrder);
65
88
  // nested C++ structs must be put before the current C++ struct
66
89
  // as they will be used in the current C++ struct
67
90
  // the order will be perfectly and easily ensured by doing this recursively
68
91
  generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder, options);
69
92
  // all referenced C++ structs are generated
70
93
  // put the current one following them
71
- aliasOrder.push(aliasName);
94
+ if (!aliasOrder.includes(aliasName)) {
95
+ aliasOrder.push(aliasName);
96
+ }
72
97
  }
73
98
  }
74
99
  function generateAliases(aliases, options) {
@@ -1 +1 @@
1
- {"version":3,"file":"AliasGen.js","sourceRoot":"","sources":["../../src/generators/AliasGen.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAQb,mDAA0D;AAC1D,+CAAgE;AAEhE,SAAS,gCAAgC,CACvC,IAAsC,EACtC,OAAiB,EACjB,aAAqB,EACrB,MAAc,EACd,OAA0B;IAE1B,OAAO,IAAI,CAAC,UAAU;SACnB,GAAG,CAAC,CAAC,IAA0D,EAAE,EAAE;QAClE,IAAI,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC;QACnC,IAAI,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,IAAI,KAAK,wBAAwB,EAAE;YAC/D,QAAQ,GAAG,EAAC,IAAI,EAAE,wBAAwB,EAAE,cAAc,EAAE,QAAQ,EAAC,CAAC;SACvE;QACD,OAAO,GAAG,MAAM,GAAG,IAAA,4BAAc,EAC/B,QAAQ,EACR,OAAO,EACP,GAAG,aAAa,IAAI,IAAI,CAAC,IAAI,EAAE,EAC/B,OAAO,CACR,IAAI,IAAI,CAAC,IAAI,GAAG,CAAC;IACpB,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED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6CAA6C;IAC7C,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAC1B,OAAO,CAAC,IAAI,GAAG,EAAE,CAAC;IAElB,uCAAuC;IACvC,KAAK,MAAM,SAAS,IAAI,IAAI,EAAE;QAC5B,wDAAwD;QACxD,uCAAuC;QACvC,sCAAsC;QACtC,mBAAmB,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QAC5D,+DAA+D;QAC/D,iDAAiD;QACjD,2EAA2E;QAC3E,mCAAmC,CACjC,OAAO,EACP,SAAS,EACT,UAAU,EACV,OAAO,CACR,CAAC;QACF,2CAA2C;QAC3C,qCAAqC;QACrC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;KAC5B;AACH,CAAC;AAED,SAAgB,eAAe,CAC7B,OAAiB,EACjB,OAA0B;IAE1B,MAAM,SAAS,GAAiB,EAAE,CAAC;IACnC,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,mCAAmC,CAAC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IAE7E,0DAA0D;IAC1D,IAAI,WAAW,GAAG,EAAE,CAAC;IACrB,IAAI,gBAAgB,GAAG,EAAE,CAAC;IAC1B,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE;QAClC,WAAW,GAAG,GAAG,WAAW,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,CAAC;QACjE,gBAAgB,GAAG,GAAG,gBAAgB,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,CAAC;KAC5E;IACD,OAAO,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAC;AACzC,CAAC;AAhBD,0CAgBC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {\n NativeModuleBaseTypeAnnotation,\n NativeModuleObjectTypeAnnotation,\n NamedShape,\n Nullable,\n} from '@react-native/codegen/lib/CodegenSchema';\nimport {AliasMap, getAliasCppName} from './AliasManaging';\nimport {CppCodegenOptions, translateField} from './ObjectTypes';\n\nfunction translateObjectMembersDefinition(\n type: NativeModuleObjectTypeAnnotation,\n aliases: AliasMap,\n baseAliasName: string,\n prefix: string,\n options: CppCodegenOptions,\n) {\n return type.properties\n .map((prop: NamedShape<Nullable<NativeModuleBaseTypeAnnotation>>) => {\n let propType = prop.typeAnnotation;\n if (prop.optional && propType.type !== 'NullableTypeAnnotation') {\n propType = {type: 'NullableTypeAnnotation', typeAnnotation: propType};\n }\n return `${prefix}${translateField(\n propType,\n aliases,\n `${baseAliasName}_${prop.name}`,\n options,\n )} ${prop.name};`;\n })\n .join('\\n');\n}\n\nfunction translateObjectMembersReflection(\n type: NativeModuleObjectTypeAnnotation,\n aliasCppName: string,\n prefix: string,\n) {\n return type.properties\n .map((prop: NamedShape<Nullable<NativeModuleBaseTypeAnnotation>>) => {\n return `${prefix}{L\"${prop.name}\", &${aliasCppName}::${prop.name}},`;\n })\n .join('\\n');\n}\n\nexport function createAliasMap(nativeModuleAliases: {\n [name: string]: NativeModuleObjectTypeAnnotation;\n}): AliasMap {\n const aliases: AliasMap = {types: {}, jobs: Object.keys(nativeModuleAliases)};\n for (const aliasName of aliases.jobs) {\n aliases.types[aliasName] = nativeModuleAliases[aliasName];\n }\n return aliases;\n}\n\ninterface AliasCode {\n definition: string;\n reflection: string;\n}\n\ninterface AliasCodeMap {\n [name: string]: AliasCode;\n}\n\nfunction generateSingleAlias(\n aliases: AliasMap,\n aliasName: string,\n aliasCode: AliasCodeMap,\n options: CppCodegenOptions,\n): void {\n const aliasCppName = getAliasCppName(aliasName);\n const aliasType = <NativeModuleObjectTypeAnnotation>aliases.types[aliasName];\n const definition = `\nstruct ${aliasCppName} {\n${translateObjectMembersDefinition(\n aliasType,\n aliases,\n aliasName,\n ' ',\n options,\n)}\n};\n`;\n const reflection = `\ninline winrt::Microsoft::ReactNative::FieldMap GetStructInfo(${aliasCppName}*) noexcept {\n winrt::Microsoft::ReactNative::FieldMap fieldMap {\n${translateObjectMembersReflection(aliasType, aliasCppName, ' ')}\n };\n return fieldMap;\n}\n`;\n aliasCode[aliasName] = {definition, reflection};\n}\n\nfunction generateNestedAliasesInCorrectOrder(\n aliases: AliasMap,\n aliasCode: AliasCodeMap,\n aliasOrder: string[],\n options: CppCodegenOptions,\n): void {\n // retrieve and clean all ungenerated aliases\n const jobs = aliases.jobs;\n aliases.jobs = [];\n\n // generate each one in its found order\n for (const aliasName of jobs) {\n // generate a new struct and all fields will be examined\n // new anonymous objects could be found\n // they will be stored in aliases.jobs\n generateSingleAlias(aliases, aliasName, aliasCode, options);\n // nested C++ structs must be put before the current C++ struct\n // as they will be used in the current C++ struct\n // the order will be perfectly and easily ensured by doing this recursively\n generateNestedAliasesInCorrectOrder(\n aliases,\n aliasCode,\n aliasOrder,\n options,\n );\n // all referenced C++ structs are generated\n // put the current one following them\n aliasOrder.push(aliasName);\n }\n}\n\nexport function generateAliases(\n aliases: AliasMap,\n options: CppCodegenOptions,\n): [string, string] {\n const aliasCode: AliasCodeMap = {};\n const aliasOrder: string[] = [];\n generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder, options);\n\n // aliasOrder now has the correct order of C++ struct code\n let customTypes = '';\n let customReflection = '';\n for (const aliasName of aliasOrder) {\n customTypes = `${customTypes}${aliasCode[aliasName].definition}`;\n customReflection = `${customReflection}${aliasCode[aliasName].reflection}`;\n }\n return [customTypes, customReflection];\n}\n"]}
1
+ {"version":3,"file":"AliasGen.js","sourceRoot":"","sources":["../../src/generators/AliasGen.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAQb,mDAA0D;AAC1D,+CAAgE;AAEhE,SAAS,gCAAgC,CACvC,IAAsC,EACtC,OAAiB,EACjB,aAAqB,EACrB,MAAc,EACd,OAA0B;IAE1B,OAAO,IAAI,CAAC,UAAU;SACnB,GAAG,CAAC,CAAC,IAA0D,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S,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,CAAC;KAC5E;IACD,OAAO,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAC;AACzC,CAAC;AAhBD,0CAgBC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {\n NativeModuleBaseTypeAnnotation,\n NativeModuleObjectTypeAnnotation,\n NamedShape,\n Nullable,\n} from '@react-native/codegen/lib/CodegenSchema';\nimport {AliasMap, getAliasCppName} from './AliasManaging';\nimport {CppCodegenOptions, translateField} from './ObjectTypes';\n\nfunction translateObjectMembersDefinition(\n type: NativeModuleObjectTypeAnnotation,\n aliases: AliasMap,\n baseAliasName: string,\n prefix: string,\n options: CppCodegenOptions,\n) {\n return type.properties\n .map((prop: NamedShape<Nullable<NativeModuleBaseTypeAnnotation>>) => {\n let propType = prop.typeAnnotation;\n if (prop.optional && propType.type !== 'NullableTypeAnnotation') {\n propType = {type: 'NullableTypeAnnotation', typeAnnotation: propType};\n }\n return `${prefix}${translateField(\n propType,\n aliases,\n `${baseAliasName}_${prop.name}`,\n options,\n )} ${prop.name};`;\n })\n .join('\\n');\n}\n\nfunction translateObjectMembersReflection(\n type: NativeModuleObjectTypeAnnotation,\n aliasCppName: string,\n prefix: string,\n) {\n return type.properties\n .map((prop: NamedShape<Nullable<NativeModuleBaseTypeAnnotation>>) => {\n return `${prefix}{L\"${prop.name}\", &${aliasCppName}::${prop.name}},`;\n })\n .join('\\n');\n}\n\nexport function createAliasMap(nativeModuleAliases: {\n [name: string]: NativeModuleObjectTypeAnnotation;\n}): AliasMap {\n const aliases: AliasMap = {types: {}, jobs: Object.keys(nativeModuleAliases)};\n for (const aliasName of aliases.jobs) {\n aliases.types[aliasName] = nativeModuleAliases[aliasName];\n }\n return aliases;\n}\n\ninterface AliasCode {\n definition: string;\n reflection: string;\n}\n\ninterface AliasCodeMap {\n [name: string]: AliasCode;\n}\n\nfunction getArrayTypeName(\n type: Nullable<NativeModuleBaseTypeAnnotation>): string {\n if (type.type === 'ArrayTypeAnnotation' && type.elementType?.type === 'TypeAliasTypeAnnotation') {\n return type.elementType.name;\n }\n\n return '';\n}\n\nfunction checkTypes(\n aliases: AliasMap,\n type: NativeModuleObjectTypeAnnotation,\n aliasOrder: string[]): void {\n for (const prop of type.properties) {\n const propType = prop.typeAnnotation;\n let propName = '';\n\n if (propType.type === 'TypeAliasTypeAnnotation') {\n propName = propType.name;\n }\n\n if (propType.type === 'ArrayTypeAnnotation') {\n propName = getArrayTypeName(propType);\n }\n\n if (propName !== '' && !aliasOrder.includes(prop.name) && !aliases.jobs.includes(propName)) {\n aliases.jobs.push(propName);\n }\n }\n}\n\nfunction generateSingleAlias(\n aliases: AliasMap,\n aliasName: string,\n aliasCode: AliasCodeMap,\n options: CppCodegenOptions,\n aliasOrder: string[],\n): void {\n const aliasCppName = getAliasCppName(aliasName);\n const aliasType = <NativeModuleObjectTypeAnnotation>aliases.types[aliasName];\n\n checkTypes(aliases, aliasType, aliasOrder);\n\n const definition = `\nstruct ${aliasCppName} {\n${translateObjectMembersDefinition(\n aliasType,\n aliases,\n aliasName,\n ' ',\n options,\n)}\n};\n`;\n const reflection = `\ninline winrt::Microsoft::ReactNative::FieldMap GetStructInfo(${aliasCppName}*) noexcept {\n winrt::Microsoft::ReactNative::FieldMap fieldMap {\n${translateObjectMembersReflection(aliasType, aliasCppName, ' ')}\n };\n return fieldMap;\n}\n`;\n aliasCode[aliasName] = {definition, reflection};\n}\n\nfunction generateNestedAliasesInCorrectOrder(\n aliases: AliasMap,\n aliasCode: AliasCodeMap,\n aliasOrder: string[],\n options: CppCodegenOptions,\n): void {\n // retrieve and clean all ungenerated aliases\n const jobs = aliases.jobs;\n aliases.jobs = [];\n\n // generate each one in its found order\n for (const aliasName of jobs) {\n // generate a new struct and all fields will be examined\n // new anonymous objects could be found\n // they will be stored in aliases.jobs\n generateSingleAlias(aliases, aliasName, aliasCode, options, aliasOrder);\n // nested C++ structs must be put before the current C++ struct\n // as they will be used in the current C++ struct\n // the order will be perfectly and easily ensured by doing this recursively\n generateNestedAliasesInCorrectOrder(\n aliases,\n aliasCode,\n aliasOrder,\n options,\n );\n // all referenced C++ structs are generated\n // put the current one following them\n if (!aliasOrder.includes(aliasName)) {\n aliasOrder.push(aliasName);\n }\n }\n}\n\nexport function generateAliases(\n aliases: AliasMap,\n options: CppCodegenOptions,\n): [string, string] {\n const aliasCode: AliasCodeMap = {};\n const aliasOrder: string[] = [];\n generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder, options);\n\n // aliasOrder now has the correct order of C++ struct code\n let customTypes = '';\n let customReflection = '';\n for (const aliasName of aliasOrder) {\n customTypes = `${customTypes}${aliasCode[aliasName].definition}`;\n customReflection = `${customReflection}${aliasCode[aliasName].reflection}`;\n }\n return [customTypes, customReflection];\n}\n"]}
@@ -18,7 +18,7 @@ const headerTemplate = `/*
18
18
  * by the TurboModule JS spec.
19
19
  */
20
20
  #pragma once`;
21
- const specTemplate = `::_MODULE_CUSTPM_TYPES_REFLECTION_::
21
+ const specTemplate = `::_MODULE_CUSTOM_TYPES_REFLECTION_::
22
22
  struct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {
23
23
  ::_MODULE_MEMBERS_TUPLES_::
24
24
 
@@ -37,7 +37,7 @@ ${headerTemplate}
37
37
  #include <vector>
38
38
 
39
39
  namespace ::_NAMESPACE_:: {
40
- ::_MODULE_CUSTPM_TYPES_::
40
+ ::_MODULE_CUSTOM_TYPES_::
41
41
  } // namespace ::_NAMESPACE_::
42
42
  `;
43
43
  const moduleOnlyTemplate = `
@@ -60,7 +60,7 @@ ${headerTemplate}
60
60
  #include <tuple>
61
61
 
62
62
  namespace ::_NAMESPACE_:: {
63
- ::_MODULE_CUSTPM_TYPES_::
63
+ ::_MODULE_CUSTOM_TYPES_::
64
64
  ${specTemplate}
65
65
  };
66
66
 
@@ -113,8 +113,8 @@ ${errors}`;
113
113
  const customTypesExist = customTypes !== '';
114
114
  const replaceContent = function (template) {
115
115
  return template
116
- .replace(/::_MODULE_CUSTPM_TYPES_::/g, customTypes)
117
- .replace(/::_MODULE_CUSTPM_TYPES_REFLECTION_::/g, customReflection)
116
+ .replace(/::_MODULE_CUSTOM_TYPES_::/g, customTypes)
117
+ .replace(/::_MODULE_CUSTOM_TYPES_REFLECTION_::/g, customReflection)
118
118
  .replace(/::_MODULE_MEMBERS_TUPLES_::/g, tuples.substring(1))
119
119
  .replace(/::_MODULE_MEMBERS_CHECKS_::/g, checks.substring(1))
120
120
  .replace(/::_MODULE_MEMBERS_ERRORS_::/g, errors)
@@ -1 +1 @@
1
- {"version":3,"file":"GenerateNM2.js","sourceRoot":"","sources":["../../src/generators/GenerateNM2.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAGb,mDAAiE;AACjE,yCAA2D;AAC3D,2DAA8D;AAC9D,uDAA0D;AAO1D,MAAM,cAAc,GAAG;;;;;;;aAOV,CAAC;AAEd,MAAM,YAAY,GAAG;;;;;;;;;IASjB,CAAC;AAEL,MAAM,gBAAgB,GAAG;EACvB,cAAc;;;;;;;;;;CAUf,CAAC;AAEF,MAAM,kBAAkB,GAAG;EACzB,cAAc;;;;;;;EAOd,YAAY;;;;CAIb,CAAC;AAEF,MAAM,gBAAgB,GAAG;EACvB,cAAc;;;;;;;EAOd,YAAY;;;;CAIb,CAAC;AAEF,SAAgB,kBAAkB,CAAC,EACjC,UAAU,EACV,SAAS,EACT,aAAa,EACb,iBAAiB,GAMlB;IACC,OAAO,CACL,YAAoB,EACpB,MAAkB,EAClB,eAAuB,EACV,EAAE;QACf,MAAM,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;QAExC,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE;YACpD,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YA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AAG,WAAW,KAAK,EAAE,CAAC;gBAE5C,MAAM,cAAc,GAAG,UAAU,QAAgB;oBAC/C,OAAO,QAAQ;yBACZ,OAAO,CAAC,4BAA4B,EAAE,WAAW,CAAC;yBAClD,OAAO,CAAC,uCAAuC,EAAE,gBAAgB,CAAC;yBAClE,OAAO,CAAC,8BAA8B,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;yBAC5D,OAAO,CAAC,8BAA8B,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;yBAC5D,OAAO,CAAC,8BAA8B,EAAE,MAAM,CAAC;yBAC/C,OAAO,CAAC,oBAAoB,EAAE,mBAAmB,CAAC;yBAClD,OAAO,CACN,gCAAgC,EAChC,gBAAgB;wBACd,CAAC,CAAC,sBAAsB,mBAAmB,sEAAsE;wBACjH,CAAC,CAAC,EAAE,CACP;yBACA,OAAO,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC;gBAC5C,CAAC,CAAC;gBAEF,IAAI,iBAAiB,EAAE;oBACrB,IAAI,gBAAgB,EAAE;wBACpB,KAAK,CAAC,GAAG,CACP,SAAS,mBAAmB,eAAe,EAC3C,cAAc,CAAC,gBAAgB,CAAC,CACjC,CAAC;qBACH;oBACD,KAAK,CAAC,GAAG,CACP,SAAS,mBAAmB,UAAU,EACtC,cAAc,CAAC,kBAAkB,CAAC,CACnC,CAAC;iBACH;qBAAM;oBACL,KAAK,CAAC,GAAG,CACP,SAAS,mBAAmB,UAAU,EACtC,cAAc,CAAC,gBAAgB,CAAC,CACjC,CAAC;iBACH;aACF;SACF;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AA1GD,gDA0GC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {SchemaType} from '@react-native/codegen/lib/CodegenSchema';\nimport {AliasMap, setPreferredModuleName} from './AliasManaging';\nimport {createAliasMap, generateAliases} from './AliasGen';\nimport {generateValidateConstants} from './ValidateConstants';\nimport {generateValidateMethods} from './ValidateMethods';\nimport type {CppStringTypes} from './ObjectTypes';\n\nexport type {CppStringTypes} from './ObjectTypes';\n\ntype FilesOutput = Map<string, string>;\n\nconst headerTemplate = `/*\n * This file is auto-generated from a NativeModule spec file in js.\n *\n * This is a C++ Spec class that should be used with MakeTurboModuleProvider to register native modules\n * in a way that also verifies at compile time that the native module matches the interface required\n * by the TurboModule JS spec.\n */\n#pragma once`;\n\nconst specTemplate = `::_MODULE_CUSTPM_TYPES_REFLECTION_::\nstruct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {\n::_MODULE_MEMBERS_TUPLES_::\n\n template <class TModule>\n static constexpr void ValidateModule() noexcept {\n::_MODULE_MEMBERS_CHECKS_::\n\n::_MODULE_MEMBERS_ERRORS_::\n }`;\n\nconst typeOnlyTemplate = `\n${headerTemplate}\n\n#include <string>\n#include <optional>\n#include <functional>\n#include <vector>\n\nnamespace ::_NAMESPACE_:: {\n::_MODULE_CUSTPM_TYPES_::\n} // namespace ::_NAMESPACE_::\n`;\n\nconst moduleOnlyTemplate = `\n${headerTemplate}\n\n::_TYPE_DEFINITION_INCLUDE_::\n#include <NativeModules.h>\n#include <tuple>\n\nnamespace ::_NAMESPACE_:: {\n${specTemplate}\n};\n\n} // namespace ::_NAMESPACE_::\n`;\n\nconst allInOneTemplate = `\n${headerTemplate}\n\n#include <NativeModules.h>\n#include <tuple>\n\nnamespace ::_NAMESPACE_:: {\n::_MODULE_CUSTPM_TYPES_::\n${specTemplate}\n};\n\n} // namespace ::_NAMESPACE_::\n`;\n\nexport function createNM2Generator({\n methodOnly,\n namespace,\n cppStringType,\n separateDataTypes,\n}: {\n methodOnly: boolean;\n namespace: string;\n cppStringType: CppStringTypes;\n separateDataTypes: boolean;\n}) {\n return (\n _libraryName: string,\n schema: SchemaType,\n _moduleSpecName: string,\n ): FilesOutput => {\n const files = new Map<string, string>();\n\n for (const moduleName of Object.keys(schema.modules)) {\n const nativeModule = schema.modules[moduleName];\n // from 0.65 facebook's react-native-codegen\n // the module name has the Native prefix comparing to 0.63\n // when reading files we provided\n const preferredModuleName = moduleName.startsWith('Native')\n ? moduleName.substr(6)\n : moduleName;\n setPreferredModuleName(preferredModuleName);\n\n if (nativeModule.type === 'NativeModule') {\n console.log(`Generating Native${preferredModuleName}Spec.g.h`);\n\n // copy all explicit to a map\n const aliases: AliasMap = createAliasMap(nativeModule.aliasMap);\n\n // prepare methods\n const methods = generateValidateMethods(nativeModule, aliases, {\n cppStringType,\n });\n let tuples = `\n static constexpr auto methods = std::tuple{\n${methods[0]}\n };`;\n let checks = `\n constexpr auto methodCheckResults = CheckMethods<TModule, ::_MODULE_NAME_::Spec>();`;\n let errors = methods[1];\n\n // prepare constants\n const constants = generateValidateConstants(nativeModule, aliases);\n if (constants !== undefined && !methodOnly) {\n tuples = `\n static constexpr auto constants = std::tuple{\n${constants[0]}\n };${tuples}`;\n checks = `\n constexpr auto constantCheckResults = CheckConstants<TModule, ::_MODULE_NAME_::Spec>();${checks}`;\n errors = `${constants[1]}\n\n${errors}`;\n }\n\n // generate code for structs\n const [customTypes, customReflection] = generateAliases(aliases, {\n cppStringType,\n });\n\n const customTypesExist = customTypes !== '';\n\n const replaceContent = function (template: string): string {\n return template\n .replace(/::_MODULE_CUSTPM_TYPES_::/g, customTypes)\n .replace(/::_MODULE_CUSTPM_TYPES_REFLECTION_::/g, customReflection)\n .replace(/::_MODULE_MEMBERS_TUPLES_::/g, tuples.substring(1))\n .replace(/::_MODULE_MEMBERS_CHECKS_::/g, checks.substring(1))\n .replace(/::_MODULE_MEMBERS_ERRORS_::/g, errors)\n .replace(/::_MODULE_NAME_::/g, preferredModuleName)\n .replace(\n /::_TYPE_DEFINITION_INCLUDE_::/g,\n customTypesExist\n ? `// #include \"Native${preferredModuleName}DataTypes.g.h\" before this file to use the generated type definition`\n : '',\n )\n .replace(/::_NAMESPACE_::/g, namespace);\n };\n\n if (separateDataTypes) {\n if (customTypesExist) {\n files.set(\n `Native${preferredModuleName}DataTypes.g.h`,\n replaceContent(typeOnlyTemplate),\n );\n }\n files.set(\n `Native${preferredModuleName}Spec.g.h`,\n replaceContent(moduleOnlyTemplate),\n );\n } else {\n files.set(\n `Native${preferredModuleName}Spec.g.h`,\n replaceContent(allInOneTemplate),\n );\n }\n }\n }\n\n return files;\n };\n}\n"]}
1
+ {"version":3,"file":"GenerateNM2.js","sourceRoot":"","sources":["../../src/generators/GenerateNM2.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAGb,mDAAiE;AACjE,yCAA2D;AAC3D,2DAA8D;AAC9D,uDAA0D;AAO1D,MAAM,cAAc,GAAG;;;;;;;aAOV,CAAC;AAEd,MAAM,YAAY,GAAG;;;;;;;;;IASjB,CAAC;AAEL,MAAM,gBAAgB,GAAG;EACvB,cAAc;;;;;;;;;;CAUf,CAAC;AAEF,MAAM,kBAAkB,GAAG;EACzB,cAAc;;;;;;;EAOd,YAAY;;;;CAIb,CAAC;AAEF,MAAM,gBAAgB,GAAG;EACvB,cAAc;;;;;;;EAOd,YAAY;;;;CAIb,CAAC;AAEF,SAAgB,kBAAkB,CAAC,EACjC,UAAU,EACV,SAAS,EACT,aAAa,EACb,iBAAiB,GAMlB;IACC,OAAO,CACL,YAAoB,EACpB,MAAkB,EAClB,eAAuB,EACV,EAAE;QACf,MAAM,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;QAExC,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE;YACpD,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YAChD,4CAA4C;YAC5C,0DAA0D;YAC1D,iCAAiC;YACjC,MAAM,mBAAmB,GAAG,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC;gBACzD,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,C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AC,uCAAuC,EAAE,gBAAgB,CAAC;yBAClE,OAAO,CAAC,8BAA8B,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;yBAC5D,OAAO,CAAC,8BAA8B,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;yBAC5D,OAAO,CAAC,8BAA8B,EAAE,MAAM,CAAC;yBAC/C,OAAO,CAAC,oBAAoB,EAAE,mBAAmB,CAAC;yBAClD,OAAO,CACN,gCAAgC,EAChC,gBAAgB;wBACd,CAAC,CAAC,sBAAsB,mBAAmB,sEAAsE;wBACjH,CAAC,CAAC,EAAE,CACP;yBACA,OAAO,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC;gBAC5C,CAAC,CAAC;gBAEF,IAAI,iBAAiB,EAAE;oBACrB,IAAI,gBAAgB,EAAE;wBACpB,KAAK,CAAC,GAAG,CACP,SAAS,mBAAmB,eAAe,EAC3C,cAAc,CAAC,gBAAgB,CAAC,CACjC,CAAC;qBACH;oBACD,KAAK,CAAC,GAAG,CACP,SAAS,mBAAmB,UAAU,EACtC,cAAc,CAAC,kBAAkB,CAAC,CACnC,CAAC;iBACH;qBAAM;oBACL,KAAK,CAAC,GAAG,CACP,SAAS,mBAAmB,UAAU,EACtC,cAAc,CAAC,gBAAgB,CAAC,CACjC,CAAC;iBACH;aACF;SACF;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AA1GD,gDA0GC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {SchemaType} from '@react-native/codegen/lib/CodegenSchema';\nimport {AliasMap, setPreferredModuleName} from './AliasManaging';\nimport {createAliasMap, generateAliases} from './AliasGen';\nimport {generateValidateConstants} from './ValidateConstants';\nimport {generateValidateMethods} from './ValidateMethods';\nimport type {CppStringTypes} from './ObjectTypes';\n\nexport type {CppStringTypes} from './ObjectTypes';\n\ntype FilesOutput = Map<string, string>;\n\nconst headerTemplate = `/*\n * This file is auto-generated from a NativeModule spec file in js.\n *\n * This is a C++ Spec class that should be used with MakeTurboModuleProvider to register native modules\n * in a way that also verifies at compile time that the native module matches the interface required\n * by the TurboModule JS spec.\n */\n#pragma once`;\n\nconst specTemplate = `::_MODULE_CUSTOM_TYPES_REFLECTION_::\nstruct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {\n::_MODULE_MEMBERS_TUPLES_::\n\n template <class TModule>\n static constexpr void ValidateModule() noexcept {\n::_MODULE_MEMBERS_CHECKS_::\n\n::_MODULE_MEMBERS_ERRORS_::\n }`;\n\nconst typeOnlyTemplate = `\n${headerTemplate}\n\n#include <string>\n#include <optional>\n#include <functional>\n#include <vector>\n\nnamespace ::_NAMESPACE_:: {\n::_MODULE_CUSTOM_TYPES_::\n} // namespace ::_NAMESPACE_::\n`;\n\nconst moduleOnlyTemplate = `\n${headerTemplate}\n\n::_TYPE_DEFINITION_INCLUDE_::\n#include <NativeModules.h>\n#include <tuple>\n\nnamespace ::_NAMESPACE_:: {\n${specTemplate}\n};\n\n} // namespace ::_NAMESPACE_::\n`;\n\nconst allInOneTemplate = `\n${headerTemplate}\n\n#include <NativeModules.h>\n#include <tuple>\n\nnamespace ::_NAMESPACE_:: {\n::_MODULE_CUSTOM_TYPES_::\n${specTemplate}\n};\n\n} // namespace ::_NAMESPACE_::\n`;\n\nexport function createNM2Generator({\n methodOnly,\n namespace,\n cppStringType,\n separateDataTypes,\n}: {\n methodOnly: boolean;\n namespace: string;\n cppStringType: CppStringTypes;\n separateDataTypes: boolean;\n}) {\n return (\n _libraryName: string,\n schema: SchemaType,\n _moduleSpecName: string,\n ): FilesOutput => {\n const files = new Map<string, string>();\n\n for (const moduleName of Object.keys(schema.modules)) {\n const nativeModule = schema.modules[moduleName];\n // from 0.65 facebook's react-native-codegen\n // the module name has the Native prefix comparing to 0.63\n // when reading files we provided\n const preferredModuleName = moduleName.startsWith('Native')\n ? moduleName.substr(6)\n : moduleName;\n setPreferredModuleName(preferredModuleName);\n\n if (nativeModule.type === 'NativeModule') {\n console.log(`Generating Native${preferredModuleName}Spec.g.h`);\n\n // copy all explicit to a map\n const aliases: AliasMap = createAliasMap(nativeModule.aliasMap);\n\n // prepare methods\n const methods = generateValidateMethods(nativeModule, aliases, {\n cppStringType,\n });\n let tuples = `\n static constexpr auto methods = std::tuple{\n${methods[0]}\n };`;\n let checks = `\n constexpr auto methodCheckResults = CheckMethods<TModule, ::_MODULE_NAME_::Spec>();`;\n let errors = methods[1];\n\n // prepare constants\n const constants = generateValidateConstants(nativeModule, aliases);\n if (constants !== undefined && !methodOnly) {\n tuples = `\n static constexpr auto constants = std::tuple{\n${constants[0]}\n };${tuples}`;\n checks = `\n constexpr auto constantCheckResults = CheckConstants<TModule, ::_MODULE_NAME_::Spec>();${checks}`;\n errors = `${constants[1]}\n\n${errors}`;\n }\n\n // generate code for structs\n const [customTypes, customReflection] = generateAliases(aliases, {\n cppStringType,\n });\n\n const customTypesExist = customTypes !== '';\n\n const replaceContent = function (template: string): string {\n return template\n .replace(/::_MODULE_CUSTOM_TYPES_::/g, customTypes)\n .replace(/::_MODULE_CUSTOM_TYPES_REFLECTION_::/g, customReflection)\n .replace(/::_MODULE_MEMBERS_TUPLES_::/g, tuples.substring(1))\n .replace(/::_MODULE_MEMBERS_CHECKS_::/g, checks.substring(1))\n .replace(/::_MODULE_MEMBERS_ERRORS_::/g, errors)\n .replace(/::_MODULE_NAME_::/g, preferredModuleName)\n .replace(\n /::_TYPE_DEFINITION_INCLUDE_::/g,\n customTypesExist\n ? `// #include \"Native${preferredModuleName}DataTypes.g.h\" before this file to use the generated type definition`\n : '',\n )\n .replace(/::_NAMESPACE_::/g, namespace);\n };\n\n if (separateDataTypes) {\n if (customTypesExist) {\n files.set(\n `Native${preferredModuleName}DataTypes.g.h`,\n replaceContent(typeOnlyTemplate),\n );\n }\n files.set(\n `Native${preferredModuleName}Spec.g.h`,\n replaceContent(moduleOnlyTemplate),\n );\n } else {\n files.set(\n `Native${preferredModuleName}Spec.g.h`,\n replaceContent(allInOneTemplate),\n );\n }\n }\n }\n\n return files;\n };\n}\n"]}
@@ -102,7 +102,7 @@ ${type.properties
102
102
  `;
103
103
  }
104
104
  function tryGetConstantType(nativeModule) {
105
- const candidates = nativeModule.spec.properties.filter(prop => prop.name === 'getConstants');
105
+ const candidates = nativeModule.spec.methods.filter(prop => prop.name === 'getConstants');
106
106
  if (candidates.length === 0) {
107
107
  return undefined;
108
108
  }
@@ -151,7 +151,7 @@ function generateTypeScript(_libraryName, schema, _moduleSpecName) {
151
151
  const constantCode = constantType === undefined
152
152
  ? ''
153
153
  : ` getConstants(): ${translateType(constantType)}`;
154
- const methods = nativeModule.spec.properties.filter(prop => prop.name !== 'getConstants');
154
+ const methods = nativeModule.spec.methods.filter(prop => prop.name !== 'getConstants');
155
155
  const membersCode = methods.map(translateMethod).join('');
156
156
  files.set(`${preferredModuleName}Spec.g.ts`, moduleTemplate
157
157
  .replace(/::_MODULE_ALIASED_STRUCTS_::/g, aliasCode)
@@ -1 +1 @@
1
- {"version":3,"file":"GenerateTypeScript.js","sourceRoot":"","sources":["../../src/generators/GenerateTypeScript.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAkBb,SAAgB,sBAAsB,CACpC,MAA0B,EAC1B,QAAiB;IAEjB,MAAM,EAAE,GAA8B,MAAM,CAAC;IAC7C,EAAE,CAAC,mBAAmB,GAAG,QAAQ,CAAC;AACpC,CAAC;AAND,wDAMC;AAED,SAAgB,sBAAsB,CAAC,MAA0B;;IAC/D,OAAO,MAA4B,MAAO,CAAC,mBAAmB,mCAAI,KAAK,CAAC;AAC1E,CAAC;AAFD,wDAEC;AAOD,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;CAetB,CAAC;AAEF,SAAS,YAAY,CAAI,GAAkB;IACzC,OAAO,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC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AC;iBACnD,OAAO,CAAC,uBAAuB,EAAE,YAAY,GAAG,WAAW,CAAC;iBAC5D,OAAO,CAAC,oBAAoB,EAAE,mBAAmB,CAAC;iBAClD,OAAO,CACN,sBAAsB,EACtB,sBAAsB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,cAAc,CAC9D,CACJ,CAAC;SACH;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAlDD,gDAkDC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {\n NamedShape,\n NativeModuleBaseTypeAnnotation,\n NativeModuleFunctionTypeAnnotation,\n NativeModuleObjectTypeAnnotation,\n NativeModuleParamTypeAnnotation,\n NativeModuleReturnTypeAnnotation,\n NativeModuleSchema,\n Nullable,\n SchemaType,\n} from '@react-native/codegen/lib/CodegenSchema';\n\ninterface CodegenNativeModuleSchema extends NativeModuleSchema {\n optionalTurboModule?: boolean;\n}\n\nexport function setOptionalTurboModule(\n schema: NativeModuleSchema,\n optional: boolean,\n): void {\n const cs = <CodegenNativeModuleSchema>schema;\n cs.optionalTurboModule = optional;\n}\n\nexport function getOptionalTurboModule(schema: NativeModuleSchema): boolean {\n return (<CodegenNativeModuleSchema>schema).optionalTurboModule ?? false;\n}\n\ntype ObjectProp = NamedShape<Nullable<NativeModuleBaseTypeAnnotation>>;\ntype FunctionParam = NamedShape<Nullable<NativeModuleParamTypeAnnotation>>;\ntype FunctionDecl = NamedShape<Nullable<NativeModuleFunctionTypeAnnotation>>;\ntype FilesOutput = Map<string, string>;\n\nconst moduleTemplate = `\n/*\n * This file is auto-generated from a NativeModule spec file in js.\n *\n * This is a TypeScript turbo module definition file.\n */\n\nimport {TurboModule, TurboModuleRegistry} from 'react-native';\n'use strict';\n::_MODULE_ALIASED_STRUCTS_::\nexport interface Spec extends TurboModule {\n::_MODULE_MEMBERS_::\n}\n\nexport default TurboModuleRegistry.::_MODULE_GETTER_::<Spec>('::_MODULE_NAME_::');\n`;\n\nfunction optionalSign<T>(obj: NamedShape<T>): string {\n return obj.optional ? '?' : '';\n}\n\nfunction translateType(\n type: Nullable<\n | NativeModuleBaseTypeAnnotation\n | NativeModuleParamTypeAnnotation\n | NativeModuleReturnTypeAnnotation\n >,\n): string {\n // avoid: Property 'type' does not exist on type 'never'\n const returnType = type.type;\n switch (type.type) {\n case 'StringTypeAnnotation':\n return 'string';\n case 'NumberTypeAnnotation':\n case 'FloatTypeAnnotation':\n case 'DoubleTypeAnnotation':\n case 'Int32TypeAnnotation':\n return 'number';\n case 'BooleanTypeAnnotation':\n return 'boolean';\n case 'ArrayTypeAnnotation':\n if (type.elementType) {\n return `${translateType(type.elementType)}[]`;\n } else {\n return `Array`;\n }\n case 'GenericObjectTypeAnnotation':\n return 'object';\n case 'ObjectTypeAnnotation':\n return `{${type.properties\n .map((prop: ObjectProp) => {\n return `${prop.name}${optionalSign(prop)}: ${translateType(\n prop.typeAnnotation,\n )}`;\n })\n .join(', ')}}`;\n case 'ReservedTypeAnnotation': {\n // avoid: Property 'name' does not exist on type 'never'\n const name = type.name;\n // (#6597)\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (name !== 'RootTag')\n throw new Error(\n `Unknown reserved function: ${name} in translateReturnType`,\n );\n return 'number';\n }\n case 'TypeAliasTypeAnnotation':\n return type.name;\n case 'NullableTypeAnnotation':\n return `(${translateType(type.typeAnnotation)} | null | undefined)`;\n case 'VoidTypeAnnotation':\n return `void`;\n case 'PromiseTypeAnnotation':\n return `Promise`;\n case `FunctionTypeAnnotation`:\n return `((${type.params\n .map((param: FunctionParam) => {\n return `${param.name}${optionalSign(param)}: ${translateType(\n param.typeAnnotation,\n )}`;\n })\n .join(', ')}) => ${translateType(type.returnTypeAnnotation)})`;\n default:\n throw new Error(`Unhandled type in translateReturnType: ${returnType}`);\n }\n}\n\nfunction translateAlias(\n name: string,\n type: NativeModuleObjectTypeAnnotation,\n): string {\n return `\nexport interface ${name} {\n${type.properties\n .map((prop: ObjectProp) => {\n return ` ${prop.name}${optionalSign(prop)}: ${translateType(\n prop.typeAnnotation,\n )};`;\n })\n .join('\\n')}\n}\n`;\n}\n\nfunction tryGetConstantType(\n nativeModule: NativeModuleSchema,\n): NativeModuleObjectTypeAnnotation | undefined {\n const candidates = nativeModule.spec.properties.filter(\n prop => prop.name === 'getConstants',\n );\n if (candidates.length === 0) {\n return undefined;\n }\n\n const getConstant = candidates[0];\n const funcType =\n getConstant.typeAnnotation.type === 'NullableTypeAnnotation'\n ? getConstant.typeAnnotation.typeAnnotation\n : getConstant.typeAnnotation;\n if (\n funcType.params.length > 0 ||\n funcType.returnTypeAnnotation.type !== 'ObjectTypeAnnotation'\n ) {\n return undefined;\n }\n\n const constantType = funcType.returnTypeAnnotation;\n if (constantType.properties.length === 0) {\n return undefined;\n }\n\n return constantType;\n}\n\nfunction translateMethod(func: FunctionDecl): string {\n const funcType =\n func.typeAnnotation.type === 'NullableTypeAnnotation'\n ? func.typeAnnotation.typeAnnotation\n : func.typeAnnotation;\n\n return `\n ${func.name}(${funcType.params\n .map((param: FunctionParam) => {\n return `${param.name}${optionalSign(param)}: ${translateType(\n param.typeAnnotation,\n )}`;\n })\n .join(', ')})${optionalSign(func)}: ${translateType(\n funcType.returnTypeAnnotation,\n )}${\n funcType.returnTypeAnnotation.type === 'ObjectTypeAnnotation' ? '' : ';'\n }`;\n}\n\nexport function generateTypeScript(\n _libraryName: string,\n schema: SchemaType,\n _moduleSpecName: string,\n): FilesOutput {\n const files = new Map<string, string>();\n\n for (const moduleName of Object.keys(schema.modules)) {\n const nativeModule = schema.modules[moduleName];\n // from 0.65 facebook's react-native-codegen\n // the module name has the Native prefix comparing to 0.63\n // when reading files we provided\n const nativePrefix = 'Native';\n const preferredModuleName = moduleName.startsWith(nativePrefix)\n ? moduleName.substr(nativePrefix.length)\n : moduleName;\n\n if (nativeModule.type === 'NativeModule') {\n console.log(`Generating ${preferredModuleName}Spec.g.ts`);\n\n const aliasCode = Object.keys(nativeModule.aliasMap)\n .map(name => translateAlias(name, nativeModule.aliasMap[name]))\n .join('');\n\n const constantType = tryGetConstantType(nativeModule);\n const constantCode =\n constantType === undefined\n ? ''\n : ` getConstants(): ${translateType(constantType)}`;\n\n const methods = nativeModule.spec.properties.filter(\n prop => prop.name !== 'getConstants',\n );\n const membersCode = methods.map(translateMethod).join('');\n\n files.set(\n `${preferredModuleName}Spec.g.ts`,\n moduleTemplate\n .replace(/::_MODULE_ALIASED_STRUCTS_::/g, aliasCode)\n .replace(/::_MODULE_MEMBERS_::/g, constantCode + membersCode)\n .replace(/::_MODULE_NAME_::/g, preferredModuleName)\n .replace(\n /::_MODULE_GETTER_::/g,\n getOptionalTurboModule(nativeModule) ? 'get' : 'getEnforcing',\n ),\n );\n }\n }\n\n return files;\n}\n"]}
1
+ {"version":3,"file":"GenerateTypeScript.js","sourceRoot":"","sources":["../../src/generators/GenerateTypeScript.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAkBb,SAAgB,sBAAsB,CACpC,MAA0B,EAC1B,QAAiB;IAEjB,MAAM,EAAE,GAA8B,MAAM,CAAC;IAC7C,EAAE,CAAC,mBAAmB,GAAG,QAAQ,CAAC;AACpC,CAAC;AAND,wDAMC;AAED,SAAgB,sBAAsB,CAAC,MAA0B;;IAC/D,OAAO,MAA4B,MAAO,CAAC,mBAAmB,mCAAI,KAAK,CAAC;AAC1E,CAAC;AAFD,wDAEC;AAOD,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;CAetB,CAAC;AAEF,SAAS,YAAY,CAAI,GAAkB;IACzC,OAAO,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;AACjC,CAAC;AAED,SAAS,aAAa,CACpB,IAIC;IAED,wDAAwD;IACxD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC;IAC7B,QAAQ,IAAI,CAA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BAAsB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,cAAc,CAC9D,CACJ,CAAC;SACH;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAlDD,gDAkDC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {\n NamedShape,\n NativeModuleBaseTypeAnnotation,\n NativeModuleFunctionTypeAnnotation,\n NativeModuleObjectTypeAnnotation,\n NativeModuleParamTypeAnnotation,\n NativeModuleReturnTypeAnnotation,\n NativeModuleSchema,\n Nullable,\n SchemaType,\n} from '@react-native/codegen/lib/CodegenSchema';\n\ninterface CodegenNativeModuleSchema extends NativeModuleSchema {\n optionalTurboModule?: boolean;\n}\n\nexport function setOptionalTurboModule(\n schema: NativeModuleSchema,\n optional: boolean,\n): void {\n const cs = <CodegenNativeModuleSchema>schema;\n cs.optionalTurboModule = optional;\n}\n\nexport function getOptionalTurboModule(schema: NativeModuleSchema): boolean {\n return (<CodegenNativeModuleSchema>schema).optionalTurboModule ?? false;\n}\n\ntype ObjectProp = NamedShape<Nullable<NativeModuleBaseTypeAnnotation>>;\ntype FunctionParam = NamedShape<Nullable<NativeModuleParamTypeAnnotation>>;\ntype FunctionDecl = NamedShape<Nullable<NativeModuleFunctionTypeAnnotation>>;\ntype FilesOutput = Map<string, string>;\n\nconst moduleTemplate = `\n/*\n * This file is auto-generated from a NativeModule spec file in js.\n *\n * This is a TypeScript turbo module definition file.\n */\n\nimport {TurboModule, TurboModuleRegistry} from 'react-native';\n'use strict';\n::_MODULE_ALIASED_STRUCTS_::\nexport interface Spec extends TurboModule {\n::_MODULE_MEMBERS_::\n}\n\nexport default TurboModuleRegistry.::_MODULE_GETTER_::<Spec>('::_MODULE_NAME_::');\n`;\n\nfunction optionalSign<T>(obj: NamedShape<T>): string {\n return obj.optional ? '?' : '';\n}\n\nfunction translateType(\n type: Nullable<\n | NativeModuleBaseTypeAnnotation\n | NativeModuleParamTypeAnnotation\n | NativeModuleReturnTypeAnnotation\n >,\n): string {\n // avoid: Property 'type' does not exist on type 'never'\n const returnType = type.type;\n switch (type.type) {\n case 'StringTypeAnnotation':\n return 'string';\n case 'NumberTypeAnnotation':\n case 'FloatTypeAnnotation':\n case 'DoubleTypeAnnotation':\n case 'Int32TypeAnnotation':\n return 'number';\n case 'BooleanTypeAnnotation':\n return 'boolean';\n case 'ArrayTypeAnnotation':\n if (type.elementType) {\n return `${translateType(type.elementType)}[]`;\n } else {\n return `Array`;\n }\n case 'GenericObjectTypeAnnotation':\n return 'object';\n case 'ObjectTypeAnnotation':\n return `{${type.properties\n .map((prop: ObjectProp) => {\n return `${prop.name}${optionalSign(prop)}: ${translateType(\n prop.typeAnnotation,\n )}`;\n })\n .join(', ')}}`;\n case 'ReservedTypeAnnotation': {\n // avoid: Property 'name' does not exist on type 'never'\n const name = type.name;\n // (#6597)\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (name !== 'RootTag')\n throw new Error(\n `Unknown reserved function: ${name} in translateReturnType`,\n );\n return 'number';\n }\n case 'TypeAliasTypeAnnotation':\n return type.name;\n case 'NullableTypeAnnotation':\n return `(${translateType(type.typeAnnotation)} | null | undefined)`;\n case 'VoidTypeAnnotation':\n return `void`;\n case 'PromiseTypeAnnotation':\n return `Promise`;\n case `FunctionTypeAnnotation`:\n return `((${type.params\n .map((param: FunctionParam) => {\n return `${param.name}${optionalSign(param)}: ${translateType(\n param.typeAnnotation,\n )}`;\n })\n .join(', ')}) => ${translateType(type.returnTypeAnnotation)})`;\n default:\n throw new Error(`Unhandled type in translateReturnType: ${returnType}`);\n }\n}\n\nfunction translateAlias(\n name: string,\n type: NativeModuleObjectTypeAnnotation,\n): string {\n return `\nexport interface ${name} {\n${type.properties\n .map((prop: ObjectProp) => {\n return ` ${prop.name}${optionalSign(prop)}: ${translateType(\n prop.typeAnnotation,\n )};`;\n })\n .join('\\n')}\n}\n`;\n}\n\nfunction tryGetConstantType(\n nativeModule: NativeModuleSchema,\n): NativeModuleObjectTypeAnnotation | undefined {\n const candidates = nativeModule.spec.methods.filter(\n prop => prop.name === 'getConstants',\n );\n if (candidates.length === 0) {\n return undefined;\n }\n\n const getConstant = candidates[0];\n const funcType =\n getConstant.typeAnnotation.type === 'NullableTypeAnnotation'\n ? getConstant.typeAnnotation.typeAnnotation\n : getConstant.typeAnnotation;\n if (\n funcType.params.length > 0 ||\n funcType.returnTypeAnnotation.type !== 'ObjectTypeAnnotation'\n ) {\n return undefined;\n }\n\n const constantType = funcType.returnTypeAnnotation;\n if (constantType.properties.length === 0) {\n return undefined;\n }\n\n return constantType;\n}\n\nfunction translateMethod(func: FunctionDecl): string {\n const funcType =\n func.typeAnnotation.type === 'NullableTypeAnnotation'\n ? func.typeAnnotation.typeAnnotation\n : func.typeAnnotation;\n\n return `\n ${func.name}(${funcType.params\n .map((param: FunctionParam) => {\n return `${param.name}${optionalSign(param)}: ${translateType(\n param.typeAnnotation,\n )}`;\n })\n .join(', ')})${optionalSign(func)}: ${translateType(\n funcType.returnTypeAnnotation,\n )}${\n funcType.returnTypeAnnotation.type === 'ObjectTypeAnnotation' ? '' : ';'\n }`;\n}\n\nexport function generateTypeScript(\n _libraryName: string,\n schema: SchemaType,\n _moduleSpecName: string,\n): FilesOutput {\n const files = new Map<string, string>();\n\n for (const moduleName of Object.keys(schema.modules)) {\n const nativeModule = schema.modules[moduleName];\n // from 0.65 facebook's react-native-codegen\n // the module name has the Native prefix comparing to 0.63\n // when reading files we provided\n const nativePrefix = 'Native';\n const preferredModuleName = moduleName.startsWith(nativePrefix)\n ? moduleName.substr(nativePrefix.length)\n : moduleName;\n\n if (nativeModule.type === 'NativeModule') {\n console.log(`Generating ${preferredModuleName}Spec.g.ts`);\n\n const aliasCode = Object.keys(nativeModule.aliasMap)\n .map(name => translateAlias(name, nativeModule.aliasMap[name]))\n .join('');\n\n const constantType = tryGetConstantType(nativeModule);\n const constantCode =\n constantType === undefined\n ? ''\n : ` getConstants(): ${translateType(constantType)}`;\n\n const methods = nativeModule.spec.methods.filter(\n prop => prop.name !== 'getConstants',\n );\n const membersCode = methods.map(translateMethod).join('');\n\n files.set(\n `${preferredModuleName}Spec.g.ts`,\n moduleTemplate\n .replace(/::_MODULE_ALIASED_STRUCTS_::/g, aliasCode)\n .replace(/::_MODULE_MEMBERS_::/g, constantCode + membersCode)\n .replace(/::_MODULE_NAME_::/g, preferredModuleName)\n .replace(\n /::_MODULE_GETTER_::/g,\n getOptionalTurboModule(nativeModule) ? 'get' : 'getEnforcing',\n ),\n );\n }\n }\n\n return files;\n}\n"]}
@@ -58,6 +58,7 @@ function translateFieldOrReturnType(type, aliases, baseAliasName, callerName, op
58
58
  return (0, AliasManaging_1.getAliasCppName)(type.name);
59
59
  case 'NullableTypeAnnotation':
60
60
  return `std::optional<${translateFieldOrReturnType(type.typeAnnotation, aliases, baseAliasName, callerName, options)}>`;
61
+ case 'FunctionTypeAnnotation':
61
62
  case 'MixedTypeAnnotation':
62
63
  return '';
63
64
  case 'EnumDeclaration':
@@ -1 +1 @@
1
- {"version":3,"file":"ObjectTypes.js","sourceRoot":"","sources":["../../src/generators/ObjectTypes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAUb,mDAIyB;AAQzB,SAAS,wBAAwB,CAC/B,IAAmE,EACnE,OAA0B;IAE1B,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;IACnC,QAAQ,IAAI,CAAC,UAAU,EAAE;QACvB,KAAK,sBAAsB;YACzB,OAAO,OAAO,CAAC,aAAa,CAAC;QAC/B,KAAK,sBAAsB;YACzB,OAAO,QAAQ,CAAC;QAClB,KAAK,sBAAsB;YACzB,OAAO,kBAAkB,CAAC;QAC5B;YACE,MAAM,IAAI,KAAK,CACb,0DAA0D,UAAU,EAAE,CACvE,CAAC;KACL;AACH,CAAC;AAED,SAAgB,0BAA0B,CACxC,IAIC,EACD,OAAiB,EACjB,aAAqB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AAK,qBAAqB;YACxB,OAAO,EAAE,CAAC;QACZ,KAAK,iBAAiB,CAAC;QACvB,KAAK,qBAAqB;YACxB,OAAO,wBAAwB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACjD;YACE,MAAM,IAAI,KAAK,CAAC,qBAAqB,UAAU,KAAK,UAAU,EAAE,CAAC,CAAC;KACrE;AACH,CAAC;AAnED,gEAmEC;AAED,SAAgB,cAAc,CAC5B,IAA8C,EAC9C,OAAiB,EACjB,aAAqB,EACrB,OAA0B;IAE1B,OAAO,0BAA0B,CAC/B,IAAI,EACJ,OAAO,EACP,aAAa,EACb,gBAAgB,EAChB,OAAO,CACR,CAAC;AACJ,CAAC;AAbD,wCAaC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {\n NativeModuleEnumDeclaration,\n NativeModuleBaseTypeAnnotation,\n NativeModuleUnionTypeAnnotation,\n NativeModuleStringTypeAnnotation,\n NativeModuleFunctionTypeAnnotation,\n Nullable,\n} from '@react-native/codegen/lib/CodegenSchema';\nimport {\n AliasMap,\n getAliasCppName,\n getAnonymousAliasCppName,\n} from './AliasManaging';\n\nexport type CppStringTypes = 'std::string' | 'std::wstring';\n\nexport interface CppCodegenOptions {\n cppStringType: CppStringTypes;\n}\n\nfunction translateUnionReturnType(\n type: NativeModuleEnumDeclaration | NativeModuleUnionTypeAnnotation,\n options: CppCodegenOptions,\n): string {\n const memberType = type.memberType;\n switch (type.memberType) {\n case 'StringTypeAnnotation':\n return options.cppStringType;\n case 'NumberTypeAnnotation':\n return 'double';\n case 'ObjectTypeAnnotation':\n return '::React::JSValue';\n default:\n throw new Error(\n `Unknown enum/union member type in translateReturnType: ${memberType}`,\n );\n }\n}\n\nexport function translateFieldOrReturnType(\n type: Nullable<\n | NativeModuleBaseTypeAnnotation\n | NativeModuleStringTypeAnnotation\n | NativeModuleFunctionTypeAnnotation\n >,\n aliases: AliasMap,\n baseAliasName: string,\n callerName: 'translateField' | 'translateReturnType',\n options: CppCodegenOptions,\n): string {\n // avoid: Property 'type' does not exist on type 'never'\n const returnType = type.type;\n switch (type.type) {\n case 'StringTypeAnnotation':\n return options.cppStringType;\n case 'NumberTypeAnnotation':\n case 'FloatTypeAnnotation':\n case 'DoubleTypeAnnotation':\n return 'double';\n case 'Int32TypeAnnotation':\n return 'int';\n case 'BooleanTypeAnnotation':\n return 'bool';\n case 'ArrayTypeAnnotation':\n if (type.elementType) {\n return `std::vector<${translateFieldOrReturnType(\n type.elementType,\n aliases,\n `${baseAliasName}_element`,\n callerName,\n options,\n )}>`;\n } else {\n return `::React::JSValueArray`;\n }\n case 'GenericObjectTypeAnnotation':\n return '::React::JSValue';\n case 'ObjectTypeAnnotation':\n return getAnonymousAliasCppName(aliases, baseAliasName, type);\n case 'ReservedTypeAnnotation': {\n // avoid: Property 'name' does not exist on type 'never'\n const name = type.name;\n // (#6597)\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (name !== 'RootTag')\n throw new Error(`Unknown reserved function: ${name} in ${callerName}`);\n return 'double';\n }\n case 'TypeAliasTypeAnnotation':\n return getAliasCppName(type.name);\n case 'NullableTypeAnnotation':\n return `std::optional<${translateFieldOrReturnType(\n type.typeAnnotation,\n aliases,\n baseAliasName,\n callerName,\n options,\n )}>`;\n case 'MixedTypeAnnotation':\n return '';\n case 'EnumDeclaration':\n case 'UnionTypeAnnotation':\n return translateUnionReturnType(type, options);\n default:\n throw new Error(`Unhandled type in ${callerName}: ${returnType}`);\n }\n}\n\nexport function translateField(\n type: Nullable<NativeModuleBaseTypeAnnotation>,\n aliases: AliasMap,\n baseAliasName: string,\n options: CppCodegenOptions,\n): string {\n return translateFieldOrReturnType(\n type,\n aliases,\n baseAliasName,\n 'translateField',\n options,\n );\n}\n"]}
1
+ {"version":3,"file":"ObjectTypes.js","sourceRoot":"","sources":["../../src/generators/ObjectTypes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,Y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AC;YAC7B,wDAAwD;YACxD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;YACvB,UAAU;YACV,uEAAuE;YACvE,IAAI,IAAI,KAAK,SAAS;gBACpB,MAAM,IAAI,KAAK,CAAC,8BAA8B,IAAI,OAAO,UAAU,EAAE,CAAC,CAAC;YACzE,OAAO,QAAQ,CAAC;SACjB;QACD,KAAK,yBAAyB;YAC5B,OAAO,IAAA,+BAAe,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpC,KAAK,wBAAwB;YAC3B,OAAO,iBAAiB,0BAA0B,CAChD,IAAI,CAAC,cAAc,EACnB,OAAO,EACP,aAAa,EACb,UAAU,EACV,OAAO,CACR,GAAG,CAAC;QACP,KAAK,wBAAwB,CAAC;QAC9B,KAAK,qBAAqB;YACxB,OAAO,EAAE,CAAC;QACZ,KAAK,iBAAiB,CAAC;QACvB,KAAK,qBAAqB;YACxB,OAAO,wBAAwB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACjD;YACE,MAAM,IAAI,KAAK,CAAC,qBAAqB,UAAU,KAAK,UAAU,EAAE,CAAC,CAAC;KACrE;AACH,CAAC;AApED,gEAoEC;AAED,SAAgB,cAAc,CAC5B,IAA8C,EAC9C,OAAiB,EACjB,aAAqB,EACrB,OAA0B;IAE1B,OAAO,0BAA0B,CAC/B,IAAI,EACJ,OAAO,EACP,aAAa,EACb,gBAAgB,EAChB,OAAO,CACR,CAAC;AACJ,CAAC;AAbD,wCAaC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {\n NativeModuleEnumDeclaration,\n NativeModuleBaseTypeAnnotation,\n NativeModuleUnionTypeAnnotation,\n NativeModuleStringTypeAnnotation,\n NativeModuleFunctionTypeAnnotation,\n Nullable,\n} from '@react-native/codegen/lib/CodegenSchema';\nimport {\n AliasMap,\n getAliasCppName,\n getAnonymousAliasCppName,\n} from './AliasManaging';\n\nexport type CppStringTypes = 'std::string' | 'std::wstring';\n\nexport interface CppCodegenOptions {\n cppStringType: CppStringTypes;\n}\n\nfunction translateUnionReturnType(\n type: NativeModuleEnumDeclaration | NativeModuleUnionTypeAnnotation,\n options: CppCodegenOptions,\n): string {\n const memberType = type.memberType;\n switch (type.memberType) {\n case 'StringTypeAnnotation':\n return options.cppStringType;\n case 'NumberTypeAnnotation':\n return 'double';\n case 'ObjectTypeAnnotation':\n return '::React::JSValue';\n default:\n throw new Error(\n `Unknown enum/union member type in translateReturnType: ${memberType}`,\n );\n }\n}\n\nexport function translateFieldOrReturnType(\n type: Nullable<\n | NativeModuleBaseTypeAnnotation\n | NativeModuleStringTypeAnnotation\n | NativeModuleFunctionTypeAnnotation\n >,\n aliases: AliasMap,\n baseAliasName: string,\n callerName: 'translateField' | 'translateReturnType',\n options: CppCodegenOptions,\n): string {\n // avoid: Property 'type' does not exist on type 'never'\n const returnType = type.type;\n switch (type.type) {\n case 'StringTypeAnnotation':\n return options.cppStringType;\n case 'NumberTypeAnnotation':\n case 'FloatTypeAnnotation':\n case 'DoubleTypeAnnotation':\n return 'double';\n case 'Int32TypeAnnotation':\n return 'int';\n case 'BooleanTypeAnnotation':\n return 'bool';\n case 'ArrayTypeAnnotation':\n if (type.elementType) {\n return `std::vector<${translateFieldOrReturnType(\n type.elementType,\n aliases,\n `${baseAliasName}_element`,\n callerName,\n options,\n )}>`;\n } else {\n return `::React::JSValueArray`;\n }\n case 'GenericObjectTypeAnnotation':\n return '::React::JSValue';\n case 'ObjectTypeAnnotation':\n return getAnonymousAliasCppName(aliases, baseAliasName, type);\n case 'ReservedTypeAnnotation': {\n // avoid: Property 'name' does not exist on type 'never'\n const name = type.name;\n // (#6597)\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (name !== 'RootTag')\n throw new Error(`Unknown reserved function: ${name} in ${callerName}`);\n return 'double';\n }\n case 'TypeAliasTypeAnnotation':\n return getAliasCppName(type.name);\n case 'NullableTypeAnnotation':\n return `std::optional<${translateFieldOrReturnType(\n type.typeAnnotation,\n aliases,\n baseAliasName,\n callerName,\n options,\n )}>`;\n case 'FunctionTypeAnnotation':\n case 'MixedTypeAnnotation':\n return '';\n case 'EnumDeclaration':\n case 'UnionTypeAnnotation':\n return translateUnionReturnType(type, options);\n default:\n throw new Error(`Unhandled type in ${callerName}: ${returnType}`);\n }\n}\n\nexport function translateField(\n type: Nullable<NativeModuleBaseTypeAnnotation>,\n aliases: AliasMap,\n baseAliasName: string,\n options: CppCodegenOptions,\n): string {\n return translateFieldOrReturnType(\n type,\n aliases,\n baseAliasName,\n 'translateField',\n options,\n );\n}\n"]}
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.generateValidateConstants = void 0;
9
9
  const AliasManaging_1 = require("./AliasManaging");
10
10
  function generateValidateConstants(nativeModule, aliases) {
11
- const candidates = nativeModule.spec.properties.filter(prop => prop.name === 'getConstants');
11
+ const candidates = nativeModule.spec.methods.filter(prop => prop.name === 'getConstants');
12
12
  if (candidates.length === 0) {
13
13
  return undefined;
14
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ValidateConstants.js","sourceRoot":"","sources":["../../src/generators/ValidateConstants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAGb,mDAAmE;AAEnE,SAAgB,yBAAyB,CACvC,YAAgC,EAChC,OAAiB;IAEjB,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CACpD,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,CACrC,CAAC;IACF,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QAC3B,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;IAClC,MAAM,QAAQ,GACZ,WAAW,CAAC,cAAc,CAAC,IAAI,KAAK,wBAAwB;QAC1D,CAAC,CAAC,WAAW,CAAC,cAAc,CAAC,cAAc;QAC3C,CAAC,CAAC,WAAW,CAAC,cAAc,CAAC;IACjC,IACE,QAAQ,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;QAC1B,QAAQ,CAAC,oBAAoB,CAAC,IAAI,KAAK,sBAAsB,EAC7D;QACA,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,YAAY,GAAG,QAAQ,CAAC,oBAAoB,CAAC;IACnD,IAAI,YAAY,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QACxC,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,OAAO,GAAG,IAAA,wCAAwB,EAAC,OAAO,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;IAE7E,OAAO;QACL,uBAAuB,OAAO,OAAO;QACrC;;aAES,OAAO;mDAC+B,OAAO;0DACA,OAAO,qDAAqD;KACnH,CAAC;AACJ,CAAC;AAtCD,8DAsCC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {NativeModuleSchema} from '@react-native/codegen/lib/CodegenSchema';\nimport {AliasMap, getAnonymousAliasCppName} from './AliasManaging';\n\nexport function generateValidateConstants(\n nativeModule: NativeModuleSchema,\n aliases: AliasMap,\n): [string, string] | undefined {\n const candidates = nativeModule.spec.properties.filter(\n prop => prop.name === 'getConstants',\n );\n if (candidates.length === 0) {\n return undefined;\n }\n\n const getConstant = candidates[0];\n const funcType =\n getConstant.typeAnnotation.type === 'NullableTypeAnnotation'\n ? getConstant.typeAnnotation.typeAnnotation\n : getConstant.typeAnnotation;\n if (\n funcType.params.length > 0 ||\n funcType.returnTypeAnnotation.type !== 'ObjectTypeAnnotation'\n ) {\n return undefined;\n }\n\n const constantType = funcType.returnTypeAnnotation;\n if (constantType.properties.length === 0) {\n return undefined;\n }\n\n const cppName = getAnonymousAliasCppName(aliases, 'Constants', constantType);\n\n return [\n ` TypedConstant<${cppName}>{0},`,\n ` REACT_SHOW_CONSTANT_SPEC_ERRORS(\n 0,\n \"${cppName}\",\n \" REACT_GET_CONSTANTS(GetConstants) ${cppName} GetConstants() noexcept {/*implementation*/}\\\\n\"\n \" REACT_GET_CONSTANTS(GetConstants) static ${cppName} GetConstants() noexcept {/*implementation*/}\\\\n\");`,\n ];\n}\n"]}
1
+ {"version":3,"file":"ValidateConstants.js","sourceRoot":"","sources":["../../src/generators/ValidateConstants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAGb,mDAAmE;AAEnE,SAAgB,yBAAyB,CACvC,YAAgC,EAChC,OAAiB;IAEjB,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CACjD,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,CACrC,CAAC;IACF,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QAC3B,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;IAClC,MAAM,QAAQ,GACZ,WAAW,CAAC,cAAc,CAAC,IAAI,KAAK,wBAAwB;QAC1D,CAAC,CAAC,WAAW,CAAC,cAAc,CAAC,cAAc;QAC3C,CAAC,CAAC,WAAW,CAAC,cAAc,CAAC;IACjC,IACE,QAAQ,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;QAC1B,QAAQ,CAAC,oBAAoB,CAAC,IAAI,KAAK,sBAAsB,EAC7D;QACA,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,YAAY,GAAG,QAAQ,CAAC,oBAAoB,CAAC;IACnD,IAAI,YAAY,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QACxC,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,OAAO,GAAG,IAAA,wCAAwB,EAAC,OAAO,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;IAE7E,OAAO;QACL,uBAAuB,OAAO,OAAO;QACrC;;aAES,OAAO;mDAC+B,OAAO;0DACA,OAAO,qDAAqD;KACnH,CAAC;AACJ,CAAC;AAtCD,8DAsCC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {NativeModuleSchema} from '@react-native/codegen/lib/CodegenSchema';\nimport {AliasMap, getAnonymousAliasCppName} from './AliasManaging';\n\nexport function generateValidateConstants(\n nativeModule: NativeModuleSchema,\n aliases: AliasMap,\n): [string, string] | undefined {\n const candidates = nativeModule.spec.methods.filter(\n prop => prop.name === 'getConstants',\n );\n if (candidates.length === 0) {\n return undefined;\n }\n\n const getConstant = candidates[0];\n const funcType =\n getConstant.typeAnnotation.type === 'NullableTypeAnnotation'\n ? getConstant.typeAnnotation.typeAnnotation\n : getConstant.typeAnnotation;\n if (\n funcType.params.length > 0 ||\n funcType.returnTypeAnnotation.type !== 'ObjectTypeAnnotation'\n ) {\n return undefined;\n }\n\n const constantType = funcType.returnTypeAnnotation;\n if (constantType.properties.length === 0) {\n return undefined;\n }\n\n const cppName = getAnonymousAliasCppName(aliases, 'Constants', constantType);\n\n return [\n ` TypedConstant<${cppName}>{0},`,\n ` REACT_SHOW_CONSTANT_SPEC_ERRORS(\n 0,\n \"${cppName}\",\n \" REACT_GET_CONSTANTS(GetConstants) ${cppName} GetConstants() noexcept {/*implementation*/}\\\\n\"\n \" REACT_GET_CONSTANTS(GetConstants) static ${cppName} GetConstants() noexcept {/*implementation*/}\\\\n\");`,\n ];\n}\n"]}
@@ -32,9 +32,9 @@ function translatePossibleMethodSignatures(prop, funcType, aliases, baseAliasNam
32
32
  .map(sig => `" ${sig}\\n"`)
33
33
  .join('\n ');
34
34
  }
35
- function renderProperties(properties, aliases, tuple, options) {
35
+ function renderProperties(methods, aliases, tuple, options) {
36
36
  // TODO: generate code for constants
37
- return properties
37
+ return methods
38
38
  .filter(prop => prop.name !== 'getConstants')
39
39
  .map((prop, index) => {
40
40
  // TODO: prop.optional === true
@@ -66,9 +66,9 @@ function renderProperties(properties, aliases, tuple, options) {
66
66
  .join('\n');
67
67
  }
68
68
  function generateValidateMethods(nativeModule, aliases, options) {
69
- const properties = nativeModule.spec.properties;
70
- const traversedProperties = renderProperties(properties, aliases, false, options);
71
- const traversedPropertyTuples = renderProperties(properties, aliases, true, options);
69
+ const methods = nativeModule.spec.methods;
70
+ const traversedProperties = renderProperties(methods, aliases, false, options);
71
+ const traversedPropertyTuples = renderProperties(methods, aliases, true, options);
72
72
  return [traversedPropertyTuples, traversedProperties];
73
73
  }
74
74
  exports.generateValidateMethods = generateValidateMethods;
@@ -1 +1 @@
1
- {"version":3,"file":"ValidateMethods.js","sourceRoot":"","sources":["../../src/generators/ValidateMethods.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AASb,6CAA8D;AAC9D,+CAA+E;AAE/E,SAAS,YAAY,CAAC,QAA4C;IAChE,OAAO,CACL,QAAQ,CAAC,oBAAoB,CAAC,IAAI,KAAK,oBAAoB;QAC3D,QAAQ,CAAC,oBAAoB,CAAC,IAAI,KAAK,uBAAuB,CAC/D,CAAC;AACJ,CAAC;AAED,SAAS,2BAA2B,CAClC,IAA+B,EAC/B,QAA4C,EAC5C,OAAiB,EACjB,aAAqB,EACrB,OAA0B;IAE1B,MAAM,IAAI,GAAG,IAAA,0BAAa,EAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;IAC7E,IAAI,QAAQ,CAAC,oBAAoB,CAAC,IAAI,KAAK,uBAAuB,EAAE;QAClE,IAAI,QAAQ,CAAC,oBAAoB,CAAC,WAAW,EAAE;YAC7C,IAAI,CAAC,IAAI,CACP,yBAAyB,IAAA,qCAAuB,EAC9C,QAAQ,CAAC,oBAAoB,CAAC,WAAW,EACzC,OAAO,EACP,aAAa,EACb,OAAO,CACR,YAAY,CACd,CAAC;SACH;aAAM;YACL,IAAI,CAAC,IAAI,CAAC,kDAAkD,CAA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B,CACrC,YAAgC,EAChC,OAAiB,EACjB,OAA0B;IAE1B,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC;IAChD,MAAM,mBAAmB,GAAG,gBAAgB,CAC1C,UAAU,EACV,OAAO,EACP,KAAK,EACL,OAAO,CACR,CAAC;IACF,MAAM,uBAAuB,GAAG,gBAAgB,CAC9C,UAAU,EACV,OAAO,EACP,IAAI,EACJ,OAAO,CACR,CAAC;IACF,OAAO,CAAC,uBAAuB,EAAE,mBAAmB,CAAC,CAAC;AACxD,CAAC;AAnBD,0DAmBC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {\n NativeModuleFunctionTypeAnnotation,\n NativeModulePropertyShape,\n NativeModuleSchema,\n} from '@react-native/codegen/lib/CodegenSchema';\nimport {AliasMap} from './AliasManaging';\nimport type {CppCodegenOptions} from './ObjectTypes';\nimport {translateArgs, translateSpecArgs} from './ParamTypes';\nimport {translateImplReturnType, translateSpecReturnType} from './ReturnTypes';\n\nfunction isMethodSync(funcType: NativeModuleFunctionTypeAnnotation) {\n return (\n funcType.returnTypeAnnotation.type !== 'VoidTypeAnnotation' &&\n funcType.returnTypeAnnotation.type !== 'PromiseTypeAnnotation'\n );\n}\n\nfunction getPossibleMethodSignatures(\n prop: NativeModulePropertyShape,\n funcType: NativeModuleFunctionTypeAnnotation,\n aliases: AliasMap,\n baseAliasName: string,\n options: CppCodegenOptions,\n): string[] {\n const args = translateArgs(funcType.params, aliases, baseAliasName, options);\n if (funcType.returnTypeAnnotation.type === 'PromiseTypeAnnotation') {\n if (funcType.returnTypeAnnotation.elementType) {\n args.push(\n `::React::ReactPromise<${translateImplReturnType(\n funcType.returnTypeAnnotation.elementType,\n aliases,\n baseAliasName,\n options,\n )}> &&result`,\n );\n } else {\n args.push('::React::ReactPromise<::React::JSValue> &&result');\n }\n }\n\n // TODO: be much more exhaustive on the possible method signatures that can be used..\n const sig = `REACT_${isMethodSync(funcType) ? 'SYNC_' : ''}METHOD(${\n prop.name\n }) ${translateImplReturnType(\n funcType.returnTypeAnnotation,\n aliases,\n baseAliasName,\n options,\n )} ${prop.name}(${args.join(', ')}) noexcept { /* implementation */ }`;\n\n const staticsig = `REACT_${isMethodSync(funcType) ? 'SYNC_' : ''}METHOD(${\n prop.name\n }) static ${translateImplReturnType(\n funcType.returnTypeAnnotation,\n aliases,\n baseAliasName,\n options,\n )} ${prop.name}(${args.join(', ')}) noexcept { /* implementation */ }`;\n\n return [sig, staticsig];\n}\n\nfunction translatePossibleMethodSignatures(\n prop: NativeModulePropertyShape,\n funcType: NativeModuleFunctionTypeAnnotation,\n aliases: AliasMap,\n baseAliasName: string,\n options: CppCodegenOptions,\n): string {\n return getPossibleMethodSignatures(\n prop,\n funcType,\n aliases,\n baseAliasName,\n options,\n )\n .map(sig => `\" ${sig}\\\\n\"`)\n .join('\\n ');\n}\n\nfunction renderProperties(\n properties: ReadonlyArray<NativeModulePropertyShape>,\n aliases: AliasMap,\n tuple: boolean,\n options: CppCodegenOptions,\n): string {\n // TODO: generate code for constants\n return properties\n .filter(prop => prop.name !== 'getConstants')\n .map((prop, index) => {\n // TODO: prop.optional === true\n // TODO: prop.typeAnnotation.type === 'NullableTypeAnnotation'\n const propAliasName = prop.name;\n const funcType =\n prop.typeAnnotation.type === 'NullableTypeAnnotation'\n ? prop.typeAnnotation.typeAnnotation\n : prop.typeAnnotation;\n\n const traversedArgs = translateSpecArgs(\n funcType.params,\n aliases,\n propAliasName,\n options,\n );\n\n const translatedReturnParam = translateSpecReturnType(\n funcType.returnTypeAnnotation,\n aliases,\n propAliasName,\n options,\n );\n\n if (funcType.returnTypeAnnotation.type === 'PromiseTypeAnnotation') {\n if (funcType.returnTypeAnnotation.elementType) {\n traversedArgs.push(\n `Promise<${translateSpecReturnType(\n funcType.returnTypeAnnotation.elementType,\n aliases,\n propAliasName,\n options,\n )}>`,\n );\n } else {\n traversedArgs.push('Promise<::React::JSValue>');\n }\n }\n\n if (tuple) {\n return ` ${\n isMethodSync(funcType) ? 'Sync' : ''\n }Method<${translatedReturnParam}(${traversedArgs.join(\n ', ',\n )}) noexcept>{${index}, L\"${prop.name}\"},`;\n } else {\n return ` REACT_SHOW_METHOD_SPEC_ERRORS(\n ${index},\n \"${prop.name}\",\n ${translatePossibleMethodSignatures(\n prop,\n funcType,\n aliases,\n propAliasName,\n options,\n )});`;\n }\n })\n .join('\\n');\n}\n\nexport function generateValidateMethods(\n nativeModule: NativeModuleSchema,\n aliases: AliasMap,\n options: CppCodegenOptions,\n): [string, string] {\n const properties = nativeModule.spec.properties;\n const traversedProperties = renderProperties(\n properties,\n aliases,\n false,\n options,\n );\n const traversedPropertyTuples = renderProperties(\n properties,\n aliases,\n true,\n options,\n );\n return [traversedPropertyTuples, traversedProperties];\n}\n"]}
1
+ {"version":3,"file":"ValidateMethods.js","sourceRoot":"","sources":["../../src/generators/ValidateMethods.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AASb,6CAA8D;AAC9D,+CAA+E;AAE/E,SAAS,YAAY,CAAC,QAA4C;IAChE,OAAO,CACL,QAAQ,CAAC,oBAAoB,CAAC,IAAI,KAAK,oBAAoB;QAC3D,QAAQ,CAAC,oBAAoB,CAAC,IAAI,KAAK,uBAAuB,CAC/D,CAAC;AACJ,CAAC;AAED,SAAS,2BAA2B,CAClC,IAA+B,EAC/B,QAA4C,EAC5C,OAAiB,EACjB,aAAqB,EACrB,OAA0B;IAE1B,MAAM,IAAI,GAAG,IAAA,0BAAa,EAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;IAC7E,IAAI,QAAQ,CAAC,oBAAoB,CAAC,IAAI,KAAK,uBAAuB,EAAE;QAClE,IAAI,QAAQ,CAAC,oBAAoB,CAAC,WAAW,EAAE;YAC7C,IAAI,CAAC,IAAI,CACP,yBAAyB,IAAA,qCAAuB,EAC9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QAAQ,EACR,OAAO,EACP,aAAa,EACb,OAAO,CACR,IAAI,CAAC;SACT;IACH,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED,SAAgB,uBAAuB,CACrC,YAAgC,EAChC,OAAiB,EACjB,OAA0B;IAE1B,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC;IAC1C,MAAM,mBAAmB,GAAG,gBAAgB,CAC1C,OAAO,EACP,OAAO,EACP,KAAK,EACL,OAAO,CACR,CAAC;IACF,MAAM,uBAAuB,GAAG,gBAAgB,CAC9C,OAAO,EACP,OAAO,EACP,IAAI,EACJ,OAAO,CACR,CAAC;IACF,OAAO,CAAC,uBAAuB,EAAE,mBAAmB,CAAC,CAAC;AACxD,CAAC;AAnBD,0DAmBC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {\n NativeModuleFunctionTypeAnnotation,\n NativeModulePropertyShape,\n NativeModuleSchema,\n} from '@react-native/codegen/lib/CodegenSchema';\nimport {AliasMap} from './AliasManaging';\nimport type {CppCodegenOptions} from './ObjectTypes';\nimport {translateArgs, translateSpecArgs} from './ParamTypes';\nimport {translateImplReturnType, translateSpecReturnType} from './ReturnTypes';\n\nfunction isMethodSync(funcType: NativeModuleFunctionTypeAnnotation) {\n return (\n funcType.returnTypeAnnotation.type !== 'VoidTypeAnnotation' &&\n funcType.returnTypeAnnotation.type !== 'PromiseTypeAnnotation'\n );\n}\n\nfunction getPossibleMethodSignatures(\n prop: NativeModulePropertyShape,\n funcType: NativeModuleFunctionTypeAnnotation,\n aliases: AliasMap,\n baseAliasName: string,\n options: CppCodegenOptions,\n): string[] {\n const args = translateArgs(funcType.params, aliases, baseAliasName, options);\n if (funcType.returnTypeAnnotation.type === 'PromiseTypeAnnotation') {\n if (funcType.returnTypeAnnotation.elementType) {\n args.push(\n `::React::ReactPromise<${translateImplReturnType(\n funcType.returnTypeAnnotation.elementType,\n aliases,\n baseAliasName,\n options,\n )}> &&result`,\n );\n } else {\n args.push('::React::ReactPromise<::React::JSValue> &&result');\n }\n }\n\n // TODO: be much more exhaustive on the possible method signatures that can be used..\n const sig = `REACT_${isMethodSync(funcType) ? 'SYNC_' : ''}METHOD(${\n prop.name\n }) ${translateImplReturnType(\n funcType.returnTypeAnnotation,\n aliases,\n baseAliasName,\n options,\n )} ${prop.name}(${args.join(', ')}) noexcept { /* implementation */ }`;\n\n const staticsig = `REACT_${isMethodSync(funcType) ? 'SYNC_' : ''}METHOD(${\n prop.name\n }) static ${translateImplReturnType(\n funcType.returnTypeAnnotation,\n aliases,\n baseAliasName,\n options,\n )} ${prop.name}(${args.join(', ')}) noexcept { /* implementation */ }`;\n\n return [sig, staticsig];\n}\n\nfunction translatePossibleMethodSignatures(\n prop: NativeModulePropertyShape,\n funcType: NativeModuleFunctionTypeAnnotation,\n aliases: AliasMap,\n baseAliasName: string,\n options: CppCodegenOptions,\n): string {\n return getPossibleMethodSignatures(\n prop,\n funcType,\n aliases,\n baseAliasName,\n options,\n )\n .map(sig => `\" ${sig}\\\\n\"`)\n .join('\\n ');\n}\n\nfunction renderProperties(\n methods: ReadonlyArray<NativeModulePropertyShape>,\n aliases: AliasMap,\n tuple: boolean,\n options: CppCodegenOptions,\n): string {\n // TODO: generate code for constants\n return methods\n .filter(prop => prop.name !== 'getConstants')\n .map((prop, index) => {\n // TODO: prop.optional === true\n // TODO: prop.typeAnnotation.type === 'NullableTypeAnnotation'\n const propAliasName = prop.name;\n const funcType =\n prop.typeAnnotation.type === 'NullableTypeAnnotation'\n ? prop.typeAnnotation.typeAnnotation\n : prop.typeAnnotation;\n\n const traversedArgs = translateSpecArgs(\n funcType.params,\n aliases,\n propAliasName,\n options,\n );\n\n const translatedReturnParam = translateSpecReturnType(\n funcType.returnTypeAnnotation,\n aliases,\n propAliasName,\n options,\n );\n\n if (funcType.returnTypeAnnotation.type === 'PromiseTypeAnnotation') {\n if (funcType.returnTypeAnnotation.elementType) {\n traversedArgs.push(\n `Promise<${translateSpecReturnType(\n funcType.returnTypeAnnotation.elementType,\n aliases,\n propAliasName,\n options,\n )}>`,\n );\n } else {\n traversedArgs.push('Promise<::React::JSValue>');\n }\n }\n\n if (tuple) {\n return ` ${\n isMethodSync(funcType) ? 'Sync' : ''\n }Method<${translatedReturnParam}(${traversedArgs.join(\n ', ',\n )}) noexcept>{${index}, L\"${prop.name}\"},`;\n } else {\n return ` REACT_SHOW_METHOD_SPEC_ERRORS(\n ${index},\n \"${prop.name}\",\n ${translatePossibleMethodSignatures(\n prop,\n funcType,\n aliases,\n propAliasName,\n options,\n )});`;\n }\n })\n .join('\\n');\n}\n\nexport function generateValidateMethods(\n nativeModule: NativeModuleSchema,\n aliases: AliasMap,\n options: CppCodegenOptions,\n): [string, string] {\n const methods = nativeModule.spec.methods;\n const traversedProperties = renderProperties(\n methods,\n aliases,\n false,\n options,\n );\n const traversedPropertyTuples = renderProperties(\n methods,\n aliases,\n true,\n options,\n );\n return [traversedPropertyTuples, traversedProperties];\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-windows/codegen",
3
- "version": "0.74.2",
3
+ "version": "0.75.0",
4
4
  "description": "Generators for react-native-codegen targeting react-native-windows",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "repository": {
@@ -22,7 +22,7 @@
22
22
  "react-native-windows-codegen": "./bin.js"
23
23
  },
24
24
  "dependencies": {
25
- "@react-native-windows/fs": "0.74.1",
25
+ "@react-native-windows/fs": "0.75.0",
26
26
  "chalk": "^4.1.0",
27
27
  "globby": "^11.1.0",
28
28
  "mustache": "^4.0.1",
@@ -30,9 +30,9 @@
30
30
  "yargs": "^16.2.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@rnw-scripts/eslint-config": "1.2.9",
33
+ "@rnw-scripts/eslint-config": "1.2.23",
34
34
  "@rnw-scripts/jest-unittest-config": "1.5.8",
35
- "@rnw-scripts/just-task": "2.3.25",
35
+ "@rnw-scripts/just-task": "2.3.40",
36
36
  "@rnw-scripts/ts-config": "2.0.5",
37
37
  "@types/chalk": "^2.2.0",
38
38
  "@types/jest": "^29.2.2",
@@ -57,7 +57,7 @@
57
57
  "src"
58
58
  ],
59
59
  "beachball": {
60
- "defaultNpmTag": "v0.74-stable",
60
+ "defaultNpmTag": "latest",
61
61
  "disallowedChangeTypes": [
62
62
  "major",
63
63
  "minor",
@@ -69,14 +69,49 @@ interface AliasCodeMap {
69
69
  [name: string]: AliasCode;
70
70
  }
71
71
 
72
+ function getArrayTypeName(
73
+ type: Nullable<NativeModuleBaseTypeAnnotation>): string {
74
+ if (type.type === 'ArrayTypeAnnotation' && type.elementType?.type === 'TypeAliasTypeAnnotation') {
75
+ return type.elementType.name;
76
+ }
77
+
78
+ return '';
79
+ }
80
+
81
+ function checkTypes(
82
+ aliases: AliasMap,
83
+ type: NativeModuleObjectTypeAnnotation,
84
+ aliasOrder: string[]): void {
85
+ for (const prop of type.properties) {
86
+ const propType = prop.typeAnnotation;
87
+ let propName = '';
88
+
89
+ if (propType.type === 'TypeAliasTypeAnnotation') {
90
+ propName = propType.name;
91
+ }
92
+
93
+ if (propType.type === 'ArrayTypeAnnotation') {
94
+ propName = getArrayTypeName(propType);
95
+ }
96
+
97
+ if (propName !== '' && !aliasOrder.includes(prop.name) && !aliases.jobs.includes(propName)) {
98
+ aliases.jobs.push(propName);
99
+ }
100
+ }
101
+ }
102
+
72
103
  function generateSingleAlias(
73
104
  aliases: AliasMap,
74
105
  aliasName: string,
75
106
  aliasCode: AliasCodeMap,
76
107
  options: CppCodegenOptions,
108
+ aliasOrder: string[],
77
109
  ): void {
78
110
  const aliasCppName = getAliasCppName(aliasName);
79
111
  const aliasType = <NativeModuleObjectTypeAnnotation>aliases.types[aliasName];
112
+
113
+ checkTypes(aliases, aliasType, aliasOrder);
114
+
80
115
  const definition = `
81
116
  struct ${aliasCppName} {
82
117
  ${translateObjectMembersDefinition(
@@ -114,7 +149,7 @@ function generateNestedAliasesInCorrectOrder(
114
149
  // generate a new struct and all fields will be examined
115
150
  // new anonymous objects could be found
116
151
  // they will be stored in aliases.jobs
117
- generateSingleAlias(aliases, aliasName, aliasCode, options);
152
+ generateSingleAlias(aliases, aliasName, aliasCode, options, aliasOrder);
118
153
  // nested C++ structs must be put before the current C++ struct
119
154
  // as they will be used in the current C++ struct
120
155
  // the order will be perfectly and easily ensured by doing this recursively
@@ -126,7 +161,9 @@ function generateNestedAliasesInCorrectOrder(
126
161
  );
127
162
  // all referenced C++ structs are generated
128
163
  // put the current one following them
129
- aliasOrder.push(aliasName);
164
+ if (!aliasOrder.includes(aliasName)) {
165
+ aliasOrder.push(aliasName);
166
+ }
130
167
  }
131
168
  }
132
169
 
@@ -26,7 +26,7 @@ const headerTemplate = `/*
26
26
  */
27
27
  #pragma once`;
28
28
 
29
- const specTemplate = `::_MODULE_CUSTPM_TYPES_REFLECTION_::
29
+ const specTemplate = `::_MODULE_CUSTOM_TYPES_REFLECTION_::
30
30
  struct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {
31
31
  ::_MODULE_MEMBERS_TUPLES_::
32
32
 
@@ -46,7 +46,7 @@ ${headerTemplate}
46
46
  #include <vector>
47
47
 
48
48
  namespace ::_NAMESPACE_:: {
49
- ::_MODULE_CUSTPM_TYPES_::
49
+ ::_MODULE_CUSTOM_TYPES_::
50
50
  } // namespace ::_NAMESPACE_::
51
51
  `;
52
52
 
@@ -71,7 +71,7 @@ ${headerTemplate}
71
71
  #include <tuple>
72
72
 
73
73
  namespace ::_NAMESPACE_:: {
74
- ::_MODULE_CUSTPM_TYPES_::
74
+ ::_MODULE_CUSTOM_TYPES_::
75
75
  ${specTemplate}
76
76
  };
77
77
 
@@ -147,8 +147,8 @@ ${errors}`;
147
147
 
148
148
  const replaceContent = function (template: string): string {
149
149
  return template
150
- .replace(/::_MODULE_CUSTPM_TYPES_::/g, customTypes)
151
- .replace(/::_MODULE_CUSTPM_TYPES_REFLECTION_::/g, customReflection)
150
+ .replace(/::_MODULE_CUSTOM_TYPES_::/g, customTypes)
151
+ .replace(/::_MODULE_CUSTOM_TYPES_REFLECTION_::/g, customReflection)
152
152
  .replace(/::_MODULE_MEMBERS_TUPLES_::/g, tuples.substring(1))
153
153
  .replace(/::_MODULE_MEMBERS_CHECKS_::/g, checks.substring(1))
154
154
  .replace(/::_MODULE_MEMBERS_ERRORS_::/g, errors)
@@ -147,7 +147,7 @@ ${type.properties
147
147
  function tryGetConstantType(
148
148
  nativeModule: NativeModuleSchema,
149
149
  ): NativeModuleObjectTypeAnnotation | undefined {
150
- const candidates = nativeModule.spec.properties.filter(
150
+ const candidates = nativeModule.spec.methods.filter(
151
151
  prop => prop.name === 'getConstants',
152
152
  );
153
153
  if (candidates.length === 0) {
@@ -224,7 +224,7 @@ export function generateTypeScript(
224
224
  ? ''
225
225
  : ` getConstants(): ${translateType(constantType)}`;
226
226
 
227
- const methods = nativeModule.spec.properties.filter(
227
+ const methods = nativeModule.spec.methods.filter(
228
228
  prop => prop.name !== 'getConstants',
229
229
  );
230
230
  const membersCode = methods.map(translateMethod).join('');
@@ -104,6 +104,7 @@ export function translateFieldOrReturnType(
104
104
  callerName,
105
105
  options,
106
106
  )}>`;
107
+ case 'FunctionTypeAnnotation':
107
108
  case 'MixedTypeAnnotation':
108
109
  return '';
109
110
  case 'EnumDeclaration':
@@ -13,7 +13,7 @@ export function generateValidateConstants(
13
13
  nativeModule: NativeModuleSchema,
14
14
  aliases: AliasMap,
15
15
  ): [string, string] | undefined {
16
- const candidates = nativeModule.spec.properties.filter(
16
+ const candidates = nativeModule.spec.methods.filter(
17
17
  prop => prop.name === 'getConstants',
18
18
  );
19
19
  if (candidates.length === 0) {
@@ -87,13 +87,13 @@ function translatePossibleMethodSignatures(
87
87
  }
88
88
 
89
89
  function renderProperties(
90
- properties: ReadonlyArray<NativeModulePropertyShape>,
90
+ methods: ReadonlyArray<NativeModulePropertyShape>,
91
91
  aliases: AliasMap,
92
92
  tuple: boolean,
93
93
  options: CppCodegenOptions,
94
94
  ): string {
95
95
  // TODO: generate code for constants
96
- return properties
96
+ return methods
97
97
  .filter(prop => prop.name !== 'getConstants')
98
98
  .map((prop, index) => {
99
99
  // TODO: prop.optional === true
@@ -160,15 +160,15 @@ export function generateValidateMethods(
160
160
  aliases: AliasMap,
161
161
  options: CppCodegenOptions,
162
162
  ): [string, string] {
163
- const properties = nativeModule.spec.properties;
163
+ const methods = nativeModule.spec.methods;
164
164
  const traversedProperties = renderProperties(
165
- properties,
165
+ methods,
166
166
  aliases,
167
167
  false,
168
168
  options,
169
169
  );
170
170
  const traversedPropertyTuples = renderProperties(
171
- properties,
171
+ methods,
172
172
  aliases,
173
173
  true,
174
174
  options,