@react-native/codegen 0.72.3 → 0.72.5
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/generators/modules/GenerateModuleH.js +1 -1
- package/lib/generators/modules/GenerateModuleH.js.flow +1 -1
- package/lib/parsers/error-utils.js +9 -15
- package/lib/parsers/error-utils.js.flow +12 -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 +18 -113
- package/lib/parsers/flow/components/index.js.flow +15 -46
- 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 -307
- package/lib/parsers/flow/modules/index.js.flow +18 -233
- package/lib/parsers/flow/parser.js +68 -12
- package/lib/parsers/flow/parser.js.flow +67 -3
- package/lib/parsers/parser.d.ts +2 -2
- package/lib/parsers/parser.js.flow +65 -3
- package/lib/parsers/parserMock.js +44 -0
- package/lib/parsers/parserMock.js.flow +52 -1
- package/lib/parsers/parsers-commons.js +361 -4
- package/lib/parsers/parsers-commons.js.flow +341 -4
- 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/__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 +20 -115
- package/lib/parsers/typescript/components/index.js.flow +17 -48
- package/lib/parsers/typescript/modules/index.js +103 -421
- package/lib/parsers/typescript/modules/index.js.flow +84 -285
- package/lib/parsers/typescript/parser.js +69 -12
- package/lib/parsers/typescript/parser.js.flow +68 -3
- package/lib/parsers/utils.js +4 -0
- package/lib/parsers/utils.js.flow +3 -0
- package/package.json +11 -11
- 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/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
|
@@ -157,27 +157,15 @@ function throwIfModuleTypeIsUnsupported(
|
|
|
157
157
|
propertyValue,
|
|
158
158
|
propertyName,
|
|
159
159
|
propertyValueType,
|
|
160
|
-
|
|
160
|
+
parser,
|
|
161
161
|
) {
|
|
162
|
-
if (
|
|
163
|
-
throw new UnsupportedModulePropertyParserError(
|
|
164
|
-
nativeModuleName,
|
|
165
|
-
propertyValue,
|
|
166
|
-
propertyName,
|
|
167
|
-
propertyValueType,
|
|
168
|
-
language,
|
|
169
|
-
);
|
|
170
|
-
} else if (
|
|
171
|
-
language === 'TypeScript' &&
|
|
172
|
-
propertyValueType !== 'TSFunctionType' &&
|
|
173
|
-
propertyValueType !== 'TSMethodSignature'
|
|
174
|
-
) {
|
|
162
|
+
if (!parser.functionTypeAnnotation(propertyValueType)) {
|
|
175
163
|
throw new UnsupportedModulePropertyParserError(
|
|
176
164
|
nativeModuleName,
|
|
177
165
|
propertyValue,
|
|
178
166
|
propertyName,
|
|
179
167
|
propertyValueType,
|
|
180
|
-
language,
|
|
168
|
+
parser.language(),
|
|
181
169
|
);
|
|
182
170
|
}
|
|
183
171
|
}
|
|
@@ -287,6 +275,11 @@ function throwIfPartialWithMoreParameter(typeAnnotation) {
|
|
|
287
275
|
throw new Error('Partials only support annotating exactly one parameter.');
|
|
288
276
|
}
|
|
289
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
|
+
}
|
|
290
283
|
module.exports = {
|
|
291
284
|
throwIfModuleInterfaceIsMisnamed,
|
|
292
285
|
throwIfUnsupportedFunctionReturnTypeAnnotationParserError,
|
|
@@ -304,4 +297,5 @@ module.exports = {
|
|
|
304
297
|
throwIfIncorrectModuleRegistryCallArgument,
|
|
305
298
|
throwIfPartialNotAnnotatingTypeParameter,
|
|
306
299
|
throwIfPartialWithMoreParameter,
|
|
300
|
+
throwIfMoreThanOneCodegenNativecommands,
|
|
307
301
|
};
|
|
@@ -160,27 +160,15 @@ function throwIfModuleTypeIsUnsupported(
|
|
|
160
160
|
propertyValue: $FlowFixMe,
|
|
161
161
|
propertyName: string,
|
|
162
162
|
propertyValueType: string,
|
|
163
|
-
|
|
163
|
+
parser: Parser,
|
|
164
164
|
) {
|
|
165
|
-
if (
|
|
166
|
-
throw new UnsupportedModulePropertyParserError(
|
|
167
|
-
nativeModuleName,
|
|
168
|
-
propertyValue,
|
|
169
|
-
propertyName,
|
|
170
|
-
propertyValueType,
|
|
171
|
-
language,
|
|
172
|
-
);
|
|
173
|
-
} else if (
|
|
174
|
-
language === 'TypeScript' &&
|
|
175
|
-
propertyValueType !== 'TSFunctionType' &&
|
|
176
|
-
propertyValueType !== 'TSMethodSignature'
|
|
177
|
-
) {
|
|
165
|
+
if (!parser.functionTypeAnnotation(propertyValueType)) {
|
|
178
166
|
throw new UnsupportedModulePropertyParserError(
|
|
179
167
|
nativeModuleName,
|
|
180
168
|
propertyValue,
|
|
181
169
|
propertyName,
|
|
182
170
|
propertyValueType,
|
|
183
|
-
language,
|
|
171
|
+
parser.language(),
|
|
184
172
|
);
|
|
185
173
|
}
|
|
186
174
|
}
|
|
@@ -302,6 +290,14 @@ function throwIfPartialWithMoreParameter(typeAnnotation: $FlowFixMe) {
|
|
|
302
290
|
}
|
|
303
291
|
}
|
|
304
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
|
+
|
|
305
301
|
module.exports = {
|
|
306
302
|
throwIfModuleInterfaceIsMisnamed,
|
|
307
303
|
throwIfUnsupportedFunctionReturnTypeAnnotationParserError,
|
|
@@ -319,4 +315,5 @@ module.exports = {
|
|
|
319
315
|
throwIfIncorrectModuleRegistryCallArgument,
|
|
320
316
|
throwIfPartialNotAnnotatingTypeParameter,
|
|
321
317
|
throwIfPartialWithMoreParameter,
|
|
318
|
+
throwIfMoreThanOneCodegenNativecommands,
|
|
322
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,68 +10,6 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
function ownKeys(object, enumerableOnly) {
|
|
14
|
-
var keys = Object.keys(object);
|
|
15
|
-
if (Object.getOwnPropertySymbols) {
|
|
16
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
17
|
-
enumerableOnly &&
|
|
18
|
-
(symbols = symbols.filter(function (sym) {
|
|
19
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
20
|
-
})),
|
|
21
|
-
keys.push.apply(keys, symbols);
|
|
22
|
-
}
|
|
23
|
-
return keys;
|
|
24
|
-
}
|
|
25
|
-
function _objectSpread(target) {
|
|
26
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
27
|
-
var source = null != arguments[i] ? arguments[i] : {};
|
|
28
|
-
i % 2
|
|
29
|
-
? ownKeys(Object(source), !0).forEach(function (key) {
|
|
30
|
-
_defineProperty(target, key, source[key]);
|
|
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
13
|
const _require = require('./commands'),
|
|
76
14
|
getCommands = _require.getCommands;
|
|
77
15
|
const _require2 = require('./events'),
|
|
@@ -79,45 +17,27 @@ const _require2 = require('./events'),
|
|
|
79
17
|
const _require3 = require('./extends'),
|
|
80
18
|
getExtendsProps = _require3.getExtendsProps,
|
|
81
19
|
removeKnownExtends = _require3.removeKnownExtends;
|
|
82
|
-
const _require4 = require('./
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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;
|
|
89
32
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
function findComponentConfig(ast) {
|
|
33
|
+
// $FlowFixMe[signature-verification-failure] there's no flowtype for AST
|
|
34
|
+
function findComponentConfig(ast, parser) {
|
|
93
35
|
const foundConfigs = [];
|
|
94
36
|
const defaultExports = ast.body.filter(
|
|
95
37
|
node => node.type === 'ExportDefaultDeclaration',
|
|
96
38
|
);
|
|
97
39
|
defaultExports.forEach(statement => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
// codegenNativeComponent can be nested inside a cast
|
|
101
|
-
// expression so we need to go one level deeper
|
|
102
|
-
if (declaration.type === 'TypeCastExpression') {
|
|
103
|
-
declaration = declaration.expression;
|
|
104
|
-
}
|
|
105
|
-
try {
|
|
106
|
-
if (declaration.callee.name === 'codegenNativeComponent') {
|
|
107
|
-
const typeArgumentParams = declaration.typeArguments.params;
|
|
108
|
-
const funcArgumentParams = declaration.arguments;
|
|
109
|
-
const nativeComponentType = {
|
|
110
|
-
propsTypeName: typeArgumentParams[0].id.name,
|
|
111
|
-
componentName: funcArgumentParams[0].value,
|
|
112
|
-
};
|
|
113
|
-
if (funcArgumentParams.length > 1) {
|
|
114
|
-
nativeComponentType.optionsExpression = funcArgumentParams[1];
|
|
115
|
-
}
|
|
116
|
-
foundConfigs.push(nativeComponentType);
|
|
117
|
-
}
|
|
118
|
-
} catch (e) {
|
|
119
|
-
// ignore
|
|
120
|
-
}
|
|
40
|
+
findNativeComponentType(statement, foundConfigs, parser);
|
|
121
41
|
});
|
|
122
42
|
if (foundConfigs.length === 0) {
|
|
123
43
|
throw new Error('Could not find component config for native component');
|
|
@@ -161,23 +81,8 @@ function findComponentConfig(ast) {
|
|
|
161
81
|
};
|
|
162
82
|
})
|
|
163
83
|
.filter(Boolean);
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
return _objectSpread(
|
|
168
|
-
_objectSpread({}, foundConfig),
|
|
169
|
-
{},
|
|
170
|
-
{
|
|
171
|
-
commandTypeName:
|
|
172
|
-
commandsTypeNames[0] == null
|
|
173
|
-
? null
|
|
174
|
-
: commandsTypeNames[0].commandTypeName,
|
|
175
|
-
commandOptionsExpression:
|
|
176
|
-
commandsTypeNames[0] == null
|
|
177
|
-
? null
|
|
178
|
-
: commandsTypeNames[0].commandOptionsExpression,
|
|
179
|
-
},
|
|
180
|
-
);
|
|
84
|
+
throwIfMoreThanOneCodegenNativecommands(commandsTypeNames);
|
|
85
|
+
return createComponentConfig(foundConfig, commandsTypeNames);
|
|
181
86
|
}
|
|
182
87
|
function getCommandProperties(
|
|
183
88
|
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
|
|
@@ -228,7 +133,7 @@ function getCommandProperties(
|
|
|
228
133
|
|
|
229
134
|
// $FlowFixMe[signature-verification-failure] there's no flowtype for AST
|
|
230
135
|
function buildComponentSchema(ast, parser) {
|
|
231
|
-
const _findComponentConfig = findComponentConfig(ast),
|
|
136
|
+
const _findComponentConfig = findComponentConfig(ast, parser),
|
|
232
137
|
componentName = _findComponentConfig.componentName,
|
|
233
138
|
propsTypeName = _findComponentConfig.propsTypeName,
|
|
234
139
|
commandTypeName = _findComponentConfig.commandTypeName,
|
|
@@ -11,51 +11,32 @@
|
|
|
11
11
|
'use strict';
|
|
12
12
|
import type {Parser} from '../../parser';
|
|
13
13
|
import type {TypeDeclarationMap} from '../../utils';
|
|
14
|
-
import type {CommandOptions} from '
|
|
14
|
+
import type {CommandOptions} from '../../parsers-commons';
|
|
15
15
|
import type {ComponentSchemaBuilderConfig} from '../../schema.js';
|
|
16
16
|
|
|
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(
|
|
@@ -190,7 +159,7 @@ function buildComponentSchema(
|
|
|
190
159
|
commandTypeName,
|
|
191
160
|
commandOptionsExpression,
|
|
192
161
|
optionsExpression,
|
|
193
|
-
} = findComponentConfig(ast);
|
|
162
|
+
} = findComponentConfig(ast, parser);
|
|
194
163
|
|
|
195
164
|
const types = parser.getTypes(ast);
|
|
196
165
|
|
|
@@ -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');
|