@react-native-windows/codegen 0.0.0-canary.97 → 0.0.0-canary.99

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,19 +1,41 @@
1
1
  # Change Log - @react-native-windows/codegen
2
2
 
3
- This log was last generated on Wed, 10 Jul 2024 05:13:27 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 08 Aug 2024 05:14:50 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## 0.0.0-canary.97
7
+ ## 0.0.0-canary.99
8
8
 
9
- Wed, 10 Jul 2024 05:13:27 GMT
9
+ Thu, 08 Aug 2024 05:14:50 GMT
10
10
 
11
11
  ### Changes
12
12
 
13
- - Bump @react-native-windows/fs to v0.0.0-canary.53
14
- - Bump @rnw-scripts/eslint-config to v1.2.24
15
- - Bump @rnw-scripts/just-task to v2.3.41
13
+ - Integrate 7/1 (jthysell@microsoft.com)
14
+ - Bump @react-native-windows/fs to v0.0.0-canary.55
15
+ - Bump @rnw-scripts/eslint-config to v1.2.26
16
+ - Bump @rnw-scripts/just-task to v2.3.43
16
17
 
18
+ ## 0.0.0-canary.98
19
+
20
+ Wed, 24 Jul 2024 05:24:36 GMT
21
+
22
+ ### Changes
23
+
24
+ - integrate 0.75.0-nightly-20240618-5df5ed1a8 (tatianakapos@microsoft.com)
25
+ - Bump @react-native-windows/fs to v0.0.0-canary.54
26
+ - Bump @rnw-scripts/eslint-config to v1.2.25
27
+ - Bump @rnw-scripts/just-task to v2.3.42
28
+
29
+ ## 0.0.0-canary.97
30
+
31
+ Wed, 10 Jul 2024 05:15:30 GMT
32
+
33
+ ### Changes
34
+
35
+ - Bump @react-native-windows/fs to v0.0.0-canary.53
36
+ - Bump @rnw-scripts/eslint-config to v1.2.24
37
+ - Bump @rnw-scripts/just-task to v2.3.41
38
+
17
39
  ## 0.0.0-canary.96
18
40
 
19
41
  Fri, 21 Jun 2024 05:17:50 GMT
@@ -86,7 +86,7 @@ if (argv.cppStringType !== 'std::string' &&
86
86
  // until yargs.options get improved in the future
87
87
  const changesNecessary = (0, index_1.runCodeGen)(argv);
88
88
  if (argv.test && changesNecessary) {
89
- console.error('There is a change in the output of codegen. Rerun "react-native codegen-windows" to regenerate.');
89
+ console.error('There is a change in the output of codegen. Rerun "npx @react-native-community/cli codegen-windows" to regenerate.');
90
90
  process.exit(2);
91
91
  }
92
92
  //# sourceMappingURL=Cli.js.map
@@ -1 +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;QACd,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,mDAAmD;QAC7D,OAAO,EAAE,KAAK;KACf;IACD,UAAU,EAAE;QACV,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,wDAAwD;QAClE,OAAO,EAAE,KAAK;KACf;IACD,eAAe,EAAE;QACf,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,kBAAkB;QAC5B,OAAO,EAAE,SAAS;KACnB;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,+CAA+C;QACzD,OAAO,EAAE,KAAK;KACf;IACD,SAAS,EAAE;QACT,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,qDAAqD;QAC/D,OAAO,EAAE,aAAa;KACvB;IACD,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,4DAA4D;KACvE;IACD,aAAa,EAAE;QACb,OAAO,EAAE,CAAC,aAAa,EAAE,cAAc,CAAC;QACxC,QAAQ,EACN,8EAA8E;QAChF,OAAO,EAAE,aAAa;KACvB;IACD,iBAAiB,EAAE;QACjB,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,wCAAwC;QAClD,OAAO,EAAE,KAAK;KACf;CACF,CAAC,CAAC,IAAI,CAAC;AAER,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;IAC5D,OAAO,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAC5D,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,kGAAkG,CACnG,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}).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 \"react-native codegen-windows\" to regenerate.',\n );\n process.exit(2);\n}\n"]}
1
+ {"version":3,"file":"Cli.js","sourceRoot":"","sources":["../src/Cli.ts"],"names":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,EAAE,wCAAwC;QAClD,OAAO,EAAE,KAAK;KACf;CACF,CAAC,CAAC,IAAI,CAAC;AAER,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;IAC5D,OAAO,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAC5D,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}).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"]}
@@ -102,7 +102,7 @@ ${type.properties
102
102
  `;
103
103
  }
104
104
  function tryGetConstantType(nativeModule) {
105
- const candidates = nativeModule.spec.properties.filter(prop => prop.name === 'getConstants');
105
+ const candidates = nativeModule.spec.methods.filter(prop => prop.name === 'getConstants');
106
106
  if (candidates.length === 0) {
107
107
  return undefined;
108
108
  }
@@ -151,7 +151,7 @@ function generateTypeScript(_libraryName, schema, _moduleSpecName) {
151
151
  const constantCode = constantType === undefined
152
152
  ? ''
153
153
  : ` getConstants(): ${translateType(constantType)}`;
154
- const methods = nativeModule.spec.properties.filter(prop => prop.name !== 'getConstants');
154
+ const methods = nativeModule.spec.methods.filter(prop => prop.name !== 'getConstants');
155
155
  const membersCode = methods.map(translateMethod).join('');
156
156
  files.set(`${preferredModuleName}Spec.g.ts`, moduleTemplate
157
157
  .replace(/::_MODULE_ALIASED_STRUCTS_::/g, aliasCode)
@@ -1 +1 @@
1
- {"version":3,"file":"GenerateTypeScript.js","sourceRoot":"","sources":["../../src/generators/GenerateTypeScript.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAkBb,SAAgB,sBAAsB,CACpC,MAA0B,EAC1B,QAAiB;IAEjB,MAAM,EAAE,GAA8B,MAAM,CAAC;IAC7C,EAAE,CAAC,mBAAmB,GAAG,QAAQ,CAAC;AACpC,CAAC;AAND,wDAMC;AAED,SAAgB,sBAAsB,CAAC,MAA0B;;IAC/D,OAAO,MAA4B,MAAO,CAAC,mBAAmB,mCAAI,KAAK,CAAC;AAC1E,CAAC;AAFD,wDAEC;AAOD,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;CAetB,CAAC;AAEF,SAAS,YAAY,CAAI,GAAkB;IACzC,OAAO,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;AACjC,CAAC;AAED,SAAS,aAAa,CACpB,IAIC;IAED,wDAAwD;IACxD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC;IAC7B,QAAQ,IAAI,CAAC,IAAI,EAAE;QACjB,KAAK,sBAAsB;YACzB,OAAO,QAAQ,CAAC;QAClB,KAAK,sBAAsB,CAAC;QAC5B,KAAK,qBAAqB,CAAC;QAC3B,KAAK,sBAAsB,CAAC;QAC5B,KAAK,qBAAqB;YACxB,OAAO,QAAQ,CAAC;QAClB,KAAK,uBAAuB;YAC1B,OAAO,SAAS,CAAC;QACnB,KAAK,qBAAqB;YACxB,IAAI,IAAI,CAAC,WAAW,EAAE;gBACpB,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;aAC/C;iBAAM;gBACL,OAAO,OAA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C,QAAQ,CAAC;iBACjD,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;iBAC9D,IAAI,CAAC,EAAE,CAAC,CAAC;YAEZ,MAAM,YAAY,GAAG,kBAAkB,CAAC,YAAY,CAAC,CAAC;YACtD,MAAM,YAAY,GAChB,YAAY,KAAK,SAAS;gBACxB,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC,qBAAqB,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;YAEzD,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CACjD,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,CACrC,CAAC;YACF,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAE1D,KAAK,CAAC,GAAG,CACP,GAAG,mBAAmB,WAAW,EACjC,cAAc;iBACX,OAAO,CAAC,+BAA+B,EAAE,SAAS,CAAC;iBACnD,OAAO,CAAC,uBAAuB,EAAE,YAAY,GAAG,WAAW,CAAC;iBAC5D,OAAO,CAAC,oBAAoB,EAAE,mBAAmB,CAAC;iBAClD,OAAO,CACN,sBAAsB,EACtB,sBAAsB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,cAAc,CAC9D,CACJ,CAAC;SACH;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAlDD,gDAkDC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {\n NamedShape,\n NativeModuleBaseTypeAnnotation,\n NativeModuleFunctionTypeAnnotation,\n NativeModuleObjectTypeAnnotation,\n NativeModuleParamTypeAnnotation,\n NativeModuleReturnTypeAnnotation,\n NativeModuleSchema,\n Nullable,\n SchemaType,\n} from '@react-native/codegen/lib/CodegenSchema';\n\ninterface CodegenNativeModuleSchema extends NativeModuleSchema {\n optionalTurboModule?: boolean;\n}\n\nexport function setOptionalTurboModule(\n schema: NativeModuleSchema,\n optional: boolean,\n): void {\n const cs = <CodegenNativeModuleSchema>schema;\n cs.optionalTurboModule = optional;\n}\n\nexport function getOptionalTurboModule(schema: NativeModuleSchema): boolean {\n return (<CodegenNativeModuleSchema>schema).optionalTurboModule ?? false;\n}\n\ntype ObjectProp = NamedShape<Nullable<NativeModuleBaseTypeAnnotation>>;\ntype FunctionParam = NamedShape<Nullable<NativeModuleParamTypeAnnotation>>;\ntype FunctionDecl = NamedShape<Nullable<NativeModuleFunctionTypeAnnotation>>;\ntype FilesOutput = Map<string, string>;\n\nconst moduleTemplate = `\n/*\n * This file is auto-generated from a NativeModule spec file in js.\n *\n * This is a TypeScript turbo module definition file.\n */\n\nimport {TurboModule, TurboModuleRegistry} from 'react-native';\n'use strict';\n::_MODULE_ALIASED_STRUCTS_::\nexport interface Spec extends TurboModule {\n::_MODULE_MEMBERS_::\n}\n\nexport default TurboModuleRegistry.::_MODULE_GETTER_::<Spec>('::_MODULE_NAME_::');\n`;\n\nfunction optionalSign<T>(obj: NamedShape<T>): string {\n return obj.optional ? '?' : '';\n}\n\nfunction translateType(\n type: Nullable<\n | NativeModuleBaseTypeAnnotation\n | NativeModuleParamTypeAnnotation\n | NativeModuleReturnTypeAnnotation\n >,\n): string {\n // avoid: Property 'type' does not exist on type 'never'\n const returnType = type.type;\n switch (type.type) {\n case 'StringTypeAnnotation':\n return 'string';\n case 'NumberTypeAnnotation':\n case 'FloatTypeAnnotation':\n case 'DoubleTypeAnnotation':\n case 'Int32TypeAnnotation':\n return 'number';\n case 'BooleanTypeAnnotation':\n return 'boolean';\n case 'ArrayTypeAnnotation':\n if (type.elementType) {\n return `${translateType(type.elementType)}[]`;\n } else {\n return `Array`;\n }\n case 'GenericObjectTypeAnnotation':\n return 'object';\n case 'ObjectTypeAnnotation':\n return `{${type.properties\n .map((prop: ObjectProp) => {\n return `${prop.name}${optionalSign(prop)}: ${translateType(\n prop.typeAnnotation,\n )}`;\n })\n .join(', ')}}`;\n case 'ReservedTypeAnnotation': {\n // avoid: Property 'name' does not exist on type 'never'\n const name = type.name;\n // (#6597)\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (name !== 'RootTag')\n throw new Error(\n `Unknown reserved function: ${name} in translateReturnType`,\n );\n return 'number';\n }\n case 'TypeAliasTypeAnnotation':\n return type.name;\n case 'NullableTypeAnnotation':\n return `(${translateType(type.typeAnnotation)} | null | undefined)`;\n case 'VoidTypeAnnotation':\n return `void`;\n case 'PromiseTypeAnnotation':\n return `Promise`;\n case `FunctionTypeAnnotation`:\n return `((${type.params\n .map((param: FunctionParam) => {\n return `${param.name}${optionalSign(param)}: ${translateType(\n param.typeAnnotation,\n )}`;\n })\n .join(', ')}) => ${translateType(type.returnTypeAnnotation)})`;\n default:\n throw new Error(`Unhandled type in translateReturnType: ${returnType}`);\n }\n}\n\nfunction translateAlias(\n name: string,\n type: NativeModuleObjectTypeAnnotation,\n): string {\n return `\nexport interface ${name} {\n${type.properties\n .map((prop: ObjectProp) => {\n return ` ${prop.name}${optionalSign(prop)}: ${translateType(\n prop.typeAnnotation,\n )};`;\n })\n .join('\\n')}\n}\n`;\n}\n\nfunction tryGetConstantType(\n nativeModule: NativeModuleSchema,\n): NativeModuleObjectTypeAnnotation | undefined {\n const candidates = nativeModule.spec.properties.filter(\n prop => prop.name === 'getConstants',\n );\n if (candidates.length === 0) {\n return undefined;\n }\n\n const getConstant = candidates[0];\n const funcType =\n getConstant.typeAnnotation.type === 'NullableTypeAnnotation'\n ? getConstant.typeAnnotation.typeAnnotation\n : getConstant.typeAnnotation;\n if (\n funcType.params.length > 0 ||\n funcType.returnTypeAnnotation.type !== 'ObjectTypeAnnotation'\n ) {\n return undefined;\n }\n\n const constantType = funcType.returnTypeAnnotation;\n if (constantType.properties.length === 0) {\n return undefined;\n }\n\n return constantType;\n}\n\nfunction translateMethod(func: FunctionDecl): string {\n const funcType =\n func.typeAnnotation.type === 'NullableTypeAnnotation'\n ? func.typeAnnotation.typeAnnotation\n : func.typeAnnotation;\n\n return `\n ${func.name}(${funcType.params\n .map((param: FunctionParam) => {\n return `${param.name}${optionalSign(param)}: ${translateType(\n param.typeAnnotation,\n )}`;\n })\n .join(', ')})${optionalSign(func)}: ${translateType(\n funcType.returnTypeAnnotation,\n )}${\n funcType.returnTypeAnnotation.type === 'ObjectTypeAnnotation' ? '' : ';'\n }`;\n}\n\nexport function generateTypeScript(\n _libraryName: string,\n schema: SchemaType,\n _moduleSpecName: string,\n): FilesOutput {\n const files = new Map<string, string>();\n\n for (const moduleName of Object.keys(schema.modules)) {\n const nativeModule = schema.modules[moduleName];\n // from 0.65 facebook's react-native-codegen\n // the module name has the Native prefix comparing to 0.63\n // when reading files we provided\n const nativePrefix = 'Native';\n const preferredModuleName = moduleName.startsWith(nativePrefix)\n ? moduleName.substr(nativePrefix.length)\n : moduleName;\n\n if (nativeModule.type === 'NativeModule') {\n console.log(`Generating ${preferredModuleName}Spec.g.ts`);\n\n const aliasCode = Object.keys(nativeModule.aliasMap)\n .map(name => translateAlias(name, nativeModule.aliasMap[name]))\n .join('');\n\n const constantType = tryGetConstantType(nativeModule);\n const constantCode =\n constantType === undefined\n ? ''\n : ` getConstants(): ${translateType(constantType)}`;\n\n const methods = nativeModule.spec.properties.filter(\n prop => prop.name !== 'getConstants',\n );\n const membersCode = methods.map(translateMethod).join('');\n\n files.set(\n `${preferredModuleName}Spec.g.ts`,\n moduleTemplate\n .replace(/::_MODULE_ALIASED_STRUCTS_::/g, aliasCode)\n .replace(/::_MODULE_MEMBERS_::/g, constantCode + membersCode)\n .replace(/::_MODULE_NAME_::/g, preferredModuleName)\n .replace(\n /::_MODULE_GETTER_::/g,\n getOptionalTurboModule(nativeModule) ? 'get' : 'getEnforcing',\n ),\n );\n }\n }\n\n return files;\n}\n"]}
1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,CAAC,EAAE,CAAC,CAAC;YAEZ,MAAM,YAAY,GAAG,kBAAkB,CAAC,YAAY,CAAC,CAAC;YACtD,MAAM,YAAY,GAChB,YAAY,KAAK,SAAS;gBACxB,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC,qBAAqB,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;YAEzD,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAC9C,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,CACrC,CAAC;YACF,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAE1D,KAAK,CAAC,GAAG,CACP,GAAG,mBAAmB,WAAW,EACjC,cAAc;iBACX,OAAO,CAAC,+BAA+B,EAAE,SAAS,CAAC;iBACnD,OAAO,CAAC,uBAAuB,EAAE,YAAY,GAAG,WAAW,CAAC;iBAC5D,OAAO,CAAC,oBAAoB,EAAE,mBAAmB,CAAC;iBAClD,OAAO,CACN,sBAAsB,EACtB,sBAAsB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,cAAc,CAC9D,CACJ,CAAC;SACH;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAlDD,gDAkDC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {\n NamedShape,\n NativeModuleBaseTypeAnnotation,\n NativeModuleFunctionTypeAnnotation,\n NativeModuleObjectTypeAnnotation,\n NativeModuleParamTypeAnnotation,\n NativeModuleReturnTypeAnnotation,\n NativeModuleSchema,\n Nullable,\n SchemaType,\n} from '@react-native/codegen/lib/CodegenSchema';\n\ninterface CodegenNativeModuleSchema extends NativeModuleSchema {\n optionalTurboModule?: boolean;\n}\n\nexport function setOptionalTurboModule(\n schema: NativeModuleSchema,\n optional: boolean,\n): void {\n const cs = <CodegenNativeModuleSchema>schema;\n cs.optionalTurboModule = optional;\n}\n\nexport function getOptionalTurboModule(schema: NativeModuleSchema): boolean {\n return (<CodegenNativeModuleSchema>schema).optionalTurboModule ?? false;\n}\n\ntype ObjectProp = NamedShape<Nullable<NativeModuleBaseTypeAnnotation>>;\ntype FunctionParam = NamedShape<Nullable<NativeModuleParamTypeAnnotation>>;\ntype FunctionDecl = NamedShape<Nullable<NativeModuleFunctionTypeAnnotation>>;\ntype FilesOutput = Map<string, string>;\n\nconst moduleTemplate = `\n/*\n * This file is auto-generated from a NativeModule spec file in js.\n *\n * This is a TypeScript turbo module definition file.\n */\n\nimport {TurboModule, TurboModuleRegistry} from 'react-native';\n'use strict';\n::_MODULE_ALIASED_STRUCTS_::\nexport interface Spec extends TurboModule {\n::_MODULE_MEMBERS_::\n}\n\nexport default TurboModuleRegistry.::_MODULE_GETTER_::<Spec>('::_MODULE_NAME_::');\n`;\n\nfunction optionalSign<T>(obj: NamedShape<T>): string {\n return obj.optional ? '?' : '';\n}\n\nfunction translateType(\n type: Nullable<\n | NativeModuleBaseTypeAnnotation\n | NativeModuleParamTypeAnnotation\n | NativeModuleReturnTypeAnnotation\n >,\n): string {\n // avoid: Property 'type' does not exist on type 'never'\n const returnType = type.type;\n switch (type.type) {\n case 'StringTypeAnnotation':\n return 'string';\n case 'NumberTypeAnnotation':\n case 'FloatTypeAnnotation':\n case 'DoubleTypeAnnotation':\n case 'Int32TypeAnnotation':\n return 'number';\n case 'BooleanTypeAnnotation':\n return 'boolean';\n case 'ArrayTypeAnnotation':\n if (type.elementType) {\n return `${translateType(type.elementType)}[]`;\n } else {\n return `Array`;\n }\n case 'GenericObjectTypeAnnotation':\n return 'object';\n case 'ObjectTypeAnnotation':\n return `{${type.properties\n .map((prop: ObjectProp) => {\n return `${prop.name}${optionalSign(prop)}: ${translateType(\n prop.typeAnnotation,\n )}`;\n })\n .join(', ')}}`;\n case 'ReservedTypeAnnotation': {\n // avoid: Property 'name' does not exist on type 'never'\n const name = type.name;\n // (#6597)\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (name !== 'RootTag')\n throw new Error(\n `Unknown reserved function: ${name} in translateReturnType`,\n );\n return 'number';\n }\n case 'TypeAliasTypeAnnotation':\n return type.name;\n case 'NullableTypeAnnotation':\n return `(${translateType(type.typeAnnotation)} | null | undefined)`;\n case 'VoidTypeAnnotation':\n return `void`;\n case 'PromiseTypeAnnotation':\n return `Promise`;\n case `FunctionTypeAnnotation`:\n return `((${type.params\n .map((param: FunctionParam) => {\n return `${param.name}${optionalSign(param)}: ${translateType(\n param.typeAnnotation,\n )}`;\n })\n .join(', ')}) => ${translateType(type.returnTypeAnnotation)})`;\n default:\n throw new Error(`Unhandled type in translateReturnType: ${returnType}`);\n }\n}\n\nfunction translateAlias(\n name: string,\n type: NativeModuleObjectTypeAnnotation,\n): string {\n return `\nexport interface ${name} {\n${type.properties\n .map((prop: ObjectProp) => {\n return ` ${prop.name}${optionalSign(prop)}: ${translateType(\n prop.typeAnnotation,\n )};`;\n })\n .join('\\n')}\n}\n`;\n}\n\nfunction tryGetConstantType(\n nativeModule: NativeModuleSchema,\n): NativeModuleObjectTypeAnnotation | undefined {\n const candidates = nativeModule.spec.methods.filter(\n prop => prop.name === 'getConstants',\n );\n if (candidates.length === 0) {\n return undefined;\n }\n\n const getConstant = candidates[0];\n const funcType =\n getConstant.typeAnnotation.type === 'NullableTypeAnnotation'\n ? getConstant.typeAnnotation.typeAnnotation\n : getConstant.typeAnnotation;\n if (\n funcType.params.length > 0 ||\n funcType.returnTypeAnnotation.type !== 'ObjectTypeAnnotation'\n ) {\n return undefined;\n }\n\n const constantType = funcType.returnTypeAnnotation;\n if (constantType.properties.length === 0) {\n return undefined;\n }\n\n return constantType;\n}\n\nfunction translateMethod(func: FunctionDecl): string {\n const funcType =\n func.typeAnnotation.type === 'NullableTypeAnnotation'\n ? func.typeAnnotation.typeAnnotation\n : func.typeAnnotation;\n\n return `\n ${func.name}(${funcType.params\n .map((param: FunctionParam) => {\n return `${param.name}${optionalSign(param)}: ${translateType(\n param.typeAnnotation,\n )}`;\n })\n .join(', ')})${optionalSign(func)}: ${translateType(\n funcType.returnTypeAnnotation,\n )}${\n funcType.returnTypeAnnotation.type === 'ObjectTypeAnnotation' ? '' : ';'\n }`;\n}\n\nexport function generateTypeScript(\n _libraryName: string,\n schema: SchemaType,\n _moduleSpecName: string,\n): FilesOutput {\n const files = new Map<string, string>();\n\n for (const moduleName of Object.keys(schema.modules)) {\n const nativeModule = schema.modules[moduleName];\n // from 0.65 facebook's react-native-codegen\n // the module name has the Native prefix comparing to 0.63\n // when reading files we provided\n const nativePrefix = 'Native';\n const preferredModuleName = moduleName.startsWith(nativePrefix)\n ? moduleName.substr(nativePrefix.length)\n : moduleName;\n\n if (nativeModule.type === 'NativeModule') {\n console.log(`Generating ${preferredModuleName}Spec.g.ts`);\n\n const aliasCode = Object.keys(nativeModule.aliasMap)\n .map(name => translateAlias(name, nativeModule.aliasMap[name]))\n .join('');\n\n const constantType = tryGetConstantType(nativeModule);\n const constantCode =\n constantType === undefined\n ? ''\n : ` getConstants(): ${translateType(constantType)}`;\n\n const methods = nativeModule.spec.methods.filter(\n prop => prop.name !== 'getConstants',\n );\n const membersCode = methods.map(translateMethod).join('');\n\n files.set(\n `${preferredModuleName}Spec.g.ts`,\n moduleTemplate\n .replace(/::_MODULE_ALIASED_STRUCTS_::/g, aliasCode)\n .replace(/::_MODULE_MEMBERS_::/g, constantCode + membersCode)\n .replace(/::_MODULE_NAME_::/g, preferredModuleName)\n .replace(\n /::_MODULE_GETTER_::/g,\n getOptionalTurboModule(nativeModule) ? 'get' : 'getEnforcing',\n ),\n );\n }\n }\n\n return files;\n}\n"]}
@@ -58,6 +58,7 @@ function translateFieldOrReturnType(type, aliases, baseAliasName, callerName, op
58
58
  return (0, AliasManaging_1.getAliasCppName)(type.name);
59
59
  case 'NullableTypeAnnotation':
60
60
  return `std::optional<${translateFieldOrReturnType(type.typeAnnotation, aliases, baseAliasName, callerName, options)}>`;
61
+ case 'FunctionTypeAnnotation':
61
62
  case 'MixedTypeAnnotation':
62
63
  return '';
63
64
  case 'EnumDeclaration':
@@ -1 +1 @@
1
- {"version":3,"file":"ObjectTypes.js","sourceRoot":"","sources":["../../src/generators/ObjectTypes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAUb,mDAIyB;AAQzB,SAAS,wBAAwB,CAC/B,IAAmE,EACnE,OAA0B;IAE1B,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;IACnC,QAAQ,IAAI,CAAC,UAAU,EAAE;QACvB,KAAK,sBAAsB;YACzB,OAAO,OAAO,CAAC,aAAa,CAAC;QAC/B,KAAK,sBAAsB;YACzB,OAAO,QAAQ,CAAC;QAClB,KAAK,sBAAsB;YACzB,OAAO,kBAAkB,CAAC;QAC5B;YACE,MAAM,IAAI,KAAK,CACb,0DAA0D,UAAU,EAAE,CACvE,CAAC;KACL;AACH,CAAC;AAED,SAAgB,0BAA0B,CACxC,IAIC,EACD,OAAiB,EACjB,aAAqB,EACrB,UAAoD,EACpD,OAA0B;IAE1B,wDAAwD;IACxD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC;IAC7B,QAAQ,IAAI,CAAC,IAAI,EAAE;QACjB,KAAK,sBAAsB;YACzB,OAAO,OAAO,CAAC,aAAa,CAAC;QAC/B,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,0BAA0B,CAC9C,IAAI,CAAC,WAAW,EAChB,OAAO,EACP,GAAG,aAAa,UAAU,EAC1B,UAAU,EACV,OAAO,CACR,GAAG,CAAC;aACN;iBAAM;gBACL,OAAO,uBAAuB,CAAC;aAChC;QACH,KAAK,6BAA6B;YAChC,OAAO,kBAAkB,CAAC;QAC5B,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,CAAC,8BAA8B,IAAI,OAAO,UAAU,EAAE,CAAC,CAAC;YACzE,OAAO,QAAQ,CAAC;SACjB;QACD,KAAK,yBAAyB;YAC5B,OAAO,IAAA,+BAAe,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpC,KAAK,wBAAwB;YAC3B,OAAO,iBAAiB,0BAA0B,CAChD,IAAI,CAAC,cAAc,EACnB,OAAO,EACP,aAAa,EACb,UAAU,EACV,OAAO,CACR,GAAG,CAAC;QACP,KAAK,qBAAqB;YACxB,OAAO,EAAE,CAAC;QACZ,KAAK,iBAAiB,CAAC;QACvB,KAAK,qBAAqB;YACxB,OAAO,wBAAwB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACjD;YACE,MAAM,IAAI,KAAK,CAAC,qBAAqB,UAAU,KAAK,UAAU,EAAE,CAAC,CAAC;KACrE;AACH,CAAC;AAnED,gEAmEC;AAED,SAAgB,cAAc,CAC5B,IAA8C,EAC9C,OAAiB,EACjB,aAAqB,EACrB,OAA0B;IAE1B,OAAO,0BAA0B,CAC/B,IAAI,EACJ,OAAO,EACP,aAAa,EACb,gBAAgB,EAChB,OAAO,CACR,CAAC;AACJ,CAAC;AAbD,wCAaC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {\n NativeModuleEnumDeclaration,\n NativeModuleBaseTypeAnnotation,\n NativeModuleUnionTypeAnnotation,\n NativeModuleStringTypeAnnotation,\n NativeModuleFunctionTypeAnnotation,\n Nullable,\n} from '@react-native/codegen/lib/CodegenSchema';\nimport {\n AliasMap,\n getAliasCppName,\n getAnonymousAliasCppName,\n} from './AliasManaging';\n\nexport type CppStringTypes = 'std::string' | 'std::wstring';\n\nexport interface CppCodegenOptions {\n cppStringType: CppStringTypes;\n}\n\nfunction translateUnionReturnType(\n type: NativeModuleEnumDeclaration | NativeModuleUnionTypeAnnotation,\n options: CppCodegenOptions,\n): string {\n const memberType = type.memberType;\n switch (type.memberType) {\n case 'StringTypeAnnotation':\n return options.cppStringType;\n case 'NumberTypeAnnotation':\n return 'double';\n case 'ObjectTypeAnnotation':\n return '::React::JSValue';\n default:\n throw new Error(\n `Unknown enum/union member type in translateReturnType: ${memberType}`,\n );\n }\n}\n\nexport function translateFieldOrReturnType(\n type: Nullable<\n | NativeModuleBaseTypeAnnotation\n | NativeModuleStringTypeAnnotation\n | NativeModuleFunctionTypeAnnotation\n >,\n aliases: AliasMap,\n baseAliasName: string,\n callerName: 'translateField' | 'translateReturnType',\n options: CppCodegenOptions,\n): string {\n // avoid: Property 'type' does not exist on type 'never'\n const returnType = type.type;\n switch (type.type) {\n case 'StringTypeAnnotation':\n return options.cppStringType;\n case 'NumberTypeAnnotation':\n case 'FloatTypeAnnotation':\n case 'DoubleTypeAnnotation':\n return 'double';\n case 'Int32TypeAnnotation':\n return 'int';\n case 'BooleanTypeAnnotation':\n return 'bool';\n case 'ArrayTypeAnnotation':\n if (type.elementType) {\n return `std::vector<${translateFieldOrReturnType(\n type.elementType,\n aliases,\n `${baseAliasName}_element`,\n callerName,\n options,\n )}>`;\n } else {\n return `::React::JSValueArray`;\n }\n case 'GenericObjectTypeAnnotation':\n return '::React::JSValue';\n case 'ObjectTypeAnnotation':\n return getAnonymousAliasCppName(aliases, baseAliasName, type);\n case 'ReservedTypeAnnotation': {\n // avoid: Property 'name' does not exist on type 'never'\n const name = type.name;\n // (#6597)\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (name !== 'RootTag')\n throw new Error(`Unknown reserved function: ${name} in ${callerName}`);\n return 'double';\n }\n case 'TypeAliasTypeAnnotation':\n return getAliasCppName(type.name);\n case 'NullableTypeAnnotation':\n return `std::optional<${translateFieldOrReturnType(\n type.typeAnnotation,\n aliases,\n baseAliasName,\n callerName,\n options,\n )}>`;\n case 'MixedTypeAnnotation':\n return '';\n case 'EnumDeclaration':\n case 'UnionTypeAnnotation':\n return translateUnionReturnType(type, options);\n default:\n throw new Error(`Unhandled type in ${callerName}: ${returnType}`);\n }\n}\n\nexport function translateField(\n type: Nullable<NativeModuleBaseTypeAnnotation>,\n aliases: AliasMap,\n baseAliasName: string,\n options: CppCodegenOptions,\n): string {\n return translateFieldOrReturnType(\n type,\n aliases,\n baseAliasName,\n 'translateField',\n options,\n );\n}\n"]}
1
+ {"version":3,"file":"ObjectTypes.js","sourceRoot":"","sources":["../../src/generators/ObjectTypes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAUb,mDAIyB;AAQzB,SAAS,wBAAwB,CAC/B,IAAmE,EACnE,OAA0B;IAE1B,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;IACnC,QAAQ,IAAI,CAAC,UAAU,EAAE;QACvB,KAAK,sBAAsB;YACzB,OAAO,OAAO,CAAC,aAAa,CAAC;QAC/B,KAAK,sBAAsB;YACzB,OAAO,QAAQ,CAAC;QAClB,KAAK,sBAAsB;YACzB,OAAO,kBAAkB,CAAC;QAC5B;YACE,MAAM,IAAI,KAAK,CACb,0DAA0D,UAAU,EAAE,CACvE,CAAC;KACL;AACH,CAAC;AAED,SAAgB,0BAA0B,CACxC,IAIC,EACD,OAAiB,EACjB,aAAqB,EACrB,UAAoD,EACpD,OAA0B;IAE1B,wDAAwD;IACxD,MAAM,UAAU,GAAG,IAAI,CAAC,I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AiB,CAAC;QACvB,KAAK,qBAAqB;YACxB,OAAO,wBAAwB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACjD;YACE,MAAM,IAAI,KAAK,CAAC,qBAAqB,UAAU,KAAK,UAAU,EAAE,CAAC,CAAC;KACrE;AACH,CAAC;AApED,gEAoEC;AAED,SAAgB,cAAc,CAC5B,IAA8C,EAC9C,OAAiB,EACjB,aAAqB,EACrB,OAA0B;IAE1B,OAAO,0BAA0B,CAC/B,IAAI,EACJ,OAAO,EACP,aAAa,EACb,gBAAgB,EAChB,OAAO,CACR,CAAC;AACJ,CAAC;AAbD,wCAaC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {\n NativeModuleEnumDeclaration,\n NativeModuleBaseTypeAnnotation,\n NativeModuleUnionTypeAnnotation,\n NativeModuleStringTypeAnnotation,\n NativeModuleFunctionTypeAnnotation,\n Nullable,\n} from '@react-native/codegen/lib/CodegenSchema';\nimport {\n AliasMap,\n getAliasCppName,\n getAnonymousAliasCppName,\n} from './AliasManaging';\n\nexport type CppStringTypes = 'std::string' | 'std::wstring';\n\nexport interface CppCodegenOptions {\n cppStringType: CppStringTypes;\n}\n\nfunction translateUnionReturnType(\n type: NativeModuleEnumDeclaration | NativeModuleUnionTypeAnnotation,\n options: CppCodegenOptions,\n): string {\n const memberType = type.memberType;\n switch (type.memberType) {\n case 'StringTypeAnnotation':\n return options.cppStringType;\n case 'NumberTypeAnnotation':\n return 'double';\n case 'ObjectTypeAnnotation':\n return '::React::JSValue';\n default:\n throw new Error(\n `Unknown enum/union member type in translateReturnType: ${memberType}`,\n );\n }\n}\n\nexport function translateFieldOrReturnType(\n type: Nullable<\n | NativeModuleBaseTypeAnnotation\n | NativeModuleStringTypeAnnotation\n | NativeModuleFunctionTypeAnnotation\n >,\n aliases: AliasMap,\n baseAliasName: string,\n callerName: 'translateField' | 'translateReturnType',\n options: CppCodegenOptions,\n): string {\n // avoid: Property 'type' does not exist on type 'never'\n const returnType = type.type;\n switch (type.type) {\n case 'StringTypeAnnotation':\n return options.cppStringType;\n case 'NumberTypeAnnotation':\n case 'FloatTypeAnnotation':\n case 'DoubleTypeAnnotation':\n return 'double';\n case 'Int32TypeAnnotation':\n return 'int';\n case 'BooleanTypeAnnotation':\n return 'bool';\n case 'ArrayTypeAnnotation':\n if (type.elementType) {\n return `std::vector<${translateFieldOrReturnType(\n type.elementType,\n aliases,\n `${baseAliasName}_element`,\n callerName,\n options,\n )}>`;\n } else {\n return `::React::JSValueArray`;\n }\n case 'GenericObjectTypeAnnotation':\n return '::React::JSValue';\n case 'ObjectTypeAnnotation':\n return getAnonymousAliasCppName(aliases, baseAliasName, type);\n case 'ReservedTypeAnnotation': {\n // avoid: Property 'name' does not exist on type 'never'\n const name = type.name;\n // (#6597)\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (name !== 'RootTag')\n throw new Error(`Unknown reserved function: ${name} in ${callerName}`);\n return 'double';\n }\n case 'TypeAliasTypeAnnotation':\n return getAliasCppName(type.name);\n case 'NullableTypeAnnotation':\n return `std::optional<${translateFieldOrReturnType(\n type.typeAnnotation,\n aliases,\n baseAliasName,\n callerName,\n options,\n )}>`;\n case 'FunctionTypeAnnotation':\n case 'MixedTypeAnnotation':\n return '';\n case 'EnumDeclaration':\n case 'UnionTypeAnnotation':\n return translateUnionReturnType(type, options);\n default:\n throw new Error(`Unhandled type in ${callerName}: ${returnType}`);\n }\n}\n\nexport function translateField(\n type: Nullable<NativeModuleBaseTypeAnnotation>,\n aliases: AliasMap,\n baseAliasName: string,\n options: CppCodegenOptions,\n): string {\n return translateFieldOrReturnType(\n type,\n aliases,\n baseAliasName,\n 'translateField',\n options,\n );\n}\n"]}
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.generateValidateConstants = void 0;
9
9
  const AliasManaging_1 = require("./AliasManaging");
10
10
  function generateValidateConstants(nativeModule, aliases) {
11
- const candidates = nativeModule.spec.properties.filter(prop => prop.name === 'getConstants');
11
+ const candidates = nativeModule.spec.methods.filter(prop => prop.name === 'getConstants');
12
12
  if (candidates.length === 0) {
13
13
  return undefined;
14
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ValidateConstants.js","sourceRoot":"","sources":["../../src/generators/ValidateConstants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAGb,mDAAmE;AAEnE,SAAgB,yBAAyB,CACvC,YAAgC,EAChC,OAAiB;IAEjB,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CACpD,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,CACrC,CAAC;IACF,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QAC3B,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;IAClC,MAAM,QAAQ,GACZ,WAAW,CAAC,cAAc,CAAC,IAAI,KAAK,wBAAwB;QAC1D,CAAC,CAAC,WAAW,CAAC,cAAc,CAAC,cAAc;QAC3C,CAAC,CAAC,WAAW,CAAC,cAAc,CAAC;IACjC,IACE,QAAQ,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;QAC1B,QAAQ,CAAC,oBAAoB,CAAC,IAAI,KAAK,sBAAsB,EAC7D;QACA,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,YAAY,GAAG,QAAQ,CAAC,oBAAoB,CAAC;IACnD,IAAI,YAAY,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QACxC,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,OAAO,GAAG,IAAA,wCAAwB,EAAC,OAAO,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;IAE7E,OAAO;QACL,uBAAuB,OAAO,OAAO;QACrC;;aAES,OAAO;mDAC+B,OAAO;0DACA,OAAO,qDAAqD;KACnH,CAAC;AACJ,CAAC;AAtCD,8DAsCC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {NativeModuleSchema} from '@react-native/codegen/lib/CodegenSchema';\nimport {AliasMap, getAnonymousAliasCppName} from './AliasManaging';\n\nexport function generateValidateConstants(\n nativeModule: NativeModuleSchema,\n aliases: AliasMap,\n): [string, string] | undefined {\n const candidates = nativeModule.spec.properties.filter(\n prop => prop.name === 'getConstants',\n );\n if (candidates.length === 0) {\n return undefined;\n }\n\n const getConstant = candidates[0];\n const funcType =\n getConstant.typeAnnotation.type === 'NullableTypeAnnotation'\n ? getConstant.typeAnnotation.typeAnnotation\n : getConstant.typeAnnotation;\n if (\n funcType.params.length > 0 ||\n funcType.returnTypeAnnotation.type !== 'ObjectTypeAnnotation'\n ) {\n return undefined;\n }\n\n const constantType = funcType.returnTypeAnnotation;\n if (constantType.properties.length === 0) {\n return undefined;\n }\n\n const cppName = getAnonymousAliasCppName(aliases, 'Constants', constantType);\n\n return [\n ` TypedConstant<${cppName}>{0},`,\n ` REACT_SHOW_CONSTANT_SPEC_ERRORS(\n 0,\n \"${cppName}\",\n \" REACT_GET_CONSTANTS(GetConstants) ${cppName} GetConstants() noexcept {/*implementation*/}\\\\n\"\n \" REACT_GET_CONSTANTS(GetConstants) static ${cppName} GetConstants() noexcept {/*implementation*/}\\\\n\");`,\n ];\n}\n"]}
1
+ {"version":3,"file":"ValidateConstants.js","sourceRoot":"","sources":["../../src/generators/ValidateConstants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAGb,mDAAmE;AAEnE,SAAgB,yBAAyB,CACvC,YAAgC,EAChC,OAAiB;IAEjB,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CACjD,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,CACrC,CAAC;IACF,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QAC3B,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;IAClC,MAAM,QAAQ,GACZ,WAAW,CAAC,cAAc,CAAC,IAAI,KAAK,wBAAwB;QAC1D,CAAC,CAAC,WAAW,CAAC,cAAc,CAAC,cAAc;QAC3C,CAAC,CAAC,WAAW,CAAC,cAAc,CAAC;IACjC,IACE,QAAQ,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;QAC1B,QAAQ,CAAC,oBAAoB,CAAC,IAAI,KAAK,sBAAsB,EAC7D;QACA,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,YAAY,GAAG,QAAQ,CAAC,oBAAoB,CAAC;IACnD,IAAI,YAAY,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QACxC,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,OAAO,GAAG,IAAA,wCAAwB,EAAC,OAAO,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;IAE7E,OAAO;QACL,uBAAuB,OAAO,OAAO;QACrC;;aAES,OAAO;mDAC+B,OAAO;0DACA,OAAO,qDAAqD;KACnH,CAAC;AACJ,CAAC;AAtCD,8DAsCC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {NativeModuleSchema} from '@react-native/codegen/lib/CodegenSchema';\nimport {AliasMap, getAnonymousAliasCppName} from './AliasManaging';\n\nexport function generateValidateConstants(\n nativeModule: NativeModuleSchema,\n aliases: AliasMap,\n): [string, string] | undefined {\n const candidates = nativeModule.spec.methods.filter(\n prop => prop.name === 'getConstants',\n );\n if (candidates.length === 0) {\n return undefined;\n }\n\n const getConstant = candidates[0];\n const funcType =\n getConstant.typeAnnotation.type === 'NullableTypeAnnotation'\n ? getConstant.typeAnnotation.typeAnnotation\n : getConstant.typeAnnotation;\n if (\n funcType.params.length > 0 ||\n funcType.returnTypeAnnotation.type !== 'ObjectTypeAnnotation'\n ) {\n return undefined;\n }\n\n const constantType = funcType.returnTypeAnnotation;\n if (constantType.properties.length === 0) {\n return undefined;\n }\n\n const cppName = getAnonymousAliasCppName(aliases, 'Constants', constantType);\n\n return [\n ` TypedConstant<${cppName}>{0},`,\n ` REACT_SHOW_CONSTANT_SPEC_ERRORS(\n 0,\n \"${cppName}\",\n \" REACT_GET_CONSTANTS(GetConstants) ${cppName} GetConstants() noexcept {/*implementation*/}\\\\n\"\n \" REACT_GET_CONSTANTS(GetConstants) static ${cppName} GetConstants() noexcept {/*implementation*/}\\\\n\");`,\n ];\n}\n"]}
@@ -32,9 +32,9 @@ function translatePossibleMethodSignatures(prop, funcType, aliases, baseAliasNam
32
32
  .map(sig => `" ${sig}\\n"`)
33
33
  .join('\n ');
34
34
  }
35
- function renderProperties(properties, aliases, tuple, options) {
35
+ function renderProperties(methods, aliases, tuple, options) {
36
36
  // TODO: generate code for constants
37
- return properties
37
+ return methods
38
38
  .filter(prop => prop.name !== 'getConstants')
39
39
  .map((prop, index) => {
40
40
  // TODO: prop.optional === true
@@ -66,9 +66,9 @@ function renderProperties(properties, aliases, tuple, options) {
66
66
  .join('\n');
67
67
  }
68
68
  function generateValidateMethods(nativeModule, aliases, options) {
69
- const properties = nativeModule.spec.properties;
70
- const traversedProperties = renderProperties(properties, aliases, false, options);
71
- const traversedPropertyTuples = renderProperties(properties, aliases, true, options);
69
+ const methods = nativeModule.spec.methods;
70
+ const traversedProperties = renderProperties(methods, aliases, false, options);
71
+ const traversedPropertyTuples = renderProperties(methods, aliases, true, options);
72
72
  return [traversedPropertyTuples, traversedProperties];
73
73
  }
74
74
  exports.generateValidateMethods = generateValidateMethods;
@@ -1 +1 @@
1
- {"version":3,"file":"ValidateMethods.js","sourceRoot":"","sources":["../../src/generators/ValidateMethods.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AASb,6CAA8D;AAC9D,+CAA+E;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,oBAAoB,CAAC,WAAW,EAAE;gBAC7C,aAAa,CAAC,IAAI,CAChB,WAAW,IAAA,qCAAuB,EAChC,QAAQ,CAAC,oBAAoB,CAAC,WAAW,EACzC,OAAO,EACP,aAAa,EACb,OAAO,CACR,GAAG,CACL,CAAC;aACH;iBAAM;gBACL,aAAa,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;aACjD;SACF;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,EACb,OAAO,CACR,IAAI,CAAC;SACT;IACH,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED,SAAgB,uBAAuB,CACrC,YAAgC,EAChC,OAAiB,EACjB,OAA0B;IAE1B,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC;IAChD,MAAM,mBAAmB,GAAG,gBAAgB,CAC1C,UAAU,EACV,OAAO,EACP,KAAK,EACL,OAAO,CACR,CAAC;IACF,MAAM,uBAAuB,GAAG,gBAAgB,CAC9C,UAAU,EACV,OAAO,EACP,IAAI,EACJ,OAAO,CACR,CAAC;IACF,OAAO,CAAC,uBAAuB,EAAE,mBAAmB,CAAC,CAAC;AACxD,CAAC;AAnBD,0DAmBC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {\n NativeModuleFunctionTypeAnnotation,\n NativeModulePropertyShape,\n NativeModuleSchema,\n} from '@react-native/codegen/lib/CodegenSchema';\nimport {AliasMap} from './AliasManaging';\nimport type {CppCodegenOptions} from './ObjectTypes';\nimport {translateArgs, translateSpecArgs} from './ParamTypes';\nimport {translateImplReturnType, translateSpecReturnType} from './ReturnTypes';\n\nfunction isMethodSync(funcType: NativeModuleFunctionTypeAnnotation) {\n return (\n funcType.returnTypeAnnotation.type !== 'VoidTypeAnnotation' &&\n funcType.returnTypeAnnotation.type !== 'PromiseTypeAnnotation'\n );\n}\n\nfunction getPossibleMethodSignatures(\n prop: NativeModulePropertyShape,\n funcType: NativeModuleFunctionTypeAnnotation,\n aliases: AliasMap,\n baseAliasName: string,\n options: CppCodegenOptions,\n): string[] {\n const args = translateArgs(funcType.params, aliases, baseAliasName, options);\n if (funcType.returnTypeAnnotation.type === 'PromiseTypeAnnotation') {\n if (funcType.returnTypeAnnotation.elementType) {\n args.push(\n `::React::ReactPromise<${translateImplReturnType(\n funcType.returnTypeAnnotation.elementType,\n aliases,\n baseAliasName,\n options,\n )}> &&result`,\n );\n } else {\n args.push('::React::ReactPromise<::React::JSValue> &&result');\n }\n }\n\n // TODO: be much more exhaustive on the possible method signatures that can be used..\n const sig = `REACT_${isMethodSync(funcType) ? 'SYNC_' : ''}METHOD(${\n prop.name\n }) ${translateImplReturnType(\n funcType.returnTypeAnnotation,\n aliases,\n baseAliasName,\n options,\n )} ${prop.name}(${args.join(', ')}) noexcept { /* implementation */ }`;\n\n const staticsig = `REACT_${isMethodSync(funcType) ? 'SYNC_' : ''}METHOD(${\n prop.name\n }) static ${translateImplReturnType(\n funcType.returnTypeAnnotation,\n aliases,\n baseAliasName,\n options,\n )} ${prop.name}(${args.join(', ')}) noexcept { /* implementation */ }`;\n\n return [sig, staticsig];\n}\n\nfunction translatePossibleMethodSignatures(\n prop: NativeModulePropertyShape,\n funcType: NativeModuleFunctionTypeAnnotation,\n aliases: AliasMap,\n baseAliasName: string,\n options: CppCodegenOptions,\n): string {\n return getPossibleMethodSignatures(\n prop,\n funcType,\n aliases,\n baseAliasName,\n options,\n )\n .map(sig => `\" ${sig}\\\\n\"`)\n .join('\\n ');\n}\n\nfunction renderProperties(\n properties: ReadonlyArray<NativeModulePropertyShape>,\n aliases: AliasMap,\n tuple: boolean,\n options: CppCodegenOptions,\n): string {\n // TODO: generate code for constants\n return properties\n .filter(prop => prop.name !== 'getConstants')\n .map((prop, index) => {\n // TODO: prop.optional === true\n // TODO: prop.typeAnnotation.type === 'NullableTypeAnnotation'\n const propAliasName = prop.name;\n const funcType =\n prop.typeAnnotation.type === 'NullableTypeAnnotation'\n ? prop.typeAnnotation.typeAnnotation\n : prop.typeAnnotation;\n\n const traversedArgs = translateSpecArgs(\n funcType.params,\n aliases,\n propAliasName,\n options,\n );\n\n const translatedReturnParam = translateSpecReturnType(\n funcType.returnTypeAnnotation,\n aliases,\n propAliasName,\n options,\n );\n\n if (funcType.returnTypeAnnotation.type === 'PromiseTypeAnnotation') {\n if (funcType.returnTypeAnnotation.elementType) {\n traversedArgs.push(\n `Promise<${translateSpecReturnType(\n funcType.returnTypeAnnotation.elementType,\n aliases,\n propAliasName,\n options,\n )}>`,\n );\n } else {\n traversedArgs.push('Promise<::React::JSValue>');\n }\n }\n\n if (tuple) {\n return ` ${\n isMethodSync(funcType) ? 'Sync' : ''\n }Method<${translatedReturnParam}(${traversedArgs.join(\n ', ',\n )}) noexcept>{${index}, L\"${prop.name}\"},`;\n } else {\n return ` REACT_SHOW_METHOD_SPEC_ERRORS(\n ${index},\n \"${prop.name}\",\n ${translatePossibleMethodSignatures(\n prop,\n funcType,\n aliases,\n propAliasName,\n options,\n )});`;\n }\n })\n .join('\\n');\n}\n\nexport function generateValidateMethods(\n nativeModule: NativeModuleSchema,\n aliases: AliasMap,\n options: CppCodegenOptions,\n): [string, string] {\n const properties = nativeModule.spec.properties;\n const traversedProperties = renderProperties(\n properties,\n aliases,\n false,\n options,\n );\n const traversedPropertyTuples = renderProperties(\n properties,\n aliases,\n true,\n options,\n );\n return [traversedPropertyTuples, traversedProperties];\n}\n"]}
1
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Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {\n NativeModuleFunctionTypeAnnotation,\n NativeModulePropertyShape,\n NativeModuleSchema,\n} from '@react-native/codegen/lib/CodegenSchema';\nimport {AliasMap} from './AliasManaging';\nimport type {CppCodegenOptions} from './ObjectTypes';\nimport {translateArgs, translateSpecArgs} from './ParamTypes';\nimport {translateImplReturnType, translateSpecReturnType} from './ReturnTypes';\n\nfunction isMethodSync(funcType: NativeModuleFunctionTypeAnnotation) {\n return (\n funcType.returnTypeAnnotation.type !== 'VoidTypeAnnotation' &&\n funcType.returnTypeAnnotation.type !== 'PromiseTypeAnnotation'\n );\n}\n\nfunction getPossibleMethodSignatures(\n prop: NativeModulePropertyShape,\n funcType: NativeModuleFunctionTypeAnnotation,\n aliases: AliasMap,\n baseAliasName: string,\n options: CppCodegenOptions,\n): string[] {\n const args = translateArgs(funcType.params, aliases, baseAliasName, options);\n if (funcType.returnTypeAnnotation.type === 'PromiseTypeAnnotation') {\n if (funcType.returnTypeAnnotation.elementType) {\n args.push(\n `::React::ReactPromise<${translateImplReturnType(\n funcType.returnTypeAnnotation.elementType,\n aliases,\n baseAliasName,\n options,\n )}> &&result`,\n );\n } else {\n args.push('::React::ReactPromise<::React::JSValue> &&result');\n }\n }\n\n // TODO: be much more exhaustive on the possible method signatures that can be used..\n const sig = `REACT_${isMethodSync(funcType) ? 'SYNC_' : ''}METHOD(${\n prop.name\n }) ${translateImplReturnType(\n funcType.returnTypeAnnotation,\n aliases,\n baseAliasName,\n options,\n )} ${prop.name}(${args.join(', ')}) noexcept { /* implementation */ }`;\n\n const staticsig = `REACT_${isMethodSync(funcType) ? 'SYNC_' : ''}METHOD(${\n prop.name\n }) static ${translateImplReturnType(\n funcType.returnTypeAnnotation,\n aliases,\n baseAliasName,\n options,\n )} ${prop.name}(${args.join(', ')}) noexcept { /* implementation */ }`;\n\n return [sig, staticsig];\n}\n\nfunction translatePossibleMethodSignatures(\n prop: NativeModulePropertyShape,\n funcType: NativeModuleFunctionTypeAnnotation,\n aliases: AliasMap,\n baseAliasName: string,\n options: CppCodegenOptions,\n): string {\n return getPossibleMethodSignatures(\n prop,\n funcType,\n aliases,\n baseAliasName,\n options,\n )\n .map(sig => `\" ${sig}\\\\n\"`)\n .join('\\n ');\n}\n\nfunction renderProperties(\n methods: ReadonlyArray<NativeModulePropertyShape>,\n aliases: AliasMap,\n tuple: boolean,\n options: CppCodegenOptions,\n): string {\n // TODO: generate code for constants\n return methods\n .filter(prop => prop.name !== 'getConstants')\n .map((prop, index) => {\n // TODO: prop.optional === true\n // TODO: prop.typeAnnotation.type === 'NullableTypeAnnotation'\n const propAliasName = prop.name;\n const funcType =\n prop.typeAnnotation.type === 'NullableTypeAnnotation'\n ? prop.typeAnnotation.typeAnnotation\n : prop.typeAnnotation;\n\n const traversedArgs = translateSpecArgs(\n funcType.params,\n aliases,\n propAliasName,\n options,\n );\n\n const translatedReturnParam = translateSpecReturnType(\n funcType.returnTypeAnnotation,\n aliases,\n propAliasName,\n options,\n );\n\n if (funcType.returnTypeAnnotation.type === 'PromiseTypeAnnotation') {\n if (funcType.returnTypeAnnotation.elementType) {\n traversedArgs.push(\n `Promise<${translateSpecReturnType(\n funcType.returnTypeAnnotation.elementType,\n aliases,\n propAliasName,\n options,\n )}>`,\n );\n } else {\n traversedArgs.push('Promise<::React::JSValue>');\n }\n }\n\n if (tuple) {\n return ` ${\n isMethodSync(funcType) ? 'Sync' : ''\n }Method<${translatedReturnParam}(${traversedArgs.join(\n ', ',\n )}) noexcept>{${index}, L\"${prop.name}\"},`;\n } else {\n return ` REACT_SHOW_METHOD_SPEC_ERRORS(\n ${index},\n \"${prop.name}\",\n ${translatePossibleMethodSignatures(\n prop,\n funcType,\n aliases,\n propAliasName,\n options,\n )});`;\n }\n })\n .join('\\n');\n}\n\nexport function generateValidateMethods(\n nativeModule: NativeModuleSchema,\n aliases: AliasMap,\n options: CppCodegenOptions,\n): [string, string] {\n const methods = nativeModule.spec.methods;\n const traversedProperties = renderProperties(\n methods,\n aliases,\n false,\n options,\n );\n const traversedPropertyTuples = renderProperties(\n methods,\n aliases,\n true,\n options,\n );\n return [traversedPropertyTuples, traversedProperties];\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-windows/codegen",
3
- "version": "0.0.0-canary.97",
3
+ "version": "0.0.0-canary.99",
4
4
  "description": "Generators for react-native-codegen targeting react-native-windows",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "repository": {
@@ -22,7 +22,7 @@
22
22
  "react-native-windows-codegen": "./bin.js"
23
23
  },
24
24
  "dependencies": {
25
- "@react-native-windows/fs": "^0.0.0-canary.53",
25
+ "@react-native-windows/fs": "^0.0.0-canary.55",
26
26
  "chalk": "^4.1.0",
27
27
  "globby": "^11.1.0",
28
28
  "mustache": "^4.0.1",
@@ -30,9 +30,9 @@
30
30
  "yargs": "^16.2.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@rnw-scripts/eslint-config": "1.2.24",
33
+ "@rnw-scripts/eslint-config": "1.2.26",
34
34
  "@rnw-scripts/jest-unittest-config": "1.5.8",
35
- "@rnw-scripts/just-task": "2.3.41",
35
+ "@rnw-scripts/just-task": "2.3.43",
36
36
  "@rnw-scripts/ts-config": "2.0.5",
37
37
  "@types/chalk": "^2.2.0",
38
38
  "@types/jest": "^29.2.2",
package/src/Cli.ts CHANGED
@@ -91,7 +91,7 @@ const changesNecessary = runCodeGen(<CodeGenOptions>argv);
91
91
 
92
92
  if (argv.test && changesNecessary) {
93
93
  console.error(
94
- 'There is a change in the output of codegen. Rerun "react-native codegen-windows" to regenerate.',
94
+ 'There is a change in the output of codegen. Rerun "npx @react-native-community/cli codegen-windows" to regenerate.',
95
95
  );
96
96
  process.exit(2);
97
97
  }
@@ -147,7 +147,7 @@ ${type.properties
147
147
  function tryGetConstantType(
148
148
  nativeModule: NativeModuleSchema,
149
149
  ): NativeModuleObjectTypeAnnotation | undefined {
150
- const candidates = nativeModule.spec.properties.filter(
150
+ const candidates = nativeModule.spec.methods.filter(
151
151
  prop => prop.name === 'getConstants',
152
152
  );
153
153
  if (candidates.length === 0) {
@@ -224,7 +224,7 @@ export function generateTypeScript(
224
224
  ? ''
225
225
  : ` getConstants(): ${translateType(constantType)}`;
226
226
 
227
- const methods = nativeModule.spec.properties.filter(
227
+ const methods = nativeModule.spec.methods.filter(
228
228
  prop => prop.name !== 'getConstants',
229
229
  );
230
230
  const membersCode = methods.map(translateMethod).join('');
@@ -104,6 +104,7 @@ export function translateFieldOrReturnType(
104
104
  callerName,
105
105
  options,
106
106
  )}>`;
107
+ case 'FunctionTypeAnnotation':
107
108
  case 'MixedTypeAnnotation':
108
109
  return '';
109
110
  case 'EnumDeclaration':
@@ -13,7 +13,7 @@ export function generateValidateConstants(
13
13
  nativeModule: NativeModuleSchema,
14
14
  aliases: AliasMap,
15
15
  ): [string, string] | undefined {
16
- const candidates = nativeModule.spec.properties.filter(
16
+ const candidates = nativeModule.spec.methods.filter(
17
17
  prop => prop.name === 'getConstants',
18
18
  );
19
19
  if (candidates.length === 0) {
@@ -87,13 +87,13 @@ function translatePossibleMethodSignatures(
87
87
  }
88
88
 
89
89
  function renderProperties(
90
- properties: ReadonlyArray<NativeModulePropertyShape>,
90
+ methods: ReadonlyArray<NativeModulePropertyShape>,
91
91
  aliases: AliasMap,
92
92
  tuple: boolean,
93
93
  options: CppCodegenOptions,
94
94
  ): string {
95
95
  // TODO: generate code for constants
96
- return properties
96
+ return methods
97
97
  .filter(prop => prop.name !== 'getConstants')
98
98
  .map((prop, index) => {
99
99
  // TODO: prop.optional === true
@@ -160,15 +160,15 @@ export function generateValidateMethods(
160
160
  aliases: AliasMap,
161
161
  options: CppCodegenOptions,
162
162
  ): [string, string] {
163
- const properties = nativeModule.spec.properties;
163
+ const methods = nativeModule.spec.methods;
164
164
  const traversedProperties = renderProperties(
165
- properties,
165
+ methods,
166
166
  aliases,
167
167
  false,
168
168
  options,
169
169
  );
170
170
  const traversedPropertyTuples = renderProperties(
171
- properties,
171
+ methods,
172
172
  aliases,
173
173
  true,
174
174
  options,