@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
|
@@ -12,43 +12,6 @@
|
|
|
12
12
|
|
|
13
13
|
import type {TypeResolutionStatus, TypeDeclarationMap} from '../utils';
|
|
14
14
|
|
|
15
|
-
/**
|
|
16
|
-
* This FlowFixMe is supposed to refer to an InterfaceDeclaration or TypeAlias
|
|
17
|
-
* declaration type. Unfortunately, we don't have those types, because flow-parser
|
|
18
|
-
* generates them, and flow-parser is not type-safe. In the future, we should find
|
|
19
|
-
* a way to get these types from our flow parser library.
|
|
20
|
-
*
|
|
21
|
-
* TODO(T71778680): Flow type AST Nodes
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
function getTypes(ast: $FlowFixMe): TypeDeclarationMap {
|
|
25
|
-
return ast.body.reduce((types, node) => {
|
|
26
|
-
if (node.type === 'ExportNamedDeclaration' && node.exportKind === 'type') {
|
|
27
|
-
if (
|
|
28
|
-
node.declaration != null &&
|
|
29
|
-
(node.declaration.type === 'TypeAlias' ||
|
|
30
|
-
node.declaration.type === 'InterfaceDeclaration')
|
|
31
|
-
) {
|
|
32
|
-
types[node.declaration.id.name] = node.declaration;
|
|
33
|
-
}
|
|
34
|
-
} else if (
|
|
35
|
-
node.type === 'ExportNamedDeclaration' &&
|
|
36
|
-
node.exportKind === 'value' &&
|
|
37
|
-
node.declaration &&
|
|
38
|
-
node.declaration.type === 'EnumDeclaration'
|
|
39
|
-
) {
|
|
40
|
-
types[node.declaration.id.name] = node.declaration;
|
|
41
|
-
} else if (
|
|
42
|
-
node.type === 'TypeAlias' ||
|
|
43
|
-
node.type === 'InterfaceDeclaration' ||
|
|
44
|
-
node.type === 'EnumDeclaration'
|
|
45
|
-
) {
|
|
46
|
-
types[node.id.name] = node;
|
|
47
|
-
}
|
|
48
|
-
return types;
|
|
49
|
-
}, {});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
15
|
// $FlowFixMe[unclear-type] there's no flowtype for ASTs
|
|
53
16
|
export type ASTNode = Object;
|
|
54
17
|
|
|
@@ -134,5 +97,4 @@ function getValueFromTypes(value: ASTNode, types: TypeDeclarationMap): ASTNode {
|
|
|
134
97
|
module.exports = {
|
|
135
98
|
getValueFromTypes,
|
|
136
99
|
resolveTypeAnnotation,
|
|
137
|
-
getTypes,
|
|
138
100
|
};
|
package/lib/parsers/parser.d.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { SchemaType } from
|
|
9
|
-
import type { ParserType } from
|
|
8
|
+
import type { SchemaType } from '../CodegenSchema';
|
|
9
|
+
import type { ParserType } from './errors';
|
|
10
10
|
|
|
11
11
|
// useful members only for downstream
|
|
12
12
|
export interface Parser {
|
|
@@ -18,8 +18,11 @@ import type {
|
|
|
18
18
|
NativeModuleParamTypeAnnotation,
|
|
19
19
|
NativeModuleEnumMemberType,
|
|
20
20
|
NativeModuleEnumMembers,
|
|
21
|
+
NativeModuleAliasMap,
|
|
22
|
+
NativeModuleEnumMap,
|
|
21
23
|
} from '../CodegenSchema';
|
|
22
24
|
import type {ParserType} from './errors';
|
|
25
|
+
import type {ParserErrorCapturer, TypeDeclarationMap} from './utils';
|
|
23
26
|
|
|
24
27
|
/**
|
|
25
28
|
* This is the main interface for Parsers of various languages.
|
|
@@ -152,4 +155,85 @@ export interface Parser {
|
|
|
152
155
|
* Calculates enum's members
|
|
153
156
|
*/
|
|
154
157
|
parseEnumMembers(typeAnnotation: $FlowFixMe): NativeModuleEnumMembers;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Given a node, it returns true if it is a module interface
|
|
161
|
+
*/
|
|
162
|
+
isModuleInterface(node: $FlowFixMe): boolean;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Given a typeAnnotation, it returns the annotated element.
|
|
166
|
+
* @parameter typeAnnotation: the annotation for a type.
|
|
167
|
+
* @parameter types: a map of type declarations.
|
|
168
|
+
* @returns: the annotated element.
|
|
169
|
+
*/
|
|
170
|
+
extractAnnotatedElement(
|
|
171
|
+
typeAnnotation: $FlowFixMe,
|
|
172
|
+
types: TypeDeclarationMap,
|
|
173
|
+
): $FlowFixMe;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Given the AST, returns the TypeDeclarationMap
|
|
177
|
+
*/
|
|
178
|
+
getTypes(ast: $FlowFixMe): TypeDeclarationMap;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Given a callExpression, it returns the typeParameters of the callExpression.
|
|
182
|
+
* @parameter callExpression: the callExpression.
|
|
183
|
+
* @returns: the typeParameters of the callExpression or null if it does not exist.
|
|
184
|
+
*/
|
|
185
|
+
callExpressionTypeParameters(callExpression: $FlowFixMe): $FlowFixMe | null;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Given an array of properties from a Partial type, it returns an array of remaped properties.
|
|
189
|
+
* @parameter properties: properties from a Partial types.
|
|
190
|
+
* @parameter hasteModuleName: a string with the native module name.
|
|
191
|
+
* @parameter types: a map of type declarations.
|
|
192
|
+
* @parameter aliasMap: a map of type aliases.
|
|
193
|
+
* @parameter enumMap: a map of type enums.
|
|
194
|
+
* @parameter tryParse: a parser error capturer.
|
|
195
|
+
* @parameter cxxOnly: a boolean specifying if the module is Cxx only.
|
|
196
|
+
* @returns: an array of remaped properties
|
|
197
|
+
*/
|
|
198
|
+
computePartialProperties(
|
|
199
|
+
properties: Array<$FlowFixMe>,
|
|
200
|
+
hasteModuleName: string,
|
|
201
|
+
types: TypeDeclarationMap,
|
|
202
|
+
aliasMap: {...NativeModuleAliasMap},
|
|
203
|
+
enumMap: {...NativeModuleEnumMap},
|
|
204
|
+
tryParse: ParserErrorCapturer,
|
|
205
|
+
cxxOnly: boolean,
|
|
206
|
+
): Array<$FlowFixMe>;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Given a propertyValueType, it returns a boolean specifying if the property is a function type annotation.
|
|
210
|
+
* @parameter propertyValueType: the propertyValueType.
|
|
211
|
+
* @returns: a boolean specifying if the property is a function type annotation.
|
|
212
|
+
*/
|
|
213
|
+
functionTypeAnnotation(propertyValueType: string): boolean;
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Given a declaration, it returns the typeArgumentParams of the declaration.
|
|
217
|
+
* @parameter declaration: the declaration.
|
|
218
|
+
* @returns: the typeArgumentParams of the declaration.
|
|
219
|
+
*/
|
|
220
|
+
getTypeArgumentParamsFromDeclaration(declaration: $FlowFixMe): $FlowFixMe;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Given a typeArgumentParams and funcArgumentParams it returns a native component type.
|
|
224
|
+
* @parameter typeArgumentParams: the typeArgumentParams.
|
|
225
|
+
* @parameter funcArgumentParams: the funcArgumentParams.
|
|
226
|
+
* @returns: a native component type.
|
|
227
|
+
*/
|
|
228
|
+
getNativeComponentType(
|
|
229
|
+
typeArgumentParams: $FlowFixMe,
|
|
230
|
+
funcArgumentParams: $FlowFixMe,
|
|
231
|
+
): {[string]: string};
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Given a annotatedElement, it returns the properties of annotated element.
|
|
235
|
+
* @parameter annotatedElement: the annotated element.
|
|
236
|
+
* @returns: the properties of annotated element.
|
|
237
|
+
*/
|
|
238
|
+
getAnnotatedElementProperties(annotatedElement: $FlowFixMe): $FlowFixMe;
|
|
155
239
|
}
|
|
@@ -150,4 +150,62 @@ export class MockedParser {
|
|
|
150
150
|
},
|
|
151
151
|
];
|
|
152
152
|
}
|
|
153
|
+
isModuleInterface(node) {
|
|
154
|
+
return (
|
|
155
|
+
node.type === 'InterfaceDeclaration' &&
|
|
156
|
+
node.extends.length === 1 &&
|
|
157
|
+
node.extends[0].type === 'InterfaceExtends' &&
|
|
158
|
+
node.extends[0].id.name === 'TurboModule'
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
extractAnnotatedElement(typeAnnotation, types) {
|
|
162
|
+
return types[typeAnnotation.typeParameters.params[0].id.name];
|
|
163
|
+
}
|
|
164
|
+
getTypes(ast) {
|
|
165
|
+
return {};
|
|
166
|
+
}
|
|
167
|
+
callExpressionTypeParameters(callExpression) {
|
|
168
|
+
return callExpression.typeArguments || null;
|
|
169
|
+
}
|
|
170
|
+
computePartialProperties(
|
|
171
|
+
properties,
|
|
172
|
+
hasteModuleName,
|
|
173
|
+
types,
|
|
174
|
+
aliasMap,
|
|
175
|
+
enumMap,
|
|
176
|
+
tryParse,
|
|
177
|
+
cxxOnly,
|
|
178
|
+
) {
|
|
179
|
+
return [
|
|
180
|
+
{
|
|
181
|
+
name: 'a',
|
|
182
|
+
optional: true,
|
|
183
|
+
typeAnnotation: {
|
|
184
|
+
type: 'StringTypeAnnotation',
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
name: 'b',
|
|
189
|
+
optional: true,
|
|
190
|
+
typeAnnotation: {
|
|
191
|
+
type: 'BooleanTypeAnnotation',
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
];
|
|
195
|
+
}
|
|
196
|
+
functionTypeAnnotation(propertyValueType) {
|
|
197
|
+
return propertyValueType === 'FunctionTypeAnnotation';
|
|
198
|
+
}
|
|
199
|
+
getTypeArgumentParamsFromDeclaration(declaration) {
|
|
200
|
+
return declaration.typeArguments.params;
|
|
201
|
+
}
|
|
202
|
+
getNativeComponentType(typeArgumentParams, funcArgumentParams) {
|
|
203
|
+
return {
|
|
204
|
+
propsTypeName: typeArgumentParams[0].id.name,
|
|
205
|
+
componentName: funcArgumentParams[0].value,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
getAnnotatedElementProperties(annotatedElement) {
|
|
209
|
+
return annotatedElement.right.properties;
|
|
210
|
+
}
|
|
153
211
|
}
|
|
@@ -20,7 +20,10 @@ import type {
|
|
|
20
20
|
NativeModuleParamTypeAnnotation,
|
|
21
21
|
NativeModuleEnumMemberType,
|
|
22
22
|
NativeModuleEnumMembers,
|
|
23
|
+
NativeModuleAliasMap,
|
|
24
|
+
NativeModuleEnumMap,
|
|
23
25
|
} from '../CodegenSchema';
|
|
26
|
+
import type {ParserErrorCapturer, TypeDeclarationMap} from './utils';
|
|
24
27
|
|
|
25
28
|
// $FlowFixMe[untyped-import] there's no flowtype flow-parser
|
|
26
29
|
const flowParser = require('flow-parser');
|
|
@@ -159,4 +162,73 @@ export class MockedParser implements Parser {
|
|
|
159
162
|
},
|
|
160
163
|
];
|
|
161
164
|
}
|
|
165
|
+
|
|
166
|
+
isModuleInterface(node: $FlowFixMe): boolean {
|
|
167
|
+
return (
|
|
168
|
+
node.type === 'InterfaceDeclaration' &&
|
|
169
|
+
node.extends.length === 1 &&
|
|
170
|
+
node.extends[0].type === 'InterfaceExtends' &&
|
|
171
|
+
node.extends[0].id.name === 'TurboModule'
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
extractAnnotatedElement(
|
|
176
|
+
typeAnnotation: $FlowFixMe,
|
|
177
|
+
types: TypeDeclarationMap,
|
|
178
|
+
): $FlowFixMe {
|
|
179
|
+
return types[typeAnnotation.typeParameters.params[0].id.name];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
getTypes(ast: $FlowFixMe): TypeDeclarationMap {
|
|
183
|
+
return {};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
callExpressionTypeParameters(callExpression: $FlowFixMe): $FlowFixMe | null {
|
|
187
|
+
return callExpression.typeArguments || null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
computePartialProperties(
|
|
191
|
+
properties: Array<$FlowFixMe>,
|
|
192
|
+
hasteModuleName: string,
|
|
193
|
+
types: TypeDeclarationMap,
|
|
194
|
+
aliasMap: {...NativeModuleAliasMap},
|
|
195
|
+
enumMap: {...NativeModuleEnumMap},
|
|
196
|
+
tryParse: ParserErrorCapturer,
|
|
197
|
+
cxxOnly: boolean,
|
|
198
|
+
): Array<$FlowFixMe> {
|
|
199
|
+
return [
|
|
200
|
+
{
|
|
201
|
+
name: 'a',
|
|
202
|
+
optional: true,
|
|
203
|
+
typeAnnotation: {type: 'StringTypeAnnotation'},
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
name: 'b',
|
|
207
|
+
optional: true,
|
|
208
|
+
typeAnnotation: {type: 'BooleanTypeAnnotation'},
|
|
209
|
+
},
|
|
210
|
+
];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
functionTypeAnnotation(propertyValueType: string): boolean {
|
|
214
|
+
return propertyValueType === 'FunctionTypeAnnotation';
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
getTypeArgumentParamsFromDeclaration(declaration: $FlowFixMe): $FlowFixMe {
|
|
218
|
+
return declaration.typeArguments.params;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
getNativeComponentType(
|
|
222
|
+
typeArgumentParams: $FlowFixMe,
|
|
223
|
+
funcArgumentParams: $FlowFixMe,
|
|
224
|
+
): {[string]: string} {
|
|
225
|
+
return {
|
|
226
|
+
propsTypeName: typeArgumentParams[0].id.name,
|
|
227
|
+
componentName: funcArgumentParams[0].value,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
getAnnotatedElementProperties(annotatedElement: $FlowFixMe): $FlowFixMe {
|
|
232
|
+
return annotatedElement.right.properties;
|
|
233
|
+
}
|
|
162
234
|
}
|