@react-native/codegen 0.72.3 → 0.73.0
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/GenerateEventEmitterCpp.js +33 -44
- package/lib/generators/components/GenerateEventEmitterCpp.js.flow +35 -44
- package/lib/generators/components/GenerateEventEmitterH.js +0 -2
- package/lib/generators/components/GenerateEventEmitterH.js.flow +0 -2
- 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/GenerateModuleCpp.js +3 -3
- package/lib/generators/modules/GenerateModuleCpp.js.flow +3 -3
- package/lib/generators/modules/GenerateModuleJavaSpec.js +1 -2
- package/lib/generators/modules/GenerateModuleJavaSpec.js.flow +1 -2
- 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 +35 -168
- package/lib/parsers/flow/components/index.js.flow +33 -107
- 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 +51 -327
- package/lib/parsers/flow/modules/index.js.flow +34 -258
- package/lib/parsers/flow/parser.js +84 -13
- package/lib/parsers/flow/parser.js.flow +80 -4
- package/lib/parsers/parser.d.ts +2 -2
- package/lib/parsers/parser.js.flow +84 -3
- package/lib/parsers/parserMock.js +53 -0
- package/lib/parsers/parserMock.js.flow +64 -1
- package/lib/parsers/parsers-commons.js +397 -4
- package/lib/parsers/parsers-commons.js.flow +391 -4
- package/lib/parsers/parsers-primitives.js +121 -3
- package/lib/parsers/parsers-primitives.js.flow +134 -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 +37 -170
- package/lib/parsers/typescript/components/index.js.flow +33 -109
- package/lib/parsers/typescript/modules/index.js +113 -441
- package/lib/parsers/typescript/modules/index.js.flow +100 -309
- package/lib/parsers/typescript/parser.js +97 -13
- package/lib/parsers/typescript/parser.js.flow +94 -4
- 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/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
|
@@ -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,30 @@ 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
|
+
propertyNames = _require7.propertyNames,
|
|
31
|
+
getCommandOptions = _require7.getCommandOptions,
|
|
32
|
+
getOptions = _require7.getOptions,
|
|
33
|
+
getCommandTypeNameAndOptionsExpression =
|
|
34
|
+
_require7.getCommandTypeNameAndOptionsExpression;
|
|
89
35
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
function findComponentConfig(ast) {
|
|
36
|
+
// $FlowFixMe[signature-verification-failure] there's no flowtype for AST
|
|
37
|
+
function findComponentConfig(ast, parser) {
|
|
93
38
|
const foundConfigs = [];
|
|
94
39
|
const defaultExports = ast.body.filter(
|
|
95
40
|
node => node.type === 'ExportDefaultDeclaration',
|
|
96
41
|
);
|
|
97
42
|
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
|
-
}
|
|
43
|
+
findNativeComponentType(statement, foundConfigs, parser);
|
|
121
44
|
});
|
|
122
45
|
if (foundConfigs.length === 0) {
|
|
123
46
|
throw new Error('Could not find component config for native component');
|
|
@@ -130,82 +53,33 @@ function findComponentConfig(ast) {
|
|
|
130
53
|
node => node.type === 'ExportNamedDeclaration',
|
|
131
54
|
);
|
|
132
55
|
const commandsTypeNames = namedExports
|
|
133
|
-
.map(statement =>
|
|
134
|
-
let callExpression;
|
|
135
|
-
let calleeName;
|
|
136
|
-
try {
|
|
137
|
-
callExpression = statement.declaration.declarations[0].init;
|
|
138
|
-
calleeName = callExpression.callee.name;
|
|
139
|
-
} catch (e) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
if (calleeName !== 'codegenNativeCommands') {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// const statement.declaration.declarations[0].init
|
|
147
|
-
if (callExpression.arguments.length !== 1) {
|
|
148
|
-
throw new Error(
|
|
149
|
-
'codegenNativeCommands must be passed options including the supported commands',
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
const typeArgumentParam = callExpression.typeArguments.params[0];
|
|
153
|
-
if (typeArgumentParam.type !== 'GenericTypeAnnotation') {
|
|
154
|
-
throw new Error(
|
|
155
|
-
"codegenNativeCommands doesn't support inline definitions. Specify a file local type alias",
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
return {
|
|
159
|
-
commandTypeName: typeArgumentParam.id.name,
|
|
160
|
-
commandOptionsExpression: callExpression.arguments[0],
|
|
161
|
-
};
|
|
162
|
-
})
|
|
56
|
+
.map(statement => getCommandTypeNameAndOptionsExpression(statement, parser))
|
|
163
57
|
.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
|
-
);
|
|
58
|
+
throwIfMoreThanOneCodegenNativecommands(commandsTypeNames);
|
|
59
|
+
return createComponentConfig(foundConfig, commandsTypeNames);
|
|
181
60
|
}
|
|
182
|
-
function getCommandProperties(
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
types,
|
|
187
|
-
commandOptions,
|
|
188
|
-
) {
|
|
61
|
+
function getCommandProperties(ast, parser) {
|
|
62
|
+
const _findComponentConfig = findComponentConfig(ast, parser),
|
|
63
|
+
commandTypeName = _findComponentConfig.commandTypeName,
|
|
64
|
+
commandOptionsExpression = _findComponentConfig.commandOptionsExpression;
|
|
189
65
|
if (commandTypeName == null) {
|
|
190
66
|
return [];
|
|
191
67
|
}
|
|
68
|
+
const types = parser.getTypes(ast);
|
|
192
69
|
const typeAlias = types[commandTypeName];
|
|
193
70
|
if (typeAlias.type !== 'InterfaceDeclaration') {
|
|
194
71
|
throw new Error(
|
|
195
72
|
`The type argument for codegenNativeCommands must be an interface, received ${typeAlias.type}`,
|
|
196
73
|
);
|
|
197
74
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
properties = typeAlias.body.properties;
|
|
201
|
-
} catch (e) {
|
|
75
|
+
const properties = parser.bodyProperties(typeAlias);
|
|
76
|
+
if (!properties) {
|
|
202
77
|
throw new Error(
|
|
203
78
|
`Failed to find type definition for "${commandTypeName}", please check that you have a valid codegen flow file`,
|
|
204
79
|
);
|
|
205
80
|
}
|
|
206
|
-
const flowPropertyNames = properties
|
|
207
|
-
|
|
208
|
-
.filter(Boolean);
|
|
81
|
+
const flowPropertyNames = propertyNames(properties);
|
|
82
|
+
const commandOptions = getCommandOptions(commandOptionsExpression);
|
|
209
83
|
if (commandOptions == null || commandOptions.supportedCommands == null) {
|
|
210
84
|
throw new Error(
|
|
211
85
|
'codegenNativeCommands must be given an options object with supportedCommands array',
|
|
@@ -228,20 +102,13 @@ function getCommandProperties(
|
|
|
228
102
|
|
|
229
103
|
// $FlowFixMe[signature-verification-failure] there's no flowtype for AST
|
|
230
104
|
function buildComponentSchema(ast, parser) {
|
|
231
|
-
const
|
|
232
|
-
componentName =
|
|
233
|
-
propsTypeName =
|
|
234
|
-
|
|
235
|
-
commandOptionsExpression = _findComponentConfig.commandOptionsExpression,
|
|
236
|
-
optionsExpression = _findComponentConfig.optionsExpression;
|
|
105
|
+
const _findComponentConfig2 = findComponentConfig(ast, parser),
|
|
106
|
+
componentName = _findComponentConfig2.componentName,
|
|
107
|
+
propsTypeName = _findComponentConfig2.propsTypeName,
|
|
108
|
+
optionsExpression = _findComponentConfig2.optionsExpression;
|
|
237
109
|
const types = parser.getTypes(ast);
|
|
238
110
|
const propProperties = getProperties(propsTypeName, types);
|
|
239
|
-
const
|
|
240
|
-
const commandProperties = getCommandProperties(
|
|
241
|
-
commandTypeName,
|
|
242
|
-
types,
|
|
243
|
-
commandOptions,
|
|
244
|
-
);
|
|
111
|
+
const commandProperties = getCommandProperties(ast, parser);
|
|
245
112
|
const extendsProps = getExtendsProps(propProperties, types);
|
|
246
113
|
const options = getOptions(optionsExpression);
|
|
247
114
|
const nonExtendsProps = removeKnownExtends(propProperties, types);
|
|
@@ -10,52 +10,33 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
import type {Parser} from '../../parser';
|
|
13
|
-
import type {TypeDeclarationMap} from '../../utils';
|
|
14
|
-
import type {CommandOptions} from './options';
|
|
15
13
|
import type {ComponentSchemaBuilderConfig} from '../../schema.js';
|
|
16
14
|
|
|
17
15
|
const {getCommands} = require('./commands');
|
|
18
16
|
const {getEvents} = require('./events');
|
|
19
17
|
const {getExtendsProps, removeKnownExtends} = require('./extends');
|
|
20
|
-
const {getCommandOptions, getOptions} = require('./options');
|
|
21
18
|
const {getProps} = require('./props');
|
|
22
19
|
const {getProperties} = require('./componentsUtils.js');
|
|
20
|
+
const {throwIfMoreThanOneCodegenNativecommands} = require('../../error-utils');
|
|
21
|
+
const {
|
|
22
|
+
createComponentConfig,
|
|
23
|
+
findNativeComponentType,
|
|
24
|
+
propertyNames,
|
|
25
|
+
getCommandOptions,
|
|
26
|
+
getOptions,
|
|
27
|
+
getCommandTypeNameAndOptionsExpression,
|
|
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) {
|
|
@@ -72,69 +53,24 @@ function findComponentConfig(ast) {
|
|
|
72
53
|
);
|
|
73
54
|
|
|
74
55
|
const commandsTypeNames = namedExports
|
|
75
|
-
.map(statement =>
|
|
76
|
-
let callExpression;
|
|
77
|
-
let calleeName;
|
|
78
|
-
try {
|
|
79
|
-
callExpression = statement.declaration.declarations[0].init;
|
|
80
|
-
calleeName = callExpression.callee.name;
|
|
81
|
-
} catch (e) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (calleeName !== 'codegenNativeCommands') {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// const statement.declaration.declarations[0].init
|
|
90
|
-
if (callExpression.arguments.length !== 1) {
|
|
91
|
-
throw new Error(
|
|
92
|
-
'codegenNativeCommands must be passed options including the supported commands',
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const typeArgumentParam = callExpression.typeArguments.params[0];
|
|
97
|
-
|
|
98
|
-
if (typeArgumentParam.type !== 'GenericTypeAnnotation') {
|
|
99
|
-
throw new Error(
|
|
100
|
-
"codegenNativeCommands doesn't support inline definitions. Specify a file local type alias",
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return {
|
|
105
|
-
commandTypeName: typeArgumentParam.id.name,
|
|
106
|
-
commandOptionsExpression: callExpression.arguments[0],
|
|
107
|
-
};
|
|
108
|
-
})
|
|
56
|
+
.map(statement => getCommandTypeNameAndOptionsExpression(statement, parser))
|
|
109
57
|
.filter(Boolean);
|
|
110
58
|
|
|
111
|
-
|
|
112
|
-
throw new Error('codegenNativeCommands may only be called once in a file');
|
|
113
|
-
}
|
|
59
|
+
throwIfMoreThanOneCodegenNativecommands(commandsTypeNames);
|
|
114
60
|
|
|
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
|
-
};
|
|
61
|
+
return createComponentConfig(foundConfig, commandsTypeNames);
|
|
126
62
|
}
|
|
127
63
|
|
|
128
|
-
function getCommandProperties(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
) {
|
|
64
|
+
function getCommandProperties(ast: $FlowFixMe, parser: Parser) {
|
|
65
|
+
const {commandTypeName, commandOptionsExpression} = findComponentConfig(
|
|
66
|
+
ast,
|
|
67
|
+
parser,
|
|
68
|
+
);
|
|
69
|
+
|
|
135
70
|
if (commandTypeName == null) {
|
|
136
71
|
return [];
|
|
137
72
|
}
|
|
73
|
+
const types = parser.getTypes(ast);
|
|
138
74
|
|
|
139
75
|
const typeAlias = types[commandTypeName];
|
|
140
76
|
|
|
@@ -144,18 +80,16 @@ function getCommandProperties(
|
|
|
144
80
|
);
|
|
145
81
|
}
|
|
146
82
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
properties = typeAlias.body.properties;
|
|
150
|
-
} catch (e) {
|
|
83
|
+
const properties = parser.bodyProperties(typeAlias);
|
|
84
|
+
if (!properties) {
|
|
151
85
|
throw new Error(
|
|
152
86
|
`Failed to find type definition for "${commandTypeName}", please check that you have a valid codegen flow file`,
|
|
153
87
|
);
|
|
154
88
|
}
|
|
155
89
|
|
|
156
|
-
const flowPropertyNames = properties
|
|
157
|
-
|
|
158
|
-
|
|
90
|
+
const flowPropertyNames = propertyNames(properties);
|
|
91
|
+
|
|
92
|
+
const commandOptions = getCommandOptions(commandOptionsExpression);
|
|
159
93
|
|
|
160
94
|
if (commandOptions == null || commandOptions.supportedCommands == null) {
|
|
161
95
|
throw new Error(
|
|
@@ -184,24 +118,16 @@ function buildComponentSchema(
|
|
|
184
118
|
ast: $FlowFixMe,
|
|
185
119
|
parser: Parser,
|
|
186
120
|
): ComponentSchemaBuilderConfig {
|
|
187
|
-
const {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
commandOptionsExpression,
|
|
192
|
-
optionsExpression,
|
|
193
|
-
} = findComponentConfig(ast);
|
|
121
|
+
const {componentName, propsTypeName, optionsExpression} = findComponentConfig(
|
|
122
|
+
ast,
|
|
123
|
+
parser,
|
|
124
|
+
);
|
|
194
125
|
|
|
195
126
|
const types = parser.getTypes(ast);
|
|
196
127
|
|
|
197
128
|
const propProperties = getProperties(propsTypeName, types);
|
|
198
|
-
const commandOptions = getCommandOptions(commandOptionsExpression);
|
|
199
129
|
|
|
200
|
-
const commandProperties = getCommandProperties(
|
|
201
|
-
commandTypeName,
|
|
202
|
-
types,
|
|
203
|
-
commandOptions,
|
|
204
|
-
);
|
|
130
|
+
const commandProperties = getCommandProperties(ast, parser);
|
|
205
131
|
|
|
206
132
|
const extendsProps = getExtendsProps(propProperties, types);
|
|
207
133
|
const options = getOptions(optionsExpression);
|
|
@@ -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');
|