@react-native-windows/codegen 0.0.0-canary.89 → 0.0.0-canary.90

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,19 +1,30 @@
1
1
  # Change Log - @react-native-windows/codegen
2
2
 
3
- This log was last generated on Thu, 23 May 2024 05:15:45 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 30 May 2024 05:15:53 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## 0.0.0-canary.89
7
+ ## 0.0.0-canary.90
8
8
 
9
- Thu, 23 May 2024 05:15:45 GMT
9
+ Thu, 30 May 2024 05:15:53 GMT
10
10
 
11
11
  ### Changes
12
12
 
13
- - Bump @react-native-windows/fs to v0.0.0-canary.46
14
- - Bump @rnw-scripts/eslint-config to v1.2.18
15
- - Bump @rnw-scripts/just-task to v2.3.34
13
+ - RN Integration 05/11 (1422161+marlenecota@users.noreply.github.com)
14
+ - Bump @react-native-windows/fs to v0.0.0-canary.47
15
+ - Bump @rnw-scripts/eslint-config to v1.2.19
16
+ - Bump @rnw-scripts/just-task to v2.3.35
16
17
 
18
+ ## 0.0.0-canary.89
19
+
20
+ Thu, 23 May 2024 05:17:50 GMT
21
+
22
+ ### Changes
23
+
24
+ - Bump @react-native-windows/fs to v0.0.0-canary.46
25
+ - Bump @rnw-scripts/eslint-config to v1.2.18
26
+ - Bump @rnw-scripts/just-task to v2.3.34
27
+
17
28
  ## 0.0.0-canary.88
18
29
 
19
30
  Wed, 22 May 2024 05:18:18 GMT
@@ -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;;;;GAI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,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,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,SAAS,gCAAgC,CACvC,IAAsC,EACtC,YAAoB,EACpB,MAAc;IAEd,OAAO,IAAI,CAAC,UAAU;SACnB,GAAG,CAA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AO,EACP,SAAS,EACT,UAAU,EACV,OAAO,CACR,CAAC;QACF,2CAA2C;QAC3C,qCAAqC;QACrC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;YACnC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;SAC5B;KACF;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 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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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,cAA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,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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-windows/codegen",
3
- "version": "0.0.0-canary.89",
3
+ "version": "0.0.0-canary.90",
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.0.0-canary.46",
25
+ "@react-native-windows/fs": "^0.0.0-canary.47",
26
26
  "chalk": "^4.1.0",
27
27
  "globby": "^11.0.4",
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.18",
33
+ "@rnw-scripts/eslint-config": "1.2.19",
34
34
  "@rnw-scripts/jest-unittest-config": "1.5.8",
35
- "@rnw-scripts/just-task": "2.3.34",
35
+ "@rnw-scripts/just-task": "2.3.35",
36
36
  "@rnw-scripts/ts-config": "2.0.5",
37
37
  "@types/chalk": "^2.2.0",
38
38
  "@types/jest": "^29.2.2",
@@ -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)