@react-native/codegen 0.72.2 → 0.72.4
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/CodegenSchema.d.ts +10 -10
- package/lib/CodegenSchema.js.flow +6 -1
- package/lib/SchemaValidator.d.ts +1 -1
- package/lib/generators/RNCodegen.d.ts +98 -0
- package/lib/generators/RNCodegen.js +33 -4
- package/lib/generators/RNCodegen.js.flow +35 -4
- package/lib/generators/components/ComponentsGeneratorUtils.js +2 -0
- package/lib/generators/components/ComponentsGeneratorUtils.js.flow +2 -0
- package/lib/generators/components/CppHelpers.js +2 -0
- package/lib/generators/components/CppHelpers.js.flow +2 -0
- package/lib/generators/components/GeneratePropsH.js +2 -0
- package/lib/generators/components/GeneratePropsH.js.flow +2 -0
- package/lib/generators/components/GeneratePropsJavaDelegate.js +2 -0
- package/lib/generators/components/GeneratePropsJavaDelegate.js.flow +2 -0
- package/lib/generators/components/GeneratePropsJavaInterface.js +2 -0
- package/lib/generators/components/GeneratePropsJavaInterface.js.flow +2 -0
- package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js.flow +3 -1
- package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js +5 -0
- package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js.flow +6 -0
- package/lib/generators/components/GenerateViewConfigJs.js +1 -0
- package/lib/generators/components/GenerateViewConfigJs.js.flow +1 -0
- package/lib/generators/components/JavaHelpers.js +7 -0
- package/lib/generators/components/JavaHelpers.js.flow +8 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js +29 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js.flow +30 -0
- package/lib/parsers/error-utils.js +50 -15
- package/lib/parsers/error-utils.js.flow +57 -15
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +5 -1
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +5 -1
- package/lib/parsers/flow/components/componentsUtils.js +4 -0
- package/lib/parsers/flow/components/componentsUtils.js.flow +4 -0
- package/lib/parsers/flow/components/index.js +27 -126
- package/lib/parsers/flow/components/index.js.flow +22 -52
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js +4 -4
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js.flow +4 -4
- package/lib/parsers/flow/modules/index.js +41 -317
- package/lib/parsers/flow/modules/index.js.flow +19 -247
- package/lib/parsers/flow/parser.js +119 -12
- package/lib/parsers/flow/parser.js.flow +124 -3
- package/lib/parsers/flow/utils.js +0 -38
- package/lib/parsers/flow/utils.js.flow +0 -38
- package/lib/parsers/parser.d.ts +2 -2
- package/lib/parsers/parser.js.flow +84 -0
- package/lib/parsers/parserMock.js +58 -0
- package/lib/parsers/parserMock.js.flow +72 -0
- package/lib/parsers/parsers-commons.js +362 -5
- package/lib/parsers/parsers-commons.js.flow +351 -8
- package/lib/parsers/parsers-primitives.js +119 -3
- package/lib/parsers/parsers-primitives.js.flow +128 -3
- package/lib/parsers/schema/index.d.ts +1 -1
- package/lib/parsers/{typescript/components/schema.js.flow → schema.js.flow} +1 -1
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +5 -1
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +5 -1
- package/lib/parsers/typescript/components/componentsUtils.js +8 -0
- package/lib/parsers/typescript/components/componentsUtils.js.flow +8 -0
- package/lib/parsers/typescript/components/index.js +28 -127
- package/lib/parsers/typescript/components/index.js.flow +24 -54
- package/lib/parsers/typescript/modules/index.js +103 -434
- package/lib/parsers/typescript/modules/index.js.flow +85 -299
- package/lib/parsers/typescript/parser.js +113 -12
- package/lib/parsers/typescript/parser.js.flow +115 -3
- package/lib/parsers/typescript/utils.js +0 -31
- package/lib/parsers/typescript/utils.js.flow +0 -31
- package/lib/parsers/utils.js +4 -0
- package/lib/parsers/utils.js.flow +3 -0
- package/package.json +1 -1
- package/lib/parsers/flow/Visitor.js +0 -37
- package/lib/parsers/flow/Visitor.js.flow +0 -41
- package/lib/parsers/flow/components/options.js +0 -72
- package/lib/parsers/flow/components/options.js.flow +0 -87
- package/lib/parsers/flow/components/schema.js +0 -106
- package/lib/parsers/flow/components/schema.js.flow +0 -62
- package/lib/parsers/typescript/Visitor.js +0 -42
- package/lib/parsers/typescript/Visitor.js.flow +0 -47
- package/lib/parsers/typescript/components/options.js +0 -72
- package/lib/parsers/typescript/components/options.js.flow +0 -87
- /package/lib/parsers/{typescript/components/schema.js → schema.js} +0 -0
|
@@ -24,6 +24,8 @@ const _require = require('./errors'),
|
|
|
24
24
|
_require.IncorrectModuleRegistryCallArityParserError,
|
|
25
25
|
IncorrectModuleRegistryCallTypeParameterParserError =
|
|
26
26
|
_require.IncorrectModuleRegistryCallTypeParameterParserError,
|
|
27
|
+
IncorrectModuleRegistryCallArgumentTypeParserError =
|
|
28
|
+
_require.IncorrectModuleRegistryCallArgumentTypeParserError,
|
|
27
29
|
UnsupportedObjectPropertyValueTypeAnnotationParserError =
|
|
28
30
|
_require.UnsupportedObjectPropertyValueTypeAnnotationParserError,
|
|
29
31
|
UntypedModuleRegistryCallParserError =
|
|
@@ -155,27 +157,15 @@ function throwIfModuleTypeIsUnsupported(
|
|
|
155
157
|
propertyValue,
|
|
156
158
|
propertyName,
|
|
157
159
|
propertyValueType,
|
|
158
|
-
|
|
160
|
+
parser,
|
|
159
161
|
) {
|
|
160
|
-
if (
|
|
162
|
+
if (!parser.functionTypeAnnotation(propertyValueType)) {
|
|
161
163
|
throw new UnsupportedModulePropertyParserError(
|
|
162
164
|
nativeModuleName,
|
|
163
165
|
propertyValue,
|
|
164
166
|
propertyName,
|
|
165
167
|
propertyValueType,
|
|
166
|
-
language,
|
|
167
|
-
);
|
|
168
|
-
} else if (
|
|
169
|
-
language === 'TypeScript' &&
|
|
170
|
-
propertyValueType !== 'TSFunctionType' &&
|
|
171
|
-
propertyValueType !== 'TSMethodSignature'
|
|
172
|
-
) {
|
|
173
|
-
throw new UnsupportedModulePropertyParserError(
|
|
174
|
-
nativeModuleName,
|
|
175
|
-
propertyValue,
|
|
176
|
-
propertyName,
|
|
177
|
-
propertyValueType,
|
|
178
|
-
language,
|
|
168
|
+
parser.language(),
|
|
179
169
|
);
|
|
180
170
|
}
|
|
181
171
|
}
|
|
@@ -249,6 +239,47 @@ function throwIfArrayElementTypeAnnotationIsUnsupported(
|
|
|
249
239
|
);
|
|
250
240
|
}
|
|
251
241
|
}
|
|
242
|
+
function throwIfIncorrectModuleRegistryCallArgument(
|
|
243
|
+
nativeModuleName,
|
|
244
|
+
callExpressionArg,
|
|
245
|
+
methodName,
|
|
246
|
+
) {
|
|
247
|
+
if (
|
|
248
|
+
callExpressionArg.type !== 'StringLiteral' &&
|
|
249
|
+
callExpressionArg.type !== 'Literal'
|
|
250
|
+
) {
|
|
251
|
+
const type = callExpressionArg.type;
|
|
252
|
+
throw new IncorrectModuleRegistryCallArgumentTypeParserError(
|
|
253
|
+
nativeModuleName,
|
|
254
|
+
callExpressionArg,
|
|
255
|
+
methodName,
|
|
256
|
+
type,
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function throwIfPartialNotAnnotatingTypeParameter(
|
|
261
|
+
typeAnnotation,
|
|
262
|
+
types,
|
|
263
|
+
parser,
|
|
264
|
+
) {
|
|
265
|
+
const annotatedElement = parser.extractAnnotatedElement(
|
|
266
|
+
typeAnnotation,
|
|
267
|
+
types,
|
|
268
|
+
);
|
|
269
|
+
if (!annotatedElement) {
|
|
270
|
+
throw new Error('Partials only support annotating a type parameter.');
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
function throwIfPartialWithMoreParameter(typeAnnotation) {
|
|
274
|
+
if (typeAnnotation.typeParameters.params.length !== 1) {
|
|
275
|
+
throw new Error('Partials only support annotating exactly one parameter.');
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function throwIfMoreThanOneCodegenNativecommands(commandsTypeNames) {
|
|
279
|
+
if (commandsTypeNames.length > 1) {
|
|
280
|
+
throw new Error('codegenNativeCommands may only be called once in a file');
|
|
281
|
+
}
|
|
282
|
+
}
|
|
252
283
|
module.exports = {
|
|
253
284
|
throwIfModuleInterfaceIsMisnamed,
|
|
254
285
|
throwIfUnsupportedFunctionReturnTypeAnnotationParserError,
|
|
@@ -263,4 +294,8 @@ module.exports = {
|
|
|
263
294
|
throwIfMoreThanOneModuleInterfaceParserError,
|
|
264
295
|
throwIfUnsupportedFunctionParamTypeAnnotationParserError,
|
|
265
296
|
throwIfArrayElementTypeAnnotationIsUnsupported,
|
|
297
|
+
throwIfIncorrectModuleRegistryCallArgument,
|
|
298
|
+
throwIfPartialNotAnnotatingTypeParameter,
|
|
299
|
+
throwIfPartialWithMoreParameter,
|
|
300
|
+
throwIfMoreThanOneCodegenNativecommands,
|
|
266
301
|
};
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import type {NativeModuleTypeAnnotation} from '../CodegenSchema';
|
|
14
14
|
import type {ParserType} from './errors';
|
|
15
15
|
import type {Parser} from './parser';
|
|
16
|
+
import type {TypeDeclarationMap} from '../parsers/utils';
|
|
16
17
|
|
|
17
18
|
const {
|
|
18
19
|
MisnamedModuleInterfaceParserError,
|
|
@@ -22,6 +23,7 @@ const {
|
|
|
22
23
|
UnusedModuleInterfaceParserError,
|
|
23
24
|
IncorrectModuleRegistryCallArityParserError,
|
|
24
25
|
IncorrectModuleRegistryCallTypeParameterParserError,
|
|
26
|
+
IncorrectModuleRegistryCallArgumentTypeParserError,
|
|
25
27
|
UnsupportedObjectPropertyValueTypeAnnotationParserError,
|
|
26
28
|
UntypedModuleRegistryCallParserError,
|
|
27
29
|
UnsupportedModulePropertyParserError,
|
|
@@ -158,27 +160,15 @@ function throwIfModuleTypeIsUnsupported(
|
|
|
158
160
|
propertyValue: $FlowFixMe,
|
|
159
161
|
propertyName: string,
|
|
160
162
|
propertyValueType: string,
|
|
161
|
-
|
|
163
|
+
parser: Parser,
|
|
162
164
|
) {
|
|
163
|
-
if (
|
|
164
|
-
throw new UnsupportedModulePropertyParserError(
|
|
165
|
-
nativeModuleName,
|
|
166
|
-
propertyValue,
|
|
167
|
-
propertyName,
|
|
168
|
-
propertyValueType,
|
|
169
|
-
language,
|
|
170
|
-
);
|
|
171
|
-
} else if (
|
|
172
|
-
language === 'TypeScript' &&
|
|
173
|
-
propertyValueType !== 'TSFunctionType' &&
|
|
174
|
-
propertyValueType !== 'TSMethodSignature'
|
|
175
|
-
) {
|
|
165
|
+
if (!parser.functionTypeAnnotation(propertyValueType)) {
|
|
176
166
|
throw new UnsupportedModulePropertyParserError(
|
|
177
167
|
nativeModuleName,
|
|
178
168
|
propertyValue,
|
|
179
169
|
propertyName,
|
|
180
170
|
propertyValueType,
|
|
181
|
-
language,
|
|
171
|
+
parser.language(),
|
|
182
172
|
);
|
|
183
173
|
}
|
|
184
174
|
}
|
|
@@ -260,6 +250,54 @@ function throwIfArrayElementTypeAnnotationIsUnsupported(
|
|
|
260
250
|
}
|
|
261
251
|
}
|
|
262
252
|
|
|
253
|
+
function throwIfIncorrectModuleRegistryCallArgument(
|
|
254
|
+
nativeModuleName: string,
|
|
255
|
+
callExpressionArg: $FlowFixMe,
|
|
256
|
+
methodName: string,
|
|
257
|
+
) {
|
|
258
|
+
if (
|
|
259
|
+
callExpressionArg.type !== 'StringLiteral' &&
|
|
260
|
+
callExpressionArg.type !== 'Literal'
|
|
261
|
+
) {
|
|
262
|
+
const {type} = callExpressionArg;
|
|
263
|
+
throw new IncorrectModuleRegistryCallArgumentTypeParserError(
|
|
264
|
+
nativeModuleName,
|
|
265
|
+
callExpressionArg,
|
|
266
|
+
methodName,
|
|
267
|
+
type,
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function throwIfPartialNotAnnotatingTypeParameter(
|
|
273
|
+
typeAnnotation: $FlowFixMe,
|
|
274
|
+
types: TypeDeclarationMap,
|
|
275
|
+
parser: Parser,
|
|
276
|
+
) {
|
|
277
|
+
const annotatedElement = parser.extractAnnotatedElement(
|
|
278
|
+
typeAnnotation,
|
|
279
|
+
types,
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
if (!annotatedElement) {
|
|
283
|
+
throw new Error('Partials only support annotating a type parameter.');
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function throwIfPartialWithMoreParameter(typeAnnotation: $FlowFixMe) {
|
|
288
|
+
if (typeAnnotation.typeParameters.params.length !== 1) {
|
|
289
|
+
throw new Error('Partials only support annotating exactly one parameter.');
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function throwIfMoreThanOneCodegenNativecommands(
|
|
294
|
+
commandsTypeNames: $ReadOnlyArray<$FlowFixMe>,
|
|
295
|
+
) {
|
|
296
|
+
if (commandsTypeNames.length > 1) {
|
|
297
|
+
throw new Error('codegenNativeCommands may only be called once in a file');
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
263
301
|
module.exports = {
|
|
264
302
|
throwIfModuleInterfaceIsMisnamed,
|
|
265
303
|
throwIfUnsupportedFunctionReturnTypeAnnotationParserError,
|
|
@@ -274,4 +312,8 @@ module.exports = {
|
|
|
274
312
|
throwIfMoreThanOneModuleInterfaceParserError,
|
|
275
313
|
throwIfUnsupportedFunctionParamTypeAnnotationParserError,
|
|
276
314
|
throwIfArrayElementTypeAnnotationIsUnsupported,
|
|
315
|
+
throwIfIncorrectModuleRegistryCallArgument,
|
|
316
|
+
throwIfPartialNotAnnotatingTypeParameter,
|
|
317
|
+
throwIfPartialWithMoreParameter,
|
|
318
|
+
throwIfMoreThanOneCodegenNativecommands,
|
|
277
319
|
};
|
|
@@ -205,7 +205,7 @@ const ALL_PROP_TYPES_NO_EVENTS = `
|
|
|
205
205
|
|
|
206
206
|
const codegenNativeComponent = require('codegenNativeComponent');
|
|
207
207
|
|
|
208
|
-
import type {Int32, Double, Float, WithDefault} from 'CodegenTypes';
|
|
208
|
+
import type {Int32, Double, Float, WithDefault, UnsafeMixed} from 'CodegenTypes';
|
|
209
209
|
import type {ImageSource} from 'ImageSource';
|
|
210
210
|
import type {ColorValue, ColorArrayValue, PointValue, EdgeInsetsValue, DimensionValue} from 'StyleSheetTypes';
|
|
211
211
|
import type {ViewProps} from 'ViewPropTypes';
|
|
@@ -313,6 +313,10 @@ type ModuleProps = $ReadOnly<{|
|
|
|
313
313
|
dimension_optional_key?: DimensionValue,
|
|
314
314
|
dimension_optional_value: ?DimensionValue,
|
|
315
315
|
dimension_optional_both?: ?DimensionValue,
|
|
316
|
+
|
|
317
|
+
// Mixed props
|
|
318
|
+
mixed_required: UnsafeMixed,
|
|
319
|
+
mixed_optional_key?: UnsafeMixed,
|
|
316
320
|
|}>;
|
|
317
321
|
|
|
318
322
|
export default (codegenNativeComponent<ModuleProps, Options>(
|
|
@@ -209,7 +209,7 @@ const ALL_PROP_TYPES_NO_EVENTS = `
|
|
|
209
209
|
|
|
210
210
|
const codegenNativeComponent = require('codegenNativeComponent');
|
|
211
211
|
|
|
212
|
-
import type {Int32, Double, Float, WithDefault} from 'CodegenTypes';
|
|
212
|
+
import type {Int32, Double, Float, WithDefault, UnsafeMixed} from 'CodegenTypes';
|
|
213
213
|
import type {ImageSource} from 'ImageSource';
|
|
214
214
|
import type {ColorValue, ColorArrayValue, PointValue, EdgeInsetsValue, DimensionValue} from 'StyleSheetTypes';
|
|
215
215
|
import type {ViewProps} from 'ViewPropTypes';
|
|
@@ -317,6 +317,10 @@ type ModuleProps = $ReadOnly<{|
|
|
|
317
317
|
dimension_optional_key?: DimensionValue,
|
|
318
318
|
dimension_optional_value: ?DimensionValue,
|
|
319
319
|
dimension_optional_both?: ?DimensionValue,
|
|
320
|
+
|
|
321
|
+
// Mixed props
|
|
322
|
+
mixed_required: UnsafeMixed,
|
|
323
|
+
mixed_optional_key?: UnsafeMixed,
|
|
320
324
|
|}>;
|
|
321
325
|
|
|
322
326
|
export default (codegenNativeComponent<ModuleProps, Options>(
|
|
@@ -364,6 +364,10 @@ function getTypeAnnotation(
|
|
|
364
364
|
throw new Error(
|
|
365
365
|
`Cannot use "${type}" type annotation for "${name}": must use a specific numeric type like Int32, Double, or Float`,
|
|
366
366
|
);
|
|
367
|
+
case 'UnsafeMixed':
|
|
368
|
+
return {
|
|
369
|
+
type: 'MixedTypeAnnotation',
|
|
370
|
+
};
|
|
367
371
|
default:
|
|
368
372
|
type;
|
|
369
373
|
throw new Error(
|
|
@@ -391,6 +391,10 @@ function getTypeAnnotation<+T>(
|
|
|
391
391
|
throw new Error(
|
|
392
392
|
`Cannot use "${type}" type annotation for "${name}": must use a specific numeric type like Int32, Double, or Float`,
|
|
393
393
|
);
|
|
394
|
+
case 'UnsafeMixed':
|
|
395
|
+
return {
|
|
396
|
+
type: 'MixedTypeAnnotation',
|
|
397
|
+
};
|
|
394
398
|
default:
|
|
395
399
|
(type: empty);
|
|
396
400
|
throw new Error(
|
|
@@ -10,116 +10,34 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
: Object.getOwnPropertyDescriptors
|
|
33
|
-
? Object.defineProperties(
|
|
34
|
-
target,
|
|
35
|
-
Object.getOwnPropertyDescriptors(source),
|
|
36
|
-
)
|
|
37
|
-
: ownKeys(Object(source)).forEach(function (key) {
|
|
38
|
-
Object.defineProperty(
|
|
39
|
-
target,
|
|
40
|
-
key,
|
|
41
|
-
Object.getOwnPropertyDescriptor(source, key),
|
|
42
|
-
);
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
return target;
|
|
46
|
-
}
|
|
47
|
-
function _defineProperty(obj, key, value) {
|
|
48
|
-
key = _toPropertyKey(key);
|
|
49
|
-
if (key in obj) {
|
|
50
|
-
Object.defineProperty(obj, key, {
|
|
51
|
-
value: value,
|
|
52
|
-
enumerable: true,
|
|
53
|
-
configurable: true,
|
|
54
|
-
writable: true,
|
|
55
|
-
});
|
|
56
|
-
} else {
|
|
57
|
-
obj[key] = value;
|
|
58
|
-
}
|
|
59
|
-
return obj;
|
|
60
|
-
}
|
|
61
|
-
function _toPropertyKey(arg) {
|
|
62
|
-
var key = _toPrimitive(arg, 'string');
|
|
63
|
-
return typeof key === 'symbol' ? key : String(key);
|
|
64
|
-
}
|
|
65
|
-
function _toPrimitive(input, hint) {
|
|
66
|
-
if (typeof input !== 'object' || input === null) return input;
|
|
67
|
-
var prim = input[Symbol.toPrimitive];
|
|
68
|
-
if (prim !== undefined) {
|
|
69
|
-
var res = prim.call(input, hint || 'default');
|
|
70
|
-
if (typeof res !== 'object') return res;
|
|
71
|
-
throw new TypeError('@@toPrimitive must return a primitive value.');
|
|
72
|
-
}
|
|
73
|
-
return (hint === 'string' ? String : Number)(input);
|
|
74
|
-
}
|
|
75
|
-
const _require = require('../utils'),
|
|
76
|
-
getTypes = _require.getTypes;
|
|
77
|
-
const _require2 = require('./commands'),
|
|
78
|
-
getCommands = _require2.getCommands;
|
|
79
|
-
const _require3 = require('./events'),
|
|
80
|
-
getEvents = _require3.getEvents;
|
|
81
|
-
const _require4 = require('./extends'),
|
|
82
|
-
getExtendsProps = _require4.getExtendsProps,
|
|
83
|
-
removeKnownExtends = _require4.removeKnownExtends;
|
|
84
|
-
const _require5 = require('./options'),
|
|
85
|
-
getCommandOptions = _require5.getCommandOptions,
|
|
86
|
-
getOptions = _require5.getOptions;
|
|
87
|
-
const _require6 = require('./props'),
|
|
88
|
-
getProps = _require6.getProps;
|
|
89
|
-
const _require7 = require('./componentsUtils.js'),
|
|
90
|
-
getProperties = _require7.getProperties;
|
|
13
|
+
const _require = require('./commands'),
|
|
14
|
+
getCommands = _require.getCommands;
|
|
15
|
+
const _require2 = require('./events'),
|
|
16
|
+
getEvents = _require2.getEvents;
|
|
17
|
+
const _require3 = require('./extends'),
|
|
18
|
+
getExtendsProps = _require3.getExtendsProps,
|
|
19
|
+
removeKnownExtends = _require3.removeKnownExtends;
|
|
20
|
+
const _require4 = require('./props'),
|
|
21
|
+
getProps = _require4.getProps;
|
|
22
|
+
const _require5 = require('./componentsUtils.js'),
|
|
23
|
+
getProperties = _require5.getProperties;
|
|
24
|
+
const _require6 = require('../../error-utils'),
|
|
25
|
+
throwIfMoreThanOneCodegenNativecommands =
|
|
26
|
+
_require6.throwIfMoreThanOneCodegenNativecommands;
|
|
27
|
+
const _require7 = require('../../parsers-commons'),
|
|
28
|
+
createComponentConfig = _require7.createComponentConfig,
|
|
29
|
+
findNativeComponentType = _require7.findNativeComponentType,
|
|
30
|
+
getCommandOptions = _require7.getCommandOptions,
|
|
31
|
+
getOptions = _require7.getOptions;
|
|
91
32
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
function findComponentConfig(ast) {
|
|
33
|
+
// $FlowFixMe[signature-verification-failure] there's no flowtype for AST
|
|
34
|
+
function findComponentConfig(ast, parser) {
|
|
95
35
|
const foundConfigs = [];
|
|
96
36
|
const defaultExports = ast.body.filter(
|
|
97
37
|
node => node.type === 'ExportDefaultDeclaration',
|
|
98
38
|
);
|
|
99
39
|
defaultExports.forEach(statement => {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
// codegenNativeComponent can be nested inside a cast
|
|
103
|
-
// expression so we need to go one level deeper
|
|
104
|
-
if (declaration.type === 'TypeCastExpression') {
|
|
105
|
-
declaration = declaration.expression;
|
|
106
|
-
}
|
|
107
|
-
try {
|
|
108
|
-
if (declaration.callee.name === 'codegenNativeComponent') {
|
|
109
|
-
const typeArgumentParams = declaration.typeArguments.params;
|
|
110
|
-
const funcArgumentParams = declaration.arguments;
|
|
111
|
-
const nativeComponentType = {
|
|
112
|
-
propsTypeName: typeArgumentParams[0].id.name,
|
|
113
|
-
componentName: funcArgumentParams[0].value,
|
|
114
|
-
};
|
|
115
|
-
if (funcArgumentParams.length > 1) {
|
|
116
|
-
nativeComponentType.optionsExpression = funcArgumentParams[1];
|
|
117
|
-
}
|
|
118
|
-
foundConfigs.push(nativeComponentType);
|
|
119
|
-
}
|
|
120
|
-
} catch (e) {
|
|
121
|
-
// ignore
|
|
122
|
-
}
|
|
40
|
+
findNativeComponentType(statement, foundConfigs, parser);
|
|
123
41
|
});
|
|
124
42
|
if (foundConfigs.length === 0) {
|
|
125
43
|
throw new Error('Could not find component config for native component');
|
|
@@ -163,23 +81,8 @@ function findComponentConfig(ast) {
|
|
|
163
81
|
};
|
|
164
82
|
})
|
|
165
83
|
.filter(Boolean);
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
return _objectSpread(
|
|
170
|
-
_objectSpread({}, foundConfig),
|
|
171
|
-
{},
|
|
172
|
-
{
|
|
173
|
-
commandTypeName:
|
|
174
|
-
commandsTypeNames[0] == null
|
|
175
|
-
? null
|
|
176
|
-
: commandsTypeNames[0].commandTypeName,
|
|
177
|
-
commandOptionsExpression:
|
|
178
|
-
commandsTypeNames[0] == null
|
|
179
|
-
? null
|
|
180
|
-
: commandsTypeNames[0].commandOptionsExpression,
|
|
181
|
-
},
|
|
182
|
-
);
|
|
84
|
+
throwIfMoreThanOneCodegenNativecommands(commandsTypeNames);
|
|
85
|
+
return createComponentConfig(foundConfig, commandsTypeNames);
|
|
183
86
|
}
|
|
184
87
|
function getCommandProperties(
|
|
185
88
|
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
|
|
@@ -229,16 +132,14 @@ function getCommandProperties(
|
|
|
229
132
|
}
|
|
230
133
|
|
|
231
134
|
// $FlowFixMe[signature-verification-failure] there's no flowtype for AST
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
function buildComponentSchema(ast) {
|
|
235
|
-
const _findComponentConfig = findComponentConfig(ast),
|
|
135
|
+
function buildComponentSchema(ast, parser) {
|
|
136
|
+
const _findComponentConfig = findComponentConfig(ast, parser),
|
|
236
137
|
componentName = _findComponentConfig.componentName,
|
|
237
138
|
propsTypeName = _findComponentConfig.propsTypeName,
|
|
238
139
|
commandTypeName = _findComponentConfig.commandTypeName,
|
|
239
140
|
commandOptionsExpression = _findComponentConfig.commandOptionsExpression,
|
|
240
141
|
optionsExpression = _findComponentConfig.optionsExpression;
|
|
241
|
-
const types = getTypes(ast);
|
|
142
|
+
const types = parser.getTypes(ast);
|
|
242
143
|
const propProperties = getProperties(propsTypeName, types);
|
|
243
144
|
const commandOptions = getCommandOptions(commandOptionsExpression);
|
|
244
145
|
const commandProperties = getCommandProperties(
|
|
@@ -9,53 +9,34 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
|
+
import type {Parser} from '../../parser';
|
|
12
13
|
import type {TypeDeclarationMap} from '../../utils';
|
|
13
|
-
import type {CommandOptions} from '
|
|
14
|
-
import type {ComponentSchemaBuilderConfig} from '
|
|
14
|
+
import type {CommandOptions} from '../../parsers-commons';
|
|
15
|
+
import type {ComponentSchemaBuilderConfig} from '../../schema.js';
|
|
15
16
|
|
|
16
|
-
const {getTypes} = require('../utils');
|
|
17
17
|
const {getCommands} = require('./commands');
|
|
18
18
|
const {getEvents} = require('./events');
|
|
19
19
|
const {getExtendsProps, removeKnownExtends} = require('./extends');
|
|
20
|
-
const {getCommandOptions, getOptions} = require('./options');
|
|
21
20
|
const {getProps} = require('./props');
|
|
22
21
|
const {getProperties} = require('./componentsUtils.js');
|
|
22
|
+
const {throwIfMoreThanOneCodegenNativecommands} = require('../../error-utils');
|
|
23
|
+
const {
|
|
24
|
+
createComponentConfig,
|
|
25
|
+
findNativeComponentType,
|
|
26
|
+
getCommandOptions,
|
|
27
|
+
getOptions,
|
|
28
|
+
} = require('../../parsers-commons');
|
|
23
29
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const foundConfigs = [];
|
|
30
|
+
// $FlowFixMe[signature-verification-failure] there's no flowtype for AST
|
|
31
|
+
function findComponentConfig(ast: $FlowFixMe, parser: Parser) {
|
|
32
|
+
const foundConfigs: Array<{[string]: string}> = [];
|
|
28
33
|
|
|
29
34
|
const defaultExports = ast.body.filter(
|
|
30
35
|
node => node.type === 'ExportDefaultDeclaration',
|
|
31
36
|
);
|
|
32
37
|
|
|
33
38
|
defaultExports.forEach(statement => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// codegenNativeComponent can be nested inside a cast
|
|
37
|
-
// expression so we need to go one level deeper
|
|
38
|
-
if (declaration.type === 'TypeCastExpression') {
|
|
39
|
-
declaration = declaration.expression;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
if (declaration.callee.name === 'codegenNativeComponent') {
|
|
44
|
-
const typeArgumentParams = declaration.typeArguments.params;
|
|
45
|
-
const funcArgumentParams = declaration.arguments;
|
|
46
|
-
|
|
47
|
-
const nativeComponentType: {[string]: string} = {
|
|
48
|
-
propsTypeName: typeArgumentParams[0].id.name,
|
|
49
|
-
componentName: funcArgumentParams[0].value,
|
|
50
|
-
};
|
|
51
|
-
if (funcArgumentParams.length > 1) {
|
|
52
|
-
nativeComponentType.optionsExpression = funcArgumentParams[1];
|
|
53
|
-
}
|
|
54
|
-
foundConfigs.push(nativeComponentType);
|
|
55
|
-
}
|
|
56
|
-
} catch (e) {
|
|
57
|
-
// ignore
|
|
58
|
-
}
|
|
39
|
+
findNativeComponentType(statement, foundConfigs, parser);
|
|
59
40
|
});
|
|
60
41
|
|
|
61
42
|
if (foundConfigs.length === 0) {
|
|
@@ -108,21 +89,9 @@ function findComponentConfig(ast) {
|
|
|
108
89
|
})
|
|
109
90
|
.filter(Boolean);
|
|
110
91
|
|
|
111
|
-
|
|
112
|
-
throw new Error('codegenNativeCommands may only be called once in a file');
|
|
113
|
-
}
|
|
92
|
+
throwIfMoreThanOneCodegenNativecommands(commandsTypeNames);
|
|
114
93
|
|
|
115
|
-
return
|
|
116
|
-
...foundConfig,
|
|
117
|
-
commandTypeName:
|
|
118
|
-
commandsTypeNames[0] == null
|
|
119
|
-
? null
|
|
120
|
-
: commandsTypeNames[0].commandTypeName,
|
|
121
|
-
commandOptionsExpression:
|
|
122
|
-
commandsTypeNames[0] == null
|
|
123
|
-
? null
|
|
124
|
-
: commandsTypeNames[0].commandOptionsExpression,
|
|
125
|
-
};
|
|
94
|
+
return createComponentConfig(foundConfig, commandsTypeNames);
|
|
126
95
|
}
|
|
127
96
|
|
|
128
97
|
function getCommandProperties(
|
|
@@ -180,18 +149,19 @@ function getCommandProperties(
|
|
|
180
149
|
}
|
|
181
150
|
|
|
182
151
|
// $FlowFixMe[signature-verification-failure] there's no flowtype for AST
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
152
|
+
function buildComponentSchema(
|
|
153
|
+
ast: $FlowFixMe,
|
|
154
|
+
parser: Parser,
|
|
155
|
+
): ComponentSchemaBuilderConfig {
|
|
186
156
|
const {
|
|
187
157
|
componentName,
|
|
188
158
|
propsTypeName,
|
|
189
159
|
commandTypeName,
|
|
190
160
|
commandOptionsExpression,
|
|
191
161
|
optionsExpression,
|
|
192
|
-
} = findComponentConfig(ast);
|
|
162
|
+
} = findComponentConfig(ast, parser);
|
|
193
163
|
|
|
194
|
-
const types = getTypes(ast);
|
|
164
|
+
const types = parser.getTypes(ast);
|
|
195
165
|
|
|
196
166
|
const propProperties = getProperties(propsTypeName, types);
|
|
197
167
|
const commandOptions = getCommandOptions(commandOptionsExpression);
|
|
@@ -302,8 +302,8 @@ export type SomeObj = {|
|
|
|
302
302
|
|
|
303
303
|
export interface Spec extends TurboModule {
|
|
304
304
|
+getSomeObj: () => SomeObj;
|
|
305
|
-
+getPartialSomeObj: () =>
|
|
306
|
-
+getSomeObjFromPartialSomeObj: (value:
|
|
305
|
+
+getPartialSomeObj: () => Partial<SomeObj>;
|
|
306
|
+
+getSomeObjFromPartialSomeObj: (value: Partial<SomeObj>) => SomeObj;
|
|
307
307
|
}
|
|
308
308
|
|
|
309
309
|
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
|
@@ -330,10 +330,10 @@ export type SomeObj = {|
|
|
|
330
330
|
b?: boolean,
|
|
331
331
|
|};
|
|
332
332
|
|
|
333
|
-
export type PartialSomeObj =
|
|
333
|
+
export type PartialSomeObj = Partial<SomeObj>;
|
|
334
334
|
|
|
335
335
|
export interface Spec extends TurboModule {
|
|
336
|
-
+getPartialPartial: (value1:
|
|
336
|
+
+getPartialPartial: (value1: Partial<SomeObj>, value2: PartialSomeObj) => SomeObj
|
|
337
337
|
}
|
|
338
338
|
|
|
339
339
|
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
|
@@ -311,8 +311,8 @@ export type SomeObj = {|
|
|
|
311
311
|
|
|
312
312
|
export interface Spec extends TurboModule {
|
|
313
313
|
+getSomeObj: () => SomeObj;
|
|
314
|
-
+getPartialSomeObj: () =>
|
|
315
|
-
+getSomeObjFromPartialSomeObj: (value:
|
|
314
|
+
+getPartialSomeObj: () => Partial<SomeObj>;
|
|
315
|
+
+getSomeObjFromPartialSomeObj: (value: Partial<SomeObj>) => SomeObj;
|
|
316
316
|
}
|
|
317
317
|
|
|
318
318
|
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
|
@@ -340,10 +340,10 @@ export type SomeObj = {|
|
|
|
340
340
|
b?: boolean,
|
|
341
341
|
|};
|
|
342
342
|
|
|
343
|
-
export type PartialSomeObj =
|
|
343
|
+
export type PartialSomeObj = Partial<SomeObj>;
|
|
344
344
|
|
|
345
345
|
export interface Spec extends TurboModule {
|
|
346
|
-
+getPartialPartial: (value1:
|
|
346
|
+
+getPartialPartial: (value1: Partial<SomeObj>, value2: PartialSomeObj) => SomeObj
|
|
347
347
|
}
|
|
348
348
|
|
|
349
349
|
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|