@react-native/codegen 0.74.0-nightly-20240102-05ec058ac → 0.74.0-nightly-20240104-9ba3bc99e
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/lib/generators/TypeUtils/Cxx/index.js +17 -0
- package/lib/generators/TypeUtils/Cxx/index.js.flow +18 -0
- package/lib/generators/TypeUtils/Java/index.js +31 -0
- package/lib/generators/TypeUtils/Java/index.js.flow +27 -0
- package/lib/generators/TypeUtils/Objective-C/index.js +17 -0
- package/lib/generators/TypeUtils/Objective-C/index.js.flow +18 -0
- package/lib/generators/modules/GenerateModuleH.js +31 -32
- package/lib/generators/modules/GenerateModuleH.js.flow +20 -24
- package/lib/generators/modules/GenerateModuleJavaSpec.js +41 -54
- package/lib/generators/modules/GenerateModuleJavaSpec.js.flow +38 -44
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js +21 -19
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js.flow +16 -14
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js +21 -19
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js.flow +16 -14
- package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js +37 -39
- package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js.flow +32 -37
- package/package.json +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
* @oncall react_native
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
function wrapOptional(type, isRequired) {
|
|
13
|
+
return isRequired ? type : `std::optional<${type}>`;
|
|
14
|
+
}
|
|
15
|
+
module.exports = {
|
|
16
|
+
wrapOptional,
|
|
17
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
* @format
|
|
9
|
+
* @oncall react_native
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
function wrapOptional(type: string, isRequired: boolean): string {
|
|
13
|
+
return isRequired ? type : `std::optional<${type}>`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = {
|
|
17
|
+
wrapOptional,
|
|
18
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
* @oncall react_native
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const objectTypeForPrimitiveType = {
|
|
13
|
+
boolean: 'Boolean',
|
|
14
|
+
double: 'Double',
|
|
15
|
+
float: 'Float',
|
|
16
|
+
int: 'Integer',
|
|
17
|
+
};
|
|
18
|
+
function wrapOptional(type, isRequired) {
|
|
19
|
+
var _objectTypeForPrimiti;
|
|
20
|
+
return isRequired
|
|
21
|
+
? type
|
|
22
|
+
: `@Nullable ${
|
|
23
|
+
(_objectTypeForPrimiti = objectTypeForPrimitiveType[type]) !== null &&
|
|
24
|
+
_objectTypeForPrimiti !== void 0
|
|
25
|
+
? _objectTypeForPrimiti
|
|
26
|
+
: type
|
|
27
|
+
}`;
|
|
28
|
+
}
|
|
29
|
+
module.exports = {
|
|
30
|
+
wrapOptional,
|
|
31
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
* @format
|
|
9
|
+
* @oncall react_native
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const objectTypeForPrimitiveType = {
|
|
13
|
+
boolean: 'Boolean',
|
|
14
|
+
double: 'Double',
|
|
15
|
+
float: 'Float',
|
|
16
|
+
int: 'Integer',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function wrapOptional(type: string, isRequired: boolean): string {
|
|
20
|
+
return isRequired
|
|
21
|
+
? type
|
|
22
|
+
: `@Nullable ${objectTypeForPrimitiveType[type] ?? type}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = {
|
|
26
|
+
wrapOptional,
|
|
27
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
* @oncall react_native
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
function wrapOptional(type, isRequired) {
|
|
13
|
+
return isRequired ? type : `${type} _Nullable`;
|
|
14
|
+
}
|
|
15
|
+
module.exports = {
|
|
16
|
+
wrapOptional,
|
|
17
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
* @format
|
|
9
|
+
* @oncall react_native
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
function wrapOptional(type: string, isRequired: boolean): string {
|
|
13
|
+
return isRequired ? type : `${type} _Nullable`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = {
|
|
17
|
+
wrapOptional,
|
|
18
|
+
};
|
|
@@ -80,17 +80,19 @@ function _arrayWithHoles(arr) {
|
|
|
80
80
|
}
|
|
81
81
|
const _require = require('../../parsers/parsers-commons'),
|
|
82
82
|
unwrapNullable = _require.unwrapNullable;
|
|
83
|
-
const _require2 = require('../
|
|
84
|
-
|
|
85
|
-
toSafeCppString = _require2.toSafeCppString;
|
|
83
|
+
const _require2 = require('../TypeUtils/Cxx'),
|
|
84
|
+
wrapOptional = _require2.wrapOptional;
|
|
86
85
|
const _require3 = require('../Utils'),
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
86
|
+
getEnumName = _require3.getEnumName,
|
|
87
|
+
toSafeCppString = _require3.toSafeCppString;
|
|
88
|
+
const _require4 = require('../Utils'),
|
|
89
|
+
indent = _require4.indent;
|
|
90
|
+
const _require5 = require('./Utils'),
|
|
91
|
+
createAliasResolver = _require5.createAliasResolver,
|
|
92
|
+
getAreEnumMembersInteger = _require5.getAreEnumMembersInteger,
|
|
93
|
+
getModules = _require5.getModules,
|
|
94
|
+
isArrayRecursiveMember = _require5.isArrayRecursiveMember,
|
|
95
|
+
isDirectRecursiveMember = _require5.isDirectRecursiveMember;
|
|
94
96
|
const ModuleClassDeclarationTemplate = ({
|
|
95
97
|
hasteModuleName,
|
|
96
98
|
moduleProperties,
|
|
@@ -176,23 +178,20 @@ function translatePrimitiveJSTypeToCpp(
|
|
|
176
178
|
_unwrapNullable2 = _slicedToArray(_unwrapNullable, 2),
|
|
177
179
|
typeAnnotation = _unwrapNullable2[0],
|
|
178
180
|
nullable = _unwrapNullable2[1];
|
|
179
|
-
const isRequired = !optional && !nullable;
|
|
180
181
|
const isRecursiveType = isDirectRecursiveMember(
|
|
181
182
|
parentObjectAliasName,
|
|
182
183
|
nullableTypeAnnotation,
|
|
183
184
|
);
|
|
185
|
+
const isRequired = (!optional && !nullable) || isRecursiveType;
|
|
184
186
|
let realTypeAnnotation = typeAnnotation;
|
|
185
187
|
if (realTypeAnnotation.type === 'TypeAliasTypeAnnotation') {
|
|
186
188
|
realTypeAnnotation = resolveAlias(realTypeAnnotation.name);
|
|
187
189
|
}
|
|
188
|
-
function wrap(type) {
|
|
189
|
-
return isRequired || isRecursiveType ? type : `std::optional<${type}>`;
|
|
190
|
-
}
|
|
191
190
|
switch (realTypeAnnotation.type) {
|
|
192
191
|
case 'ReservedTypeAnnotation':
|
|
193
192
|
switch (realTypeAnnotation.name) {
|
|
194
193
|
case 'RootTag':
|
|
195
|
-
return
|
|
194
|
+
return wrapOptional('double', isRequired);
|
|
196
195
|
default:
|
|
197
196
|
realTypeAnnotation.name;
|
|
198
197
|
throw new Error(createErrorMessage(realTypeAnnotation.name));
|
|
@@ -200,49 +199,49 @@ function translatePrimitiveJSTypeToCpp(
|
|
|
200
199
|
case 'VoidTypeAnnotation':
|
|
201
200
|
return 'void';
|
|
202
201
|
case 'StringTypeAnnotation':
|
|
203
|
-
return
|
|
202
|
+
return wrapOptional('jsi::String', isRequired);
|
|
204
203
|
case 'NumberTypeAnnotation':
|
|
205
|
-
return
|
|
204
|
+
return wrapOptional('double', isRequired);
|
|
206
205
|
case 'DoubleTypeAnnotation':
|
|
207
|
-
return
|
|
206
|
+
return wrapOptional('double', isRequired);
|
|
208
207
|
case 'FloatTypeAnnotation':
|
|
209
|
-
return
|
|
208
|
+
return wrapOptional('double', isRequired);
|
|
210
209
|
case 'Int32TypeAnnotation':
|
|
211
|
-
return
|
|
210
|
+
return wrapOptional('int', isRequired);
|
|
212
211
|
case 'BooleanTypeAnnotation':
|
|
213
|
-
return
|
|
212
|
+
return wrapOptional('bool', isRequired);
|
|
214
213
|
case 'EnumDeclaration':
|
|
215
214
|
switch (realTypeAnnotation.memberType) {
|
|
216
215
|
case 'NumberTypeAnnotation':
|
|
217
|
-
return
|
|
216
|
+
return wrapOptional('jsi::Value', isRequired);
|
|
218
217
|
case 'StringTypeAnnotation':
|
|
219
|
-
return
|
|
218
|
+
return wrapOptional('jsi::String', isRequired);
|
|
220
219
|
default:
|
|
221
220
|
throw new Error(createErrorMessage(realTypeAnnotation.type));
|
|
222
221
|
}
|
|
223
222
|
case 'GenericObjectTypeAnnotation':
|
|
224
|
-
return
|
|
223
|
+
return wrapOptional('jsi::Object', isRequired);
|
|
225
224
|
case 'UnionTypeAnnotation':
|
|
226
225
|
switch (typeAnnotation.memberType) {
|
|
227
226
|
case 'NumberTypeAnnotation':
|
|
228
|
-
return
|
|
227
|
+
return wrapOptional('double', isRequired);
|
|
229
228
|
case 'ObjectTypeAnnotation':
|
|
230
|
-
return
|
|
229
|
+
return wrapOptional('jsi::Object', isRequired);
|
|
231
230
|
case 'StringTypeAnnotation':
|
|
232
|
-
return
|
|
231
|
+
return wrapOptional('jsi::String', isRequired);
|
|
233
232
|
default:
|
|
234
233
|
throw new Error(createErrorMessage(realTypeAnnotation.type));
|
|
235
234
|
}
|
|
236
235
|
case 'ObjectTypeAnnotation':
|
|
237
|
-
return
|
|
236
|
+
return wrapOptional('jsi::Object', isRequired);
|
|
238
237
|
case 'ArrayTypeAnnotation':
|
|
239
|
-
return
|
|
238
|
+
return wrapOptional('jsi::Array', isRequired);
|
|
240
239
|
case 'FunctionTypeAnnotation':
|
|
241
|
-
return
|
|
240
|
+
return wrapOptional('jsi::Function', isRequired);
|
|
242
241
|
case 'PromiseTypeAnnotation':
|
|
243
|
-
return
|
|
242
|
+
return wrapOptional('jsi::Value', isRequired);
|
|
244
243
|
case 'MixedTypeAnnotation':
|
|
245
|
-
return
|
|
244
|
+
return wrapOptional('jsi::Value', isRequired);
|
|
246
245
|
default:
|
|
247
246
|
realTypeAnnotation.type;
|
|
248
247
|
throw new Error(createErrorMessage(realTypeAnnotation.type));
|
|
@@ -27,6 +27,7 @@ import type {
|
|
|
27
27
|
import type {AliasResolver} from './Utils';
|
|
28
28
|
|
|
29
29
|
const {unwrapNullable} = require('../../parsers/parsers-commons');
|
|
30
|
+
const {wrapOptional} = require('../TypeUtils/Cxx');
|
|
30
31
|
const {getEnumName, toSafeCppString} = require('../Utils');
|
|
31
32
|
const {indent} = require('../Utils');
|
|
32
33
|
const {
|
|
@@ -139,26 +140,21 @@ function translatePrimitiveJSTypeToCpp(
|
|
|
139
140
|
const [typeAnnotation, nullable] = unwrapNullable<NativeModuleTypeAnnotation>(
|
|
140
141
|
nullableTypeAnnotation,
|
|
141
142
|
);
|
|
142
|
-
const isRequired = !optional && !nullable;
|
|
143
143
|
const isRecursiveType = isDirectRecursiveMember(
|
|
144
144
|
parentObjectAliasName,
|
|
145
145
|
nullableTypeAnnotation,
|
|
146
146
|
);
|
|
147
|
-
|
|
147
|
+
const isRequired = (!optional && !nullable) || isRecursiveType;
|
|
148
148
|
let realTypeAnnotation = typeAnnotation;
|
|
149
149
|
if (realTypeAnnotation.type === 'TypeAliasTypeAnnotation') {
|
|
150
150
|
realTypeAnnotation = resolveAlias(realTypeAnnotation.name);
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
function wrap(type: string) {
|
|
154
|
-
return isRequired || isRecursiveType ? type : `std::optional<${type}>`;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
153
|
switch (realTypeAnnotation.type) {
|
|
158
154
|
case 'ReservedTypeAnnotation':
|
|
159
155
|
switch (realTypeAnnotation.name) {
|
|
160
156
|
case 'RootTag':
|
|
161
|
-
return
|
|
157
|
+
return wrapOptional('double', isRequired);
|
|
162
158
|
default:
|
|
163
159
|
(realTypeAnnotation.name: empty);
|
|
164
160
|
throw new Error(createErrorMessage(realTypeAnnotation.name));
|
|
@@ -166,49 +162,49 @@ function translatePrimitiveJSTypeToCpp(
|
|
|
166
162
|
case 'VoidTypeAnnotation':
|
|
167
163
|
return 'void';
|
|
168
164
|
case 'StringTypeAnnotation':
|
|
169
|
-
return
|
|
165
|
+
return wrapOptional('jsi::String', isRequired);
|
|
170
166
|
case 'NumberTypeAnnotation':
|
|
171
|
-
return
|
|
167
|
+
return wrapOptional('double', isRequired);
|
|
172
168
|
case 'DoubleTypeAnnotation':
|
|
173
|
-
return
|
|
169
|
+
return wrapOptional('double', isRequired);
|
|
174
170
|
case 'FloatTypeAnnotation':
|
|
175
|
-
return
|
|
171
|
+
return wrapOptional('double', isRequired);
|
|
176
172
|
case 'Int32TypeAnnotation':
|
|
177
|
-
return
|
|
173
|
+
return wrapOptional('int', isRequired);
|
|
178
174
|
case 'BooleanTypeAnnotation':
|
|
179
|
-
return
|
|
175
|
+
return wrapOptional('bool', isRequired);
|
|
180
176
|
case 'EnumDeclaration':
|
|
181
177
|
switch (realTypeAnnotation.memberType) {
|
|
182
178
|
case 'NumberTypeAnnotation':
|
|
183
|
-
return
|
|
179
|
+
return wrapOptional('jsi::Value', isRequired);
|
|
184
180
|
case 'StringTypeAnnotation':
|
|
185
|
-
return
|
|
181
|
+
return wrapOptional('jsi::String', isRequired);
|
|
186
182
|
default:
|
|
187
183
|
throw new Error(createErrorMessage(realTypeAnnotation.type));
|
|
188
184
|
}
|
|
189
185
|
case 'GenericObjectTypeAnnotation':
|
|
190
|
-
return
|
|
186
|
+
return wrapOptional('jsi::Object', isRequired);
|
|
191
187
|
case 'UnionTypeAnnotation':
|
|
192
188
|
switch (typeAnnotation.memberType) {
|
|
193
189
|
case 'NumberTypeAnnotation':
|
|
194
|
-
return
|
|
190
|
+
return wrapOptional('double', isRequired);
|
|
195
191
|
case 'ObjectTypeAnnotation':
|
|
196
|
-
return
|
|
192
|
+
return wrapOptional('jsi::Object', isRequired);
|
|
197
193
|
case 'StringTypeAnnotation':
|
|
198
|
-
return
|
|
194
|
+
return wrapOptional('jsi::String', isRequired);
|
|
199
195
|
default:
|
|
200
196
|
throw new Error(createErrorMessage(realTypeAnnotation.type));
|
|
201
197
|
}
|
|
202
198
|
case 'ObjectTypeAnnotation':
|
|
203
|
-
return
|
|
199
|
+
return wrapOptional('jsi::Object', isRequired);
|
|
204
200
|
case 'ArrayTypeAnnotation':
|
|
205
|
-
return
|
|
201
|
+
return wrapOptional('jsi::Array', isRequired);
|
|
206
202
|
case 'FunctionTypeAnnotation':
|
|
207
|
-
return
|
|
203
|
+
return wrapOptional('jsi::Function', isRequired);
|
|
208
204
|
case 'PromiseTypeAnnotation':
|
|
209
|
-
return
|
|
205
|
+
return wrapOptional('jsi::Value', isRequired);
|
|
210
206
|
case 'MixedTypeAnnotation':
|
|
211
|
-
return
|
|
207
|
+
return wrapOptional('jsi::Value', isRequired);
|
|
212
208
|
default:
|
|
213
209
|
(realTypeAnnotation.type: empty);
|
|
214
210
|
throw new Error(createErrorMessage(realTypeAnnotation.type));
|
|
@@ -80,9 +80,11 @@ function _arrayWithHoles(arr) {
|
|
|
80
80
|
}
|
|
81
81
|
const _require = require('../../parsers/parsers-commons'),
|
|
82
82
|
unwrapNullable = _require.unwrapNullable;
|
|
83
|
-
const _require2 = require('
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
const _require2 = require('../TypeUtils/Java'),
|
|
84
|
+
wrapOptional = _require2.wrapOptional;
|
|
85
|
+
const _require3 = require('./Utils'),
|
|
86
|
+
createAliasResolver = _require3.createAliasResolver,
|
|
87
|
+
getModules = _require3.getModules;
|
|
86
88
|
function FileTemplate(config) {
|
|
87
89
|
const packageName = config.packageName,
|
|
88
90
|
className = config.className,
|
|
@@ -152,16 +154,8 @@ function translateFunctionParamToJavaType(
|
|
|
152
154
|
typeAnnotation = _unwrapNullable2[0],
|
|
153
155
|
nullable = _unwrapNullable2[1];
|
|
154
156
|
const isRequired = !optional && !nullable;
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
imports.add('javax.annotation.Nullable');
|
|
158
|
-
return `@Nullable ${
|
|
159
|
-
nullableType !== null && nullableType !== void 0
|
|
160
|
-
? nullableType
|
|
161
|
-
: javaType
|
|
162
|
-
}`;
|
|
163
|
-
}
|
|
164
|
-
return javaType;
|
|
157
|
+
if (!isRequired) {
|
|
158
|
+
imports.add('javax.annotation.Nullable');
|
|
165
159
|
}
|
|
166
160
|
|
|
167
161
|
// FIXME: support class alias for args
|
|
@@ -173,41 +167,41 @@ function translateFunctionParamToJavaType(
|
|
|
173
167
|
case 'ReservedTypeAnnotation':
|
|
174
168
|
switch (realTypeAnnotation.name) {
|
|
175
169
|
case 'RootTag':
|
|
176
|
-
return
|
|
170
|
+
return wrapOptional('double', isRequired);
|
|
177
171
|
default:
|
|
178
172
|
realTypeAnnotation.name;
|
|
179
173
|
throw new Error(createErrorMessage(realTypeAnnotation.name));
|
|
180
174
|
}
|
|
181
175
|
case 'StringTypeAnnotation':
|
|
182
|
-
return
|
|
176
|
+
return wrapOptional('String', isRequired);
|
|
183
177
|
case 'NumberTypeAnnotation':
|
|
184
|
-
return
|
|
178
|
+
return wrapOptional('double', isRequired);
|
|
185
179
|
case 'FloatTypeAnnotation':
|
|
186
|
-
return
|
|
180
|
+
return wrapOptional('double', isRequired);
|
|
187
181
|
case 'DoubleTypeAnnotation':
|
|
188
|
-
return
|
|
182
|
+
return wrapOptional('double', isRequired);
|
|
189
183
|
case 'Int32TypeAnnotation':
|
|
190
|
-
return
|
|
184
|
+
return wrapOptional('double', isRequired);
|
|
191
185
|
case 'BooleanTypeAnnotation':
|
|
192
|
-
return
|
|
186
|
+
return wrapOptional('boolean', isRequired);
|
|
193
187
|
case 'EnumDeclaration':
|
|
194
188
|
switch (realTypeAnnotation.memberType) {
|
|
195
189
|
case 'NumberTypeAnnotation':
|
|
196
|
-
return
|
|
190
|
+
return wrapOptional('double', isRequired);
|
|
197
191
|
case 'StringTypeAnnotation':
|
|
198
|
-
return
|
|
192
|
+
return wrapOptional('String', isRequired);
|
|
199
193
|
default:
|
|
200
194
|
throw new Error(createErrorMessage(realTypeAnnotation.type));
|
|
201
195
|
}
|
|
202
196
|
case 'UnionTypeAnnotation':
|
|
203
197
|
switch (typeAnnotation.memberType) {
|
|
204
198
|
case 'NumberTypeAnnotation':
|
|
205
|
-
return
|
|
199
|
+
return wrapOptional('double', isRequired);
|
|
206
200
|
case 'ObjectTypeAnnotation':
|
|
207
201
|
imports.add('com.facebook.react.bridge.ReadableMap');
|
|
208
|
-
return
|
|
202
|
+
return wrapOptional('ReadableMap', isRequired);
|
|
209
203
|
case 'StringTypeAnnotation':
|
|
210
|
-
return
|
|
204
|
+
return wrapOptional('String', isRequired);
|
|
211
205
|
default:
|
|
212
206
|
throw new Error(
|
|
213
207
|
`Unsupported union member returning value, found: ${realTypeAnnotation.memberType}"`,
|
|
@@ -215,17 +209,17 @@ function translateFunctionParamToJavaType(
|
|
|
215
209
|
}
|
|
216
210
|
case 'ObjectTypeAnnotation':
|
|
217
211
|
imports.add('com.facebook.react.bridge.ReadableMap');
|
|
218
|
-
return
|
|
212
|
+
return wrapOptional('ReadableMap', isRequired);
|
|
219
213
|
case 'GenericObjectTypeAnnotation':
|
|
220
214
|
// Treat this the same as ObjectTypeAnnotation for now.
|
|
221
215
|
imports.add('com.facebook.react.bridge.ReadableMap');
|
|
222
|
-
return
|
|
216
|
+
return wrapOptional('ReadableMap', isRequired);
|
|
223
217
|
case 'ArrayTypeAnnotation':
|
|
224
218
|
imports.add('com.facebook.react.bridge.ReadableArray');
|
|
225
|
-
return
|
|
219
|
+
return wrapOptional('ReadableArray', isRequired);
|
|
226
220
|
case 'FunctionTypeAnnotation':
|
|
227
221
|
imports.add('com.facebook.react.bridge.Callback');
|
|
228
|
-
return
|
|
222
|
+
return wrapOptional('Callback', isRequired);
|
|
229
223
|
default:
|
|
230
224
|
realTypeAnnotation.type;
|
|
231
225
|
throw new Error(createErrorMessage(realTypeAnnotation.type));
|
|
@@ -241,17 +235,10 @@ function translateFunctionReturnTypeToJavaType(
|
|
|
241
235
|
_unwrapNullable4 = _slicedToArray(_unwrapNullable3, 2),
|
|
242
236
|
returnTypeAnnotation = _unwrapNullable4[0],
|
|
243
237
|
nullable = _unwrapNullable4[1];
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
imports.add('javax.annotation.Nullable');
|
|
247
|
-
return `@Nullable ${
|
|
248
|
-
nullableType !== null && nullableType !== void 0
|
|
249
|
-
? nullableType
|
|
250
|
-
: javaType
|
|
251
|
-
}`;
|
|
252
|
-
}
|
|
253
|
-
return javaType;
|
|
238
|
+
if (nullable) {
|
|
239
|
+
imports.add('javax.annotation.Nullable');
|
|
254
240
|
}
|
|
241
|
+
const isRequired = !nullable;
|
|
255
242
|
|
|
256
243
|
// FIXME: support class alias for args
|
|
257
244
|
let realTypeAnnotation = returnTypeAnnotation;
|
|
@@ -262,7 +249,7 @@ function translateFunctionReturnTypeToJavaType(
|
|
|
262
249
|
case 'ReservedTypeAnnotation':
|
|
263
250
|
switch (realTypeAnnotation.name) {
|
|
264
251
|
case 'RootTag':
|
|
265
|
-
return
|
|
252
|
+
return wrapOptional('double', isRequired);
|
|
266
253
|
default:
|
|
267
254
|
realTypeAnnotation.name;
|
|
268
255
|
throw new Error(createErrorMessage(realTypeAnnotation.name));
|
|
@@ -272,35 +259,35 @@ function translateFunctionReturnTypeToJavaType(
|
|
|
272
259
|
case 'PromiseTypeAnnotation':
|
|
273
260
|
return 'void';
|
|
274
261
|
case 'StringTypeAnnotation':
|
|
275
|
-
return
|
|
262
|
+
return wrapOptional('String', isRequired);
|
|
276
263
|
case 'NumberTypeAnnotation':
|
|
277
|
-
return
|
|
264
|
+
return wrapOptional('double', isRequired);
|
|
278
265
|
case 'FloatTypeAnnotation':
|
|
279
|
-
return
|
|
266
|
+
return wrapOptional('double', isRequired);
|
|
280
267
|
case 'DoubleTypeAnnotation':
|
|
281
|
-
return
|
|
268
|
+
return wrapOptional('double', isRequired);
|
|
282
269
|
case 'Int32TypeAnnotation':
|
|
283
|
-
return
|
|
270
|
+
return wrapOptional('double', isRequired);
|
|
284
271
|
case 'BooleanTypeAnnotation':
|
|
285
|
-
return
|
|
272
|
+
return wrapOptional('boolean', isRequired);
|
|
286
273
|
case 'EnumDeclaration':
|
|
287
274
|
switch (realTypeAnnotation.memberType) {
|
|
288
275
|
case 'NumberTypeAnnotation':
|
|
289
|
-
return
|
|
276
|
+
return wrapOptional('double', isRequired);
|
|
290
277
|
case 'StringTypeAnnotation':
|
|
291
|
-
return
|
|
278
|
+
return wrapOptional('String', isRequired);
|
|
292
279
|
default:
|
|
293
280
|
throw new Error(createErrorMessage(realTypeAnnotation.type));
|
|
294
281
|
}
|
|
295
282
|
case 'UnionTypeAnnotation':
|
|
296
283
|
switch (realTypeAnnotation.memberType) {
|
|
297
284
|
case 'NumberTypeAnnotation':
|
|
298
|
-
return
|
|
285
|
+
return wrapOptional('double', isRequired);
|
|
299
286
|
case 'ObjectTypeAnnotation':
|
|
300
287
|
imports.add('com.facebook.react.bridge.WritableMap');
|
|
301
|
-
return
|
|
288
|
+
return wrapOptional('WritableMap', isRequired);
|
|
302
289
|
case 'StringTypeAnnotation':
|
|
303
|
-
return
|
|
290
|
+
return wrapOptional('String', isRequired);
|
|
304
291
|
default:
|
|
305
292
|
throw new Error(
|
|
306
293
|
`Unsupported union member returning value, found: ${realTypeAnnotation.memberType}"`,
|
|
@@ -308,13 +295,13 @@ function translateFunctionReturnTypeToJavaType(
|
|
|
308
295
|
}
|
|
309
296
|
case 'ObjectTypeAnnotation':
|
|
310
297
|
imports.add('com.facebook.react.bridge.WritableMap');
|
|
311
|
-
return
|
|
298
|
+
return wrapOptional('WritableMap', isRequired);
|
|
312
299
|
case 'GenericObjectTypeAnnotation':
|
|
313
300
|
imports.add('com.facebook.react.bridge.WritableMap');
|
|
314
|
-
return
|
|
301
|
+
return wrapOptional('WritableMap', isRequired);
|
|
315
302
|
case 'ArrayTypeAnnotation':
|
|
316
303
|
imports.add('com.facebook.react.bridge.WritableArray');
|
|
317
|
-
return
|
|
304
|
+
return wrapOptional('WritableArray', isRequired);
|
|
318
305
|
default:
|
|
319
306
|
realTypeAnnotation.type;
|
|
320
307
|
throw new Error(createErrorMessage(realTypeAnnotation.type));
|