@react-native-windows/codegen 0.0.0-canary.17 → 0.0.0-canary.18

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 (34) hide show
  1. package/CHANGELOG.json +16 -1
  2. package/CHANGELOG.md +12 -4
  3. package/lib-commonjs/Cli.d.ts +7 -0
  4. package/lib-commonjs/Cli.js +201 -0
  5. package/lib-commonjs/Cli.js.map +1 -0
  6. package/lib-commonjs/generators/AliasGen.d.ts +11 -0
  7. package/lib-commonjs/generators/AliasGen.js +72 -0
  8. package/lib-commonjs/generators/AliasGen.js.map +1 -0
  9. package/lib-commonjs/generators/AliasManaging.d.ts +15 -0
  10. package/lib-commonjs/generators/AliasManaging.js +49 -0
  11. package/lib-commonjs/generators/AliasManaging.js.map +1 -0
  12. package/lib-commonjs/generators/GenerateNM2.d.ts +11 -0
  13. package/lib-commonjs/generators/GenerateNM2.js +94 -0
  14. package/lib-commonjs/generators/GenerateNM2.js.map +1 -0
  15. package/lib-commonjs/generators/ObjectTypes.d.ts +8 -0
  16. package/lib-commonjs/generators/ObjectTypes.js +53 -0
  17. package/lib-commonjs/generators/ObjectTypes.js.map +1 -0
  18. package/lib-commonjs/generators/ParamTypes.d.ts +11 -0
  19. package/lib-commonjs/generators/ParamTypes.js +114 -0
  20. package/lib-commonjs/generators/ParamTypes.js.map +1 -0
  21. package/lib-commonjs/generators/ReturnTypes.d.ts +9 -0
  22. package/lib-commonjs/generators/ReturnTypes.js +63 -0
  23. package/lib-commonjs/generators/ReturnTypes.js.map +1 -0
  24. package/lib-commonjs/generators/ValidateConstants.d.ts +8 -0
  25. package/lib-commonjs/generators/ValidateConstants.js +38 -0
  26. package/lib-commonjs/generators/ValidateConstants.js.map +1 -0
  27. package/lib-commonjs/generators/ValidateMethods.d.ts +8 -0
  28. package/lib-commonjs/generators/ValidateMethods.js +70 -0
  29. package/lib-commonjs/generators/ValidateMethods.js.map +1 -0
  30. package/package.json +8 -1
  31. package/.eslintrc.js +0 -4
  32. package/.vscode/launch.json +0 -23
  33. package/jest.config.js +0 -1
  34. package/tsconfig.json +0 -5
package/CHANGELOG.json CHANGED
@@ -2,7 +2,22 @@
2
2
  "name": "@react-native-windows/codegen",
3
3
  "entries": [
4
4
  {
5
- "date": "Thu, 21 Oct 2021 05:07:06 GMT",
5
+ "date": "Fri, 22 Oct 2021 05:06:27 GMT",
6
+ "tag": "@react-native-windows/codegen_v0.0.0-canary.18",
7
+ "version": "0.0.0-canary.18",
8
+ "comments": {
9
+ "prerelease": [
10
+ {
11
+ "author": "30809111+acoates-ms@users.noreply.github.com",
12
+ "package": "@react-native-windows/codegen",
13
+ "comment": "Built files not included in published package",
14
+ "commit": "e8d09f86fce740a0c16b6f6f9fd876d2122cfc74"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Thu, 21 Oct 2021 05:08:01 GMT",
6
21
  "tag": "@react-native-windows/codegen_v0.0.0-canary.17",
7
22
  "version": "0.0.0-canary.17",
8
23
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,17 +1,25 @@
1
1
  # Change Log - @react-native-windows/codegen
2
2
 
3
- This log was last generated on Thu, 21 Oct 2021 05:07:06 GMT and should not be manually modified.
3
+ This log was last generated on Fri, 22 Oct 2021 05:06:27 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## 0.0.0-canary.17
7
+ ## 0.0.0-canary.18
8
8
 
9
- Thu, 21 Oct 2021 05:07:06 GMT
9
+ Fri, 22 Oct 2021 05:06:27 GMT
10
10
 
11
11
  ### Changes
12
12
 
13
- - Update to typescript 4 (30809111+acoates-ms@users.noreply.github.com)
13
+ - Built files not included in published package (30809111+acoates-ms@users.noreply.github.com)
14
14
 
15
+ ## 0.0.0-canary.17
16
+
17
+ Thu, 21 Oct 2021 05:08:01 GMT
18
+
19
+ ### Changes
20
+
21
+ - Update to typescript 4 (30809111+acoates-ms@users.noreply.github.com)
22
+
15
23
  ## 0.0.0-canary.16
16
24
 
17
25
  Wed, 29 Sep 2021 05:06:54 GMT
@@ -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,201 @@
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 path_1 = __importDefault(require("path"));
14
+ const fs_1 = __importDefault(require("fs"));
15
+ const globby_1 = __importDefault(require("globby"));
16
+ const GenerateNM2_1 = require("./generators/GenerateNM2");
17
+ // @ts-ignore
18
+ const flow_1 = require("react-native-tscodegen/lib/rncodegen/src/parsers/flow");
19
+ // @ts-ignore
20
+ const schemaValidator_1 = __importDefault(require("react-native-tscodegen/lib/rncodegen/src/schemaValidator"));
21
+ const argv = yargs_1.default.options({
22
+ file: {
23
+ type: 'string',
24
+ describe: 'file which contains spec',
25
+ },
26
+ files: {
27
+ type: 'array',
28
+ describe: 'glob patterns for files which contains specs',
29
+ },
30
+ test: {
31
+ type: 'boolean',
32
+ describe: 'Verify that the generated output is unchanged',
33
+ },
34
+ namespace: {
35
+ type: 'string',
36
+ describe: 'C++/C# Namespace to put generated native modules in',
37
+ default: 'MyNamespace',
38
+ },
39
+ libraryName: {
40
+ type: 'string',
41
+ required: true,
42
+ describe: 'Used for part of the path generated within the codegen dir',
43
+ },
44
+ }).argv;
45
+ /*
46
+ const GENERATORS = {
47
+ descriptors: [generateComponentDescriptorH.generate],
48
+ events: [
49
+ generateEventEmitterCpp.generate,
50
+ generateEventEmitterH.generate,
51
+ generateModuleHObjCpp.generate,
52
+ generateModuleMm.generate,
53
+ ],
54
+ props: [
55
+ generateComponentHObjCpp.generate,
56
+ generatePropsCpp.generate,
57
+ generatePropsH.generate,
58
+ generatePropsJavaInterface.generate,
59
+ generatePropsJavaDelegate.generate,
60
+ ],
61
+ modules: [generateModuleCpp.generate, generateModuleH.generate],
62
+ tests: [generateTests.generate],
63
+ 'shadow-nodes': [
64
+ generateShadowNodeCpp.generate,
65
+ generateShadowNodeH.generate,
66
+ ],
67
+ };
68
+ */
69
+ function normalizeFileMap(map, outputDir, outMap) {
70
+ for (const [fileName, contents] of map) {
71
+ const location = path_1.default.join(outputDir, fileName);
72
+ outMap.set(path_1.default.normalize(location), contents);
73
+ }
74
+ }
75
+ function checkFilesForChanges(map, outputDir) {
76
+ let hasChanges = false;
77
+ const allExistingFiles = globby_1.default
78
+ .sync(`${outputDir}/**`)
79
+ .map(_ => path_1.default.normalize(_))
80
+ .sort();
81
+ const allGeneratedFiles = [...map.keys()].map(_ => path_1.default.normalize(_)).sort();
82
+ if (allExistingFiles.length !== allGeneratedFiles.length ||
83
+ !allExistingFiles.every((val, index) => val === allGeneratedFiles[index]))
84
+ return true;
85
+ for (const [fileName, contents] of map) {
86
+ if (!fs_1.default.existsSync(fileName)) {
87
+ hasChanges = true;
88
+ continue;
89
+ }
90
+ const currentContents = fs_1.default.readFileSync(fileName, 'utf8');
91
+ if (currentContents !== contents) {
92
+ console.error(`- ${fileName} has changed`);
93
+ hasChanges = true;
94
+ continue;
95
+ }
96
+ }
97
+ return hasChanges;
98
+ }
99
+ function writeMapToFiles(map, outputDir) {
100
+ let success = true;
101
+ // This ensures that we delete any generated files from modules that have been deleted
102
+ const allExistingFiles = globby_1.default.sync(`${outputDir}/**`);
103
+ allExistingFiles.forEach(existingFile => {
104
+ if (!map.has(path_1.default.normalize(existingFile))) {
105
+ fs_1.default.unlinkSync(existingFile);
106
+ }
107
+ });
108
+ for (const [fileName, contents] of map) {
109
+ try {
110
+ fs_1.default.mkdirSync(path_1.default.dirname(fileName), { recursive: true });
111
+ if (fs_1.default.existsSync(fileName)) {
112
+ const currentContents = fs_1.default.readFileSync(fileName, 'utf8');
113
+ // Don't update the files if there are no changes as this breaks incremental builds
114
+ if (currentContents === contents) {
115
+ continue;
116
+ }
117
+ }
118
+ fs_1.default.writeFileSync(fileName, contents);
119
+ }
120
+ catch (error) {
121
+ success = false;
122
+ console.error(`Failed to write ${fileName} to ${fileName}`, error);
123
+ }
124
+ }
125
+ return success;
126
+ }
127
+ function parseFlowFile(filename) {
128
+ try {
129
+ return (0, flow_1.parseFile)(filename);
130
+ }
131
+ catch (e) {
132
+ if (e instanceof Error) {
133
+ e.message = `(${filename}): ${e.message}`;
134
+ }
135
+ throw e;
136
+ }
137
+ }
138
+ function combineSchemas(files) {
139
+ return files.reduce((merged, filename) => {
140
+ const contents = fs_1.default.readFileSync(filename, 'utf8');
141
+ if (contents &&
142
+ (/export\s+default\s+\(?codegenNativeComponent</.test(contents) ||
143
+ contents.includes('extends TurboModule'))) {
144
+ const schema = parseFlowFile(filename);
145
+ merged.modules = { ...merged.modules, ...schema.modules };
146
+ }
147
+ return merged;
148
+ }, { modules: {} });
149
+ }
150
+ function generate({ libraryName, schema, outputDirectory, moduleSpecName }, { /*generators,*/ test }) {
151
+ schemaValidator_1.default.validate(schema);
152
+ const componentOutputdir = path_1.default.join(outputDirectory, 'react/components', libraryName);
153
+ const generatedFiles = new Map();
154
+ generatedFiles.set(path_1.default.join(outputDirectory, '.clang-format'), 'DisableFormat: true\nSortIncludes: false');
155
+ const generateNM2 = (0, GenerateNM2_1.createNM2Generator)({ namespace: argv.namespace });
156
+ const generatorPropsH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsH')
157
+ .generate;
158
+ const generatorPropsCPP = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsCPP')
159
+ .generate;
160
+ const generatorShadowNodeH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeH')
161
+ .generate;
162
+ const generatorShadowNodeCPP = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeCPP')
163
+ .generate;
164
+ const generatorComponentDescriptorH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateComponentDescriptorH')
165
+ .generate;
166
+ const generatorEventEmitterH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateEventEmitterH')
167
+ .generate;
168
+ normalizeFileMap(generateNM2(libraryName, schema, moduleSpecName), outputDirectory, generatedFiles);
169
+ const componentGenerators = [
170
+ generatorPropsH,
171
+ generatorPropsCPP,
172
+ generatorShadowNodeH,
173
+ generatorShadowNodeCPP,
174
+ generatorComponentDescriptorH,
175
+ generatorEventEmitterH,
176
+ ];
177
+ componentGenerators.forEach(generator => {
178
+ const generated = generator(libraryName, schema, moduleSpecName);
179
+ normalizeFileMap(generated, componentOutputdir, generatedFiles);
180
+ });
181
+ if (test === true) {
182
+ return checkFilesForChanges(generatedFiles, outputDirectory);
183
+ }
184
+ return writeMapToFiles(generatedFiles, outputDirectory);
185
+ }
186
+ if ((argv.file && argv.files) || (!argv.file && !argv.files)) {
187
+ console.error('You must specify either --file or --files.');
188
+ process.exit(1);
189
+ }
190
+ let schema;
191
+ if (argv.file) {
192
+ schema = parseFlowFile(argv.file);
193
+ }
194
+ else {
195
+ schema = combineSchemas(globby_1.default.sync(argv.files));
196
+ }
197
+ const libraryName = argv.libraryName;
198
+ const moduleSpecName = 'moduleSpecName';
199
+ const outputDirectory = 'codegen';
200
+ generate({ libraryName, schema, outputDirectory, moduleSpecName }, { generators: [], test: false });
201
+ //# 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,gDAAwB;AACxB,4CAAoB;AACpB,oDAA4B;AAC5B,0DAA4D;AAC5D,aAAa;AACb,gFAAgF;AAChF,aAAa;AACb,+GAAuF;AAEvF,MAAM,IAAI,GAAG,eAAK,CAAC,OAAO,CAA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soft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport yargs from 'yargs';\nimport path from 'path';\nimport fs from 'fs';\nimport globby from 'globby';\nimport {createNM2Generator} from './generators/GenerateNM2';\n// @ts-ignore\nimport {parseFile} from 'react-native-tscodegen/lib/rncodegen/src/parsers/flow';\n// @ts-ignore\nimport schemaValidator from 'react-native-tscodegen/lib/rncodegen/src/schemaValidator';\n\nconst argv = yargs.options({\n file: {\n type: 'string',\n describe: 'file which contains spec',\n },\n files: {\n type: 'array',\n describe: 'glob patterns for files which contains specs',\n },\n test: {\n type: 'boolean',\n describe: 'Verify that the generated output is unchanged',\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}).argv;\n\nimport {SchemaType} from 'react-native-tscodegen';\n\ninterface Options {\n libraryName: string;\n schema: SchemaType;\n outputDirectory: string;\n moduleSpecName: string;\n}\n\ninterface Config {\n generators: any[] /*Generators[]*/;\n test?: boolean;\n}\n\n/*\nconst GENERATORS = {\n descriptors: [generateComponentDescriptorH.generate],\n events: [\n generateEventEmitterCpp.generate,\n generateEventEmitterH.generate,\n generateModuleHObjCpp.generate,\n generateModuleMm.generate,\n ],\n props: [\n generateComponentHObjCpp.generate,\n generatePropsCpp.generate,\n generatePropsH.generate,\n generatePropsJavaInterface.generate,\n generatePropsJavaDelegate.generate,\n ],\n modules: [generateModuleCpp.generate, generateModuleH.generate],\n tests: [generateTests.generate],\n 'shadow-nodes': [\n generateShadowNodeCpp.generate,\n generateShadowNodeH.generate,\n ],\n};\n*/\n\nfunction normalizeFileMap(\n map: Map<string, string>,\n outputDir: string,\n outMap: Map<string, string>,\n): void {\n for (const [fileName, contents] of map) {\n const location = path.join(outputDir, fileName);\n outMap.set(path.normalize(location), contents);\n }\n}\n\nfunction checkFilesForChanges(\n map: Map<string, string>,\n outputDir: string,\n): boolean {\n let hasChanges = false;\n\n const allExistingFiles = globby\n .sync(`${outputDir}/**`)\n .map(_ => path.normalize(_))\n .sort();\n const allGeneratedFiles = [...map.keys()].map(_ => path.normalize(_)).sort();\n\n if (\n allExistingFiles.length !== allGeneratedFiles.length ||\n !allExistingFiles.every((val, index) => val === allGeneratedFiles[index])\n )\n return true;\n\n for (const [fileName, contents] of map) {\n if (!fs.existsSync(fileName)) {\n hasChanges = true;\n continue;\n }\n\n const currentContents = fs.readFileSync(fileName, 'utf8');\n if (currentContents !== contents) {\n console.error(`- ${fileName} has changed`);\n hasChanges = true;\n continue;\n }\n }\n\n return hasChanges;\n}\n\nfunction writeMapToFiles(map: Map<string, string>, outputDir: string) {\n let success = true;\n\n // This ensures that we delete any generated files from modules that have been deleted\n const allExistingFiles = globby.sync(`${outputDir}/**`);\n allExistingFiles.forEach(existingFile => {\n if (!map.has(path.normalize(existingFile))) {\n fs.unlinkSync(existingFile);\n }\n });\n\n for (const [fileName, contents] of map) {\n try {\n fs.mkdirSync(path.dirname(fileName), {recursive: true});\n\n if (fs.existsSync(fileName)) {\n const currentContents = fs.readFileSync(fileName, 'utf8');\n // Don't update the files if there are no changes as this breaks incremental builds\n if (currentContents === contents) {\n continue;\n }\n }\n\n fs.writeFileSync(fileName, contents);\n } catch (error) {\n success = false;\n console.error(`Failed to write ${fileName} to ${fileName}`, error);\n }\n }\n\n return success;\n}\n\nfunction parseFlowFile(filename: string): SchemaType {\n try {\n return parseFile(filename);\n } catch (e) {\n if (e instanceof Error) {\n e.message = `(${filename}): ${e.message}`;\n }\n throw e;\n }\n}\n\nfunction combineSchemas(files: string[]): SchemaType {\n return files.reduce(\n (merged, filename) => {\n const contents = fs.readFileSync(filename, 'utf8');\n if (\n contents &&\n (/export\\s+default\\s+\\(?codegenNativeComponent</.test(contents) ||\n contents.includes('extends TurboModule'))\n ) {\n const schema = parseFlowFile(filename);\n merged.modules = {...merged.modules, ...schema.modules};\n }\n return merged;\n },\n {modules: {}},\n );\n}\n\nfunction generate(\n {libraryName, schema, outputDirectory, moduleSpecName}: Options,\n {/*generators,*/ test}: Config,\n): boolean {\n schemaValidator.validate(schema);\n\n const componentOutputdir = path.join(\n outputDirectory,\n 'react/components',\n libraryName,\n );\n\n const generatedFiles = new Map<string, string>();\n\n generatedFiles.set(\n path.join(outputDirectory, '.clang-format'),\n 'DisableFormat: true\\nSortIncludes: false',\n );\n\n const generateNM2 = createNM2Generator({namespace: argv.namespace});\n const generatorPropsH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsH')\n .generate;\n const generatorPropsCPP = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsCPP')\n .generate;\n const generatorShadowNodeH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeH')\n .generate;\n const generatorShadowNodeCPP = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeCPP')\n .generate;\n const generatorComponentDescriptorH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateComponentDescriptorH')\n .generate;\n const generatorEventEmitterH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateEventEmitterH')\n .generate;\n\n normalizeFileMap(\n generateNM2(libraryName, schema, moduleSpecName),\n outputDirectory,\n generatedFiles,\n );\n\n const componentGenerators = [\n generatorPropsH,\n generatorPropsCPP,\n generatorShadowNodeH,\n generatorShadowNodeCPP,\n generatorComponentDescriptorH,\n generatorEventEmitterH,\n ];\n\n componentGenerators.forEach(generator => {\n const generated: Map<string, string> = generator(\n libraryName,\n schema,\n moduleSpecName,\n );\n normalizeFileMap(generated, componentOutputdir, generatedFiles);\n });\n\n if (test === true) {\n return checkFilesForChanges(generatedFiles, outputDirectory);\n }\n\n return writeMapToFiles(generatedFiles, outputDirectory);\n}\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\nlet schema: SchemaType;\nif (argv.file) {\n schema = parseFlowFile(argv.file);\n} else {\n schema = combineSchemas(globby.sync(argv.files as string[]));\n}\n\nconst libraryName = argv.libraryName;\nconst moduleSpecName = 'moduleSpecName';\nconst outputDirectory = 'codegen';\ngenerate(\n {libraryName, schema, outputDirectory, moduleSpecName},\n {generators: [], test: false},\n);\n"]}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ import { NativeModuleObjectTypeAnnotation } from 'react-native-tscodegen';
7
+ import { AliasMap } from './AliasManaging';
8
+ export declare function createAliasMap(nativeModuleAliases: {
9
+ [name: string]: NativeModuleObjectTypeAnnotation;
10
+ }): AliasMap;
11
+ export declare function generateAliases(aliases: AliasMap): string;
@@ -0,0 +1,72 @@
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 translateObjectBody(type, aliases, baseAliasName, prefix) {
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
+ const first = `${prefix}REACT_FIELD(${prop.name})`;
19
+ const second = `${prefix}${(0, ObjectTypes_1.translateField)(propType, aliases, `${baseAliasName}_${prop.name}`)} ${prop.name};`;
20
+ return `${first}\n${second}`;
21
+ })
22
+ .join('\n');
23
+ }
24
+ function createAliasMap(nativeModuleAliases) {
25
+ const aliases = { types: {}, jobs: Object.keys(nativeModuleAliases) };
26
+ for (const aliasName of aliases.jobs) {
27
+ aliases.types[aliasName] = nativeModuleAliases[aliasName];
28
+ }
29
+ return aliases;
30
+ }
31
+ exports.createAliasMap = createAliasMap;
32
+ function generateSingleAlias(aliases, aliasName, aliasCode) {
33
+ const aliasType = aliases.types[aliasName];
34
+ aliasCode[aliasName] = `
35
+ REACT_STRUCT(${(0, AliasManaging_1.getAliasCppName)(aliasName)})
36
+ struct ${(0, AliasManaging_1.getAliasCppName)(aliasName)} {
37
+ ${translateObjectBody(aliasType, aliases, aliasName, ' ')}
38
+ };
39
+ `;
40
+ }
41
+ function generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder) {
42
+ // retrieve and clean all ungenerated aliases
43
+ const jobs = aliases.jobs;
44
+ aliases.jobs = [];
45
+ // generate each one in its found order
46
+ for (const aliasName of jobs) {
47
+ // generate a new struct and all fields will be examined
48
+ // new anonymous objects could be found
49
+ // they will be stored in aliases.jobs
50
+ generateSingleAlias(aliases, aliasName, aliasCode);
51
+ // nested C++ structs must be put before the current C++ struct
52
+ // as they will be used in the current C++ struct
53
+ // the order will be perfectly and easily ensured by doing this recursively
54
+ generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder);
55
+ // all referenced C++ structs are generated
56
+ // put the current one following them
57
+ aliasOrder.push(aliasName);
58
+ }
59
+ }
60
+ function generateAliases(aliases) {
61
+ const aliasCode = {};
62
+ const aliasOrder = [];
63
+ generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder);
64
+ // aliasOrder now has the correct order of C++ struct code
65
+ let traversedAliasedStructs = '';
66
+ for (const aliasName of aliasOrder) {
67
+ traversedAliasedStructs = `${traversedAliasedStructs}${aliasCode[aliasName]}`;
68
+ }
69
+ return traversedAliasedStructs;
70
+ }
71
+ exports.generateAliases = generateAliases;
72
+ //# 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,+CAA6C;AAE7C,SAAS,mBAAmB,CAC1B,IAAsC,EACtC,OAAi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EAAC,SAAS,CAAC;EACjC,mBAAmB,CAAC,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC;;CAE3D,CAAC;AACF,CAAC;AAED,SAAS,mCAAmC,CAC1C,OAAiB,EACjB,SAAuB,EACvB,UAAoB;IAEpB,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,CAAC,CAAC;QACnD,+DAA+D;QAC/D,iDAAiD;QACjD,2EAA2E;QAC3E,mCAAmC,CAAC,OAAO,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;QACpE,2CAA2C;QAC3C,qCAAqC;QACrC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;KAC5B;AACH,CAAC;AAED,SAAgB,eAAe,CAAC,OAAiB;IAC/C,MAAM,SAAS,GAAiB,EAAE,CAAC;IACnC,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,mCAAmC,CAAC,OAAO,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;IAEpE,0DAA0D;IAC1D,IAAI,uBAAuB,GAAG,EAAE,CAAC;IACjC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE;QAClC,uBAAuB,GAAG,GAAG,uBAAuB,GAAG,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC;KAC/E;IACD,OAAO,uBAAuB,CAAC;AACjC,CAAC;AAXD,0CAWC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport {\n NativeModuleBaseTypeAnnotation,\n NativeModuleObjectTypeAnnotation,\n NamedShape,\n Nullable,\n} from 'react-native-tscodegen';\nimport {AliasMap, getAliasCppName} from './AliasManaging';\nimport {translateField} from './ObjectTypes';\n\nfunction translateObjectBody(\n type: NativeModuleObjectTypeAnnotation,\n aliases: AliasMap,\n baseAliasName: string,\n prefix: string,\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 const first = `${prefix}REACT_FIELD(${prop.name})`;\n const second = `${prefix}${translateField(\n propType,\n aliases,\n `${baseAliasName}_${prop.name}`,\n )} ${prop.name};`;\n return `${first}\\n${second}`;\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 AliasCodeMap {\n [name: string]: string;\n}\n\nfunction generateSingleAlias(\n aliases: AliasMap,\n aliasName: string,\n aliasCode: AliasCodeMap,\n): void {\n const aliasType = <NativeModuleObjectTypeAnnotation>aliases.types[aliasName];\n aliasCode[aliasName] = `\nREACT_STRUCT(${getAliasCppName(aliasName)})\nstruct ${getAliasCppName(aliasName)} {\n${translateObjectBody(aliasType, aliases, aliasName, ' ')}\n};\n`;\n}\n\nfunction generateNestedAliasesInCorrectOrder(\n aliases: AliasMap,\n aliasCode: AliasCodeMap,\n aliasOrder: string[],\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);\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(aliases, aliasCode, aliasOrder);\n // all referenced C++ structs are generated\n // put the current one following them\n aliasOrder.push(aliasName);\n }\n}\n\nexport function generateAliases(aliases: AliasMap): string {\n const aliasCode: AliasCodeMap = {};\n const aliasOrder: string[] = [];\n generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder);\n\n // aliasOrder now has the correct order of C++ struct code\n let traversedAliasedStructs = '';\n for (const aliasName of aliasOrder) {\n traversedAliasedStructs = `${traversedAliasedStructs}${aliasCode[aliasName]}`;\n }\n return traversedAliasedStructs;\n}\n"]}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ import { NativeModuleObjectTypeAnnotation } from 'react-native-tscodegen';
7
+ export declare function setPreferredModuleName(moduleName: string): void;
8
+ export declare function getAliasCppName(typeName: string): string;
9
+ export interface AliasMap {
10
+ types: {
11
+ [name: string]: NativeModuleObjectTypeAnnotation | undefined;
12
+ };
13
+ jobs: string[];
14
+ }
15
+ export declare function getAnonymousAliasCppName(aliases: AliasMap, baseAliasName: string, objectType: NativeModuleObjectTypeAnnotation): 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 recordAnonymouseAlias(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(recordAnonymouseAlias(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(recordAnonymouseAlias(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,qBAAqB,CAC5B,OAAiB,EACjB,aAAqB,EACrB,QAAwB;IAExB,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,OAAiB,EACjB,aAAqB,EACrB,UAA4C;IAE5C,iDAAiD;IACjD,6CAA6C;IAC7C,yBAAyB;IACzB,uFAAuF;IACvF,MAAM,QAAQ,GAAmB,UAAU,CAAC;IAC5C,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,qBAAqB,CAAC,OAAO,EAAE,aAAa,EAAE,QAAQ,CAAC,CACxD,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,qBAAqB,CAAC,OAAO,EAAE,GAAG,aAAa,GAAG,KAAK,EAAE,EAAE,QAAQ,CAAC,CACrE,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 {NativeModuleObjectTypeAnnotation} from 'react-native-tscodegen';\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 {\n types: {[name: string]: NativeModuleObjectTypeAnnotation | undefined};\n jobs: string[];\n}\n\nconst ExtendedObjectKey = '$RNW-TURBOMODULE-ALIAS';\ninterface ExtendedObject extends NativeModuleObjectTypeAnnotation {\n '$RNW-TURBOMODULE-ALIAS'?: string;\n}\n\nfunction recordAnonymouseAlias(\n aliases: AliasMap,\n baseAliasName: string,\n extended: ExtendedObject,\n): string {\n extended[ExtendedObjectKey] = baseAliasName;\n aliases.types[baseAliasName] = extended;\n aliases.jobs.push(baseAliasName);\n return baseAliasName;\n}\n\nexport function getAnonymousAliasCppName(\n aliases: AliasMap,\n baseAliasName: string,\n objectType: NativeModuleObjectTypeAnnotation,\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>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 recordAnonymouseAlias(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 recordAnonymouseAlias(aliases, `${baseAliasName}${index}`, extended),\n );\n}\n"]}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ import { SchemaType } from 'react-native-tscodegen';
7
+ declare type FilesOutput = Map<string, string>;
8
+ export declare function createNM2Generator({ namespace }: {
9
+ namespace: string;
10
+ }): (_libraryName: string, schema: SchemaType, _moduleSpecName: string) => FilesOutput;
11
+ export {};
@@ -0,0 +1,94 @@
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.createNM2Generator = void 0;
9
+ const AliasManaging_1 = require("./AliasManaging");
10
+ const AliasGen_1 = require("./AliasGen");
11
+ const ValidateConstants_1 = require("./ValidateConstants");
12
+ const ValidateMethods_1 = require("./ValidateMethods");
13
+ const moduleTemplate = `
14
+ /*
15
+ * This file is auto-generated from a NativeModule spec file in js.
16
+ *
17
+ * This is a C++ Spec class that should be used with MakeTurboModuleProvider to register native modules
18
+ * in a way that also verifies at compile time that the native module matches the interface required
19
+ * by the TurboModule JS spec.
20
+ */
21
+ #pragma once
22
+
23
+ #include "NativeModules.h"
24
+ #include <tuple>
25
+
26
+ namespace ::_NAMESPACE_:: {
27
+ ::_MODULE_ALIASED_STRUCTS_::
28
+ struct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {
29
+ ::_MODULE_MEMBERS_TUPLES_::
30
+
31
+ template <class TModule>
32
+ static constexpr void ValidateModule() noexcept {
33
+ ::_MODULE_MEMBERS_CHECKS_::
34
+
35
+ ::_MODULE_MEMBERS_ERRORS_::
36
+ }
37
+ };
38
+
39
+ } // namespace ::_NAMESPACE_::
40
+ `;
41
+ function createNM2Generator({ namespace }) {
42
+ return (_libraryName, schema, _moduleSpecName) => {
43
+ const files = new Map();
44
+ for (const moduleName of Object.keys(schema.modules)) {
45
+ const nativeModule = schema.modules[moduleName];
46
+ // from 0.65 facebook's react-native-codegen
47
+ // the module name has the Native prefix comparing to 0.63
48
+ // when reading files we provided
49
+ const preferredModuleName = moduleName.startsWith('Native')
50
+ ? moduleName.substr(6)
51
+ : moduleName;
52
+ (0, AliasManaging_1.setPreferredModuleName)(preferredModuleName);
53
+ if (nativeModule.type === 'NativeModule') {
54
+ console.log(`Generating Native${preferredModuleName}Spec.g.h`);
55
+ // copy all explicit to a map
56
+ const aliases = (0, AliasGen_1.createAliasMap)(nativeModule.aliases);
57
+ // prepare methods
58
+ const methods = (0, ValidateMethods_1.generateValidateMethods)(nativeModule, aliases);
59
+ let tuples = `
60
+ static constexpr auto methods = std::tuple{
61
+ ${methods[0]}
62
+ };`;
63
+ let checks = `
64
+ constexpr auto methodCheckResults = CheckMethods<TModule, ::_MODULE_NAME_::Spec>();`;
65
+ let errors = methods[1];
66
+ // prepare constants
67
+ const constants = (0, ValidateConstants_1.generateValidateConstants)(nativeModule, aliases);
68
+ if (constants !== undefined) {
69
+ tuples = `
70
+ static constexpr auto constants = std::tuple{
71
+ ${constants[0]}
72
+ };${tuples}`;
73
+ checks = `
74
+ constexpr auto constantCheckResults = CheckConstants<TModule, ::_MODULE_NAME_::Spec>();${checks}`;
75
+ errors = `${constants[1]}
76
+
77
+ ${errors}`;
78
+ }
79
+ // generate code for structs
80
+ const traversedAliasedStructs = (0, AliasGen_1.generateAliases)(aliases);
81
+ files.set(`Native${preferredModuleName}Spec.g.h`, moduleTemplate
82
+ .replace(/::_MODULE_ALIASED_STRUCTS_::/g, traversedAliasedStructs)
83
+ .replace(/::_MODULE_MEMBERS_TUPLES_::/g, tuples.substr(1))
84
+ .replace(/::_MODULE_MEMBERS_CHECKS_::/g, checks.substr(1))
85
+ .replace(/::_MODULE_MEMBERS_ERRORS_::/g, errors)
86
+ .replace(/::_MODULE_NAME_::/g, preferredModuleName)
87
+ .replace(/::_NAMESPACE_::/g, namespace));
88
+ }
89
+ }
90
+ return files;
91
+ };
92
+ }
93
+ exports.createNM2Generator = createNM2Generator;
94
+ //# sourceMappingURL=GenerateNM2.js.map
@@ -0,0 +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;AAI1D,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BtB,CAAC;AAEF,SAAgB,kBAAkB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E,CAAC;oBAC5F,MAAM,GAAG,GAAG,SAAS,CAAC,CAAC,CAAC;;EAEhC,MAAM,EAAE,CAAC;iBACF;gBAED,4BAA4B;gBAC5B,MAAM,uBAAuB,GAAG,IAAA,0BAAe,EAAC,OAAO,CAAC,CAAC;gBAEzD,KAAK,CAAC,GAAG,CACP,SAAS,mBAAmB,UAAU,EACtC,cAAc;qBACX,OAAO,CAAC,+BAA+B,EAAE,uBAAuB,CAAC;qBACjE,OAAO,CAAC,8BAA8B,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;qBACzD,OAAO,CAAC,8BAA8B,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;qBACzD,OAAO,CAAC,8BAA8B,EAAE,MAAM,CAAC;qBAC/C,OAAO,CAAC,oBAAoB,EAAE,mBAAmB,CAAC;qBAClD,OAAO,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAC1C,CAAC;aACH;SACF;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AAlED,gDAkEC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport {SchemaType} from 'react-native-tscodegen';\nimport {AliasMap, setPreferredModuleName} from './AliasManaging';\nimport {createAliasMap, generateAliases} from './AliasGen';\nimport {generateValidateConstants} from './ValidateConstants';\nimport {generateValidateMethods} from './ValidateMethods';\n\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 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\n#include \"NativeModules.h\"\n#include <tuple>\n\nnamespace ::_NAMESPACE_:: {\n::_MODULE_ALIASED_STRUCTS_::\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};\n\n} // namespace ::_NAMESPACE_::\n`;\n\nexport function createNM2Generator({namespace}: {namespace: string}) {\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.aliases);\n\n // prepare methods\n const methods = generateValidateMethods(nativeModule, aliases);\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) {\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 traversedAliasedStructs = generateAliases(aliases);\n\n files.set(\n `Native${preferredModuleName}Spec.g.h`,\n moduleTemplate\n .replace(/::_MODULE_ALIASED_STRUCTS_::/g, traversedAliasedStructs)\n .replace(/::_MODULE_MEMBERS_TUPLES_::/g, tuples.substr(1))\n .replace(/::_MODULE_MEMBERS_CHECKS_::/g, checks.substr(1))\n .replace(/::_MODULE_MEMBERS_ERRORS_::/g, errors)\n .replace(/::_MODULE_NAME_::/g, preferredModuleName)\n .replace(/::_NAMESPACE_::/g, namespace),\n );\n }\n }\n\n return files;\n };\n}\n"]}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ import { NativeModuleBaseTypeAnnotation, Nullable } from 'react-native-tscodegen';
7
+ import { AliasMap } from './AliasManaging';
8
+ export declare function translateField(type: Nullable<NativeModuleBaseTypeAnnotation>, aliases: AliasMap, baseAliasName: string): string;
@@ -0,0 +1,53 @@
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.translateField = void 0;
9
+ const AliasManaging_1 = require("./AliasManaging");
10
+ function translateField(type, aliases, baseAliasName) {
11
+ // avoid: Property 'type' does not exist on type 'never'
12
+ const returnType = type.type;
13
+ switch (type.type) {
14
+ case 'StringTypeAnnotation':
15
+ return 'std::string';
16
+ case 'NumberTypeAnnotation':
17
+ case 'FloatTypeAnnotation':
18
+ case 'DoubleTypeAnnotation':
19
+ return 'double';
20
+ case 'Int32TypeAnnotation':
21
+ return 'int';
22
+ case 'BooleanTypeAnnotation':
23
+ return 'bool';
24
+ case 'ArrayTypeAnnotation':
25
+ if (type.elementType) {
26
+ return `std::vector<${translateField(type.elementType, aliases, `${baseAliasName}_element`)}>`;
27
+ }
28
+ else {
29
+ return `React::JSValueArray`;
30
+ }
31
+ case 'GenericObjectTypeAnnotation':
32
+ return 'React::JSValue';
33
+ case 'ObjectTypeAnnotation':
34
+ return (0, AliasManaging_1.getAnonymousAliasCppName)(aliases, baseAliasName, type);
35
+ case 'ReservedTypeAnnotation': {
36
+ // avoid: Property 'name' does not exist on type 'never'
37
+ const name = type.name;
38
+ // (#6597)
39
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
40
+ if (name !== 'RootTag')
41
+ throw new Error(`Unknown reserved function: ${name} in translateReturnType`);
42
+ return 'double';
43
+ }
44
+ case 'TypeAliasTypeAnnotation':
45
+ return (0, AliasManaging_1.getAliasCppName)(type.name);
46
+ case 'NullableTypeAnnotation':
47
+ return `std::optional<${translateField(type.typeAnnotation, aliases, baseAliasName)}>`;
48
+ default:
49
+ throw new Error(`Unhandled type in translateReturnType: ${returnType}`);
50
+ }
51
+ }
52
+ exports.translateField = translateField;
53
+ //# sourceMappingURL=ObjectTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ObjectTypes.js","sourceRoot":"","sources":["../../src/generators/ObjectTypes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAGb,mDAIyB;AAEzB,SAAgB,cAAc,CAC5B,IAA8C,EAC9C,OAAiB,EACjB,aAAqB;IAErB,wDAAwD;IACxD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC;IAC7B,QAAQ,IAAI,CAAC,IAAI,EAAE;QACjB,KAAK,sBAAsB;YACzB,OAAO,aAAa,CAAC;QACvB,KAAK,sBAAsB,CAAC;QAC5B,KAAK,qBAAqB,CAAC;QAC3B,KAAK,sBAAsB;YACzB,OAAO,QAAQ,CAAC;QAClB,KAAK,qBAAqB;YACxB,OAAO,KAAK,CAAC;QACf,KAAK,uBAAuB;YAC1B,OAAO,MAAM,CAAC;QAChB,KAAK,qBAAqB;YACxB,IAAI,IAAI,CAAC,WAAW,EAAE;gBACpB,OAAO,eAAe,cAAc,CAClC,IAAI,CAAC,WAAW,EAChB,OAAO,EACP,GAAG,aAAa,UAAU,CAC3B,GAAG,CAAC;aACN;iBAAM;gBACL,OAAO,qBAAqB,CAAC;aAC9B;QACH,KAAK,6BAA6B;YAChC,OAAO,gBAAgB,CAAC;QAC1B,KAAK,sBAAsB;YACzB,OAAO,IAAA,wCAAwB,EAAC,OAAO,EAAE,aAAa,EAAE,IAAI,CAAC,CAAC;QAChE,KAAK,wBAAwB,CAAC,CAAC;YAC7B,wDAAwD;YACxD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;YACvB,UAAU;YACV,uEAAuE;YACvE,IAAI,IAAI,KAAK,SAAS;gBACpB,MAAM,IAAI,KAAK,CACb,8BAA8B,IAAI,yBAAyB,CAC5D,CAAC;YACJ,OAAO,QAAQ,CAAC;SACjB;QACD,KAAK,yBAAyB;YAC5B,OAAO,IAAA,+BAAe,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpC,KAAK,wBAAwB;YAC3B,OAAO,iBAAiB,cAAc,CACpC,IAAI,CAAC,cAAc,EACnB,OAAO,EACP,aAAa,CACd,GAAG,CAAC;QACP;YACE,MAAM,IAAI,KAAK,CAAC,0CAA0C,UAAU,EAAE,CAAC,CAAC;KAC3E;AACH,CAAC;AAtDD,wCAsDC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport {NativeModuleBaseTypeAnnotation, Nullable} from 'react-native-tscodegen';\nimport {\n AliasMap,\n getAliasCppName,\n getAnonymousAliasCppName,\n} from './AliasManaging';\n\nexport function translateField(\n type: Nullable<NativeModuleBaseTypeAnnotation>,\n aliases: AliasMap,\n baseAliasName: string,\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 'std::string';\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<${translateField(\n type.elementType,\n aliases,\n `${baseAliasName}_element`,\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(\n `Unknown reserved function: ${name} in translateReturnType`,\n );\n return 'double';\n }\n case 'TypeAliasTypeAnnotation':\n return getAliasCppName(type.name);\n case 'NullableTypeAnnotation':\n return `std::optional<${translateField(\n type.typeAnnotation,\n aliases,\n baseAliasName,\n )}>`;\n default:\n throw new Error(`Unhandled type in translateReturnType: ${returnType}`);\n }\n}\n"]}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ import { NamedShape, NativeModuleParamTypeAnnotation, Nullable } from 'react-native-tscodegen';
7
+ import { AliasMap } from './AliasManaging';
8
+ declare type NativeModuleParamShape = NamedShape<Nullable<NativeModuleParamTypeAnnotation>>;
9
+ export declare function translateSpecArgs(params: ReadonlyArray<NativeModuleParamShape>, aliases: AliasMap, baseAliasName: string): string[];
10
+ export declare function translateArgs(params: ReadonlyArray<NativeModuleParamShape>, aliases: AliasMap, baseAliasName: string): string[];
11
+ export {};
@@ -0,0 +1,114 @@
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.translateArgs = exports.translateSpecArgs = void 0;
9
+ const AliasManaging_1 = require("./AliasManaging");
10
+ function decorateType(type, target) {
11
+ switch (target) {
12
+ case 'method-arg':
13
+ return `${type} &&`;
14
+ case 'callback-arg':
15
+ return `${type} const &`;
16
+ default:
17
+ return type;
18
+ }
19
+ }
20
+ function translateParam(param, aliases, baseAliasName, target) {
21
+ // avoid: Property 'type' does not exist on type 'never'
22
+ const paramType = param.type;
23
+ switch (param.type) {
24
+ case 'StringTypeAnnotation':
25
+ return 'std::string';
26
+ case 'NumberTypeAnnotation':
27
+ case 'FloatTypeAnnotation':
28
+ case 'DoubleTypeAnnotation':
29
+ return 'double';
30
+ case 'Int32TypeAnnotation':
31
+ return 'int';
32
+ case 'BooleanTypeAnnotation':
33
+ return 'bool';
34
+ case 'FunctionTypeAnnotation': {
35
+ // TODO: type.returnTypeAnnotation
36
+ switch (target) {
37
+ case 'spec':
38
+ return `Callback<${param.params
39
+ .map((p) => translateSpecFunctionParam(p, aliases, `${baseAliasName}_${p.name}`))
40
+ .join(', ')}>`;
41
+ case 'template':
42
+ return `std::function<void(${param.params
43
+ .map((p) => translateCallbackParam(p, aliases, `${baseAliasName}_${p.name}`))
44
+ .join(', ')})>`;
45
+ default:
46
+ return `std::function<void(${param.params
47
+ .map((p) => translateCallbackParam(p, aliases, `${baseAliasName}_${p.name}`))
48
+ .join(', ')})> const &`;
49
+ }
50
+ }
51
+ case 'ArrayTypeAnnotation':
52
+ if (param.elementType) {
53
+ switch (target) {
54
+ case 'spec':
55
+ case 'template':
56
+ return `std::vector<${translateNullableParamType(param.elementType, aliases, `${baseAliasName}_element`, 'template', 'template')}>`;
57
+ default:
58
+ return `std::vector<${translateNullableParamType(param.elementType, aliases, `${baseAliasName}_element`, 'template', 'template')}> const &`;
59
+ }
60
+ }
61
+ else {
62
+ return decorateType('React::JSValueArray', target);
63
+ }
64
+ case 'GenericObjectTypeAnnotation':
65
+ return decorateType('React::JSValue', target);
66
+ case 'ObjectTypeAnnotation':
67
+ return decorateType((0, AliasManaging_1.getAnonymousAliasCppName)(aliases, baseAliasName, param), target);
68
+ case 'ReservedTypeAnnotation': {
69
+ // avoid: Property 'name' does not exist on type 'never'
70
+ const name = param.name;
71
+ // (#6597)
72
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
73
+ if (name !== 'RootTag')
74
+ throw new Error(`Unknown reserved function: ${name} in translateParam`);
75
+ return 'double';
76
+ }
77
+ case 'TypeAliasTypeAnnotation':
78
+ return decorateType((0, AliasManaging_1.getAliasCppName)(param.name), target);
79
+ default:
80
+ throw new Error(`Unhandled type in translateParam: ${paramType}`);
81
+ }
82
+ }
83
+ function translateNullableParamType(paramType, aliases, baseAliasName, nullableTarget, target) {
84
+ switch (paramType.type) {
85
+ case 'NullableTypeAnnotation':
86
+ return `std::optional<${translateParam(paramType.typeAnnotation, aliases, baseAliasName, nullableTarget)}>`;
87
+ default:
88
+ return translateParam(paramType, aliases, baseAliasName, target);
89
+ }
90
+ }
91
+ function translateSpecFunctionParam(param, aliases, baseAliasName) {
92
+ return translateNullableParamType(param.typeAnnotation, aliases, baseAliasName, 'spec', 'spec');
93
+ }
94
+ function translateCallbackParam(param, aliases, baseAliasName) {
95
+ return translateNullableParamType(param.typeAnnotation, aliases, baseAliasName, 'template', 'callback-arg');
96
+ }
97
+ function translateFunctionParam(param, aliases, baseAliasName) {
98
+ return translateNullableParamType(param.typeAnnotation, aliases, baseAliasName, 'template', 'method-arg');
99
+ }
100
+ function translateSpecArgs(params, aliases, baseAliasName) {
101
+ return params.map(param => {
102
+ const translatedParam = translateSpecFunctionParam(param, aliases, `${baseAliasName}_${param.name}`);
103
+ return `${translatedParam}`;
104
+ });
105
+ }
106
+ exports.translateSpecArgs = translateSpecArgs;
107
+ function translateArgs(params, aliases, baseAliasName) {
108
+ return params.map(param => {
109
+ const translatedParam = translateFunctionParam(param, aliases, `${baseAliasName}_${param.name}`);
110
+ return `${translatedParam} ${param.name}`;
111
+ });
112
+ }
113
+ exports.translateArgs = translateArgs;
114
+ //# sourceMappingURL=ParamTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ParamTypes.js","sourceRoot":"","sources":["../../src/generators/ParamTypes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAOb,mDAIyB;AAQzB,SAAS,YAAY,CAAC,IAAY,EAAE,MAAmB;IACrD,QAAQ,MAAM,EAAE;QACd,KAAK,YAAY;YACf,OAAO,GAAG,IAAI,KAAK,CAAC;QACtB,KAAK,cAAc;YACjB,OAAO,GAA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eAAe,GAAG,sBAAsB,CAC5C,KAAK,EACL,OAAO,EACP,GAAG,aAAa,IAAI,KAAK,CAAC,IAAI,EAAE,CACjC,CAAC;QACF,OAAO,GAAG,eAAe,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;IAC5C,CAAC,CAAC,CAAC;AACL,CAAC;AAbD,sCAaC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport {\n NamedShape,\n NativeModuleParamTypeAnnotation,\n Nullable,\n} from 'react-native-tscodegen';\nimport {\n AliasMap,\n getAliasCppName,\n getAnonymousAliasCppName,\n} from './AliasManaging';\n\ntype NativeModuleParamShape = NamedShape<\n Nullable<NativeModuleParamTypeAnnotation>\n>;\n\ntype ParamTarget = 'spec' | 'template' | 'callback-arg' | 'method-arg';\n\nfunction decorateType(type: string, target: ParamTarget): string {\n switch (target) {\n case 'method-arg':\n return `${type} &&`;\n case 'callback-arg':\n return `${type} const &`;\n default:\n return type;\n }\n}\n\nfunction translateParam(\n param: NativeModuleParamTypeAnnotation,\n aliases: AliasMap,\n baseAliasName: string,\n target: ParamTarget,\n): string {\n // avoid: Property 'type' does not exist on type 'never'\n const paramType = param.type;\n switch (param.type) {\n case 'StringTypeAnnotation':\n return 'std::string';\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 'FunctionTypeAnnotation': {\n // TODO: type.returnTypeAnnotation\n switch (target) {\n case 'spec':\n return `Callback<${param.params\n .map((p: NativeModuleParamShape) =>\n translateSpecFunctionParam(\n p,\n aliases,\n `${baseAliasName}_${p.name}`,\n ),\n )\n .join(', ')}>`;\n case 'template':\n return `std::function<void(${param.params\n .map((p: NativeModuleParamShape) =>\n translateCallbackParam(p, aliases, `${baseAliasName}_${p.name}`),\n )\n .join(', ')})>`;\n default:\n return `std::function<void(${param.params\n .map((p: NativeModuleParamShape) =>\n translateCallbackParam(p, aliases, `${baseAliasName}_${p.name}`),\n )\n .join(', ')})> const &`;\n }\n }\n case 'ArrayTypeAnnotation':\n if (param.elementType) {\n switch (target) {\n case 'spec':\n case 'template':\n return `std::vector<${translateNullableParamType(\n param.elementType,\n aliases,\n `${baseAliasName}_element`,\n 'template',\n 'template',\n )}>`;\n default:\n return `std::vector<${translateNullableParamType(\n param.elementType,\n aliases,\n `${baseAliasName}_element`,\n 'template',\n 'template',\n )}> const &`;\n }\n } else {\n return decorateType('React::JSValueArray', target);\n }\n case 'GenericObjectTypeAnnotation':\n return decorateType('React::JSValue', target);\n case 'ObjectTypeAnnotation':\n return decorateType(\n getAnonymousAliasCppName(aliases, baseAliasName, param),\n target,\n );\n case 'ReservedTypeAnnotation': {\n // avoid: Property 'name' does not exist on type 'never'\n const name = param.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 translateParam`);\n return 'double';\n }\n case 'TypeAliasTypeAnnotation':\n return decorateType(getAliasCppName(param.name), target);\n default:\n throw new Error(`Unhandled type in translateParam: ${paramType}`);\n }\n}\n\nfunction translateNullableParamType(\n paramType: Nullable<NativeModuleParamTypeAnnotation>,\n aliases: AliasMap,\n baseAliasName: string,\n nullableTarget: ParamTarget,\n target: ParamTarget,\n): string {\n switch (paramType.type) {\n case 'NullableTypeAnnotation':\n return `std::optional<${translateParam(\n paramType.typeAnnotation,\n aliases,\n baseAliasName,\n nullableTarget,\n )}>`;\n default:\n return translateParam(paramType, aliases, baseAliasName, target);\n }\n}\n\nfunction translateSpecFunctionParam(\n param: NativeModuleParamShape,\n aliases: AliasMap,\n baseAliasName: string,\n): string {\n return translateNullableParamType(\n param.typeAnnotation,\n aliases,\n baseAliasName,\n 'spec',\n 'spec',\n );\n}\n\nfunction translateCallbackParam(\n param: NativeModuleParamShape,\n aliases: AliasMap,\n baseAliasName: string,\n): string {\n return translateNullableParamType(\n param.typeAnnotation,\n aliases,\n baseAliasName,\n 'template',\n 'callback-arg',\n );\n}\n\nfunction translateFunctionParam(\n param: NativeModuleParamShape,\n aliases: AliasMap,\n baseAliasName: string,\n): string {\n return translateNullableParamType(\n param.typeAnnotation,\n aliases,\n baseAliasName,\n 'template',\n 'method-arg',\n );\n}\n\nexport function translateSpecArgs(\n params: ReadonlyArray<NativeModuleParamShape>,\n aliases: AliasMap,\n baseAliasName: string,\n) {\n return params.map(param => {\n const translatedParam = translateSpecFunctionParam(\n param,\n aliases,\n `${baseAliasName}_${param.name}`,\n );\n return `${translatedParam}`;\n });\n}\n\nexport function translateArgs(\n params: ReadonlyArray<NativeModuleParamShape>,\n aliases: AliasMap,\n baseAliasName: string,\n) {\n return params.map(param => {\n const translatedParam = translateFunctionParam(\n param,\n aliases,\n `${baseAliasName}_${param.name}`,\n );\n return `${translatedParam} ${param.name}`;\n });\n}\n"]}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ import { NativeModuleReturnTypeAnnotation, Nullable } from 'react-native-tscodegen';
7
+ import { AliasMap } from './AliasManaging';
8
+ export declare function translateSpecReturnType(type: Nullable<NativeModuleReturnTypeAnnotation>, aliases: AliasMap, baseAliasName: string): string;
9
+ export declare function translateImplReturnType(type: Nullable<NativeModuleReturnTypeAnnotation>, aliases: AliasMap, baseAliasName: string): string;
@@ -0,0 +1,63 @@
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.translateImplReturnType = exports.translateSpecReturnType = void 0;
9
+ const AliasManaging_1 = require("./AliasManaging");
10
+ function translateReturnType(type, aliases, baseAliasName) {
11
+ // avoid: Property 'type' does not exist on type 'never'
12
+ const returnType = type.type;
13
+ switch (type.type) {
14
+ case 'VoidTypeAnnotation':
15
+ case 'PromiseTypeAnnotation':
16
+ return 'void';
17
+ case 'StringTypeAnnotation':
18
+ return 'std::string';
19
+ case 'NumberTypeAnnotation':
20
+ case 'FloatTypeAnnotation':
21
+ case 'DoubleTypeAnnotation':
22
+ return 'double';
23
+ case 'Int32TypeAnnotation':
24
+ return 'int';
25
+ case 'BooleanTypeAnnotation':
26
+ return 'bool';
27
+ case 'ArrayTypeAnnotation':
28
+ if (type.elementType) {
29
+ return `std::vector<${translateReturnType(type.elementType, aliases, `${baseAliasName}_element`)}>`;
30
+ }
31
+ else {
32
+ return 'React::JSValueArray';
33
+ }
34
+ case 'GenericObjectTypeAnnotation':
35
+ return 'React::JSValue';
36
+ case 'ObjectTypeAnnotation':
37
+ return (0, AliasManaging_1.getAnonymousAliasCppName)(aliases, baseAliasName, type);
38
+ case 'ReservedTypeAnnotation': {
39
+ // avoid: Property 'name' does not exist on type 'never'
40
+ const name = type.name;
41
+ // (#6597)
42
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
43
+ if (name !== 'RootTag')
44
+ throw new Error(`Unknown reserved function: ${name} in translateReturnType`);
45
+ return 'double';
46
+ }
47
+ case 'TypeAliasTypeAnnotation':
48
+ return (0, AliasManaging_1.getAliasCppName)(type.name);
49
+ case 'NullableTypeAnnotation':
50
+ return `std::optional<${translateReturnType(type.typeAnnotation, aliases, baseAliasName)}>`;
51
+ default:
52
+ throw new Error(`Unhandled type in translateReturnType: ${returnType}`);
53
+ }
54
+ }
55
+ function translateSpecReturnType(type, aliases, baseAliasName) {
56
+ return translateReturnType(type, aliases, `${baseAliasName}_returnType`);
57
+ }
58
+ exports.translateSpecReturnType = translateSpecReturnType;
59
+ function translateImplReturnType(type, aliases, baseAliasName) {
60
+ return translateReturnType(type, aliases, `${baseAliasName}_returnType`);
61
+ }
62
+ exports.translateImplReturnType = translateImplReturnType;
63
+ //# sourceMappingURL=ReturnTypes.js.map
@@ -0,0 +1 @@
1
+ {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A,+BAAe,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpC,KAAK,wBAAwB;YAC3B,OAAO,iBAAiB,mBAAmB,CACzC,IAAI,CAAC,cAAc,EACnB,OAAO,EACP,aAAa,CACd,GAAG,CAAC;QACP;YACE,MAAM,IAAI,KAAK,CAAC,0CAA0C,UAAU,EAAE,CAAC,CAAC;KAC3E;AACH,CAAC;AAED,SAAgB,uBAAuB,CACrC,IAAgD,EAChD,OAAiB,EACjB,aAAqB;IAErB,OAAO,mBAAmB,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,aAAa,aAAa,CAAC,CAAC;AAC3E,CAAC;AAND,0DAMC;AAED,SAAgB,uBAAuB,CACrC,IAAgD,EAChD,OAAiB,EACjB,aAAqB;IAErB,OAAO,mBAAmB,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,aAAa,aAAa,CAAC,CAAC;AAC3E,CAAC;AAND,0DAMC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport {\n NativeModuleReturnTypeAnnotation,\n Nullable,\n} from 'react-native-tscodegen';\nimport {\n AliasMap,\n getAliasCppName,\n getAnonymousAliasCppName,\n} from './AliasManaging';\n\nfunction translateReturnType(\n type: Nullable<NativeModuleReturnTypeAnnotation>,\n aliases: AliasMap,\n baseAliasName: string,\n): string {\n // avoid: Property 'type' does not exist on type 'never'\n const returnType = type.type;\n switch (type.type) {\n case 'VoidTypeAnnotation':\n case 'PromiseTypeAnnotation':\n return 'void';\n case 'StringTypeAnnotation':\n return 'std::string';\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<${translateReturnType(\n type.elementType,\n aliases,\n `${baseAliasName}_element`,\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(\n `Unknown reserved function: ${name} in translateReturnType`,\n );\n return 'double';\n }\n case 'TypeAliasTypeAnnotation':\n return getAliasCppName(type.name);\n case 'NullableTypeAnnotation':\n return `std::optional<${translateReturnType(\n type.typeAnnotation,\n aliases,\n baseAliasName,\n )}>`;\n default:\n throw new Error(`Unhandled type in translateReturnType: ${returnType}`);\n }\n}\n\nexport function translateSpecReturnType(\n type: Nullable<NativeModuleReturnTypeAnnotation>,\n aliases: AliasMap,\n baseAliasName: string,\n) {\n return translateReturnType(type, aliases, `${baseAliasName}_returnType`);\n}\n\nexport function translateImplReturnType(\n type: Nullable<NativeModuleReturnTypeAnnotation>,\n aliases: AliasMap,\n baseAliasName: string,\n) {\n return translateReturnType(type, aliases, `${baseAliasName}_returnType`);\n}\n"]}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ import { NativeModuleSchema } from 'react-native-tscodegen';
7
+ import { AliasMap } from './AliasManaging';
8
+ export declare function generateValidateConstants(nativeModule: NativeModuleSchema, aliases: AliasMap): [string, string] | undefined;
@@ -0,0 +1,38 @@
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.generateValidateConstants = void 0;
9
+ const AliasManaging_1 = require("./AliasManaging");
10
+ function generateValidateConstants(nativeModule, aliases) {
11
+ const candidates = nativeModule.spec.properties.filter(prop => prop.name === 'getConstants');
12
+ if (candidates.length === 0) {
13
+ return undefined;
14
+ }
15
+ const getConstant = candidates[0];
16
+ const funcType = getConstant.typeAnnotation.type === 'NullableTypeAnnotation'
17
+ ? getConstant.typeAnnotation.typeAnnotation
18
+ : getConstant.typeAnnotation;
19
+ if (funcType.params.length > 0 ||
20
+ funcType.returnTypeAnnotation.type !== 'ObjectTypeAnnotation') {
21
+ return undefined;
22
+ }
23
+ const constantType = funcType.returnTypeAnnotation;
24
+ if (constantType.properties.length === 0) {
25
+ return undefined;
26
+ }
27
+ const cppName = (0, AliasManaging_1.getAnonymousAliasCppName)(aliases, 'Constants', constantType);
28
+ return [
29
+ ` TypedConstant<${cppName}>{0},`,
30
+ ` REACT_SHOW_CONSTANT_SPEC_ERRORS(
31
+ 0,
32
+ "${cppName}",
33
+ " REACT_GET_CONSTANTS(GetConstants) ${cppName} GetConstants() noexcept {/*implementation*/}\\n"
34
+ " REACT_GET_CONSTANTS(GetConstants) static ${cppName} GetConstants() noexcept {/*implementation*/}\\n");`,
35
+ ];
36
+ }
37
+ exports.generateValidateConstants = generateValidateConstants;
38
+ //# sourceMappingURL=ValidateConstants.js.map
@@ -0,0 +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 {NativeModuleSchema} from 'react-native-tscodegen';\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"]}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ import { NativeModuleSchema } from 'react-native-tscodegen';
7
+ import { AliasMap } from './AliasManaging';
8
+ export declare function generateValidateMethods(nativeModule: NativeModuleSchema, aliases: AliasMap): [string, string];
@@ -0,0 +1,70 @@
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.generateValidateMethods = void 0;
9
+ const ParamTypes_1 = require("./ParamTypes");
10
+ const ReturnTypes_1 = require("./ReturnTypes");
11
+ function isMethodSync(funcType) {
12
+ return (funcType.returnTypeAnnotation.type !== 'VoidTypeAnnotation' &&
13
+ funcType.returnTypeAnnotation.type !== 'PromiseTypeAnnotation');
14
+ }
15
+ function isMethodReturnPromise(funcType) {
16
+ return funcType.returnTypeAnnotation.type === 'PromiseTypeAnnotation';
17
+ }
18
+ function getPossibleMethodSignatures(prop, funcType, aliases, baseAliasName) {
19
+ const args = (0, ParamTypes_1.translateArgs)(funcType.params, aliases, baseAliasName);
20
+ if (isMethodReturnPromise(funcType)) {
21
+ // TODO: type of the promise could be provided in the future
22
+ args.push('React::ReactPromise<React::JSValue> &&result');
23
+ }
24
+ // TODO: be much more exhastive on the possible method signatures that can be used..
25
+ const sig = `REACT_${isMethodSync(funcType) ? 'SYNC_' : ''}METHOD(${prop.name}) ${(0, ReturnTypes_1.translateImplReturnType)(funcType.returnTypeAnnotation, aliases, baseAliasName)} ${prop.name}(${args.join(', ')}) noexcept { /* implementation */ }}`;
26
+ const staticsig = `REACT_${isMethodSync(funcType) ? 'SYNC_' : ''}METHOD(${prop.name}) static ${(0, ReturnTypes_1.translateImplReturnType)(funcType.returnTypeAnnotation, aliases, baseAliasName)} ${prop.name}(${args.join(', ')}) noexcept { /* implementation */ }}`;
27
+ return [sig, staticsig];
28
+ }
29
+ function translatePossibleMethodSignatures(prop, funcType, aliases, baseAliasName) {
30
+ return getPossibleMethodSignatures(prop, funcType, aliases, baseAliasName)
31
+ .map(sig => `" ${sig}\\n"`)
32
+ .join('\n ');
33
+ }
34
+ function renderProperties(properties, aliases, tuple) {
35
+ // TODO: generate code for constants
36
+ return properties
37
+ .filter(prop => prop.name !== 'getConstants')
38
+ .map((prop, index) => {
39
+ // TODO: prop.optional === true
40
+ // TODO: prop.typeAnnotation.type === 'NullableTypeAnnotation'
41
+ const propAliasName = prop.name;
42
+ const funcType = prop.typeAnnotation.type === 'NullableTypeAnnotation'
43
+ ? prop.typeAnnotation.typeAnnotation
44
+ : prop.typeAnnotation;
45
+ const traversedArgs = (0, ParamTypes_1.translateSpecArgs)(funcType.params, aliases, propAliasName);
46
+ const translatedReturnParam = (0, ReturnTypes_1.translateSpecReturnType)(funcType.returnTypeAnnotation, aliases, propAliasName);
47
+ if (isMethodReturnPromise(funcType)) {
48
+ // TODO: type of the promise could be provided in the future
49
+ traversedArgs.push('Promise<React::JSValue>');
50
+ }
51
+ if (tuple) {
52
+ return ` ${isMethodSync(funcType) ? 'Sync' : ''}Method<${translatedReturnParam}(${traversedArgs.join(', ')}) noexcept>{${index}, L"${prop.name}"},`;
53
+ }
54
+ else {
55
+ return ` REACT_SHOW_METHOD_SPEC_ERRORS(
56
+ ${index},
57
+ "${prop.name}",
58
+ ${translatePossibleMethodSignatures(prop, funcType, aliases, propAliasName)});`;
59
+ }
60
+ })
61
+ .join('\n');
62
+ }
63
+ function generateValidateMethods(nativeModule, aliases) {
64
+ const properties = nativeModule.spec.properties;
65
+ const traversedProperties = renderProperties(properties, aliases, false);
66
+ const traversedPropertyTuples = renderProperties(properties, aliases, true);
67
+ return [traversedPropertyTuples, traversedProperties];
68
+ }
69
+ exports.generateValidateMethods = generateValidateMethods;
70
+ //# sourceMappingURL=ValidateMethods.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidateMethods.js","sourceRoot":"","sources":["../../src/generators/ValidateMethods.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAQb,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,qBAAqB,CAAC,QAA4C;IACzE,OAAO,QAAQ,CAAC,oBAAoB,CAAC,IAAI,KAAK,uBAAuB,CAAC;AACxE,CAAC;AAED,SAAS,2BAA2B,CAClC,IAA+B,EAC/B,QAA4C,EAC5C,OAAiB,EACjB,aAAqB;IAErB,MAAM,IAAI,GAAG,IAAA,0BAAa,EAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC;IACpE,IAAI,qBAAqB,CAAC,QAAQ,CAAC,EAAE;QACnC,4DAA4D;QAC5D,IAAI,CAAC,IAAI,CAAC,8CAA8C,CAAC,CAAC;KAC3D;IAED,oFAAoF;IACpF,MAAM,GAAG,GAAG,SAAS,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,UACxD,IAAI,CAAC,IACP,KAAK,IAAA,qCAAuB,EAC1B,QAAQ,CAAC,oBAAoB,EAC7B,OAAO,EACP,aAAa,CACd,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,sCAAsC,CAAC;IAExE,MAAM,SAAS,GAAG,SAAS,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AAa,CACd,CAAC;QAEF,IAAI,qBAAqB,CAAC,QAAQ,CAAC,EAAE;YACnC,4DAA4D;YAC5D,aAAa,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;SAC/C;QAED,IAAI,KAAK,EAAE;YACT,OAAO,SACL,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EACpC,UAAU,qBAAqB,IAAI,aAAa,CAAC,IAAI,CACnD,IAAI,CACL,eAAe,KAAK,OAAO,IAAI,CAAC,IAAI,KAAK,CAAC;SAC5C;aAAM;YACL,OAAO;YACH,KAAK;aACJ,IAAI,CAAC,IAAI;YACV,iCAAiC,CACjC,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,aAAa,CACd,IAAI,CAAC;SACT;IACH,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED,SAAgB,uBAAuB,CACrC,YAAgC,EAChC,OAAiB;IAEjB,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC;IAChD,MAAM,mBAAmB,GAAG,gBAAgB,CAAC,UAAU,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IACzE,MAAM,uBAAuB,GAAG,gBAAgB,CAAC,UAAU,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IAC5E,OAAO,CAAC,uBAAuB,EAAE,mBAAmB,CAAC,CAAC;AACxD,CAAC;AARD,0DAQC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport {\n NativeModuleFunctionTypeAnnotation,\n NativeModulePropertyShape,\n NativeModuleSchema,\n} from 'react-native-tscodegen';\nimport {AliasMap} from './AliasManaging';\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 isMethodReturnPromise(funcType: NativeModuleFunctionTypeAnnotation) {\n return funcType.returnTypeAnnotation.type === 'PromiseTypeAnnotation';\n}\n\nfunction getPossibleMethodSignatures(\n prop: NativeModulePropertyShape,\n funcType: NativeModuleFunctionTypeAnnotation,\n aliases: AliasMap,\n baseAliasName: string,\n): string[] {\n const args = translateArgs(funcType.params, aliases, baseAliasName);\n if (isMethodReturnPromise(funcType)) {\n // TODO: type of the promise could be provided in the future\n args.push('React::ReactPromise<React::JSValue> &&result');\n }\n\n // TODO: be much more exhastive 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 )} ${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 )} ${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): string {\n return getPossibleMethodSignatures(prop, funcType, aliases, baseAliasName)\n .map(sig => `\" ${sig}\\\\n\"`)\n .join('\\n ');\n}\n\nfunction renderProperties(\n properties: ReadonlyArray<NativeModulePropertyShape>,\n aliases: AliasMap,\n tuple: boolean,\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 );\n\n const translatedReturnParam = translateSpecReturnType(\n funcType.returnTypeAnnotation,\n aliases,\n propAliasName,\n );\n\n if (isMethodReturnPromise(funcType)) {\n // TODO: type of the promise could be provided in the future\n traversedArgs.push('Promise<React::JSValue>');\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 )});`;\n }\n })\n .join('\\n');\n}\n\nexport function generateValidateMethods(\n nativeModule: NativeModuleSchema,\n aliases: AliasMap,\n): [string, string] {\n const properties = nativeModule.spec.properties;\n const traversedProperties = renderProperties(properties, aliases, false);\n const traversedPropertyTuples = renderProperties(properties, aliases, true);\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.0.0-canary.17",
3
+ "version": "0.0.0-canary.18",
4
4
  "description": "Generators for react-native-codegen targeting react-native-windows",
5
5
  "main": "index.js",
6
6
  "repository": "https://github.com/microsoft/react-native-windows",
@@ -42,6 +42,13 @@
42
42
  "prettier": "1.19.1",
43
43
  "typescript": "^4.4.4"
44
44
  },
45
+ "files": [
46
+ "bin.js",
47
+ "CHANGELOG.md",
48
+ "README.md",
49
+ "lib-commonjs",
50
+ "src"
51
+ ],
45
52
  "beachball": {
46
53
  "defaultNpmTag": "canary",
47
54
  "disallowedChangeTypes": [
package/.eslintrc.js DELETED
@@ -1,4 +0,0 @@
1
- module.exports = {
2
- extends: ['@rnw-scripts'],
3
- parserOptions: {tsconfigRootDir : __dirname},
4
- };
@@ -1,23 +0,0 @@
1
- {
2
- // Use IntelliSense to learn about possible attributes.
3
- // Hover to view descriptions of existing attributes.
4
- // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
- "version": "0.2.0",
6
- "configurations": [
7
- {
8
- "name": "vscode-jest-tests",
9
- "type": "node",
10
- "request": "launch",
11
- "runtimeArgs": [
12
- "--inspect-brk",
13
- "../../node_modules/jest/bin/jest.js",
14
- "--runInBand",
15
- "--config",
16
- "../@rnw-scripts/jest-debug-config/jest.debug.config.js",
17
- ],
18
- "console": "integratedTerminal",
19
- "internalConsoleOptions": "neverOpen",
20
- "port": 9229,
21
- },
22
- ]
23
- }
package/jest.config.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('@rnw-scripts/jest-unittest-config');
package/tsconfig.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "extends": "@rnw-scripts/ts-config",
3
- "include": ["src"],
4
- "exclude": ["node_modules"]
5
- }