@react-native-windows/codegen 0.0.0-canary.11 → 0.0.0-canary.110
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 +950 -4
- package/README.md +1 -1
- package/bin.js +0 -0
- package/lib-commonjs/Cli.d.ts +7 -0
- package/lib-commonjs/Cli.js +103 -0
- package/lib-commonjs/Cli.js.map +1 -0
- package/lib-commonjs/generators/AliasGen.d.ts +12 -0
- package/lib-commonjs/generators/AliasGen.js +115 -0
- package/lib-commonjs/generators/AliasGen.js.map +1 -0
- package/lib-commonjs/generators/AliasManaging.d.ts +15 -0
- package/lib-commonjs/generators/AliasManaging.js +49 -0
- package/lib-commonjs/generators/AliasManaging.js.map +1 -0
- package/lib-commonjs/generators/GenerateComponentWindows.d.ts +13 -0
- package/lib-commonjs/generators/GenerateComponentWindows.js +406 -0
- package/lib-commonjs/generators/GenerateComponentWindows.js.map +1 -0
- package/lib-commonjs/generators/GenerateNM2.d.ts +15 -0
- package/lib-commonjs/generators/GenerateNM2.js +144 -0
- package/lib-commonjs/generators/GenerateNM2.js.map +1 -0
- package/lib-commonjs/generators/GenerateTypeScript.d.ts +11 -0
- package/lib-commonjs/generators/GenerateTypeScript.js +166 -0
- package/lib-commonjs/generators/GenerateTypeScript.js.map +1 -0
- package/lib-commonjs/generators/ObjectTypes.d.ts +13 -0
- package/lib-commonjs/generators/ObjectTypes.js +78 -0
- package/lib-commonjs/generators/ObjectTypes.js.map +1 -0
- package/lib-commonjs/generators/ParamTypes.d.ts +13 -0
- package/lib-commonjs/generators/ParamTypes.js +181 -0
- package/lib-commonjs/generators/ParamTypes.js.map +1 -0
- package/lib-commonjs/generators/PropObjectTypes.d.ts +18 -0
- package/lib-commonjs/generators/PropObjectTypes.js +217 -0
- package/lib-commonjs/generators/PropObjectTypes.js.map +1 -0
- package/lib-commonjs/generators/ReturnTypes.d.ts +10 -0
- package/lib-commonjs/generators/ReturnTypes.js +29 -0
- package/lib-commonjs/generators/ReturnTypes.js.map +1 -0
- package/lib-commonjs/generators/ValidateConstants.d.ts +8 -0
- package/lib-commonjs/generators/ValidateConstants.js +38 -0
- package/lib-commonjs/generators/ValidateConstants.js.map +1 -0
- package/lib-commonjs/generators/ValidateMethods.d.ts +14 -0
- package/lib-commonjs/generators/ValidateMethods.js +112 -0
- package/lib-commonjs/generators/ValidateMethods.js.map +1 -0
- package/lib-commonjs/index.d.ts +39 -0
- package/lib-commonjs/index.js +227 -0
- package/lib-commonjs/index.js.map +1 -0
- package/package.json +41 -21
- package/src/Cli.ts +69 -232
- package/src/generators/AliasGen.ts +195 -0
- package/src/generators/AliasManaging.ts +75 -0
- package/src/generators/GenerateComponentWindows.ts +540 -0
- package/src/generators/GenerateNM2.ts +128 -132
- package/src/generators/GenerateTypeScript.ts +250 -0
- package/src/generators/ObjectTypes.ts +88 -37
- package/src/generators/ParamTypes.ts +324 -44
- package/src/generators/PropObjectTypes.ts +233 -0
- package/src/generators/ReturnTypes.ts +38 -41
- package/src/generators/ValidateConstants.ts +50 -0
- package/src/generators/ValidateMethods.ts +270 -0
- package/src/index.ts +415 -0
- package/.eslintrc.js +0 -4
- package/.vscode/launch.json +0 -23
- package/CHANGELOG.json +0 -658
- package/jest.config.js +0 -1
- package/tsconfig.json +0 -5
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.translateCommandParamType = exports.translateComponentEventType = exports.translateComponentPropsFieldType = void 0;
|
|
4
|
+
const AliasManaging_1 = require("./AliasManaging");
|
|
5
|
+
// eslint-disable-next-line complexity
|
|
6
|
+
function translateComponentPropsFieldType(type, aliases, baseAliasName, options) {
|
|
7
|
+
switch (type.type) {
|
|
8
|
+
case 'StringTypeAnnotation':
|
|
9
|
+
return { type: options.cppStringType, initializer: type.default ? `{${type.default}}` : '', alreadySupportsOptionalOrHasDefault: !!type.default };
|
|
10
|
+
case 'FloatTypeAnnotation':
|
|
11
|
+
return { type: 'float', initializer: type.default ? `{${type.default}}` : '{}', alreadySupportsOptionalOrHasDefault: !!type.default };
|
|
12
|
+
case 'DoubleTypeAnnotation':
|
|
13
|
+
return { type: 'double', initializer: type.default ? `{${type.default}}` : '{}', alreadySupportsOptionalOrHasDefault: !!type.default };
|
|
14
|
+
case 'Int32TypeAnnotation':
|
|
15
|
+
return { type: 'int32_t', initializer: type.default ? `{${type.default}}` : '{}', alreadySupportsOptionalOrHasDefault: !!type.default };
|
|
16
|
+
case 'BooleanTypeAnnotation':
|
|
17
|
+
return { type: 'bool', initializer: type.default ? `{${type.default}}` : '{}', alreadySupportsOptionalOrHasDefault: !!type.default };
|
|
18
|
+
case 'ArrayTypeAnnotation':
|
|
19
|
+
let arrayTemplateArg = '';
|
|
20
|
+
switch (type.elementType.type) {
|
|
21
|
+
case 'BooleanTypeAnnotation':
|
|
22
|
+
arrayTemplateArg = 'bool';
|
|
23
|
+
break;
|
|
24
|
+
case 'DoubleTypeAnnotation':
|
|
25
|
+
arrayTemplateArg = 'double';
|
|
26
|
+
break;
|
|
27
|
+
case 'FloatTypeAnnotation':
|
|
28
|
+
arrayTemplateArg = 'float';
|
|
29
|
+
break;
|
|
30
|
+
case 'Int32TypeAnnotation':
|
|
31
|
+
arrayTemplateArg = 'int32_t';
|
|
32
|
+
break;
|
|
33
|
+
case 'StringTypeAnnotation':
|
|
34
|
+
arrayTemplateArg = options.cppStringType;
|
|
35
|
+
break;
|
|
36
|
+
case 'ArrayTypeAnnotation':
|
|
37
|
+
const innerType = translateComponentPropsFieldType(type.elementType, aliases, baseAliasName, options);
|
|
38
|
+
arrayTemplateArg = `std::vector<${innerType.type}>`;
|
|
39
|
+
break;
|
|
40
|
+
case 'ObjectTypeAnnotation':
|
|
41
|
+
arrayTemplateArg = translateComponentPropsFieldType(type.elementType, aliases, baseAliasName, options).type;
|
|
42
|
+
break;
|
|
43
|
+
case 'ReservedPropTypeAnnotation':
|
|
44
|
+
switch (type.elementType.name) {
|
|
45
|
+
case 'ColorPrimitive':
|
|
46
|
+
arrayTemplateArg = 'winrt::Microsoft::ReactNative::Color';
|
|
47
|
+
break;
|
|
48
|
+
case 'DimensionPrimitive':
|
|
49
|
+
case 'EdgeInsetsPrimitive':
|
|
50
|
+
case 'ImageRequestPrimitive':
|
|
51
|
+
case 'ImageSourcePrimitive':
|
|
52
|
+
case 'PointPrimitive':
|
|
53
|
+
arrayTemplateArg = 'winrt::Microsoft::ReactNative::JSValue'; // TODO - better handling for these types than JSValue
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
throw new Error(`Unhandled ReservedPropTypeAnnotation type: ${type.elementType.name}`);
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
case 'StringEnumTypeAnnotation':
|
|
60
|
+
arrayTemplateArg = options.cppStringType; // TODO - better enum type handling than just passing a string
|
|
61
|
+
break;
|
|
62
|
+
default:
|
|
63
|
+
throw new Error(`Unhandled type: ${type.type}`);
|
|
64
|
+
}
|
|
65
|
+
return { type: `std::vector<${arrayTemplateArg}>`, initializer: '' };
|
|
66
|
+
case 'ReservedPropTypeAnnotation':
|
|
67
|
+
switch (type.name) {
|
|
68
|
+
case 'ColorPrimitive':
|
|
69
|
+
return { type: 'winrt::Microsoft::ReactNative::Color', initializer: '{nullptr}', alreadySupportsOptionalOrHasDefault: true };
|
|
70
|
+
case 'DimensionPrimitive':
|
|
71
|
+
case 'EdgeInsetsPrimitive':
|
|
72
|
+
case 'ImageRequestPrimitive':
|
|
73
|
+
case 'ImageSourcePrimitive':
|
|
74
|
+
case 'PointPrimitive':
|
|
75
|
+
return { type: 'winrt::Microsoft::ReactNative::JSValue', initializer: '{nullptr}', alreadySupportsOptionalOrHasDefault: true }; // TODO - better handling for these types than JSValue
|
|
76
|
+
default:
|
|
77
|
+
throw new Error(`Unhandled ReservedPropTypeAnnotation type: ${type.name}`);
|
|
78
|
+
}
|
|
79
|
+
case 'ObjectTypeAnnotation': {
|
|
80
|
+
return { type: (0, AliasManaging_1.getAnonymousAliasCppName)(aliases, baseAliasName, type), initializer: '' };
|
|
81
|
+
}
|
|
82
|
+
case 'MixedTypeAnnotation':
|
|
83
|
+
return { type: 'winrt::Microsoft::ReactNative::JSValue', initializer: '{nullptr}', alreadySupportsOptionalOrHasDefault: true };
|
|
84
|
+
case 'Int32EnumTypeAnnotation':
|
|
85
|
+
return { type: 'int32_t', initializer: '' }; // TODO - better enum type handling than just passing a string
|
|
86
|
+
case 'StringEnumTypeAnnotation':
|
|
87
|
+
return { type: options.cppStringType, initializer: '' }; // TODO - better enum type handling than just passing an int
|
|
88
|
+
default:
|
|
89
|
+
throw new Error(`Unhandled type: ${type.type}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.translateComponentPropsFieldType = translateComponentPropsFieldType;
|
|
93
|
+
function translateComponentEventType(type, aliases, baseAliasName, options) {
|
|
94
|
+
switch (type.type) {
|
|
95
|
+
case 'StringTypeAnnotation':
|
|
96
|
+
return { type: options.cppStringType, initializer: '' };
|
|
97
|
+
case 'FloatTypeAnnotation':
|
|
98
|
+
return { type: 'float', initializer: '{}' };
|
|
99
|
+
case 'DoubleTypeAnnotation':
|
|
100
|
+
return { type: 'double', initializer: '{}' };
|
|
101
|
+
case 'Int32TypeAnnotation':
|
|
102
|
+
return { type: 'int32_t', initializer: '{}' };
|
|
103
|
+
case 'BooleanTypeAnnotation':
|
|
104
|
+
return { type: 'bool', initializer: '{}' };
|
|
105
|
+
case 'ArrayTypeAnnotation':
|
|
106
|
+
{
|
|
107
|
+
let arrayTemplateArg = '';
|
|
108
|
+
switch (type.elementType.type) {
|
|
109
|
+
case 'BooleanTypeAnnotation':
|
|
110
|
+
arrayTemplateArg = 'bool';
|
|
111
|
+
break;
|
|
112
|
+
case 'DoubleTypeAnnotation':
|
|
113
|
+
arrayTemplateArg = 'double';
|
|
114
|
+
break;
|
|
115
|
+
case 'FloatTypeAnnotation':
|
|
116
|
+
arrayTemplateArg = 'float';
|
|
117
|
+
break;
|
|
118
|
+
case 'Int32TypeAnnotation':
|
|
119
|
+
arrayTemplateArg = 'int32_t';
|
|
120
|
+
break;
|
|
121
|
+
case 'StringTypeAnnotation':
|
|
122
|
+
arrayTemplateArg = options.cppStringType;
|
|
123
|
+
break;
|
|
124
|
+
case 'ArrayTypeAnnotation':
|
|
125
|
+
const innerType = translateComponentEventType(type.elementType, aliases, baseAliasName, options);
|
|
126
|
+
arrayTemplateArg = `std::vector<${innerType.type}>`;
|
|
127
|
+
break;
|
|
128
|
+
case 'MixedTypeAnnotation':
|
|
129
|
+
arrayTemplateArg = 'winrt::Microsoft::ReactNative::JSValue';
|
|
130
|
+
break;
|
|
131
|
+
case 'ObjectTypeAnnotation':
|
|
132
|
+
arrayTemplateArg = translateComponentEventType(type.elementType, aliases, baseAliasName, options).type;
|
|
133
|
+
break;
|
|
134
|
+
case 'StringEnumTypeAnnotation':
|
|
135
|
+
arrayTemplateArg = options.cppStringType; // TODO - better enum type handling than just passing a string
|
|
136
|
+
break;
|
|
137
|
+
default:
|
|
138
|
+
throw new Error(`Unhandled type: ${type.type}`);
|
|
139
|
+
}
|
|
140
|
+
return { type: `std::vector<${arrayTemplateArg}>`, initializer: '{}' };
|
|
141
|
+
}
|
|
142
|
+
case 'ObjectTypeAnnotation': {
|
|
143
|
+
return { type: (0, AliasManaging_1.getAnonymousAliasCppName)(aliases, baseAliasName, type), initializer: '' };
|
|
144
|
+
}
|
|
145
|
+
case 'MixedTypeAnnotation': {
|
|
146
|
+
return { type: 'winrt::Microsoft::ReactNative::JSValue', initializer: '{nullptr}', alreadySupportsOptionalOrHasDefault: true };
|
|
147
|
+
}
|
|
148
|
+
case 'StringEnumTypeAnnotation':
|
|
149
|
+
return { type: options.cppStringType, initializer: '' }; // TODO - better enum type handling than just passing a string
|
|
150
|
+
default:
|
|
151
|
+
throw new Error(`Unhandled type: ${type.type}`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.translateComponentEventType = translateComponentEventType;
|
|
155
|
+
function translateCommandParamType(type, aliases, baseAliasName, options) {
|
|
156
|
+
switch (type.type) {
|
|
157
|
+
case 'StringTypeAnnotation':
|
|
158
|
+
return { type: options.cppStringType, initializer: '' };
|
|
159
|
+
case 'FloatTypeAnnotation':
|
|
160
|
+
return { type: 'float', initializer: '{}' };
|
|
161
|
+
case 'DoubleTypeAnnotation':
|
|
162
|
+
return { type: 'double', initializer: '{}' };
|
|
163
|
+
case 'Int32TypeAnnotation':
|
|
164
|
+
return { type: 'int32_t', initializer: '{}' };
|
|
165
|
+
case 'BooleanTypeAnnotation':
|
|
166
|
+
return { type: 'bool', initializer: '{}' };
|
|
167
|
+
case 'ArrayTypeAnnotation':
|
|
168
|
+
{
|
|
169
|
+
let arrayTemplateArg = '';
|
|
170
|
+
switch (type.elementType.type) {
|
|
171
|
+
case 'BooleanTypeAnnotation':
|
|
172
|
+
arrayTemplateArg = 'bool';
|
|
173
|
+
break;
|
|
174
|
+
case 'DoubleTypeAnnotation':
|
|
175
|
+
arrayTemplateArg = 'double';
|
|
176
|
+
break;
|
|
177
|
+
case 'FloatTypeAnnotation':
|
|
178
|
+
arrayTemplateArg = 'float';
|
|
179
|
+
break;
|
|
180
|
+
case 'Int32TypeAnnotation':
|
|
181
|
+
arrayTemplateArg = 'int32_t';
|
|
182
|
+
break;
|
|
183
|
+
case 'StringTypeAnnotation':
|
|
184
|
+
arrayTemplateArg = options.cppStringType;
|
|
185
|
+
break;
|
|
186
|
+
case 'ArrayTypeAnnotation':
|
|
187
|
+
const innerType = translateCommandParamType(type.elementType, aliases, baseAliasName, options);
|
|
188
|
+
arrayTemplateArg = `std::vector<${innerType.type}>`;
|
|
189
|
+
break;
|
|
190
|
+
case 'ReservedPropTypeAnnotation':
|
|
191
|
+
arrayTemplateArg = 'winrt::Microsoft::ReactNative::JSValue';
|
|
192
|
+
break;
|
|
193
|
+
case 'ObjectTypeAnnotation':
|
|
194
|
+
arrayTemplateArg = 'winrt::Microsoft::ReactNative::JSValueObject'; // TODO - better typing
|
|
195
|
+
break;
|
|
196
|
+
case 'StringEnumTypeAnnotation':
|
|
197
|
+
arrayTemplateArg = options.cppStringType; // TODO - better enum type handling than just passing a string
|
|
198
|
+
break;
|
|
199
|
+
case 'GenericTypeAnnotation': // TODO verify schema - Getting this type when running codegen on all the built in types
|
|
200
|
+
arrayTemplateArg = 'winrt::Microsoft::ReactNative::JSValue';
|
|
201
|
+
break;
|
|
202
|
+
default:
|
|
203
|
+
throw new Error(`Unhandled type: ${type.elementType.type} - ${JSON.stringify(type.elementType, null, 2)}`);
|
|
204
|
+
}
|
|
205
|
+
return { type: `std::vector<${arrayTemplateArg}>`, initializer: '{}' };
|
|
206
|
+
}
|
|
207
|
+
case 'ReservedTypeAnnotation':
|
|
208
|
+
if (type.name !== 'RootTag') {
|
|
209
|
+
throw new Error(`Unhandled ReservedTypeAnnotation: ${type.name}`);
|
|
210
|
+
}
|
|
211
|
+
return { type: 'bool', initializer: '{-1}' };
|
|
212
|
+
default:
|
|
213
|
+
throw new Error(`Unhandled type: ${type.type}`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
exports.translateCommandParamType = translateCommandParamType;
|
|
217
|
+
//# sourceMappingURL=PropObjectTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PropObjectTypes.js","sourceRoot":"","sources":["../../src/generators/PropObjectTypes.ts"],"names":[],"mappings":";;;AAEA,mDAGyB;AAGzB,sCAAsC;AACtC,SAAgB,gCAAgC,CAAC,IAAwB,EACvE,OAA2D,EAC3D,aAAqB,EACrB,OAA0B;IAC1B,QAAQ,IAAI,CAAC,IAAI,EAAE;QACjB,KAAK,sBAAsB;YACzB,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,aAAa,EAAE,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,mCA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AK,0BAA0B;wBAC7B,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,8DAA8D;wBACxG,MAAM;oBACR,KAAK,uBAA8B,EAAE,wFAAwF;wBAC3H,gBAAgB,GAAG,wCAAwC,CAAC;wBAC5D,MAAM;oBACR;wBACE,MAAM,IAAI,KAAK,CAAC,mBAAoB,IAAI,CAAC,WAAmB,CAAC,IAAI,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;iBACvH;gBAED,OAAO,EAAE,IAAI,EAAE,eAAe,gBAAgB,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;aACxE;QACH,KAAK,wBAAwB;YAC3B,IAAK,IAAI,CAAC,IAAY,KAAK,SAAS,EAAE;gBACpC,MAAM,IAAI,KAAK,CAAC,qCAAqC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;aAClE;YACD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;QAC/C;YACE,MAAM,IAAI,KAAK,CAAC,mBAAoB,IAAY,CAAC,IAAI,EAAE,CAAC,CAAC;KAC5D;AACH,CAAC;AAhED,8DAgEC","sourcesContent":["import type { PropTypeAnnotation, ObjectTypeAnnotation, EventTypeAnnotation, CommandParamTypeAnnotation } from '@react-native/codegen/lib/CodegenSchema';\nimport type { CppCodegenOptions } from './ObjectTypes';\nimport {\n AliasMap,\n getAnonymousAliasCppName,\n} from './AliasManaging';\n\n\n// eslint-disable-next-line complexity\nexport function translateComponentPropsFieldType(type: PropTypeAnnotation,\n aliases: AliasMap<ObjectTypeAnnotation<PropTypeAnnotation>>,\n baseAliasName: string,\n options: CppCodegenOptions): { type: string, initializer: string, alreadySupportsOptionalOrHasDefault?: boolean } {\n switch (type.type) {\n case 'StringTypeAnnotation':\n return { type: options.cppStringType, initializer: type.default ? `{${type.default}}` : '', alreadySupportsOptionalOrHasDefault: !!type.default };\n case 'FloatTypeAnnotation':\n return { type: 'float', initializer: type.default ? `{${type.default}}` : '{}', alreadySupportsOptionalOrHasDefault: !!type.default };\n case 'DoubleTypeAnnotation':\n return { type: 'double', initializer: type.default ? `{${type.default}}` : '{}', alreadySupportsOptionalOrHasDefault: !!type.default };\n case 'Int32TypeAnnotation':\n return { type: 'int32_t', initializer: type.default ? `{${type.default}}` : '{}', alreadySupportsOptionalOrHasDefault: !!type.default };\n case 'BooleanTypeAnnotation':\n return { type: 'bool', initializer: type.default ? `{${type.default}}` : '{}', alreadySupportsOptionalOrHasDefault: !!type.default };\n case 'ArrayTypeAnnotation':\n\n let arrayTemplateArg = '';\n switch (type.elementType.type) {\n case 'BooleanTypeAnnotation':\n arrayTemplateArg = 'bool';\n break;\n case 'DoubleTypeAnnotation':\n arrayTemplateArg = 'double';\n break;\n case 'FloatTypeAnnotation':\n arrayTemplateArg = 'float';\n break;\n case 'Int32TypeAnnotation':\n arrayTemplateArg = 'int32_t';\n break;\n case 'StringTypeAnnotation':\n arrayTemplateArg = options.cppStringType;\n break;\n case 'ArrayTypeAnnotation':\n const innerType = translateComponentPropsFieldType(type.elementType, aliases, baseAliasName, options);\n arrayTemplateArg = `std::vector<${innerType.type}>`;\n break;\n case 'ObjectTypeAnnotation':\n arrayTemplateArg = translateComponentPropsFieldType(type.elementType, aliases, baseAliasName, options).type;\n break;\n case 'ReservedPropTypeAnnotation':\n switch (type.elementType.name) {\n case 'ColorPrimitive':\n arrayTemplateArg = 'winrt::Microsoft::ReactNative::Color';\n break;\n case 'DimensionPrimitive':\n case 'EdgeInsetsPrimitive':\n case 'ImageRequestPrimitive':\n case 'ImageSourcePrimitive':\n case 'PointPrimitive':\n arrayTemplateArg = 'winrt::Microsoft::ReactNative::JSValue'; // TODO - better handling for these types than JSValue\n break;\n default:\n throw new Error(`Unhandled ReservedPropTypeAnnotation type: ${type.elementType.name}`);\n }\n break;\n case 'StringEnumTypeAnnotation':\n arrayTemplateArg = options.cppStringType; // TODO - better enum type handling than just passing a string\n break;\n default:\n throw new Error(`Unhandled type: ${type.type}`);\n }\n\n return { type: `std::vector<${arrayTemplateArg}>`, initializer: '' };\n case 'ReservedPropTypeAnnotation':\n switch (type.name) {\n case 'ColorPrimitive':\n return { type: 'winrt::Microsoft::ReactNative::Color', initializer: '{nullptr}', alreadySupportsOptionalOrHasDefault: true };\n case 'DimensionPrimitive':\n case 'EdgeInsetsPrimitive':\n case 'ImageRequestPrimitive':\n case 'ImageSourcePrimitive':\n case 'PointPrimitive':\n return { type: 'winrt::Microsoft::ReactNative::JSValue', initializer: '{nullptr}', alreadySupportsOptionalOrHasDefault: true }; // TODO - better handling for these types than JSValue\n default:\n throw new Error(`Unhandled ReservedPropTypeAnnotation type: ${type.name}`);\n }\n case 'ObjectTypeAnnotation': {\n return { type: getAnonymousAliasCppName<ObjectTypeAnnotation<PropTypeAnnotation>>(aliases, baseAliasName, type), initializer: '' };\n }\n case 'MixedTypeAnnotation':\n return { type: 'winrt::Microsoft::ReactNative::JSValue', initializer: '{nullptr}', alreadySupportsOptionalOrHasDefault: true };\n case 'Int32EnumTypeAnnotation':\n return { type: 'int32_t', initializer: '' }; // TODO - better enum type handling than just passing a string\n case 'StringEnumTypeAnnotation':\n return { type: options.cppStringType, initializer: '' }; // TODO - better enum type handling than just passing an int\n default:\n throw new Error(`Unhandled type: ${(type as any).type}`);\n }\n}\n\nexport function translateComponentEventType(type: EventTypeAnnotation,\n aliases: AliasMap<ObjectTypeAnnotation<EventTypeAnnotation>>,\n baseAliasName: string,\n options: CppCodegenOptions): { type: string, initializer: string, alreadySupportsOptionalOrHasDefault?: boolean } {\n switch (type.type) {\n case 'StringTypeAnnotation':\n return { type: options.cppStringType, initializer: '' };\n case 'FloatTypeAnnotation':\n return { type: 'float', initializer: '{}' };\n case 'DoubleTypeAnnotation':\n return { type: 'double', initializer: '{}' };\n case 'Int32TypeAnnotation':\n return { type: 'int32_t', initializer: '{}' };\n case 'BooleanTypeAnnotation':\n return { type: 'bool', initializer: '{}' };\n case 'ArrayTypeAnnotation':\n {\n let arrayTemplateArg = '';\n switch (type.elementType.type) {\n case 'BooleanTypeAnnotation':\n arrayTemplateArg = 'bool';\n break;\n case 'DoubleTypeAnnotation':\n arrayTemplateArg = 'double';\n break;\n case 'FloatTypeAnnotation':\n arrayTemplateArg = 'float';\n break;\n case 'Int32TypeAnnotation':\n arrayTemplateArg = 'int32_t';\n break;\n case 'StringTypeAnnotation':\n arrayTemplateArg = options.cppStringType;\n break;\n case 'ArrayTypeAnnotation':\n const innerType = translateComponentEventType(type.elementType, aliases, baseAliasName, options);\n arrayTemplateArg = `std::vector<${innerType.type}>`;\n break;\n case 'MixedTypeAnnotation':\n arrayTemplateArg = 'winrt::Microsoft::ReactNative::JSValue';\n break;\n case 'ObjectTypeAnnotation':\n arrayTemplateArg = translateComponentEventType(type.elementType, aliases, baseAliasName, options).type;\n break;\n case 'StringEnumTypeAnnotation':\n arrayTemplateArg = options.cppStringType; // TODO - better enum type handling than just passing a string\n break;\n default:\n throw new Error(`Unhandled type: ${type.type}`);\n }\n\n return { type: `std::vector<${arrayTemplateArg}>`, initializer: '{}' };\n }\n case 'ObjectTypeAnnotation': {\n return { type: getAnonymousAliasCppName<ObjectTypeAnnotation<EventTypeAnnotation>>(aliases, baseAliasName, type), initializer: '' };\n }\n case 'MixedTypeAnnotation': {\n return { type: 'winrt::Microsoft::ReactNative::JSValue', initializer: '{nullptr}', alreadySupportsOptionalOrHasDefault: true };\n }\n case 'StringEnumTypeAnnotation':\n return { type: options.cppStringType, initializer: '' }; // TODO - better enum type handling than just passing a string\n default:\n throw new Error(`Unhandled type: ${(type as any).type}`);\n }\n}\n\n\nexport function translateCommandParamType(type: CommandParamTypeAnnotation,\n aliases: AliasMap<ObjectTypeAnnotation<CommandParamTypeAnnotation>>,\n baseAliasName: string,\n options: CppCodegenOptions): { type: string, initializer: string, alreadySupportsOptionalOrHasDefault?: boolean } {\n switch (type.type) {\n case 'StringTypeAnnotation':\n return { type: options.cppStringType, initializer: '' };\n case 'FloatTypeAnnotation':\n return { type: 'float', initializer: '{}' };\n case 'DoubleTypeAnnotation':\n return { type: 'double', initializer: '{}' };\n case 'Int32TypeAnnotation':\n return { type: 'int32_t', initializer: '{}' };\n case 'BooleanTypeAnnotation':\n return { type: 'bool', initializer: '{}' };\n case 'ArrayTypeAnnotation':\n {\n let arrayTemplateArg = '';\n switch (type.elementType.type) {\n case 'BooleanTypeAnnotation':\n arrayTemplateArg = 'bool';\n break;\n case 'DoubleTypeAnnotation':\n arrayTemplateArg = 'double';\n break;\n case 'FloatTypeAnnotation':\n arrayTemplateArg = 'float';\n break;\n case 'Int32TypeAnnotation':\n arrayTemplateArg = 'int32_t';\n break;\n case 'StringTypeAnnotation':\n arrayTemplateArg = options.cppStringType;\n break;\n case 'ArrayTypeAnnotation':\n const innerType = translateCommandParamType(type.elementType, aliases, baseAliasName, options);\n arrayTemplateArg = `std::vector<${innerType.type}>`;\n break;\n case 'ReservedPropTypeAnnotation':\n arrayTemplateArg = 'winrt::Microsoft::ReactNative::JSValue';\n break;\n case 'ObjectTypeAnnotation':\n arrayTemplateArg = 'winrt::Microsoft::ReactNative::JSValueObject'; // TODO - better typing\n break;\n case 'StringEnumTypeAnnotation':\n arrayTemplateArg = options.cppStringType; // TODO - better enum type handling than just passing a string\n break;\n case 'GenericTypeAnnotation' as any: // TODO verify schema - Getting this type when running codegen on all the built in types\n arrayTemplateArg = 'winrt::Microsoft::ReactNative::JSValue';\n break;\n default:\n throw new Error(`Unhandled type: ${(type.elementType as any).type} - ${JSON.stringify(type.elementType, null, 2)}`);\n }\n\n return { type: `std::vector<${arrayTemplateArg}>`, initializer: '{}' };\n }\n case 'ReservedTypeAnnotation': \n if ((type.name as any) !== 'RootTag') {\n throw new Error(`Unhandled ReservedTypeAnnotation: ${type.name}`)\n }\n return { type: 'bool', initializer: '{-1}' };\n default:\n throw new Error(`Unhandled type: ${(type as any).type}`);\n }\n}"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
* @format
|
|
5
|
+
*/
|
|
6
|
+
import type { NativeModuleReturnTypeAnnotation, Nullable } from '@react-native/codegen/lib/CodegenSchema';
|
|
7
|
+
import { AliasMap } from './AliasManaging';
|
|
8
|
+
import { CppCodegenOptions } from './ObjectTypes';
|
|
9
|
+
export declare function translateSpecReturnType(type: Nullable<NativeModuleReturnTypeAnnotation>, aliases: AliasMap, baseAliasName: string, options: CppCodegenOptions): string;
|
|
10
|
+
export declare function translateImplReturnType(type: Nullable<NativeModuleReturnTypeAnnotation>, aliases: AliasMap, baseAliasName: string, options: CppCodegenOptions): string;
|
|
@@ -0,0 +1,29 @@
|
|
|
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 ObjectTypes_1 = require("./ObjectTypes");
|
|
10
|
+
function translateReturnType(type, aliases, baseAliasName, options) {
|
|
11
|
+
switch (type.type) {
|
|
12
|
+
case 'VoidTypeAnnotation':
|
|
13
|
+
case 'PromiseTypeAnnotation':
|
|
14
|
+
return 'void';
|
|
15
|
+
case 'NullableTypeAnnotation':
|
|
16
|
+
return `std::optional<${translateReturnType(type.typeAnnotation, aliases, baseAliasName, options)}>`;
|
|
17
|
+
default:
|
|
18
|
+
return (0, ObjectTypes_1.translateFieldOrReturnType)(type, aliases, baseAliasName, 'translateReturnType', options);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function translateSpecReturnType(type, aliases, baseAliasName, options) {
|
|
22
|
+
return translateReturnType(type, aliases, `${baseAliasName}_returnType`, options);
|
|
23
|
+
}
|
|
24
|
+
exports.translateSpecReturnType = translateSpecReturnType;
|
|
25
|
+
function translateImplReturnType(type, aliases, baseAliasName, options) {
|
|
26
|
+
return translateReturnType(type, aliases, `${baseAliasName}_returnType`, options);
|
|
27
|
+
}
|
|
28
|
+
exports.translateImplReturnType = translateImplReturnType;
|
|
29
|
+
//# sourceMappingURL=ReturnTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReturnTypes.js","sourceRoot":"","sources":["../../src/generators/ReturnTypes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAOb,+CAA4E;AAE5E,SAAS,mBAAmB,CAC1B,IAAgD,EAChD,OAAiB,EACjB,aAAqB,EACrB,OAA0B;IAE1B,QAAQ,IAAI,CAAC,IAAI,EAAE;QACjB,KAAK,oBAAoB,CAAC;QAC1B,KAAK,uBAAuB;YAC1B,OAAO,MAAM,CAAC;QAChB,KAAK,wBAAwB;YAC3B,OAAO,iBAAiB,mBAAmB,CACzC,IAAI,CAAC,cAAc,EACnB,OAAO,EACP,aAAa,EACb,OAAO,CACR,GAAG,CAAC;QACP;YACE,OAAO,IAAA,wCAA0B,EAC/B,IAAI,EACJ,OAAO,EACP,aAAa,EACb,qBAAqB,EACrB,OAAO,CACR,CAAC;KACL;AACH,CAAC;AAED,SAAgB,uBAAuB,CACrC,IAAgD,EAChD,OAAiB,EACjB,aAAqB,EACrB,OAA0B;IAE1B,OAAO,mBAAmB,CACxB,IAAI,EACJ,OAAO,EACP,GAAG,aAAa,aAAa,EAC7B,OAAO,CACR,CAAC;AACJ,CAAC;AAZD,0DAYC;AAED,SAAgB,uBAAuB,CACrC,IAAgD,EAChD,OAAiB,EACjB,aAAqB,EACrB,OAA0B;IAE1B,OAAO,mBAAmB,CACxB,IAAI,EACJ,OAAO,EACP,GAAG,aAAa,aAAa,EAC7B,OAAO,CACR,CAAC;AACJ,CAAC;AAZD,0DAYC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {\n NativeModuleReturnTypeAnnotation,\n Nullable,\n} from '@react-native/codegen/lib/CodegenSchema';\nimport {AliasMap} from './AliasManaging';\nimport {CppCodegenOptions, translateFieldOrReturnType} from './ObjectTypes';\n\nfunction translateReturnType(\n type: Nullable<NativeModuleReturnTypeAnnotation>,\n aliases: AliasMap,\n baseAliasName: string,\n options: CppCodegenOptions,\n): string {\n switch (type.type) {\n case 'VoidTypeAnnotation':\n case 'PromiseTypeAnnotation':\n return 'void';\n case 'NullableTypeAnnotation':\n return `std::optional<${translateReturnType(\n type.typeAnnotation,\n aliases,\n baseAliasName,\n options,\n )}>`;\n default:\n return translateFieldOrReturnType(\n type,\n aliases,\n baseAliasName,\n 'translateReturnType',\n options,\n );\n }\n}\n\nexport function translateSpecReturnType(\n type: Nullable<NativeModuleReturnTypeAnnotation>,\n aliases: AliasMap,\n baseAliasName: string,\n options: CppCodegenOptions,\n) {\n return translateReturnType(\n type,\n aliases,\n `${baseAliasName}_returnType`,\n options,\n );\n}\n\nexport function translateImplReturnType(\n type: Nullable<NativeModuleReturnTypeAnnotation>,\n aliases: AliasMap,\n baseAliasName: string,\n options: CppCodegenOptions,\n) {\n return translateReturnType(\n type,\n aliases,\n `${baseAliasName}_returnType`,\n options,\n );\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
* @format
|
|
5
|
+
*/
|
|
6
|
+
import type { NativeModuleSchema } from '@react-native/codegen/lib/CodegenSchema';
|
|
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.methods.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,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"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
* @format
|
|
5
|
+
*/
|
|
6
|
+
import type { NativeModuleSchema } from '@react-native/codegen/lib/CodegenSchema';
|
|
7
|
+
import { AliasMap } from './AliasManaging';
|
|
8
|
+
import type { CppCodegenOptions } from './ObjectTypes';
|
|
9
|
+
export declare function generateValidateMethods(nativeModule: NativeModuleSchema, aliases: AliasMap, options: CppCodegenOptions): {
|
|
10
|
+
traversedProperties: string;
|
|
11
|
+
traversedEventEmitters: string;
|
|
12
|
+
traversedPropertyTuples: string;
|
|
13
|
+
traversedEventEmitterTuples: string;
|
|
14
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
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
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
19
|
+
if (funcType.returnTypeAnnotation.elementType) {
|
|
20
|
+
args.push(`::React::ReactPromise<${(0, ReturnTypes_1.translateImplReturnType)(funcType.returnTypeAnnotation.elementType, aliases, baseAliasName, options)}> &&result`);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
args.push('::React::ReactPromise<::React::JSValue> &&result');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
// TODO: be much more exhaustive on the possible method signatures that can be used..
|
|
27
|
+
const sig = `REACT_${isMethodSync(funcType) ? 'SYNC_' : ''}METHOD(${prop.name}) ${(0, ReturnTypes_1.translateImplReturnType)(funcType.returnTypeAnnotation, aliases, baseAliasName, options)} ${prop.name}(${args.join(', ')}) noexcept { /* implementation */ }`;
|
|
28
|
+
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 */ }`;
|
|
29
|
+
return [sig, staticsig];
|
|
30
|
+
}
|
|
31
|
+
function translatePossibleMethodSignatures(prop, funcType, aliases, baseAliasName, options) {
|
|
32
|
+
return getPossibleMethodSignatures(prop, funcType, aliases, baseAliasName, options)
|
|
33
|
+
.map(sig => `" ${sig}\\n"`)
|
|
34
|
+
.join('\n ');
|
|
35
|
+
}
|
|
36
|
+
function renderProperties(methods, aliases, tuple, options) {
|
|
37
|
+
// TODO: generate code for constants
|
|
38
|
+
const properties = methods
|
|
39
|
+
.filter(prop => prop.name !== 'getConstants')
|
|
40
|
+
.map((prop, index) => {
|
|
41
|
+
// TODO: prop.optional === true
|
|
42
|
+
// TODO: prop.typeAnnotation.type === 'NullableTypeAnnotation'
|
|
43
|
+
const propAliasName = prop.name;
|
|
44
|
+
const funcType = prop.typeAnnotation.type === 'NullableTypeAnnotation'
|
|
45
|
+
? prop.typeAnnotation.typeAnnotation
|
|
46
|
+
: prop.typeAnnotation;
|
|
47
|
+
const traversedArgs = (0, ParamTypes_1.translateSpecArgs)(funcType.params, aliases, propAliasName, options);
|
|
48
|
+
const translatedReturnParam = (0, ReturnTypes_1.translateSpecReturnType)(funcType.returnTypeAnnotation, aliases, propAliasName, options);
|
|
49
|
+
if (funcType.returnTypeAnnotation.type === 'PromiseTypeAnnotation') {
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
51
|
+
if (funcType.returnTypeAnnotation.elementType) {
|
|
52
|
+
traversedArgs.push(`Promise<${(0, ReturnTypes_1.translateSpecReturnType)(funcType.returnTypeAnnotation.elementType, aliases, propAliasName, options)}>`);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
traversedArgs.push('Promise<::React::JSValue>');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (tuple) {
|
|
59
|
+
return ` ${isMethodSync(funcType) ? 'Sync' : ''}Method<${translatedReturnParam}(${traversedArgs.join(', ')}) noexcept>{${index}, L"${prop.name}"},`;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
return ` REACT_SHOW_METHOD_SPEC_ERRORS(
|
|
63
|
+
${index},
|
|
64
|
+
"${prop.name}",
|
|
65
|
+
${translatePossibleMethodSignatures(prop, funcType, aliases, propAliasName, options)});`;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return { code: properties.join('\n'), numberOfProperties: properties.length };
|
|
69
|
+
}
|
|
70
|
+
function getPossibleEventEmitterSignatures(eventEmitter, aliases, options) {
|
|
71
|
+
const traversedArgs = (0, ParamTypes_1.translateEventEmitterArgs)(eventEmitter.typeAnnotation.typeAnnotation, aliases, eventEmitter.name, options);
|
|
72
|
+
return [
|
|
73
|
+
`REACT_EVENT(${eventEmitter.name}) std::function<void(${traversedArgs})> ${eventEmitter.name};`,
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
function translatePossibleEventSignatures(eventEmitter, aliases, options) {
|
|
77
|
+
return getPossibleEventEmitterSignatures(eventEmitter, aliases, options)
|
|
78
|
+
.map(sig => `" ${sig}\\n"`)
|
|
79
|
+
.join('\n ');
|
|
80
|
+
}
|
|
81
|
+
function renderEventEmitters(eventEmitters, indexOffset, aliases, tuple, options) {
|
|
82
|
+
return eventEmitters
|
|
83
|
+
.map((eventEmitter, index) => {
|
|
84
|
+
const traversedArgs = (0, ParamTypes_1.translateEventEmitterArgs)(eventEmitter.typeAnnotation.typeAnnotation, aliases, eventEmitter.name, options);
|
|
85
|
+
if (tuple) {
|
|
86
|
+
return ` EventEmitter<void(${traversedArgs})>{${index + indexOffset}, L"${eventEmitter.name}"},`;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
return ` REACT_SHOW_EVENTEMITTER_SPEC_ERRORS(
|
|
90
|
+
${index + indexOffset},
|
|
91
|
+
"${eventEmitter.name}",
|
|
92
|
+
${translatePossibleEventSignatures(eventEmitter, aliases, options)});`;
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
.join('\n');
|
|
96
|
+
}
|
|
97
|
+
function generateValidateMethods(nativeModule, aliases, options) {
|
|
98
|
+
const methods = nativeModule.spec.methods;
|
|
99
|
+
const eventEmitters = nativeModule.spec.eventEmitters;
|
|
100
|
+
const traversedProperties = renderProperties(methods, aliases, false, options);
|
|
101
|
+
const traversedEventEmitters = renderEventEmitters(eventEmitters, traversedProperties.numberOfProperties, aliases, false, options);
|
|
102
|
+
const traversedPropertyTuples = renderProperties(methods, aliases, true, options);
|
|
103
|
+
const traversedEventEmitterTuples = renderEventEmitters(eventEmitters, traversedProperties.numberOfProperties, aliases, true, options);
|
|
104
|
+
return {
|
|
105
|
+
traversedPropertyTuples: traversedPropertyTuples.code,
|
|
106
|
+
traversedEventEmitterTuples,
|
|
107
|
+
traversedProperties: traversedProperties.code,
|
|
108
|
+
traversedEventEmitters,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
exports.generateValidateMethods = generateValidateMethods;
|
|
112
|
+
//# 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;;;AAUb,6CAIsB;AACtB,+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,2BAA2B,CAClC,IAA+B,EAC/B,QAA4C,EAC5C,OAAiB,EACjB,aAAqB,EACrB,OAA0B;IAE1B,MAAM,IAAI,GAAG,IAAA,0BAAa,EAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;IAC7E,IAAI,QAAQ,CAA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,OAAO,CACR,CAAC;QAEF,IAAI,KAAK,EAAE;YACT,OAAO,2BAA2B,aAAa,MAC7C,KAAK,GAAG,WACV,OAAO,YAAY,CAAC,IAAI,KAAK,CAAC;SAC/B;aAAM;YACL,OAAO;YACH,KAAK,GAAG,WAAW;aAClB,YAAY,CAAC,IAAI;YAClB,gCAAgC,CAChC,YAAY,EACZ,OAAO,EACP,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;IAO1B,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC;IAC1C,MAAM,aAAa,GAAG,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC;IACtD,MAAM,mBAAmB,GAAG,gBAAgB,CAC1C,OAAO,EACP,OAAO,EACP,KAAK,EACL,OAAO,CACR,CAAC;IACF,MAAM,sBAAsB,GAAG,mBAAmB,CAChD,aAAa,EACb,mBAAmB,CAAC,kBAAkB,EACtC,OAAO,EACP,KAAK,EACL,OAAO,CACR,CAAC;IACF,MAAM,uBAAuB,GAAG,gBAAgB,CAC9C,OAAO,EACP,OAAO,EACP,IAAI,EACJ,OAAO,CACR,CAAC;IACF,MAAM,2BAA2B,GAAG,mBAAmB,CACrD,aAAa,EACb,mBAAmB,CAAC,kBAAkB,EACtC,OAAO,EACP,IAAI,EACJ,OAAO,CACR,CAAC;IACF,OAAO;QACL,uBAAuB,EAAE,uBAAuB,CAAC,IAAI;QACrD,2BAA2B;QAC3B,mBAAmB,EAAE,mBAAmB,CAAC,IAAI;QAC7C,sBAAsB;KACvB,CAAC;AACJ,CAAC;AA5CD,0DA4CC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {\n NativeModuleEventEmitterShape,\n NativeModuleFunctionTypeAnnotation,\n NativeModulePropertyShape,\n NativeModuleSchema,\n} from '@react-native/codegen/lib/CodegenSchema';\nimport {AliasMap} from './AliasManaging';\nimport type {CppCodegenOptions} from './ObjectTypes';\nimport {\n translateArgs,\n translateSpecArgs,\n translateEventEmitterArgs,\n} 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 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\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): {code: string; numberOfProperties: number} {\n // TODO: generate code for constants\n const properties = 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 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\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\n return {code: properties.join('\\n'), numberOfProperties: properties.length};\n}\n\nfunction getPossibleEventEmitterSignatures(\n eventEmitter: NativeModuleEventEmitterShape,\n aliases: AliasMap,\n options: CppCodegenOptions,\n): string[] {\n const traversedArgs = translateEventEmitterArgs(\n eventEmitter.typeAnnotation.typeAnnotation,\n aliases,\n eventEmitter.name,\n options,\n );\n return [\n `REACT_EVENT(${eventEmitter.name}) std::function<void(${traversedArgs})> ${eventEmitter.name};`,\n ];\n}\n\nfunction translatePossibleEventSignatures(\n eventEmitter: NativeModuleEventEmitterShape,\n aliases: AliasMap,\n options: CppCodegenOptions,\n): string {\n return getPossibleEventEmitterSignatures(eventEmitter, aliases, options)\n .map(sig => `\" ${sig}\\\\n\"`)\n .join('\\n ');\n}\n\nfunction renderEventEmitters(\n eventEmitters: ReadonlyArray<NativeModuleEventEmitterShape>,\n indexOffset: number,\n aliases: AliasMap,\n tuple: boolean,\n options: CppCodegenOptions,\n): string {\n return eventEmitters\n .map((eventEmitter, index) => {\n const traversedArgs = translateEventEmitterArgs(\n eventEmitter.typeAnnotation.typeAnnotation,\n aliases,\n eventEmitter.name,\n options,\n );\n\n if (tuple) {\n return ` EventEmitter<void(${traversedArgs})>{${\n index + indexOffset\n }, L\"${eventEmitter.name}\"},`;\n } else {\n return ` REACT_SHOW_EVENTEMITTER_SPEC_ERRORS(\n ${index + indexOffset},\n \"${eventEmitter.name}\",\n ${translatePossibleEventSignatures(\n eventEmitter,\n aliases,\n options,\n )});`;\n }\n })\n .join('\\n');\n}\n\nexport function generateValidateMethods(\n nativeModule: NativeModuleSchema,\n aliases: AliasMap,\n options: CppCodegenOptions,\n): {\n traversedProperties: string;\n traversedEventEmitters: string;\n traversedPropertyTuples: string;\n traversedEventEmitterTuples: string;\n} {\n const methods = nativeModule.spec.methods;\n const eventEmitters = nativeModule.spec.eventEmitters;\n const traversedProperties = renderProperties(\n methods,\n aliases,\n false,\n options,\n );\n const traversedEventEmitters = renderEventEmitters(\n eventEmitters,\n traversedProperties.numberOfProperties,\n aliases,\n false,\n options,\n );\n const traversedPropertyTuples = renderProperties(\n methods,\n aliases,\n true,\n options,\n );\n const traversedEventEmitterTuples = renderEventEmitters(\n eventEmitters,\n traversedProperties.numberOfProperties,\n aliases,\n true,\n options,\n );\n return {\n traversedPropertyTuples: traversedPropertyTuples.code,\n traversedEventEmitterTuples,\n traversedProperties: traversedProperties.code,\n traversedEventEmitters,\n };\n}\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
componentsWindows: boolean;
|
|
17
|
+
internalComponents: boolean;
|
|
18
|
+
namespace: string;
|
|
19
|
+
outputDirectory: string;
|
|
20
|
+
cppStringType: CppStringTypes;
|
|
21
|
+
separateDataTypes: boolean;
|
|
22
|
+
}
|
|
23
|
+
interface Options extends SharedOptions {
|
|
24
|
+
moduleSpecName: string;
|
|
25
|
+
schema: SchemaType;
|
|
26
|
+
}
|
|
27
|
+
interface Config {
|
|
28
|
+
generators: any[];
|
|
29
|
+
test?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export declare function parseFile(filename: string): SchemaType;
|
|
32
|
+
export declare function combineSchemas(files: string[]): SchemaType;
|
|
33
|
+
export declare function generate({ libraryName, methodOnly, modulesCxx, modulesTypeScriptTypes, modulesWindows, internalComponents, componentsWindows, namespace, outputDirectory, cppStringType, separateDataTypes, moduleSpecName, schema, }: Options, { /*generators,*/ test }: Config): boolean;
|
|
34
|
+
export interface CodeGenOptions extends SharedOptions {
|
|
35
|
+
file?: string;
|
|
36
|
+
files?: string[];
|
|
37
|
+
test: boolean;
|
|
38
|
+
}
|
|
39
|
+
export declare function runCodeGen(options: CodeGenOptions): boolean;
|