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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/CHANGELOG.md +1135 -16
  2. package/README.md +1 -1
  3. package/bin.js +0 -0
  4. package/lib-commonjs/Cli.d.ts +7 -0
  5. package/lib-commonjs/Cli.js +103 -0
  6. package/lib-commonjs/Cli.js.map +1 -0
  7. package/lib-commonjs/generators/AliasGen.d.ts +12 -0
  8. package/lib-commonjs/generators/AliasGen.js +115 -0
  9. package/lib-commonjs/generators/AliasGen.js.map +1 -0
  10. package/lib-commonjs/generators/AliasManaging.d.ts +15 -0
  11. package/lib-commonjs/generators/AliasManaging.js +49 -0
  12. package/lib-commonjs/generators/AliasManaging.js.map +1 -0
  13. package/lib-commonjs/generators/GenerateComponentWindows.d.ts +13 -0
  14. package/lib-commonjs/generators/GenerateComponentWindows.js +468 -0
  15. package/lib-commonjs/generators/GenerateComponentWindows.js.map +1 -0
  16. package/lib-commonjs/generators/GenerateNM2.d.ts +15 -0
  17. package/lib-commonjs/generators/GenerateNM2.js +145 -0
  18. package/lib-commonjs/generators/GenerateNM2.js.map +1 -0
  19. package/lib-commonjs/generators/GenerateTypeScript.d.ts +11 -0
  20. package/lib-commonjs/generators/GenerateTypeScript.js +165 -0
  21. package/lib-commonjs/generators/GenerateTypeScript.js.map +1 -0
  22. package/lib-commonjs/generators/ObjectTypes.d.ts +13 -0
  23. package/lib-commonjs/generators/ObjectTypes.js +81 -0
  24. package/lib-commonjs/generators/ObjectTypes.js.map +1 -0
  25. package/lib-commonjs/generators/ParamTypes.d.ts +13 -0
  26. package/lib-commonjs/generators/ParamTypes.js +183 -0
  27. package/lib-commonjs/generators/ParamTypes.js.map +1 -0
  28. package/lib-commonjs/generators/PropObjectTypes.d.ts +18 -0
  29. package/lib-commonjs/generators/PropObjectTypes.js +208 -0
  30. package/lib-commonjs/generators/PropObjectTypes.js.map +1 -0
  31. package/lib-commonjs/generators/ReturnTypes.d.ts +10 -0
  32. package/lib-commonjs/generators/ReturnTypes.js +29 -0
  33. package/lib-commonjs/generators/ReturnTypes.js.map +1 -0
  34. package/lib-commonjs/generators/ValidateConstants.d.ts +8 -0
  35. package/lib-commonjs/generators/ValidateConstants.js +38 -0
  36. package/lib-commonjs/generators/ValidateConstants.js.map +1 -0
  37. package/lib-commonjs/generators/ValidateMethods.d.ts +14 -0
  38. package/lib-commonjs/generators/ValidateMethods.js +112 -0
  39. package/lib-commonjs/generators/ValidateMethods.js.map +1 -0
  40. package/lib-commonjs/index.d.ts +39 -0
  41. package/lib-commonjs/index.js +227 -0
  42. package/lib-commonjs/index.js.map +1 -0
  43. package/package.json +39 -21
  44. package/src/Cli.ts +69 -232
  45. package/src/generators/AliasGen.ts +195 -0
  46. package/src/generators/AliasManaging.ts +75 -0
  47. package/src/generators/GenerateComponentWindows.ts +616 -0
  48. package/src/generators/GenerateNM2.ts +128 -131
  49. package/src/generators/GenerateTypeScript.ts +250 -0
  50. package/src/generators/ObjectTypes.ts +95 -37
  51. package/src/generators/ParamTypes.ts +309 -53
  52. package/src/generators/PropObjectTypes.ts +223 -0
  53. package/src/generators/ReturnTypes.ts +38 -40
  54. package/src/generators/ValidateConstants.ts +50 -0
  55. package/src/generators/ValidateMethods.ts +270 -0
  56. package/src/index.ts +412 -0
  57. package/.eslintrc.js +0 -4
  58. package/.vscode/launch.json +0 -23
  59. package/CHANGELOG.json +0 -726
  60. package/jest.config.js +0 -1
  61. package/tsconfig.json +0 -5
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @react-native-windows/codegen
2
2
 
3
- Generators for react-native-codegen targeting react-native-windows
3
+ Generators for @react-native/codegen targeting react-native-windows
4
4
 
5
5
  ## Usage
6
6
 
package/bin.js CHANGED
File without changes
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ *
5
+ * @format
6
+ */
7
+ export {};
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation.
4
+ * Licensed under the MIT License.
5
+ *
6
+ * @format
7
+ */
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const yargs_1 = __importDefault(require("yargs"));
13
+ const index_1 = require("./index");
14
+ const argv = yargs_1.default.options({
15
+ file: {
16
+ type: 'string',
17
+ describe: 'file which contains spec',
18
+ },
19
+ files: {
20
+ type: 'string',
21
+ array: true,
22
+ describe: 'glob patterns for files which contains specs',
23
+ },
24
+ modulesTypeScriptTypes: {
25
+ type: 'boolean',
26
+ describe: 'generate turbo module definition files in TypeScript',
27
+ default: false,
28
+ },
29
+ modulesCxx: {
30
+ type: 'boolean',
31
+ describe: 'generate C++ JSI turbo module spec files',
32
+ default: false,
33
+ },
34
+ modulesWindows: {
35
+ type: 'boolean',
36
+ describe: 'generate turbo module spec files for REACT_MODULE',
37
+ default: false,
38
+ },
39
+ methodOnly: {
40
+ type: 'boolean',
41
+ describe: 'generate only method metadata in C++ turbo module spec',
42
+ default: false,
43
+ },
44
+ outputDirectory: {
45
+ type: 'string',
46
+ describe: 'output directory',
47
+ default: 'codegen',
48
+ },
49
+ test: {
50
+ type: 'boolean',
51
+ describe: 'Verify that the generated output is unchanged',
52
+ default: false,
53
+ },
54
+ namespace: {
55
+ type: 'string',
56
+ describe: 'C++/C# Namespace to put generated native modules in',
57
+ default: 'MyNamespace',
58
+ },
59
+ libraryName: {
60
+ type: 'string',
61
+ required: true,
62
+ describe: 'Used for part of the path generated within the codegen dir',
63
+ },
64
+ cppStringType: {
65
+ choices: ['std::string', 'std::wstring'],
66
+ describe: 'C++ string type in generated code, should be "std::string" or "std::wstring"',
67
+ default: 'std::string',
68
+ },
69
+ separateDataTypes: {
70
+ type: 'boolean',
71
+ describe: 'generate data types in a separate file',
72
+ default: false,
73
+ },
74
+ componentsWindows: {
75
+ type: 'boolean',
76
+ describe: 'generate component cpp files for custom native components',
77
+ default: false,
78
+ },
79
+ internalComponents: {
80
+ type: 'boolean',
81
+ describe: 'generate non-ABI cpp/h for internal usage of built in native components [Only used within RNW itself]',
82
+ default: false,
83
+ hidden: true,
84
+ },
85
+ }).argv;
86
+ if ((argv.file && argv.files) || (!argv.file && !argv.files)) {
87
+ console.error('You must specify either --file or --files.');
88
+ process.exit(1);
89
+ }
90
+ if (argv.cppStringType !== 'std::string' &&
91
+ argv.cppStringType !== 'std::wstring') {
92
+ console.error('cppStringType should be "std::string" or "std::wstring".');
93
+ process.exit(1);
94
+ }
95
+ // type casting is necessary here because
96
+ // cppStringType does not become union of string literals
97
+ // until yargs.options get improved in the future
98
+ const changesNecessary = (0, index_1.runCodeGen)(argv);
99
+ if (argv.test && changesNecessary) {
100
+ console.error('There is a change in the output of codegen. Rerun "npx @react-native-community/cli codegen-windows" to regenerate.');
101
+ process.exit(2);
102
+ }
103
+ //# sourceMappingURL=Cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Cli.js","sourceRoot":"","sources":["../src/Cli.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;AAEH,kDAA0B;AAC1B,mCAAmD;AAEnD,MAAM,IAAI,GAAG,eAAK,CAAC,OAAO,CAAC;IACzB,IAAI,EAAE;QACJ,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,0BAA0B;KACrC;IACD,KAAK,EAAE;QACL,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,IAAI;QACX,QAAQ,EAAE,8CAA8C;KACzD;IACD,sBAAsB,EAAE;QACtB,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,sDAAsD;QAChE,OAAO,EAAE,KAAK;KACf;IACD,UAAU,EAAE;QACV,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,0CAA0C;QACpD,OAAO,EAAE,KAAK;KACf;IACD,cAAc,EAAE;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D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB;AAED,IACE,IAAI,CAAC,aAAa,KAAK,aAAa;IACpC,IAAI,CAAC,aAAa,KAAK,cAAc,EACrC;IACA,OAAO,CAAC,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC1E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB;AAED,yCAAyC;AACzC,yDAAyD;AACzD,iDAAiD;AACjD,MAAM,gBAAgB,GAAG,IAAA,kBAAU,EAAiB,IAAI,CAAC,CAAC;AAE1D,IAAI,IAAI,CAAC,IAAI,IAAI,gBAAgB,EAAE;IACjC,OAAO,CAAC,KAAK,CACX,qHAAqH,CACtH,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport yargs from 'yargs';\nimport {CodeGenOptions, runCodeGen} from './index';\n\nconst argv = yargs.options({\n file: {\n type: 'string',\n describe: 'file which contains spec',\n },\n files: {\n type: 'string',\n array: true,\n describe: 'glob patterns for files which contains specs',\n },\n modulesTypeScriptTypes: {\n type: 'boolean',\n describe: 'generate turbo module definition files in TypeScript',\n default: false,\n },\n modulesCxx: {\n type: 'boolean',\n describe: 'generate C++ JSI turbo module spec files',\n default: false,\n },\n modulesWindows: {\n type: 'boolean',\n describe: 'generate turbo module spec files for REACT_MODULE',\n default: false,\n },\n methodOnly: {\n type: 'boolean',\n describe: 'generate only method metadata in C++ turbo module spec',\n default: false,\n },\n outputDirectory: {\n type: 'string',\n describe: 'output directory',\n default: 'codegen',\n },\n test: {\n type: 'boolean',\n describe: 'Verify that the generated output is unchanged',\n default: false,\n },\n namespace: {\n type: 'string',\n describe: 'C++/C# Namespace to put generated native modules in',\n default: 'MyNamespace',\n },\n libraryName: {\n type: 'string',\n required: true,\n describe: 'Used for part of the path generated within the codegen dir',\n },\n cppStringType: {\n choices: ['std::string', 'std::wstring'],\n describe:\n 'C++ string type in generated code, should be \"std::string\" or \"std::wstring\"',\n default: 'std::string',\n },\n separateDataTypes: {\n type: 'boolean',\n describe: 'generate data types in a separate file',\n default: false,\n },\n componentsWindows: {\n type: 'boolean',\n describe: 'generate component cpp files for custom native components',\n default: false,\n },\n internalComponents: {\n type: 'boolean',\n describe:\n 'generate non-ABI cpp/h for internal usage of built in native components [Only used within RNW itself]',\n default: false,\n hidden: true,\n },\n}).argv;\n\nif ((argv.file && argv.files) || (!argv.file && !argv.files)) {\n console.error('You must specify either --file or --files.');\n process.exit(1);\n}\n\nif (\n argv.cppStringType !== 'std::string' &&\n argv.cppStringType !== 'std::wstring'\n) {\n console.error('cppStringType should be \"std::string\" or \"std::wstring\".');\n process.exit(1);\n}\n\n// type casting is necessary here because\n// cppStringType does not become union of string literals\n// until yargs.options get improved in the future\nconst changesNecessary = runCodeGen(<CodeGenOptions>argv);\n\nif (argv.test && changesNecessary) {\n console.error(\n 'There is a change in the output of codegen. Rerun \"npx @react-native-community/cli codegen-windows\" to regenerate.',\n );\n process.exit(2);\n}\n"]}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ import type { NativeModuleObjectTypeAnnotation } from '@react-native/codegen/lib/CodegenSchema';
7
+ import { AliasMap } from './AliasManaging';
8
+ import { CppCodegenOptions } from './ObjectTypes';
9
+ export declare function createAliasMap(nativeModuleAliases: {
10
+ [name: string]: NativeModuleObjectTypeAnnotation;
11
+ }): AliasMap;
12
+ export declare function generateAliases(aliases: AliasMap, options: CppCodegenOptions): [string, string];
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ 'use strict';
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.generateAliases = exports.createAliasMap = void 0;
9
+ const AliasManaging_1 = require("./AliasManaging");
10
+ const ObjectTypes_1 = require("./ObjectTypes");
11
+ function translateObjectMembersDefinition(type, aliases, baseAliasName, prefix, options) {
12
+ return type.properties
13
+ .map((prop) => {
14
+ let propType = prop.typeAnnotation;
15
+ if (prop.optional && propType.type !== 'NullableTypeAnnotation') {
16
+ propType = { type: 'NullableTypeAnnotation', typeAnnotation: propType };
17
+ }
18
+ return `${prefix}${(0, ObjectTypes_1.translateField)(propType, aliases, `${baseAliasName}_${prop.name}`, options)} ${prop.name};`;
19
+ })
20
+ .join('\n');
21
+ }
22
+ function translateObjectMembersReflection(type, aliasCppName, prefix) {
23
+ return type.properties
24
+ .map((prop) => {
25
+ return `${prefix}{L"${prop.name}", &${aliasCppName}::${prop.name}},`;
26
+ })
27
+ .join('\n');
28
+ }
29
+ function createAliasMap(nativeModuleAliases) {
30
+ const aliases = { types: {}, jobs: Object.keys(nativeModuleAliases) };
31
+ for (const aliasName of aliases.jobs) {
32
+ aliases.types[aliasName] = nativeModuleAliases[aliasName];
33
+ }
34
+ return aliases;
35
+ }
36
+ exports.createAliasMap = createAliasMap;
37
+ function getArrayTypeName(type) {
38
+ if (type.type === 'ArrayTypeAnnotation' &&
39
+ type.elementType.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 !== '' &&
55
+ !aliasOrder.includes(prop.name) &&
56
+ !aliases.jobs.includes(propName)) {
57
+ aliases.jobs.push(propName);
58
+ }
59
+ }
60
+ }
61
+ function generateSingleAlias(aliases, aliasName, aliasCode, options, aliasOrder) {
62
+ const aliasCppName = (0, AliasManaging_1.getAliasCppName)(aliasName);
63
+ const aliasType = aliases.types[aliasName];
64
+ checkTypes(aliases, aliasType, aliasOrder);
65
+ const definition = `
66
+ struct ${aliasCppName} {
67
+ ${translateObjectMembersDefinition(aliasType, aliases, aliasName, ' ', options)}
68
+ };
69
+ `;
70
+ const reflection = `
71
+ inline winrt::Microsoft::ReactNative::FieldMap GetStructInfo(${aliasCppName}*) noexcept {
72
+ winrt::Microsoft::ReactNative::FieldMap fieldMap {
73
+ ${translateObjectMembersReflection(aliasType, aliasCppName, ' ')}
74
+ };
75
+ return fieldMap;
76
+ }
77
+ `;
78
+ aliasCode[aliasName] = { definition, reflection };
79
+ }
80
+ function generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder, options) {
81
+ // retrieve and clean all ungenerated aliases
82
+ const jobs = aliases.jobs;
83
+ aliases.jobs = [];
84
+ // generate each one in its found order
85
+ for (const aliasName of jobs) {
86
+ // generate a new struct and all fields will be examined
87
+ // new anonymous objects could be found
88
+ // they will be stored in aliases.jobs
89
+ generateSingleAlias(aliases, aliasName, aliasCode, options, aliasOrder);
90
+ // nested C++ structs must be put before the current C++ struct
91
+ // as they will be used in the current C++ struct
92
+ // the order will be perfectly and easily ensured by doing this recursively
93
+ generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder, options);
94
+ // all referenced C++ structs are generated
95
+ // put the current one following them
96
+ if (!aliasOrder.includes(aliasName)) {
97
+ aliasOrder.push(aliasName);
98
+ }
99
+ }
100
+ }
101
+ function generateAliases(aliases, options) {
102
+ const aliasCode = {};
103
+ const aliasOrder = [];
104
+ generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder, options);
105
+ // aliasOrder now has the correct order of C++ struct code
106
+ let customTypes = '';
107
+ let customReflection = '';
108
+ for (const aliasName of aliasOrder) {
109
+ customTypes = `${customTypes}${aliasCode[aliasName].definition}`;
110
+ customReflection = `${customReflection}${aliasCode[aliasName].reflection}`;
111
+ }
112
+ return [customTypes, customReflection];
113
+ }
114
+ exports.generateAliases = generateAliases;
115
+ //# sourceMappingURL=AliasGen.js.map
@@ -0,0 +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,SAAS,gCAAgC,CACvC,IAAsC,EACtC,YAAoB,EACpB,MAAc;IAEd,OAAO,IAAI,CAAC,UAAU;SACnB,GAAG,CAAC,CAAC,IAA0D,EAAE,EAAE;QAClE,OAAO,GAAG,MAAM,MAAM,IAAI,CAAC,IAAI,OAAO,YAAY,KAAK,IAAI,CAAC,IAAI,IAAI,CAAC;IACvE,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED,SAAgB,cAAc,CAAC,mBAE9B;IACC,MAAM,OAAO,GAAa,EAAC,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,E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C,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>,\n): string {\n if (\n type.type === 'ArrayTypeAnnotation' &&\n type.elementType.type === 'TypeAliasTypeAnnotation'\n ) {\n return type.elementType.name;\n }\n\n return '';\n}\n\nfunction checkTypes(\n aliases: AliasMap,\n type: NativeModuleObjectTypeAnnotation,\n aliasOrder: string[],\n): 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 (\n propName !== '' &&\n !aliasOrder.includes(prop.name) &&\n !aliases.jobs.includes(propName)\n ) {\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"]}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ import type { NativeModuleObjectTypeAnnotation } from '@react-native/codegen/lib/CodegenSchema';
7
+ export declare function setPreferredModuleName(moduleName: string): void;
8
+ export declare function getAliasCppName(typeName: string): string;
9
+ export interface AliasMap<T = NativeModuleObjectTypeAnnotation> {
10
+ types: {
11
+ [name: string]: T | undefined;
12
+ };
13
+ jobs: string[];
14
+ }
15
+ export declare function getAnonymousAliasCppName<T = NativeModuleObjectTypeAnnotation>(aliases: AliasMap<T>, baseAliasName: string, objectType: T): string;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ 'use strict';
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.getAnonymousAliasCppName = exports.getAliasCppName = exports.setPreferredModuleName = void 0;
9
+ let preferredModuleName = '';
10
+ function setPreferredModuleName(moduleName) {
11
+ preferredModuleName = moduleName;
12
+ }
13
+ exports.setPreferredModuleName = setPreferredModuleName;
14
+ function getAliasCppName(typeName) {
15
+ return `${preferredModuleName}Spec_${typeName}`;
16
+ }
17
+ exports.getAliasCppName = getAliasCppName;
18
+ const ExtendedObjectKey = '$RNW-TURBOMODULE-ALIAS';
19
+ function recordAnonymousAlias(aliases, baseAliasName, extended) {
20
+ extended[ExtendedObjectKey] = baseAliasName;
21
+ aliases.types[baseAliasName] = extended;
22
+ aliases.jobs.push(baseAliasName);
23
+ return baseAliasName;
24
+ }
25
+ function getAnonymousAliasCppName(aliases, baseAliasName, objectType) {
26
+ // someone found an anonymous object literal type
27
+ // if the ExtendedObjectKey flag has been set
28
+ // then it is a known one
29
+ // this happens because method signatures are generate twice in spec and error messages
30
+ const extended = objectType;
31
+ const key = extended[ExtendedObjectKey];
32
+ if (key !== undefined) {
33
+ return getAliasCppName(key);
34
+ }
35
+ // if the ExtendedObjectKey flag has not been set
36
+ // it means it is a unknown one
37
+ // associate the name with this object literal type and return
38
+ if (aliases.types[baseAliasName] === undefined) {
39
+ return getAliasCppName(recordAnonymousAlias(aliases, baseAliasName, extended));
40
+ }
41
+ // sometimes names could be anonymous
42
+ let index = 2;
43
+ while (aliases.types[`${baseAliasName}${index}`] !== undefined) {
44
+ index++;
45
+ }
46
+ return getAliasCppName(recordAnonymousAlias(aliases, `${baseAliasName}${index}`, extended));
47
+ }
48
+ exports.getAnonymousAliasCppName = getAnonymousAliasCppName;
49
+ //# sourceMappingURL=AliasManaging.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AliasManaging.js","sourceRoot":"","sources":["../../src/generators/AliasManaging.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAIb,IAAI,mBAAmB,GAAW,EAAE,CAAC;AAErC,SAAgB,sBAAsB,CAAC,UAAkB;IACvD,mBAAmB,GAAG,UAAU,CAAC;AACnC,CAAC;AAFD,wDAEC;AAED,SAAgB,eAAe,CAAC,QAAgB;IAC9C,OAAO,GAAG,mBAAmB,QAAQ,QAAQ,EAAE,CAAC;AAClD,CAAC;AAFD,0CAEC;AAOD,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AAKnD,SAAS,oBAAoB,CAC3B,OAAoB,EACpB,aAAqB,EACrB,QAA2B;IAE3B,QAAQ,CAAC,iBAAiB,CAAC,GAAG,aAAa,CAAC;IAC5C,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,QAAQ,CAAC;IACxC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACjC,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,SAAgB,wBAAwB,CACtC,OAAoB,EACpB,aAAqB,EACrB,UAAa;IAEb,iDAAiD;IACjD,6CAA6C;IAC7C,yBAAyB;IACzB,uFAAuF;IACvF,MAAM,QAAQ,GAAsB,UAAU,CAAC;IAC/C,MAAM,GAAG,GAAG,QAAQ,CAAC,iBAAiB,CAAC,CAAC;IACxC,IAAI,GAAG,KAAK,SAAS,EAAE;QACrB,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC;KAC7B;IAED,iDAAiD;IACjD,+BAA+B;IAC/B,8DAA8D;IAC9D,IAAI,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,SAAS,EAAE;QAC9C,OAAO,eAAe,CACpB,oBAAoB,CAAI,OAAO,EAAE,aAAa,EAAE,QAAQ,CAAC,CAC1D,CAAC;KACH;IAED,qCAAqC;IACrC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,OAAO,OAAO,CAAC,KAAK,CAAC,GAAG,aAAa,GAAG,KAAK,EAAE,CAAC,KAAK,SAAS,EAAE;QAC9D,KAAK,EAAE,CAAC;KACT;IAED,OAAO,eAAe,CACpB,oBAAoB,CAAC,OAAO,EAAE,GAAG,aAAa,GAAG,KAAK,EAAE,EAAE,QAAQ,CAAC,CACpE,CAAC;AACJ,CAAC;AAjCD,4DAiCC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {NativeModuleObjectTypeAnnotation} from '@react-native/codegen/lib/CodegenSchema';\n\nlet preferredModuleName: string = '';\n\nexport function setPreferredModuleName(moduleName: string): void {\n preferredModuleName = moduleName;\n}\n\nexport function getAliasCppName(typeName: string): string {\n return `${preferredModuleName}Spec_${typeName}`;\n}\n\nexport interface AliasMap<T = NativeModuleObjectTypeAnnotation> {\n types: {[name: string]: T | undefined};\n jobs: string[];\n}\n\nconst ExtendedObjectKey = '$RNW-TURBOMODULE-ALIAS';\ntype ExtendedObject<T> = {\n '$RNW-TURBOMODULE-ALIAS'?: string;\n} & T;\n\nfunction recordAnonymousAlias<T = NativeModuleObjectTypeAnnotation>(\n aliases: AliasMap<T>,\n baseAliasName: string,\n extended: ExtendedObject<T>,\n): string {\n extended[ExtendedObjectKey] = baseAliasName;\n aliases.types[baseAliasName] = extended;\n aliases.jobs.push(baseAliasName);\n return baseAliasName;\n}\n\nexport function getAnonymousAliasCppName<T = NativeModuleObjectTypeAnnotation>(\n aliases: AliasMap<T>,\n baseAliasName: string,\n objectType: T,\n): string {\n // someone found an anonymous object literal type\n // if the ExtendedObjectKey flag has been set\n // then it is a known one\n // this happens because method signatures are generate twice in spec and error messages\n const extended = <ExtendedObject<T>>objectType;\n const key = extended[ExtendedObjectKey];\n if (key !== undefined) {\n return getAliasCppName(key);\n }\n\n // if the ExtendedObjectKey flag has not been set\n // it means it is a unknown one\n // associate the name with this object literal type and return\n if (aliases.types[baseAliasName] === undefined) {\n return getAliasCppName(\n recordAnonymousAlias<T>(aliases, baseAliasName, extended),\n );\n }\n\n // sometimes names could be anonymous\n let index = 2;\n while (aliases.types[`${baseAliasName}${index}`] !== undefined) {\n index++;\n }\n\n return getAliasCppName(\n recordAnonymousAlias(aliases, `${baseAliasName}${index}`, extended),\n );\n}\n"]}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ import type { SchemaType } from '@react-native/codegen/lib/CodegenSchema';
7
+ import type { CppStringTypes } from './ObjectTypes';
8
+ export type { CppStringTypes } from './ObjectTypes';
9
+ type FilesOutput = Map<string, string>;
10
+ export declare function createComponentGenerator({ namespace, cppStringType, }: {
11
+ namespace: string;
12
+ cppStringType: CppStringTypes;
13
+ }): (_libraryName: string, schema: SchemaType, _moduleSpecName: string) => FilesOutput;