@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
|
@@ -18,19 +18,24 @@ import type {
|
|
|
18
18
|
NativeModuleParamTypeAnnotation,
|
|
19
19
|
NativeModuleEnumMembers,
|
|
20
20
|
NativeModuleEnumMemberType,
|
|
21
|
+
NativeModuleAliasMap,
|
|
22
|
+
NativeModuleEnumMap,
|
|
21
23
|
} from '../../CodegenSchema';
|
|
22
24
|
import type {ParserType} from '../errors';
|
|
23
25
|
import type {Parser} from '../parser';
|
|
24
|
-
import type {TypeDeclarationMap} from '../utils';
|
|
26
|
+
import type {ParserErrorCapturer, TypeDeclarationMap} from '../utils';
|
|
27
|
+
|
|
28
|
+
const {typeScriptTranslateTypeAnnotation} = require('./modules');
|
|
25
29
|
|
|
26
30
|
// $FlowFixMe[untyped-import] Use flow-types for @babel/parser
|
|
27
31
|
const babelParser = require('@babel/parser');
|
|
28
32
|
|
|
29
33
|
const {buildSchema} = require('../parsers-commons');
|
|
30
|
-
const {Visitor} = require('
|
|
34
|
+
const {Visitor} = require('../parsers-primitives');
|
|
31
35
|
const {buildComponentSchema} = require('./components');
|
|
32
36
|
const {wrapComponentSchema} = require('../schema.js');
|
|
33
|
-
const {buildModuleSchema} = require('
|
|
37
|
+
const {buildModuleSchema} = require('../parsers-commons.js');
|
|
38
|
+
const {resolveTypeAnnotation} = require('./utils');
|
|
34
39
|
|
|
35
40
|
const fs = require('fs');
|
|
36
41
|
|
|
@@ -62,7 +67,7 @@ class TypeScriptParser implements Parser {
|
|
|
62
67
|
}
|
|
63
68
|
|
|
64
69
|
nameForGenericTypeAnnotation(typeAnnotation: $FlowFixMe): string {
|
|
65
|
-
return typeAnnotation
|
|
70
|
+
return typeAnnotation?.typeName?.name;
|
|
66
71
|
}
|
|
67
72
|
|
|
68
73
|
checkIfInvalidModule(typeArguments: $FlowFixMe): boolean {
|
|
@@ -103,6 +108,8 @@ class TypeScriptParser implements Parser {
|
|
|
103
108
|
buildModuleSchema,
|
|
104
109
|
Visitor,
|
|
105
110
|
this,
|
|
111
|
+
resolveTypeAnnotation,
|
|
112
|
+
typeScriptTranslateTypeAnnotation,
|
|
106
113
|
);
|
|
107
114
|
}
|
|
108
115
|
|
|
@@ -203,6 +210,10 @@ class TypeScriptParser implements Parser {
|
|
|
203
210
|
);
|
|
204
211
|
}
|
|
205
212
|
|
|
213
|
+
isGenericTypeAnnotation(type: $FlowFixMe): boolean {
|
|
214
|
+
return type === 'TSTypeReference';
|
|
215
|
+
}
|
|
216
|
+
|
|
206
217
|
extractAnnotatedElement(
|
|
207
218
|
typeAnnotation: $FlowFixMe,
|
|
208
219
|
types: TypeDeclarationMap,
|
|
@@ -239,7 +250,86 @@ class TypeScriptParser implements Parser {
|
|
|
239
250
|
return types;
|
|
240
251
|
}, {});
|
|
241
252
|
}
|
|
253
|
+
|
|
254
|
+
callExpressionTypeParameters(callExpression: $FlowFixMe): $FlowFixMe | null {
|
|
255
|
+
return callExpression.typeParameters || null;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
computePartialProperties(
|
|
259
|
+
properties: Array<$FlowFixMe>,
|
|
260
|
+
hasteModuleName: string,
|
|
261
|
+
types: TypeDeclarationMap,
|
|
262
|
+
aliasMap: {...NativeModuleAliasMap},
|
|
263
|
+
enumMap: {...NativeModuleEnumMap},
|
|
264
|
+
tryParse: ParserErrorCapturer,
|
|
265
|
+
cxxOnly: boolean,
|
|
266
|
+
): Array<$FlowFixMe> {
|
|
267
|
+
return properties.map(prop => {
|
|
268
|
+
return {
|
|
269
|
+
name: prop.key.name,
|
|
270
|
+
optional: true,
|
|
271
|
+
typeAnnotation: typeScriptTranslateTypeAnnotation(
|
|
272
|
+
hasteModuleName,
|
|
273
|
+
prop.typeAnnotation.typeAnnotation,
|
|
274
|
+
types,
|
|
275
|
+
aliasMap,
|
|
276
|
+
enumMap,
|
|
277
|
+
tryParse,
|
|
278
|
+
cxxOnly,
|
|
279
|
+
this,
|
|
280
|
+
),
|
|
281
|
+
};
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
functionTypeAnnotation(propertyValueType: string): boolean {
|
|
286
|
+
return (
|
|
287
|
+
propertyValueType === 'TSFunctionType' ||
|
|
288
|
+
propertyValueType === 'TSMethodSignature'
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
getTypeArgumentParamsFromDeclaration(declaration: $FlowFixMe): $FlowFixMe {
|
|
293
|
+
return declaration.typeParameters.params;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// This FlowFixMe is supposed to refer to typeArgumentParams and funcArgumentParams of generated AST.
|
|
297
|
+
getNativeComponentType(
|
|
298
|
+
typeArgumentParams: $FlowFixMe,
|
|
299
|
+
funcArgumentParams: $FlowFixMe,
|
|
300
|
+
): {[string]: string} {
|
|
301
|
+
return {
|
|
302
|
+
propsTypeName: typeArgumentParams[0].typeName.name,
|
|
303
|
+
componentName: funcArgumentParams[0].value,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
getAnnotatedElementProperties(annotatedElement: $FlowFixMe): $FlowFixMe {
|
|
308
|
+
return annotatedElement.typeAnnotation.members;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
bodyProperties(typeAlias: TypeDeclarationMap): $ReadOnlyArray<$FlowFixMe> {
|
|
312
|
+
return typeAlias.body.body;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
convertKeywordToTypeAnnotation(keyword: string): string {
|
|
316
|
+
switch (keyword) {
|
|
317
|
+
case 'TSBooleanKeyword':
|
|
318
|
+
return 'BooleanTypeAnnotation';
|
|
319
|
+
case 'TSNumberKeyword':
|
|
320
|
+
return 'NumberTypeAnnotation';
|
|
321
|
+
case 'TSVoidKeyword':
|
|
322
|
+
return 'VoidTypeAnnotation';
|
|
323
|
+
case 'TSStringKeyword':
|
|
324
|
+
return 'StringTypeAnnotation';
|
|
325
|
+
case 'TSUnknownKeyword':
|
|
326
|
+
return 'MixedTypeAnnotation';
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return keyword;
|
|
330
|
+
}
|
|
242
331
|
}
|
|
332
|
+
|
|
243
333
|
module.exports = {
|
|
244
334
|
TypeScriptParser,
|
|
245
335
|
};
|
package/lib/parsers/utils.js
CHANGED
|
@@ -19,6 +19,7 @@ function extractNativeModuleName(filename) {
|
|
|
19
19
|
return path.basename(filename).split('.')[0];
|
|
20
20
|
}
|
|
21
21
|
function createParserErrorCapturer() {
|
|
22
|
+
// $FlowFixMe[missing-empty-array-annot]
|
|
22
23
|
const errors = [];
|
|
23
24
|
function guard(fn) {
|
|
24
25
|
try {
|
|
@@ -27,10 +28,13 @@ function createParserErrorCapturer() {
|
|
|
27
28
|
if (!(error instanceof ParserError)) {
|
|
28
29
|
throw error;
|
|
29
30
|
}
|
|
31
|
+
// $FlowFixMe[incompatible-call]
|
|
30
32
|
errors.push(error);
|
|
31
33
|
return null;
|
|
32
34
|
}
|
|
33
35
|
}
|
|
36
|
+
|
|
37
|
+
// $FlowFixMe[incompatible-return]
|
|
34
38
|
return [errors, guard];
|
|
35
39
|
}
|
|
36
40
|
function verifyPlatforms(hasteModuleName, moduleName) {
|
|
@@ -38,6 +38,7 @@ function createParserErrorCapturer(): [
|
|
|
38
38
|
Array<ParserError>,
|
|
39
39
|
ParserErrorCapturer,
|
|
40
40
|
] {
|
|
41
|
+
// $FlowFixMe[missing-empty-array-annot]
|
|
41
42
|
const errors = [];
|
|
42
43
|
function guard<T>(fn: () => T): ?T {
|
|
43
44
|
try {
|
|
@@ -46,12 +47,14 @@ function createParserErrorCapturer(): [
|
|
|
46
47
|
if (!(error instanceof ParserError)) {
|
|
47
48
|
throw error;
|
|
48
49
|
}
|
|
50
|
+
// $FlowFixMe[incompatible-call]
|
|
49
51
|
errors.push(error);
|
|
50
52
|
|
|
51
53
|
return null;
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
56
|
|
|
57
|
+
// $FlowFixMe[incompatible-return]
|
|
55
58
|
return [errors, guard];
|
|
56
59
|
}
|
|
57
60
|
|
package/package.json
CHANGED
|
@@ -1,37 +0,0 @@
|
|
|
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
|
-
*/
|
|
10
|
-
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
const _require = require('../utils'),
|
|
14
|
-
isModuleRegistryCall = _require.isModuleRegistryCall;
|
|
15
|
-
function Visitor(infoMap) {
|
|
16
|
-
return {
|
|
17
|
-
CallExpression(node) {
|
|
18
|
-
if (
|
|
19
|
-
node.callee.type === 'Identifier' &&
|
|
20
|
-
node.callee.name === 'codegenNativeComponent'
|
|
21
|
-
) {
|
|
22
|
-
infoMap.isComponent = true;
|
|
23
|
-
}
|
|
24
|
-
if (isModuleRegistryCall(node)) {
|
|
25
|
-
infoMap.isModule = true;
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
InterfaceExtends(node) {
|
|
29
|
-
if (node.id.name === 'TurboModule') {
|
|
30
|
-
infoMap.isModule = true;
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
module.exports = {
|
|
36
|
-
Visitor,
|
|
37
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
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
|
-
*/
|
|
10
|
-
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
const {isModuleRegistryCall} = require('../utils');
|
|
14
|
-
|
|
15
|
-
function Visitor(infoMap: {isComponent: boolean, isModule: boolean}): {
|
|
16
|
-
[type: string]: (node: $FlowFixMe) => void,
|
|
17
|
-
} {
|
|
18
|
-
return {
|
|
19
|
-
CallExpression(node: $FlowFixMe) {
|
|
20
|
-
if (
|
|
21
|
-
node.callee.type === 'Identifier' &&
|
|
22
|
-
node.callee.name === 'codegenNativeComponent'
|
|
23
|
-
) {
|
|
24
|
-
infoMap.isComponent = true;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (isModuleRegistryCall(node)) {
|
|
28
|
-
infoMap.isModule = true;
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
InterfaceExtends(node: $FlowFixMe) {
|
|
32
|
-
if (node.id.name === 'TurboModule') {
|
|
33
|
-
infoMap.isModule = true;
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
module.exports = {
|
|
40
|
-
Visitor,
|
|
41
|
-
};
|
|
@@ -1,72 +0,0 @@
|
|
|
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
|
-
*/
|
|
10
|
-
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
// $FlowFixMe[unclear-type] there's no flowtype for ASTs
|
|
14
|
-
|
|
15
|
-
function getCommandOptions(commandOptionsExpression) {
|
|
16
|
-
if (commandOptionsExpression == null) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
let foundOptions;
|
|
20
|
-
try {
|
|
21
|
-
foundOptions = commandOptionsExpression.properties.reduce(
|
|
22
|
-
(options, prop) => {
|
|
23
|
-
options[prop.key.name] = (
|
|
24
|
-
(prop && prop.value && prop.value.elements) ||
|
|
25
|
-
[]
|
|
26
|
-
).map(element => element && element.value);
|
|
27
|
-
return options;
|
|
28
|
-
},
|
|
29
|
-
{},
|
|
30
|
-
);
|
|
31
|
-
} catch (e) {
|
|
32
|
-
throw new Error(
|
|
33
|
-
'Failed to parse command options, please check that they are defined correctly',
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
return foundOptions;
|
|
37
|
-
}
|
|
38
|
-
function getOptions(optionsExpression) {
|
|
39
|
-
if (!optionsExpression) {
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
let foundOptions;
|
|
43
|
-
try {
|
|
44
|
-
foundOptions = optionsExpression.properties.reduce((options, prop) => {
|
|
45
|
-
if (prop.value.type === 'ArrayExpression') {
|
|
46
|
-
options[prop.key.name] = prop.value.elements.map(
|
|
47
|
-
element => element.value,
|
|
48
|
-
);
|
|
49
|
-
} else {
|
|
50
|
-
options[prop.key.name] = prop.value.value;
|
|
51
|
-
}
|
|
52
|
-
return options;
|
|
53
|
-
}, {});
|
|
54
|
-
} catch (e) {
|
|
55
|
-
throw new Error(
|
|
56
|
-
'Failed to parse codegen options, please check that they are defined correctly',
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
if (
|
|
60
|
-
foundOptions.paperComponentName &&
|
|
61
|
-
foundOptions.paperComponentNameDeprecated
|
|
62
|
-
) {
|
|
63
|
-
throw new Error(
|
|
64
|
-
'Failed to parse codegen options, cannot use both paperComponentName and paperComponentNameDeprecated',
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
return foundOptions;
|
|
68
|
-
}
|
|
69
|
-
module.exports = {
|
|
70
|
-
getCommandOptions,
|
|
71
|
-
getOptions,
|
|
72
|
-
};
|
|
@@ -1,87 +0,0 @@
|
|
|
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
|
-
*/
|
|
10
|
-
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
import type {OptionsShape} from '../../../CodegenSchema.js';
|
|
14
|
-
|
|
15
|
-
// $FlowFixMe[unclear-type] there's no flowtype for ASTs
|
|
16
|
-
type OptionsAST = Object;
|
|
17
|
-
|
|
18
|
-
export type CommandOptions = $ReadOnly<{
|
|
19
|
-
supportedCommands: $ReadOnlyArray<string>,
|
|
20
|
-
}>;
|
|
21
|
-
|
|
22
|
-
function getCommandOptions(
|
|
23
|
-
commandOptionsExpression: OptionsAST,
|
|
24
|
-
): ?CommandOptions {
|
|
25
|
-
if (commandOptionsExpression == null) {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
let foundOptions;
|
|
30
|
-
try {
|
|
31
|
-
foundOptions = commandOptionsExpression.properties.reduce(
|
|
32
|
-
(options, prop) => {
|
|
33
|
-
options[prop.key.name] = (
|
|
34
|
-
(prop && prop.value && prop.value.elements) ||
|
|
35
|
-
[]
|
|
36
|
-
).map(element => element && element.value);
|
|
37
|
-
return options;
|
|
38
|
-
},
|
|
39
|
-
{},
|
|
40
|
-
);
|
|
41
|
-
} catch (e) {
|
|
42
|
-
throw new Error(
|
|
43
|
-
'Failed to parse command options, please check that they are defined correctly',
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return foundOptions;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function getOptions(optionsExpression: OptionsAST): ?OptionsShape {
|
|
51
|
-
if (!optionsExpression) {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
let foundOptions;
|
|
55
|
-
try {
|
|
56
|
-
foundOptions = optionsExpression.properties.reduce((options, prop) => {
|
|
57
|
-
if (prop.value.type === 'ArrayExpression') {
|
|
58
|
-
options[prop.key.name] = prop.value.elements.map(
|
|
59
|
-
element => element.value,
|
|
60
|
-
);
|
|
61
|
-
} else {
|
|
62
|
-
options[prop.key.name] = prop.value.value;
|
|
63
|
-
}
|
|
64
|
-
return options;
|
|
65
|
-
}, {});
|
|
66
|
-
} catch (e) {
|
|
67
|
-
throw new Error(
|
|
68
|
-
'Failed to parse codegen options, please check that they are defined correctly',
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (
|
|
73
|
-
foundOptions.paperComponentName &&
|
|
74
|
-
foundOptions.paperComponentNameDeprecated
|
|
75
|
-
) {
|
|
76
|
-
throw new Error(
|
|
77
|
-
'Failed to parse codegen options, cannot use both paperComponentName and paperComponentNameDeprecated',
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return foundOptions;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
module.exports = {
|
|
85
|
-
getCommandOptions,
|
|
86
|
-
getOptions,
|
|
87
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
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
|
-
*/
|
|
10
|
-
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
const _require = require('../utils'),
|
|
14
|
-
isModuleRegistryCall = _require.isModuleRegistryCall;
|
|
15
|
-
function Visitor(infoMap) {
|
|
16
|
-
return {
|
|
17
|
-
CallExpression(node) {
|
|
18
|
-
if (
|
|
19
|
-
node.callee.type === 'Identifier' &&
|
|
20
|
-
node.callee.name === 'codegenNativeComponent'
|
|
21
|
-
) {
|
|
22
|
-
infoMap.isComponent = true;
|
|
23
|
-
}
|
|
24
|
-
if (isModuleRegistryCall(node)) {
|
|
25
|
-
infoMap.isModule = true;
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
TSInterfaceDeclaration(node) {
|
|
29
|
-
if (
|
|
30
|
-
Array.isArray(node.extends) &&
|
|
31
|
-
node.extends.some(
|
|
32
|
-
extension => extension.expression.name === 'TurboModule',
|
|
33
|
-
)
|
|
34
|
-
) {
|
|
35
|
-
infoMap.isModule = true;
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
module.exports = {
|
|
41
|
-
Visitor,
|
|
42
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
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
|
-
*/
|
|
10
|
-
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
const {isModuleRegistryCall} = require('../utils');
|
|
14
|
-
|
|
15
|
-
function Visitor(infoMap: {isComponent: boolean, isModule: boolean}): {
|
|
16
|
-
[type: string]: (node: $FlowFixMe) => void,
|
|
17
|
-
} {
|
|
18
|
-
return {
|
|
19
|
-
CallExpression(node: $FlowFixMe) {
|
|
20
|
-
if (
|
|
21
|
-
node.callee.type === 'Identifier' &&
|
|
22
|
-
node.callee.name === 'codegenNativeComponent'
|
|
23
|
-
) {
|
|
24
|
-
infoMap.isComponent = true;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (isModuleRegistryCall(node)) {
|
|
28
|
-
infoMap.isModule = true;
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
TSInterfaceDeclaration(node: $FlowFixMe) {
|
|
33
|
-
if (
|
|
34
|
-
Array.isArray(node.extends) &&
|
|
35
|
-
node.extends.some(
|
|
36
|
-
extension => extension.expression.name === 'TurboModule',
|
|
37
|
-
)
|
|
38
|
-
) {
|
|
39
|
-
infoMap.isModule = true;
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
module.exports = {
|
|
46
|
-
Visitor,
|
|
47
|
-
};
|
|
@@ -1,72 +0,0 @@
|
|
|
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
|
-
*/
|
|
10
|
-
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
// $FlowFixMe[unclear-type] TODO(T108222691): Use flow-types for @babel/parser
|
|
14
|
-
|
|
15
|
-
function getCommandOptions(commandOptionsExpression) {
|
|
16
|
-
if (commandOptionsExpression == null) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
let foundOptions;
|
|
20
|
-
try {
|
|
21
|
-
foundOptions = commandOptionsExpression.properties.reduce(
|
|
22
|
-
(options, prop) => {
|
|
23
|
-
options[prop.key.name] = (
|
|
24
|
-
(prop && prop.value && prop.value.elements) ||
|
|
25
|
-
[]
|
|
26
|
-
).map(element => element && element.value);
|
|
27
|
-
return options;
|
|
28
|
-
},
|
|
29
|
-
{},
|
|
30
|
-
);
|
|
31
|
-
} catch (e) {
|
|
32
|
-
throw new Error(
|
|
33
|
-
'Failed to parse command options, please check that they are defined correctly',
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
return foundOptions;
|
|
37
|
-
}
|
|
38
|
-
function getOptions(optionsExpression) {
|
|
39
|
-
if (!optionsExpression) {
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
let foundOptions;
|
|
43
|
-
try {
|
|
44
|
-
foundOptions = optionsExpression.properties.reduce((options, prop) => {
|
|
45
|
-
if (prop.value.type === 'ArrayExpression') {
|
|
46
|
-
options[prop.key.name] = prop.value.elements.map(
|
|
47
|
-
element => element.value,
|
|
48
|
-
);
|
|
49
|
-
} else {
|
|
50
|
-
options[prop.key.name] = prop.value.value;
|
|
51
|
-
}
|
|
52
|
-
return options;
|
|
53
|
-
}, {});
|
|
54
|
-
} catch (e) {
|
|
55
|
-
throw new Error(
|
|
56
|
-
'Failed to parse codegen options, please check that they are defined correctly',
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
if (
|
|
60
|
-
foundOptions.paperComponentName &&
|
|
61
|
-
foundOptions.paperComponentNameDeprecated
|
|
62
|
-
) {
|
|
63
|
-
throw new Error(
|
|
64
|
-
'Failed to parse codegen options, cannot use both paperComponentName and paperComponentNameDeprecated',
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
return foundOptions;
|
|
68
|
-
}
|
|
69
|
-
module.exports = {
|
|
70
|
-
getCommandOptions,
|
|
71
|
-
getOptions,
|
|
72
|
-
};
|
|
@@ -1,87 +0,0 @@
|
|
|
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
|
-
*/
|
|
10
|
-
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
import type {OptionsShape} from '../../../CodegenSchema.js';
|
|
14
|
-
|
|
15
|
-
// $FlowFixMe[unclear-type] TODO(T108222691): Use flow-types for @babel/parser
|
|
16
|
-
type OptionsAST = Object;
|
|
17
|
-
|
|
18
|
-
export type CommandOptions = $ReadOnly<{
|
|
19
|
-
supportedCommands: $ReadOnlyArray<string>,
|
|
20
|
-
}>;
|
|
21
|
-
|
|
22
|
-
function getCommandOptions(
|
|
23
|
-
commandOptionsExpression: OptionsAST,
|
|
24
|
-
): ?CommandOptions {
|
|
25
|
-
if (commandOptionsExpression == null) {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
let foundOptions;
|
|
30
|
-
try {
|
|
31
|
-
foundOptions = commandOptionsExpression.properties.reduce(
|
|
32
|
-
(options, prop) => {
|
|
33
|
-
options[prop.key.name] = (
|
|
34
|
-
(prop && prop.value && prop.value.elements) ||
|
|
35
|
-
[]
|
|
36
|
-
).map(element => element && element.value);
|
|
37
|
-
return options;
|
|
38
|
-
},
|
|
39
|
-
{},
|
|
40
|
-
);
|
|
41
|
-
} catch (e) {
|
|
42
|
-
throw new Error(
|
|
43
|
-
'Failed to parse command options, please check that they are defined correctly',
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return foundOptions;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function getOptions(optionsExpression: OptionsAST): ?OptionsShape {
|
|
51
|
-
if (!optionsExpression) {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
let foundOptions;
|
|
55
|
-
try {
|
|
56
|
-
foundOptions = optionsExpression.properties.reduce((options, prop) => {
|
|
57
|
-
if (prop.value.type === 'ArrayExpression') {
|
|
58
|
-
options[prop.key.name] = prop.value.elements.map(
|
|
59
|
-
element => element.value,
|
|
60
|
-
);
|
|
61
|
-
} else {
|
|
62
|
-
options[prop.key.name] = prop.value.value;
|
|
63
|
-
}
|
|
64
|
-
return options;
|
|
65
|
-
}, {});
|
|
66
|
-
} catch (e) {
|
|
67
|
-
throw new Error(
|
|
68
|
-
'Failed to parse codegen options, please check that they are defined correctly',
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (
|
|
73
|
-
foundOptions.paperComponentName &&
|
|
74
|
-
foundOptions.paperComponentNameDeprecated
|
|
75
|
-
) {
|
|
76
|
-
throw new Error(
|
|
77
|
-
'Failed to parse codegen options, cannot use both paperComponentName and paperComponentNameDeprecated',
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return foundOptions;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
module.exports = {
|
|
85
|
-
getCommandOptions,
|
|
86
|
-
getOptions,
|
|
87
|
-
};
|