@react-native-windows/codegen 0.73.0 → 0.74.0-preview.1
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 +100 -10
- package/lib-commonjs/Cli.d.ts +7 -7
- package/lib-commonjs/Cli.js +91 -91
- package/lib-commonjs/generators/AliasGen.d.ts +12 -12
- package/lib-commonjs/generators/AliasGen.js +76 -76
- package/lib-commonjs/generators/AliasManaging.d.ts +15 -15
- package/lib-commonjs/generators/AliasManaging.js +48 -48
- package/lib-commonjs/generators/GenerateNM2.d.ts +15 -15
- package/lib-commonjs/generators/GenerateNM2.js +80 -80
- package/lib-commonjs/generators/GenerateTypeScript.d.ts +11 -11
- package/lib-commonjs/generators/GenerateTypeScript.js +145 -145
- package/lib-commonjs/generators/ObjectTypes.d.ts +13 -13
- package/lib-commonjs/generators/ObjectTypes.js +74 -74
- package/lib-commonjs/generators/ParamTypes.d.ts +12 -12
- package/lib-commonjs/generators/ParamTypes.js +136 -136
- package/lib-commonjs/generators/ReturnTypes.d.ts +10 -10
- package/lib-commonjs/generators/ReturnTypes.js +28 -28
- package/lib-commonjs/generators/ValidateConstants.d.ts +8 -8
- package/lib-commonjs/generators/ValidateConstants.js +33 -33
- package/lib-commonjs/generators/ValidateMethods.d.ts +9 -9
- package/lib-commonjs/generators/ValidateMethods.js +71 -71
- package/lib-commonjs/index.d.ts +37 -37
- package/lib-commonjs/index.js +223 -223
- package/package.json +11 -11
|
@@ -1,75 +1,75 @@
|
|
|
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 getPossibleMethodSignatures(prop, funcType, aliases, baseAliasName, options) {
|
|
16
|
-
const args = (0, ParamTypes_1.translateArgs)(funcType.params, aliases, baseAliasName, options);
|
|
17
|
-
if (funcType.returnTypeAnnotation.type === 'PromiseTypeAnnotation') {
|
|
18
|
-
if (funcType.returnTypeAnnotation.elementType) {
|
|
19
|
-
args.push(`::React::ReactPromise<${(0, ReturnTypes_1.translateImplReturnType)(funcType.returnTypeAnnotation.elementType, aliases, baseAliasName, options)}> &&result`);
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
args.push('::React::ReactPromise<::React::JSValue> &&result');
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
// TODO: be much more exhaustive on the possible method signatures that can be used..
|
|
26
|
-
const sig = `REACT_${isMethodSync(funcType) ? 'SYNC_' : ''}METHOD(${prop.name}) ${(0, ReturnTypes_1.translateImplReturnType)(funcType.returnTypeAnnotation, aliases, baseAliasName, options)} ${prop.name}(${args.join(', ')}) noexcept { /* implementation */ }`;
|
|
27
|
-
const staticsig = `REACT_${isMethodSync(funcType) ? 'SYNC_' : ''}METHOD(${prop.name}) static ${(0, ReturnTypes_1.translateImplReturnType)(funcType.returnTypeAnnotation, aliases, baseAliasName, options)} ${prop.name}(${args.join(', ')}) noexcept { /* implementation */ }`;
|
|
28
|
-
return [sig, staticsig];
|
|
29
|
-
}
|
|
30
|
-
function translatePossibleMethodSignatures(prop, funcType, aliases, baseAliasName, options) {
|
|
31
|
-
return getPossibleMethodSignatures(prop, funcType, aliases, baseAliasName, options)
|
|
32
|
-
.map(sig => `" ${sig}\\n"`)
|
|
33
|
-
.join('\n ');
|
|
34
|
-
}
|
|
35
|
-
function renderProperties(properties, aliases, tuple, options) {
|
|
36
|
-
// TODO: generate code for constants
|
|
37
|
-
return properties
|
|
38
|
-
.filter(prop => prop.name !== 'getConstants')
|
|
39
|
-
.map((prop, index) => {
|
|
40
|
-
// TODO: prop.optional === true
|
|
41
|
-
// TODO: prop.typeAnnotation.type === 'NullableTypeAnnotation'
|
|
42
|
-
const propAliasName = prop.name;
|
|
43
|
-
const funcType = prop.typeAnnotation.type === 'NullableTypeAnnotation'
|
|
44
|
-
? prop.typeAnnotation.typeAnnotation
|
|
45
|
-
: prop.typeAnnotation;
|
|
46
|
-
const traversedArgs = (0, ParamTypes_1.translateSpecArgs)(funcType.params, aliases, propAliasName, options);
|
|
47
|
-
const translatedReturnParam = (0, ReturnTypes_1.translateSpecReturnType)(funcType.returnTypeAnnotation, aliases, propAliasName, options);
|
|
48
|
-
if (funcType.returnTypeAnnotation.type === 'PromiseTypeAnnotation') {
|
|
49
|
-
if (funcType.returnTypeAnnotation.elementType) {
|
|
50
|
-
traversedArgs.push(`Promise<${(0, ReturnTypes_1.translateSpecReturnType)(funcType.returnTypeAnnotation.elementType, aliases, propAliasName, options)}>`);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
traversedArgs.push('Promise<::React::JSValue>');
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (tuple) {
|
|
57
|
-
return ` ${isMethodSync(funcType) ? 'Sync' : ''}Method<${translatedReturnParam}(${traversedArgs.join(', ')}) noexcept>{${index}, L"${prop.name}"},`;
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
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 getPossibleMethodSignatures(prop, funcType, aliases, baseAliasName, options) {
|
|
16
|
+
const args = (0, ParamTypes_1.translateArgs)(funcType.params, aliases, baseAliasName, options);
|
|
17
|
+
if (funcType.returnTypeAnnotation.type === 'PromiseTypeAnnotation') {
|
|
18
|
+
if (funcType.returnTypeAnnotation.elementType) {
|
|
19
|
+
args.push(`::React::ReactPromise<${(0, ReturnTypes_1.translateImplReturnType)(funcType.returnTypeAnnotation.elementType, aliases, baseAliasName, options)}> &&result`);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
args.push('::React::ReactPromise<::React::JSValue> &&result');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// TODO: be much more exhaustive on the possible method signatures that can be used..
|
|
26
|
+
const sig = `REACT_${isMethodSync(funcType) ? 'SYNC_' : ''}METHOD(${prop.name}) ${(0, ReturnTypes_1.translateImplReturnType)(funcType.returnTypeAnnotation, aliases, baseAliasName, options)} ${prop.name}(${args.join(', ')}) noexcept { /* implementation */ }`;
|
|
27
|
+
const staticsig = `REACT_${isMethodSync(funcType) ? 'SYNC_' : ''}METHOD(${prop.name}) static ${(0, ReturnTypes_1.translateImplReturnType)(funcType.returnTypeAnnotation, aliases, baseAliasName, options)} ${prop.name}(${args.join(', ')}) noexcept { /* implementation */ }`;
|
|
28
|
+
return [sig, staticsig];
|
|
29
|
+
}
|
|
30
|
+
function translatePossibleMethodSignatures(prop, funcType, aliases, baseAliasName, options) {
|
|
31
|
+
return getPossibleMethodSignatures(prop, funcType, aliases, baseAliasName, options)
|
|
32
|
+
.map(sig => `" ${sig}\\n"`)
|
|
33
|
+
.join('\n ');
|
|
34
|
+
}
|
|
35
|
+
function renderProperties(properties, aliases, tuple, options) {
|
|
36
|
+
// TODO: generate code for constants
|
|
37
|
+
return properties
|
|
38
|
+
.filter(prop => prop.name !== 'getConstants')
|
|
39
|
+
.map((prop, index) => {
|
|
40
|
+
// TODO: prop.optional === true
|
|
41
|
+
// TODO: prop.typeAnnotation.type === 'NullableTypeAnnotation'
|
|
42
|
+
const propAliasName = prop.name;
|
|
43
|
+
const funcType = prop.typeAnnotation.type === 'NullableTypeAnnotation'
|
|
44
|
+
? prop.typeAnnotation.typeAnnotation
|
|
45
|
+
: prop.typeAnnotation;
|
|
46
|
+
const traversedArgs = (0, ParamTypes_1.translateSpecArgs)(funcType.params, aliases, propAliasName, options);
|
|
47
|
+
const translatedReturnParam = (0, ReturnTypes_1.translateSpecReturnType)(funcType.returnTypeAnnotation, aliases, propAliasName, options);
|
|
48
|
+
if (funcType.returnTypeAnnotation.type === 'PromiseTypeAnnotation') {
|
|
49
|
+
if (funcType.returnTypeAnnotation.elementType) {
|
|
50
|
+
traversedArgs.push(`Promise<${(0, ReturnTypes_1.translateSpecReturnType)(funcType.returnTypeAnnotation.elementType, aliases, propAliasName, options)}>`);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
traversedArgs.push('Promise<::React::JSValue>');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (tuple) {
|
|
57
|
+
return ` ${isMethodSync(funcType) ? 'Sync' : ''}Method<${translatedReturnParam}(${traversedArgs.join(', ')}) noexcept>{${index}, L"${prop.name}"},`;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
60
|
return ` REACT_SHOW_METHOD_SPEC_ERRORS(
|
|
61
61
|
${index},
|
|
62
62
|
"${prop.name}",
|
|
63
|
-
${translatePossibleMethodSignatures(prop, funcType, aliases, propAliasName, options)});`;
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
.join('\n');
|
|
67
|
-
}
|
|
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);
|
|
72
|
-
return [traversedPropertyTuples, traversedProperties];
|
|
73
|
-
}
|
|
74
|
-
exports.generateValidateMethods = generateValidateMethods;
|
|
63
|
+
${translatePossibleMethodSignatures(prop, funcType, aliases, propAliasName, options)});`;
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
.join('\n');
|
|
67
|
+
}
|
|
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);
|
|
72
|
+
return [traversedPropertyTuples, traversedProperties];
|
|
73
|
+
}
|
|
74
|
+
exports.generateValidateMethods = generateValidateMethods;
|
|
75
75
|
//# sourceMappingURL=ValidateMethods.js.map
|
package/lib-commonjs/index.d.ts
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Microsoft Corporation.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*
|
|
5
|
-
* @format
|
|
6
|
-
*/
|
|
7
|
-
import type { CppStringTypes } from './generators/GenerateNM2';
|
|
8
|
-
import type { SchemaType } from '@react-native/codegen/lib/CodegenSchema';
|
|
9
|
-
export type { CppStringTypes } from './generators/GenerateNM2';
|
|
10
|
-
export interface SharedOptions {
|
|
11
|
-
libraryName: string;
|
|
12
|
-
methodOnly: boolean;
|
|
13
|
-
modulesCxx: boolean;
|
|
14
|
-
modulesTypeScriptTypes: boolean;
|
|
15
|
-
modulesWindows: boolean;
|
|
16
|
-
namespace: string;
|
|
17
|
-
outputDirectory: string;
|
|
18
|
-
cppStringType: CppStringTypes;
|
|
19
|
-
separateDataTypes: boolean;
|
|
20
|
-
}
|
|
21
|
-
interface Options extends SharedOptions {
|
|
22
|
-
moduleSpecName: string;
|
|
23
|
-
schema: SchemaType;
|
|
24
|
-
}
|
|
25
|
-
interface Config {
|
|
26
|
-
generators: any[];
|
|
27
|
-
test?: boolean;
|
|
28
|
-
}
|
|
29
|
-
export declare function parseFile(filename: string): SchemaType;
|
|
30
|
-
export declare function combineSchemas(files: string[]): SchemaType;
|
|
31
|
-
export declare function generate({ libraryName, methodOnly, modulesCxx, modulesTypeScriptTypes, modulesWindows, namespace, outputDirectory, cppStringType, separateDataTypes, moduleSpecName, schema, }: Options, { /*generators,*/ test }: Config): boolean;
|
|
32
|
-
export interface CodeGenOptions extends SharedOptions {
|
|
33
|
-
file?: string;
|
|
34
|
-
files?: string[];
|
|
35
|
-
test: boolean;
|
|
36
|
-
}
|
|
37
|
-
export declare function runCodeGen(options: CodeGenOptions): boolean;
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*
|
|
5
|
+
* @format
|
|
6
|
+
*/
|
|
7
|
+
import type { CppStringTypes } from './generators/GenerateNM2';
|
|
8
|
+
import type { SchemaType } from '@react-native/codegen/lib/CodegenSchema';
|
|
9
|
+
export type { CppStringTypes } from './generators/GenerateNM2';
|
|
10
|
+
export interface SharedOptions {
|
|
11
|
+
libraryName: string;
|
|
12
|
+
methodOnly: boolean;
|
|
13
|
+
modulesCxx: boolean;
|
|
14
|
+
modulesTypeScriptTypes: boolean;
|
|
15
|
+
modulesWindows: boolean;
|
|
16
|
+
namespace: string;
|
|
17
|
+
outputDirectory: string;
|
|
18
|
+
cppStringType: CppStringTypes;
|
|
19
|
+
separateDataTypes: boolean;
|
|
20
|
+
}
|
|
21
|
+
interface Options extends SharedOptions {
|
|
22
|
+
moduleSpecName: string;
|
|
23
|
+
schema: SchemaType;
|
|
24
|
+
}
|
|
25
|
+
interface Config {
|
|
26
|
+
generators: any[];
|
|
27
|
+
test?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export declare function parseFile(filename: string): SchemaType;
|
|
30
|
+
export declare function combineSchemas(files: string[]): SchemaType;
|
|
31
|
+
export declare function generate({ libraryName, methodOnly, modulesCxx, modulesTypeScriptTypes, modulesWindows, namespace, outputDirectory, cppStringType, separateDataTypes, moduleSpecName, schema, }: Options, { /*generators,*/ test }: Config): boolean;
|
|
32
|
+
export interface CodeGenOptions extends SharedOptions {
|
|
33
|
+
file?: string;
|
|
34
|
+
files?: string[];
|
|
35
|
+
test: boolean;
|
|
36
|
+
}
|
|
37
|
+
export declare function runCodeGen(options: CodeGenOptions): boolean;
|