@react-native/codegen 0.72.1 → 0.72.3
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 +348 -0
- package/lib/CodegenSchema.js.flow +31 -3
- package/lib/SchemaValidator.d.ts +11 -0
- package/lib/cli/combine/combine-js-to-schema.js +8 -8
- package/lib/cli/combine/combine-js-to-schema.js.flow +8 -7
- package/lib/cli/parser/parser.js +8 -15
- package/lib/cli/parser/parser.js.flow +8 -14
- package/lib/generators/Utils.js +16 -0
- package/lib/generators/Utils.js.flow +20 -0
- package/lib/generators/__test_fixtures__/fixtures.js +2 -1
- package/lib/generators/__test_fixtures__/fixtures.js.flow +2 -1
- package/lib/generators/components/ComponentsGeneratorUtils.js +10 -1
- package/lib/generators/components/ComponentsGeneratorUtils.js.flow +12 -2
- package/lib/generators/components/CppHelpers.js +8 -15
- package/lib/generators/components/CppHelpers.js.flow +8 -19
- package/lib/generators/components/GenerateEventEmitterCpp.js +7 -3
- package/lib/generators/components/GenerateEventEmitterCpp.js.flow +7 -3
- package/lib/generators/components/GenerateEventEmitterH.js +2 -2
- package/lib/generators/components/GenerateEventEmitterH.js.flow +1 -2
- package/lib/generators/components/GeneratePropsH.js +3 -4
- package/lib/generators/components/GeneratePropsH.js.flow +2 -4
- package/lib/generators/components/GeneratePropsJavaDelegate.js +2 -0
- package/lib/generators/components/GeneratePropsJavaDelegate.js.flow +2 -0
- package/lib/generators/components/GeneratePropsJavaInterface.js +3 -0
- package/lib/generators/components/GeneratePropsJavaInterface.js.flow +3 -0
- package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js +8 -0
- package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js.flow +12 -0
- package/lib/generators/components/GenerateTests.js +3 -2
- package/lib/generators/components/GenerateTests.js.flow +3 -1
- package/lib/generators/components/GenerateViewConfigJs.js +5 -2
- package/lib/generators/components/GenerateViewConfigJs.js.flow +5 -2
- package/lib/generators/components/JavaHelpers.js +9 -0
- package/lib/generators/components/JavaHelpers.js.flow +12 -1
- package/lib/generators/components/__test_fixtures__/fixtures.js +41 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js.flow +42 -0
- package/lib/generators/modules/GenerateModuleCpp.js +9 -4
- package/lib/generators/modules/GenerateModuleCpp.js.flow +11 -3
- package/lib/generators/modules/GenerateModuleH.js +185 -33
- package/lib/generators/modules/GenerateModuleH.js.flow +203 -25
- package/lib/generators/modules/GenerateModuleJavaSpec.js +2 -2
- package/lib/generators/modules/GenerateModuleJavaSpec.js.flow +5 -5
- package/lib/generators/modules/GenerateModuleJniCpp.js +2 -2
- package/lib/generators/modules/GenerateModuleJniCpp.js.flow +5 -5
- package/lib/generators/modules/GenerateModuleObjCpp/index.js +2 -2
- package/lib/generators/modules/GenerateModuleObjCpp/index.js.flow +2 -2
- package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js.flow +2 -2
- package/lib/generators/modules/Utils.js +4 -0
- package/lib/generators/modules/Utils.js.flow +6 -0
- package/lib/generators/modules/__test_fixtures__/fixtures.js +152 -10
- package/lib/generators/modules/__test_fixtures__/fixtures.js.flow +152 -10
- package/lib/parsers/error-utils.js +42 -19
- package/lib/parsers/error-utils.js.flow +46 -19
- package/lib/parsers/errors.d.ts +10 -0
- package/lib/parsers/errors.js +9 -29
- package/lib/parsers/errors.js.flow +2 -20
- package/lib/parsers/flow/Visitor.js +37 -0
- package/lib/parsers/flow/Visitor.js.flow +41 -0
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +20 -2
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +20 -2
- package/lib/parsers/flow/components/commands.js +3 -0
- package/lib/parsers/flow/components/commands.js.flow +2 -1
- package/lib/parsers/flow/components/componentsUtils.js +10 -0
- package/lib/parsers/flow/components/componentsUtils.js.flow +11 -1
- package/lib/parsers/flow/components/events.js.flow +1 -1
- package/lib/parsers/flow/components/extends.js.flow +1 -1
- package/lib/parsers/flow/components/index.js +16 -20
- package/lib/parsers/flow/components/index.js.flow +8 -7
- package/lib/parsers/flow/components/options.js.flow +1 -1
- package/lib/parsers/flow/components/props.js.flow +1 -1
- package/lib/parsers/flow/modules/__test_fixtures__/failures.js +54 -0
- package/lib/parsers/flow/modules/__test_fixtures__/failures.js.flow +56 -0
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js +64 -1
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js.flow +66 -1
- package/lib/parsers/flow/modules/index.js +112 -48
- package/lib/parsers/flow/modules/index.js.flow +115 -44
- package/lib/parsers/flow/parser.d.ts +10 -0
- package/lib/parsers/flow/parser.js +173 -32
- package/lib/parsers/flow/parser.js.flow +201 -24
- package/lib/parsers/flow/utils.js +33 -57
- package/lib/parsers/flow/utils.js.flow +37 -60
- package/lib/parsers/parser.d.ts +17 -0
- package/lib/parsers/parser.js.flow +124 -17
- package/lib/parsers/parserMock.js +101 -30
- package/lib/parsers/parserMock.js.flow +139 -24
- package/lib/parsers/parsers-commons.js +121 -119
- package/lib/parsers/parsers-commons.js.flow +136 -131
- package/lib/parsers/parsers-primitives.js +75 -12
- package/lib/parsers/parsers-primitives.js.flow +92 -13
- package/lib/parsers/schema/index.d.ts +10 -0
- package/lib/parsers/{typescript/components/schema.js.flow → schema.js.flow} +1 -1
- package/lib/parsers/typescript/Visitor.js +42 -0
- package/lib/parsers/typescript/Visitor.js.flow +47 -0
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +22 -0
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +22 -0
- package/lib/parsers/typescript/components/commands.js +3 -0
- package/lib/parsers/typescript/components/commands.js.flow +2 -1
- package/lib/parsers/typescript/components/componentsUtils.js +5 -0
- package/lib/parsers/typescript/components/componentsUtils.js.flow +6 -1
- package/lib/parsers/typescript/components/events.js.flow +1 -1
- package/lib/parsers/typescript/components/extends.js.flow +1 -1
- package/lib/parsers/typescript/components/index.js +15 -19
- package/lib/parsers/typescript/components/index.js.flow +8 -7
- package/lib/parsers/typescript/components/options.js.flow +1 -1
- package/lib/parsers/typescript/components/props.js.flow +1 -1
- package/lib/parsers/typescript/modules/__test_fixtures__/failures.js +52 -0
- package/lib/parsers/typescript/modules/__test_fixtures__/failures.js.flow +54 -0
- package/lib/parsers/typescript/modules/__test_fixtures__/fixtures.js +142 -0
- package/lib/parsers/typescript/modules/__test_fixtures__/fixtures.js.flow +146 -0
- package/lib/parsers/typescript/modules/index.js +276 -110
- package/lib/parsers/typescript/modules/index.js.flow +237 -68
- package/lib/parsers/typescript/parser.d.ts +10 -0
- package/lib/parsers/typescript/parser.js +175 -25
- package/lib/parsers/typescript/parser.js.flow +184 -26
- package/lib/parsers/typescript/utils.js +40 -51
- package/lib/parsers/typescript/utils.js.flow +44 -55
- package/lib/parsers/utils.js +0 -125
- package/lib/parsers/utils.js.flow +3 -70
- package/package.json +4 -1
- package/lib/parsers/flow/components/schema.js +0 -106
- package/lib/parsers/flow/components/schema.js.flow +0 -62
- package/lib/parsers/flow/index.js +0 -80
- package/lib/parsers/flow/index.js.flow +0 -85
- package/lib/parsers/typescript/index.js +0 -85
- package/lib/parsers/typescript/index.js.flow +0 -94
- /package/lib/parsers/{typescript/components/schema.js → schema.js} +0 -0
|
@@ -10,41 +10,10 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
import type {
|
|
13
|
+
import type {TypeResolutionStatus, TypeDeclarationMap} from '../utils';
|
|
14
14
|
|
|
15
15
|
const {parseTopLevelType} = require('./parseTopLevelType');
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* TODO(T108222691): Use flow-types for @babel/parser
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
function getTypes(ast: $FlowFixMe): TypeDeclarationMap {
|
|
22
|
-
return ast.body.reduce((types, node) => {
|
|
23
|
-
switch (node.type) {
|
|
24
|
-
case 'ExportNamedDeclaration': {
|
|
25
|
-
if (node.declaration) {
|
|
26
|
-
switch (node.declaration.type) {
|
|
27
|
-
case 'TSTypeAliasDeclaration':
|
|
28
|
-
case 'TSInterfaceDeclaration':
|
|
29
|
-
case 'TSEnumDeclaration': {
|
|
30
|
-
types[node.declaration.id.name] = node.declaration;
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
case 'TSTypeAliasDeclaration':
|
|
38
|
-
case 'TSInterfaceDeclaration':
|
|
39
|
-
case 'TSEnumDeclaration': {
|
|
40
|
-
types[node.id.name] = node;
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return types;
|
|
45
|
-
}, {});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
17
|
// $FlowFixMe[unclear-type] Use flow-types for @babel/parser
|
|
49
18
|
export type ASTNode = Object;
|
|
50
19
|
|
|
@@ -57,7 +26,7 @@ function resolveTypeAnnotation(
|
|
|
57
26
|
): {
|
|
58
27
|
nullable: boolean,
|
|
59
28
|
typeAnnotation: $FlowFixMe,
|
|
60
|
-
|
|
29
|
+
typeResolutionStatus: TypeResolutionStatus,
|
|
61
30
|
} {
|
|
62
31
|
invariant(
|
|
63
32
|
typeAnnotation != null,
|
|
@@ -69,7 +38,7 @@ function resolveTypeAnnotation(
|
|
|
69
38
|
? typeAnnotation.typeAnnotation
|
|
70
39
|
: typeAnnotation;
|
|
71
40
|
let nullable = false;
|
|
72
|
-
let
|
|
41
|
+
let typeResolutionStatus: TypeResolutionStatus = {
|
|
73
42
|
successful: false,
|
|
74
43
|
};
|
|
75
44
|
|
|
@@ -78,38 +47,58 @@ function resolveTypeAnnotation(
|
|
|
78
47
|
nullable = nullable || topLevelType.optional;
|
|
79
48
|
node = topLevelType.type;
|
|
80
49
|
|
|
81
|
-
if (node.type
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
aliasName: node.typeName.name,
|
|
85
|
-
};
|
|
86
|
-
const resolvedTypeAnnotation = types[node.typeName.name];
|
|
87
|
-
if (
|
|
88
|
-
resolvedTypeAnnotation == null ||
|
|
89
|
-
resolvedTypeAnnotation.type === 'TSEnumDeclaration'
|
|
90
|
-
) {
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
invariant(
|
|
95
|
-
resolvedTypeAnnotation.type === 'TSTypeAliasDeclaration',
|
|
96
|
-
`GenericTypeAnnotation '${node.typeName.name}' must resolve to a TSTypeAliasDeclaration. Instead, it resolved to a '${resolvedTypeAnnotation.type}'`,
|
|
97
|
-
);
|
|
50
|
+
if (node.type !== 'TSTypeReference') {
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
98
53
|
|
|
99
|
-
|
|
100
|
-
|
|
54
|
+
const resolvedTypeAnnotation = types[node.typeName.name];
|
|
55
|
+
if (resolvedTypeAnnotation == null) {
|
|
101
56
|
break;
|
|
102
57
|
}
|
|
58
|
+
|
|
59
|
+
switch (resolvedTypeAnnotation.type) {
|
|
60
|
+
case 'TSTypeAliasDeclaration': {
|
|
61
|
+
typeResolutionStatus = {
|
|
62
|
+
successful: true,
|
|
63
|
+
type: 'alias',
|
|
64
|
+
name: node.typeName.name,
|
|
65
|
+
};
|
|
66
|
+
node = resolvedTypeAnnotation.typeAnnotation;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case 'TSInterfaceDeclaration': {
|
|
70
|
+
typeResolutionStatus = {
|
|
71
|
+
successful: true,
|
|
72
|
+
type: 'alias',
|
|
73
|
+
name: node.typeName.name,
|
|
74
|
+
};
|
|
75
|
+
node = resolvedTypeAnnotation;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
case 'TSEnumDeclaration': {
|
|
79
|
+
typeResolutionStatus = {
|
|
80
|
+
successful: true,
|
|
81
|
+
type: 'enum',
|
|
82
|
+
name: node.typeName.name,
|
|
83
|
+
};
|
|
84
|
+
node = resolvedTypeAnnotation;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
default: {
|
|
88
|
+
throw new TypeError(
|
|
89
|
+
`A non GenericTypeAnnotation must be a type declaration ('TSTypeAliasDeclaration'), an interface ('TSInterfaceDeclaration'), or enum ('TSEnumDeclaration'). Instead, got the unsupported ${resolvedTypeAnnotation.type}.`,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
103
93
|
}
|
|
104
94
|
|
|
105
95
|
return {
|
|
106
96
|
nullable: nullable,
|
|
107
97
|
typeAnnotation: node,
|
|
108
|
-
|
|
98
|
+
typeResolutionStatus,
|
|
109
99
|
};
|
|
110
100
|
}
|
|
111
101
|
|
|
112
102
|
module.exports = {
|
|
113
103
|
resolveTypeAnnotation,
|
|
114
|
-
getTypes,
|
|
115
104
|
};
|
package/lib/parsers/utils.js
CHANGED
|
@@ -10,81 +10,9 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
function _slicedToArray(arr, i) {
|
|
14
|
-
return (
|
|
15
|
-
_arrayWithHoles(arr) ||
|
|
16
|
-
_iterableToArrayLimit(arr, i) ||
|
|
17
|
-
_unsupportedIterableToArray(arr, i) ||
|
|
18
|
-
_nonIterableRest()
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
function _nonIterableRest() {
|
|
22
|
-
throw new TypeError(
|
|
23
|
-
'Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.',
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
27
|
-
if (!o) return;
|
|
28
|
-
if (typeof o === 'string') return _arrayLikeToArray(o, minLen);
|
|
29
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
30
|
-
if (n === 'Object' && o.constructor) n = o.constructor.name;
|
|
31
|
-
if (n === 'Map' || n === 'Set') return Array.from(o);
|
|
32
|
-
if (n === 'Arguments' || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
33
|
-
return _arrayLikeToArray(o, minLen);
|
|
34
|
-
}
|
|
35
|
-
function _arrayLikeToArray(arr, len) {
|
|
36
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
37
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
38
|
-
return arr2;
|
|
39
|
-
}
|
|
40
|
-
function _iterableToArrayLimit(arr, i) {
|
|
41
|
-
var _i =
|
|
42
|
-
null == arr
|
|
43
|
-
? null
|
|
44
|
-
: ('undefined' != typeof Symbol && arr[Symbol.iterator]) ||
|
|
45
|
-
arr['@@iterator'];
|
|
46
|
-
if (null != _i) {
|
|
47
|
-
var _s,
|
|
48
|
-
_e,
|
|
49
|
-
_x,
|
|
50
|
-
_r,
|
|
51
|
-
_arr = [],
|
|
52
|
-
_n = !0,
|
|
53
|
-
_d = !1;
|
|
54
|
-
try {
|
|
55
|
-
if (((_x = (_i = _i.call(arr)).next), 0 === i)) {
|
|
56
|
-
if (Object(_i) !== _i) return;
|
|
57
|
-
_n = !1;
|
|
58
|
-
} else
|
|
59
|
-
for (
|
|
60
|
-
;
|
|
61
|
-
!(_n = (_s = _x.call(_i)).done) &&
|
|
62
|
-
(_arr.push(_s.value), _arr.length !== i);
|
|
63
|
-
_n = !0
|
|
64
|
-
);
|
|
65
|
-
} catch (err) {
|
|
66
|
-
(_d = !0), (_e = err);
|
|
67
|
-
} finally {
|
|
68
|
-
try {
|
|
69
|
-
if (!_n && null != _i.return && ((_r = _i.return()), Object(_r) !== _r))
|
|
70
|
-
return;
|
|
71
|
-
} finally {
|
|
72
|
-
if (_d) throw _e;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return _arr;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
function _arrayWithHoles(arr) {
|
|
79
|
-
if (Array.isArray(arr)) return arr;
|
|
80
|
-
}
|
|
81
13
|
const _require = require('./errors'),
|
|
82
14
|
ParserError = _require.ParserError;
|
|
83
|
-
const _require2 = require('./parsers-commons'),
|
|
84
|
-
wrapModuleSchema = _require2.wrapModuleSchema;
|
|
85
|
-
const fs = require('fs');
|
|
86
15
|
const path = require('path');
|
|
87
|
-
const invariant = require('invariant');
|
|
88
16
|
function extractNativeModuleName(filename) {
|
|
89
17
|
// this should drop everything after the file name. For Example it will drop:
|
|
90
18
|
// .android.js, .android.ts, .android.tsx, .ios.js, .ios.ts, .ios.tsx, .js, .ts, .tsx
|
|
@@ -130,10 +58,6 @@ function verifyPlatforms(hasteModuleName, moduleName) {
|
|
|
130
58
|
excludedPlatforms: Array.from(excludedPlatforms),
|
|
131
59
|
};
|
|
132
60
|
}
|
|
133
|
-
function parseFile(filename, callback) {
|
|
134
|
-
const contents = fs.readFileSync(filename, 'utf8');
|
|
135
|
-
return callback(contents, filename);
|
|
136
|
-
}
|
|
137
61
|
|
|
138
62
|
// TODO(T108222691): Use flow-types for @babel/parser
|
|
139
63
|
function visit(astNode, visitor) {
|
|
@@ -156,53 +80,6 @@ function visit(astNode, visitor) {
|
|
|
156
80
|
}
|
|
157
81
|
}
|
|
158
82
|
}
|
|
159
|
-
function buildSchemaFromConfigType(
|
|
160
|
-
configType,
|
|
161
|
-
filename,
|
|
162
|
-
ast,
|
|
163
|
-
wrapComponentSchema,
|
|
164
|
-
buildComponentSchema,
|
|
165
|
-
buildModuleSchema,
|
|
166
|
-
) {
|
|
167
|
-
switch (configType) {
|
|
168
|
-
case 'component': {
|
|
169
|
-
return wrapComponentSchema(buildComponentSchema(ast));
|
|
170
|
-
}
|
|
171
|
-
case 'module': {
|
|
172
|
-
if (filename === undefined || filename === null) {
|
|
173
|
-
throw new Error('Filepath expected while parasing a module');
|
|
174
|
-
}
|
|
175
|
-
const nativeModuleName = extractNativeModuleName(filename);
|
|
176
|
-
const _createParserErrorCap = createParserErrorCapturer(),
|
|
177
|
-
_createParserErrorCap2 = _slicedToArray(_createParserErrorCap, 2),
|
|
178
|
-
parsingErrors = _createParserErrorCap2[0],
|
|
179
|
-
tryParse = _createParserErrorCap2[1];
|
|
180
|
-
const schema = tryParse(() =>
|
|
181
|
-
buildModuleSchema(nativeModuleName, ast, tryParse),
|
|
182
|
-
);
|
|
183
|
-
if (parsingErrors.length > 0) {
|
|
184
|
-
/**
|
|
185
|
-
* TODO(T77968131): We have two options:
|
|
186
|
-
* - Throw the first error, but indicate there are more then one errors.
|
|
187
|
-
* - Display all errors, nicely formatted.
|
|
188
|
-
*
|
|
189
|
-
* For the time being, we're just throw the first error.
|
|
190
|
-
**/
|
|
191
|
-
|
|
192
|
-
throw parsingErrors[0];
|
|
193
|
-
}
|
|
194
|
-
invariant(
|
|
195
|
-
schema != null,
|
|
196
|
-
'When there are no parsing errors, the schema should not be null',
|
|
197
|
-
);
|
|
198
|
-
return wrapModuleSchema(schema, nativeModuleName);
|
|
199
|
-
}
|
|
200
|
-
default:
|
|
201
|
-
return {
|
|
202
|
-
modules: {},
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
83
|
function getConfigType(
|
|
207
84
|
// TODO(T71778680): Flow-type this node.
|
|
208
85
|
ast,
|
|
@@ -266,8 +143,6 @@ module.exports = {
|
|
|
266
143
|
extractNativeModuleName,
|
|
267
144
|
createParserErrorCapturer,
|
|
268
145
|
verifyPlatforms,
|
|
269
|
-
parseFile,
|
|
270
146
|
visit,
|
|
271
|
-
buildSchemaFromConfigType,
|
|
272
147
|
isModuleRegistryCall,
|
|
273
148
|
};
|
|
@@ -10,21 +10,17 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
import type {ComponentSchemaBuilderConfig} from './flow/components/schema';
|
|
14
|
-
import type {NativeModuleSchema, SchemaType} from '../CodegenSchema';
|
|
15
13
|
const {ParserError} = require('./errors');
|
|
16
|
-
const {wrapModuleSchema} = require('./parsers-commons');
|
|
17
14
|
|
|
18
|
-
const fs = require('fs');
|
|
19
15
|
const path = require('path');
|
|
20
|
-
const invariant = require('invariant');
|
|
21
16
|
|
|
22
17
|
export type TypeDeclarationMap = {[declarationName: string]: $FlowFixMe};
|
|
23
18
|
|
|
24
|
-
export type
|
|
19
|
+
export type TypeResolutionStatus =
|
|
25
20
|
| $ReadOnly<{
|
|
21
|
+
type: 'alias' | 'enum',
|
|
26
22
|
successful: true,
|
|
27
|
-
|
|
23
|
+
name: string,
|
|
28
24
|
}>
|
|
29
25
|
| $ReadOnly<{
|
|
30
26
|
successful: false,
|
|
@@ -95,15 +91,6 @@ function verifyPlatforms(
|
|
|
95
91
|
};
|
|
96
92
|
}
|
|
97
93
|
|
|
98
|
-
function parseFile(
|
|
99
|
-
filename: string,
|
|
100
|
-
callback: (contents: string, filename: string) => SchemaType,
|
|
101
|
-
): SchemaType {
|
|
102
|
-
const contents = fs.readFileSync(filename, 'utf8');
|
|
103
|
-
|
|
104
|
-
return callback(contents, filename);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
94
|
// TODO(T108222691): Use flow-types for @babel/parser
|
|
108
95
|
function visit(
|
|
109
96
|
astNode: $FlowFixMe,
|
|
@@ -133,58 +120,6 @@ function visit(
|
|
|
133
120
|
}
|
|
134
121
|
}
|
|
135
122
|
|
|
136
|
-
function buildSchemaFromConfigType(
|
|
137
|
-
configType: 'module' | 'component' | 'none',
|
|
138
|
-
filename: ?string,
|
|
139
|
-
ast: $FlowFixMe,
|
|
140
|
-
wrapComponentSchema: (config: ComponentSchemaBuilderConfig) => SchemaType,
|
|
141
|
-
buildComponentSchema: (ast: $FlowFixMe) => ComponentSchemaBuilderConfig,
|
|
142
|
-
buildModuleSchema: (
|
|
143
|
-
hasteModuleName: string,
|
|
144
|
-
ast: $FlowFixMe,
|
|
145
|
-
tryParse: ParserErrorCapturer,
|
|
146
|
-
) => NativeModuleSchema,
|
|
147
|
-
): SchemaType {
|
|
148
|
-
switch (configType) {
|
|
149
|
-
case 'component': {
|
|
150
|
-
return wrapComponentSchema(buildComponentSchema(ast));
|
|
151
|
-
}
|
|
152
|
-
case 'module': {
|
|
153
|
-
if (filename === undefined || filename === null) {
|
|
154
|
-
throw new Error('Filepath expected while parasing a module');
|
|
155
|
-
}
|
|
156
|
-
const nativeModuleName = extractNativeModuleName(filename);
|
|
157
|
-
|
|
158
|
-
const [parsingErrors, tryParse] = createParserErrorCapturer();
|
|
159
|
-
|
|
160
|
-
const schema = tryParse(() =>
|
|
161
|
-
buildModuleSchema(nativeModuleName, ast, tryParse),
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
if (parsingErrors.length > 0) {
|
|
165
|
-
/**
|
|
166
|
-
* TODO(T77968131): We have two options:
|
|
167
|
-
* - Throw the first error, but indicate there are more then one errors.
|
|
168
|
-
* - Display all errors, nicely formatted.
|
|
169
|
-
*
|
|
170
|
-
* For the time being, we're just throw the first error.
|
|
171
|
-
**/
|
|
172
|
-
|
|
173
|
-
throw parsingErrors[0];
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
invariant(
|
|
177
|
-
schema != null,
|
|
178
|
-
'When there are no parsing errors, the schema should not be null',
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
return wrapModuleSchema(schema, nativeModuleName);
|
|
182
|
-
}
|
|
183
|
-
default:
|
|
184
|
-
return {modules: {}};
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
123
|
function getConfigType(
|
|
189
124
|
// TODO(T71778680): Flow-type this node.
|
|
190
125
|
ast: $FlowFixMe,
|
|
@@ -259,8 +194,6 @@ module.exports = {
|
|
|
259
194
|
extractNativeModuleName,
|
|
260
195
|
createParserErrorCapturer,
|
|
261
196
|
verifyPlatforms,
|
|
262
|
-
parseFile,
|
|
263
197
|
visit,
|
|
264
|
-
buildSchemaFromConfigType,
|
|
265
198
|
isModuleRegistryCall,
|
|
266
199
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native/codegen",
|
|
3
|
-
"version": "0.72.
|
|
3
|
+
"version": "0.72.3",
|
|
4
4
|
"description": "⚛️ Code generation tools for React Native",
|
|
5
5
|
"homepage": "https://github.com/facebook/react-native/tree/HEAD/packages/react-native-codegen",
|
|
6
6
|
"repository": {
|
|
@@ -41,5 +41,8 @@
|
|
|
41
41
|
"mkdirp": "^0.5.1",
|
|
42
42
|
"prettier": "^2.4.1",
|
|
43
43
|
"rimraf": "^3.0.2"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"@babel/preset-env": "^7.1.6"
|
|
44
47
|
}
|
|
45
48
|
}
|
|
@@ -1,106 +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
|
-
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
|
-
function wrapComponentSchema({
|
|
76
|
-
filename,
|
|
77
|
-
componentName,
|
|
78
|
-
extendsProps,
|
|
79
|
-
events,
|
|
80
|
-
props,
|
|
81
|
-
options,
|
|
82
|
-
commands,
|
|
83
|
-
}) {
|
|
84
|
-
return {
|
|
85
|
-
modules: {
|
|
86
|
-
[filename]: {
|
|
87
|
-
type: 'Component',
|
|
88
|
-
components: {
|
|
89
|
-
[componentName]: _objectSpread(
|
|
90
|
-
_objectSpread({}, options || {}),
|
|
91
|
-
{},
|
|
92
|
-
{
|
|
93
|
-
extendsProps,
|
|
94
|
-
events,
|
|
95
|
-
props,
|
|
96
|
-
commands,
|
|
97
|
-
},
|
|
98
|
-
),
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
module.exports = {
|
|
105
|
-
wrapComponentSchema,
|
|
106
|
-
};
|
|
@@ -1,62 +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 {
|
|
14
|
-
EventTypeShape,
|
|
15
|
-
NamedShape,
|
|
16
|
-
CommandTypeAnnotation,
|
|
17
|
-
PropTypeAnnotation,
|
|
18
|
-
ExtendsPropsShape,
|
|
19
|
-
SchemaType,
|
|
20
|
-
OptionsShape,
|
|
21
|
-
} from '../../../CodegenSchema.js';
|
|
22
|
-
|
|
23
|
-
export type ComponentSchemaBuilderConfig = $ReadOnly<{
|
|
24
|
-
filename: string,
|
|
25
|
-
componentName: string,
|
|
26
|
-
extendsProps: $ReadOnlyArray<ExtendsPropsShape>,
|
|
27
|
-
events: $ReadOnlyArray<EventTypeShape>,
|
|
28
|
-
props: $ReadOnlyArray<NamedShape<PropTypeAnnotation>>,
|
|
29
|
-
commands: $ReadOnlyArray<NamedShape<CommandTypeAnnotation>>,
|
|
30
|
-
options?: ?OptionsShape,
|
|
31
|
-
}>;
|
|
32
|
-
|
|
33
|
-
function wrapComponentSchema({
|
|
34
|
-
filename,
|
|
35
|
-
componentName,
|
|
36
|
-
extendsProps,
|
|
37
|
-
events,
|
|
38
|
-
props,
|
|
39
|
-
options,
|
|
40
|
-
commands,
|
|
41
|
-
}: ComponentSchemaBuilderConfig): SchemaType {
|
|
42
|
-
return {
|
|
43
|
-
modules: {
|
|
44
|
-
[filename]: {
|
|
45
|
-
type: 'Component',
|
|
46
|
-
components: {
|
|
47
|
-
[componentName]: {
|
|
48
|
-
...(options || {}),
|
|
49
|
-
extendsProps,
|
|
50
|
-
events,
|
|
51
|
-
props,
|
|
52
|
-
commands,
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
module.exports = {
|
|
61
|
-
wrapComponentSchema,
|
|
62
|
-
};
|
|
@@ -1,80 +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[untyped-import] there's no flowtype flow-parser
|
|
14
|
-
const flowParser = require('flow-parser');
|
|
15
|
-
const fs = require('fs');
|
|
16
|
-
const _require = require('../utils'),
|
|
17
|
-
buildSchemaFromConfigType = _require.buildSchemaFromConfigType,
|
|
18
|
-
getConfigType = _require.getConfigType,
|
|
19
|
-
isModuleRegistryCall = _require.isModuleRegistryCall;
|
|
20
|
-
const _require2 = require('./components'),
|
|
21
|
-
buildComponentSchema = _require2.buildComponentSchema;
|
|
22
|
-
const _require3 = require('./components/schema'),
|
|
23
|
-
wrapComponentSchema = _require3.wrapComponentSchema;
|
|
24
|
-
const _require4 = require('./modules'),
|
|
25
|
-
buildModuleSchema = _require4.buildModuleSchema;
|
|
26
|
-
function Visitor(infoMap) {
|
|
27
|
-
return {
|
|
28
|
-
CallExpression(node) {
|
|
29
|
-
if (
|
|
30
|
-
node.callee.type === 'Identifier' &&
|
|
31
|
-
node.callee.name === 'codegenNativeComponent'
|
|
32
|
-
) {
|
|
33
|
-
infoMap.isComponent = true;
|
|
34
|
-
}
|
|
35
|
-
if (isModuleRegistryCall(node)) {
|
|
36
|
-
infoMap.isModule = true;
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
InterfaceExtends(node) {
|
|
40
|
-
if (node.id.name === 'TurboModule') {
|
|
41
|
-
infoMap.isModule = true;
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function buildSchema(contents, filename) {
|
|
47
|
-
// Early return for non-Spec JavaScript files
|
|
48
|
-
if (
|
|
49
|
-
!contents.includes('codegenNativeComponent') &&
|
|
50
|
-
!contents.includes('TurboModule')
|
|
51
|
-
) {
|
|
52
|
-
return {
|
|
53
|
-
modules: {},
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
const ast = flowParser.parse(contents, {
|
|
57
|
-
enums: true,
|
|
58
|
-
});
|
|
59
|
-
const configType = getConfigType(ast, Visitor);
|
|
60
|
-
return buildSchemaFromConfigType(
|
|
61
|
-
configType,
|
|
62
|
-
filename,
|
|
63
|
-
ast,
|
|
64
|
-
wrapComponentSchema,
|
|
65
|
-
buildComponentSchema,
|
|
66
|
-
buildModuleSchema,
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
function parseModuleFixture(filename) {
|
|
70
|
-
const contents = fs.readFileSync(filename, 'utf8');
|
|
71
|
-
return buildSchema(contents, 'path/NativeSampleTurboModule.js');
|
|
72
|
-
}
|
|
73
|
-
function parseString(contents, filename) {
|
|
74
|
-
return buildSchema(contents, filename);
|
|
75
|
-
}
|
|
76
|
-
module.exports = {
|
|
77
|
-
buildSchema,
|
|
78
|
-
parseModuleFixture,
|
|
79
|
-
parseString,
|
|
80
|
-
};
|