@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
|
@@ -11,53 +11,34 @@
|
|
|
11
11
|
'use strict';
|
|
12
12
|
import type {ExtendsPropsShape} from '../../../CodegenSchema.js';
|
|
13
13
|
import type {Parser} from '../../parser';
|
|
14
|
-
import type {TypeDeclarationMap} from '../../utils';
|
|
15
|
-
import type {CommandOptions} from './options';
|
|
16
14
|
import type {ComponentSchemaBuilderConfig} from '../../schema.js';
|
|
17
15
|
|
|
18
16
|
const {getCommands} = require('./commands');
|
|
19
17
|
const {getEvents} = require('./events');
|
|
20
18
|
const {categorizeProps} = require('./extends');
|
|
21
|
-
const {getCommandOptions, getOptions} = require('./options');
|
|
22
19
|
const {getProps} = require('./props');
|
|
23
20
|
const {getProperties} = require('./componentsUtils.js');
|
|
21
|
+
const {throwIfMoreThanOneCodegenNativecommands} = require('../../error-utils');
|
|
22
|
+
const {
|
|
23
|
+
createComponentConfig,
|
|
24
|
+
findNativeComponentType,
|
|
25
|
+
propertyNames,
|
|
26
|
+
getCommandOptions,
|
|
27
|
+
getOptions,
|
|
28
|
+
getCommandTypeNameAndOptionsExpression,
|
|
29
|
+
} = require('../../parsers-commons');
|
|
24
30
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const foundConfigs = [];
|
|
31
|
+
// $FlowFixMe[signature-verification-failure] TODO(T108222691): Use flow-types for @babel/parser
|
|
32
|
+
function findComponentConfig(ast: $FlowFixMe, parser: Parser) {
|
|
33
|
+
const foundConfigs: Array<{[string]: string}> = [];
|
|
29
34
|
|
|
30
35
|
const defaultExports = ast.body.filter(
|
|
31
36
|
node => node.type === 'ExportDefaultDeclaration',
|
|
32
37
|
);
|
|
33
38
|
|
|
34
|
-
defaultExports.forEach(statement =>
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// codegenNativeComponent can be nested inside a cast
|
|
38
|
-
// expression so we need to go one level deeper
|
|
39
|
-
if (declaration.type === 'TSAsExpression') {
|
|
40
|
-
declaration = declaration.expression;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
if (declaration.callee.name === 'codegenNativeComponent') {
|
|
45
|
-
const typeArgumentParams = declaration.typeParameters.params;
|
|
46
|
-
const funcArgumentParams = declaration.arguments;
|
|
47
|
-
|
|
48
|
-
const nativeComponentType: {[string]: string} = {
|
|
49
|
-
propsTypeName: typeArgumentParams[0].typeName.name,
|
|
50
|
-
componentName: funcArgumentParams[0].value,
|
|
51
|
-
};
|
|
52
|
-
if (funcArgumentParams.length > 1) {
|
|
53
|
-
nativeComponentType.optionsExpression = funcArgumentParams[1];
|
|
54
|
-
}
|
|
55
|
-
foundConfigs.push(nativeComponentType);
|
|
56
|
-
}
|
|
57
|
-
} catch (e) {
|
|
58
|
-
// ignore
|
|
59
|
-
}
|
|
60
|
-
});
|
|
39
|
+
defaultExports.forEach(statement =>
|
|
40
|
+
findNativeComponentType(statement, foundConfigs, parser),
|
|
41
|
+
);
|
|
61
42
|
|
|
62
43
|
if (foundConfigs.length === 0) {
|
|
63
44
|
throw new Error('Could not find component config for native component');
|
|
@@ -73,70 +54,24 @@ function findComponentConfig(ast) {
|
|
|
73
54
|
);
|
|
74
55
|
|
|
75
56
|
const commandsTypeNames = namedExports
|
|
76
|
-
.map(statement =>
|
|
77
|
-
let callExpression;
|
|
78
|
-
let calleeName;
|
|
79
|
-
try {
|
|
80
|
-
callExpression = statement.declaration.declarations[0].init;
|
|
81
|
-
calleeName = callExpression.callee.name;
|
|
82
|
-
} catch (e) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (calleeName !== 'codegenNativeCommands') {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// const statement.declaration.declarations[0].init
|
|
91
|
-
if (callExpression.arguments.length !== 1) {
|
|
92
|
-
throw new Error(
|
|
93
|
-
'codegenNativeCommands must be passed options including the supported commands',
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const typeArgumentParam = callExpression.typeParameters.params[0];
|
|
98
|
-
|
|
99
|
-
if (typeArgumentParam.type !== 'TSTypeReference') {
|
|
100
|
-
throw new Error(
|
|
101
|
-
"codegenNativeCommands doesn't support inline definitions. Specify a file local type alias",
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return {
|
|
106
|
-
commandTypeName: typeArgumentParam.typeName.name,
|
|
107
|
-
commandOptionsExpression: callExpression.arguments[0],
|
|
108
|
-
};
|
|
109
|
-
})
|
|
57
|
+
.map(statement => getCommandTypeNameAndOptionsExpression(statement, parser))
|
|
110
58
|
.filter(Boolean);
|
|
111
59
|
|
|
112
|
-
|
|
113
|
-
throw new Error('codegenNativeCommands may only be called once in a file');
|
|
114
|
-
}
|
|
60
|
+
throwIfMoreThanOneCodegenNativecommands(commandsTypeNames);
|
|
115
61
|
|
|
116
|
-
return
|
|
117
|
-
...foundConfig,
|
|
118
|
-
commandTypeName:
|
|
119
|
-
commandsTypeNames[0] == null
|
|
120
|
-
? null
|
|
121
|
-
: commandsTypeNames[0].commandTypeName,
|
|
122
|
-
commandOptionsExpression:
|
|
123
|
-
commandsTypeNames[0] == null
|
|
124
|
-
? null
|
|
125
|
-
: commandsTypeNames[0].commandOptionsExpression,
|
|
126
|
-
};
|
|
62
|
+
return createComponentConfig(foundConfig, commandsTypeNames);
|
|
127
63
|
}
|
|
128
64
|
|
|
129
|
-
function getCommandProperties(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
commandOptions: ?CommandOptions,
|
|
135
|
-
) {
|
|
65
|
+
function getCommandProperties(ast: $FlowFixMe, parser: Parser) {
|
|
66
|
+
const {commandTypeName, commandOptionsExpression} = findComponentConfig(
|
|
67
|
+
ast,
|
|
68
|
+
parser,
|
|
69
|
+
);
|
|
136
70
|
if (commandTypeName == null) {
|
|
137
71
|
return [];
|
|
138
72
|
}
|
|
139
73
|
|
|
74
|
+
const types = parser.getTypes(ast);
|
|
140
75
|
const typeAlias = types[commandTypeName];
|
|
141
76
|
|
|
142
77
|
if (typeAlias.type !== 'TSInterfaceDeclaration') {
|
|
@@ -145,19 +80,16 @@ function getCommandProperties(
|
|
|
145
80
|
);
|
|
146
81
|
}
|
|
147
82
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
properties = typeAlias.body.body;
|
|
151
|
-
} catch (e) {
|
|
83
|
+
const properties = parser.bodyProperties(typeAlias);
|
|
84
|
+
if (!properties) {
|
|
152
85
|
throw new Error(
|
|
153
86
|
`Failed to find type definition for "${commandTypeName}", please check that you have a valid codegen typescript file`,
|
|
154
87
|
);
|
|
155
88
|
}
|
|
156
89
|
|
|
157
|
-
const typeScriptPropertyNames = properties
|
|
158
|
-
.map(property => property && property.key && property.key.name)
|
|
159
|
-
.filter(Boolean);
|
|
90
|
+
const typeScriptPropertyNames = propertyNames(properties);
|
|
160
91
|
|
|
92
|
+
const commandOptions = getCommandOptions(commandOptionsExpression);
|
|
161
93
|
if (commandOptions == null || commandOptions.supportedCommands == null) {
|
|
162
94
|
throw new Error(
|
|
163
95
|
'codegenNativeCommands must be given an options object with supportedCommands array',
|
|
@@ -189,24 +121,16 @@ function buildComponentSchema(
|
|
|
189
121
|
ast: $FlowFixMe,
|
|
190
122
|
parser: Parser,
|
|
191
123
|
): ComponentSchemaBuilderConfig {
|
|
192
|
-
const {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
commandOptionsExpression,
|
|
197
|
-
optionsExpression,
|
|
198
|
-
} = findComponentConfig(ast);
|
|
124
|
+
const {componentName, propsTypeName, optionsExpression} = findComponentConfig(
|
|
125
|
+
ast,
|
|
126
|
+
parser,
|
|
127
|
+
);
|
|
199
128
|
|
|
200
129
|
const types = parser.getTypes(ast);
|
|
201
130
|
|
|
202
131
|
const propProperties = getProperties(propsTypeName, types);
|
|
203
|
-
const commandOptions = getCommandOptions(commandOptionsExpression);
|
|
204
132
|
|
|
205
|
-
const commandProperties = getCommandProperties(
|
|
206
|
-
commandTypeName,
|
|
207
|
-
types,
|
|
208
|
-
commandOptions,
|
|
209
|
-
);
|
|
133
|
+
const commandProperties = getCommandProperties(ast, parser);
|
|
210
134
|
|
|
211
135
|
const options = getOptions(optionsExpression);
|
|
212
136
|
|