@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.
Files changed (77) hide show
  1. package/lib/CodegenSchema.d.ts +10 -10
  2. package/lib/CodegenSchema.js.flow +6 -1
  3. package/lib/SchemaValidator.d.ts +1 -1
  4. package/lib/generators/RNCodegen.d.ts +98 -0
  5. package/lib/generators/RNCodegen.js +33 -4
  6. package/lib/generators/RNCodegen.js.flow +35 -4
  7. package/lib/generators/components/ComponentsGeneratorUtils.js +2 -0
  8. package/lib/generators/components/ComponentsGeneratorUtils.js.flow +2 -0
  9. package/lib/generators/components/CppHelpers.js +2 -0
  10. package/lib/generators/components/CppHelpers.js.flow +2 -0
  11. package/lib/generators/components/GeneratePropsH.js +2 -0
  12. package/lib/generators/components/GeneratePropsH.js.flow +2 -0
  13. package/lib/generators/components/GeneratePropsJavaDelegate.js +2 -0
  14. package/lib/generators/components/GeneratePropsJavaDelegate.js.flow +2 -0
  15. package/lib/generators/components/GeneratePropsJavaInterface.js +2 -0
  16. package/lib/generators/components/GeneratePropsJavaInterface.js.flow +2 -0
  17. package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js.flow +3 -1
  18. package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js +5 -0
  19. package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js.flow +6 -0
  20. package/lib/generators/components/GenerateViewConfigJs.js +1 -0
  21. package/lib/generators/components/GenerateViewConfigJs.js.flow +1 -0
  22. package/lib/generators/components/JavaHelpers.js +7 -0
  23. package/lib/generators/components/JavaHelpers.js.flow +8 -0
  24. package/lib/generators/components/__test_fixtures__/fixtures.js +29 -0
  25. package/lib/generators/components/__test_fixtures__/fixtures.js.flow +30 -0
  26. package/lib/parsers/error-utils.js +50 -15
  27. package/lib/parsers/error-utils.js.flow +57 -15
  28. package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +5 -1
  29. package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +5 -1
  30. package/lib/parsers/flow/components/componentsUtils.js +4 -0
  31. package/lib/parsers/flow/components/componentsUtils.js.flow +4 -0
  32. package/lib/parsers/flow/components/index.js +27 -126
  33. package/lib/parsers/flow/components/index.js.flow +22 -52
  34. package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js +4 -4
  35. package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js.flow +4 -4
  36. package/lib/parsers/flow/modules/index.js +41 -317
  37. package/lib/parsers/flow/modules/index.js.flow +19 -247
  38. package/lib/parsers/flow/parser.js +119 -12
  39. package/lib/parsers/flow/parser.js.flow +124 -3
  40. package/lib/parsers/flow/utils.js +0 -38
  41. package/lib/parsers/flow/utils.js.flow +0 -38
  42. package/lib/parsers/parser.d.ts +2 -2
  43. package/lib/parsers/parser.js.flow +84 -0
  44. package/lib/parsers/parserMock.js +58 -0
  45. package/lib/parsers/parserMock.js.flow +72 -0
  46. package/lib/parsers/parsers-commons.js +362 -5
  47. package/lib/parsers/parsers-commons.js.flow +351 -8
  48. package/lib/parsers/parsers-primitives.js +119 -3
  49. package/lib/parsers/parsers-primitives.js.flow +128 -3
  50. package/lib/parsers/schema/index.d.ts +1 -1
  51. package/lib/parsers/{typescript/components/schema.js.flow → schema.js.flow} +1 -1
  52. package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +5 -1
  53. package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +5 -1
  54. package/lib/parsers/typescript/components/componentsUtils.js +8 -0
  55. package/lib/parsers/typescript/components/componentsUtils.js.flow +8 -0
  56. package/lib/parsers/typescript/components/index.js +28 -127
  57. package/lib/parsers/typescript/components/index.js.flow +24 -54
  58. package/lib/parsers/typescript/modules/index.js +103 -434
  59. package/lib/parsers/typescript/modules/index.js.flow +85 -299
  60. package/lib/parsers/typescript/parser.js +113 -12
  61. package/lib/parsers/typescript/parser.js.flow +115 -3
  62. package/lib/parsers/typescript/utils.js +0 -31
  63. package/lib/parsers/typescript/utils.js.flow +0 -31
  64. package/lib/parsers/utils.js +4 -0
  65. package/lib/parsers/utils.js.flow +3 -0
  66. package/package.json +1 -1
  67. package/lib/parsers/flow/Visitor.js +0 -37
  68. package/lib/parsers/flow/Visitor.js.flow +0 -41
  69. package/lib/parsers/flow/components/options.js +0 -72
  70. package/lib/parsers/flow/components/options.js.flow +0 -87
  71. package/lib/parsers/flow/components/schema.js +0 -106
  72. package/lib/parsers/flow/components/schema.js.flow +0 -62
  73. package/lib/parsers/typescript/Visitor.js +0 -42
  74. package/lib/parsers/typescript/Visitor.js.flow +0 -47
  75. package/lib/parsers/typescript/components/options.js +0 -72
  76. package/lib/parsers/typescript/components/options.js.flow +0 -87
  77. /package/lib/parsers/{typescript/components/schema.js → schema.js} +0 -0
@@ -18,18 +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';
26
+ import type {ParserErrorCapturer, TypeDeclarationMap} from '../utils';
27
+
28
+ const {typeScriptTranslateTypeAnnotation} = require('./modules');
24
29
 
25
30
  // $FlowFixMe[untyped-import] Use flow-types for @babel/parser
26
31
  const babelParser = require('@babel/parser');
27
32
 
28
33
  const {buildSchema} = require('../parsers-commons');
29
- const {Visitor} = require('./Visitor');
34
+ const {Visitor} = require('../parsers-primitives');
30
35
  const {buildComponentSchema} = require('./components');
31
- const {wrapComponentSchema} = require('./components/schema');
32
- const {buildModuleSchema} = require('./modules');
36
+ const {wrapComponentSchema} = require('../schema.js');
37
+ const {buildModuleSchema} = require('../parsers-commons.js');
38
+ const {resolveTypeAnnotation} = require('./utils');
33
39
 
34
40
  const fs = require('fs');
35
41
 
@@ -102,6 +108,8 @@ class TypeScriptParser implements Parser {
102
108
  buildModuleSchema,
103
109
  Visitor,
104
110
  this,
111
+ resolveTypeAnnotation,
112
+ typeScriptTranslateTypeAnnotation,
105
113
  );
106
114
  }
107
115
 
@@ -192,7 +200,111 @@ class TypeScriptParser implements Parser {
192
200
  value: member.initializer?.value ?? member.id.name,
193
201
  }));
194
202
  }
203
+
204
+ isModuleInterface(node: $FlowFixMe): boolean {
205
+ return (
206
+ node.type === 'TSInterfaceDeclaration' &&
207
+ node.extends?.length === 1 &&
208
+ node.extends[0].type === 'TSExpressionWithTypeArguments' &&
209
+ node.extends[0].expression.name === 'TurboModule'
210
+ );
211
+ }
212
+
213
+ extractAnnotatedElement(
214
+ typeAnnotation: $FlowFixMe,
215
+ types: TypeDeclarationMap,
216
+ ): $FlowFixMe {
217
+ return types[typeAnnotation.typeParameters.params[0].typeName.name];
218
+ }
219
+
220
+ /**
221
+ * TODO(T108222691): Use flow-types for @babel/parser
222
+ */
223
+ getTypes(ast: $FlowFixMe): TypeDeclarationMap {
224
+ return ast.body.reduce((types, node) => {
225
+ switch (node.type) {
226
+ case 'ExportNamedDeclaration': {
227
+ if (node.declaration) {
228
+ switch (node.declaration.type) {
229
+ case 'TSTypeAliasDeclaration':
230
+ case 'TSInterfaceDeclaration':
231
+ case 'TSEnumDeclaration': {
232
+ types[node.declaration.id.name] = node.declaration;
233
+ break;
234
+ }
235
+ }
236
+ }
237
+ break;
238
+ }
239
+ case 'TSTypeAliasDeclaration':
240
+ case 'TSInterfaceDeclaration':
241
+ case 'TSEnumDeclaration': {
242
+ types[node.id.name] = node;
243
+ break;
244
+ }
245
+ }
246
+ return types;
247
+ }, {});
248
+ }
249
+
250
+ callExpressionTypeParameters(callExpression: $FlowFixMe): $FlowFixMe | null {
251
+ return callExpression.typeParameters || null;
252
+ }
253
+
254
+ computePartialProperties(
255
+ properties: Array<$FlowFixMe>,
256
+ hasteModuleName: string,
257
+ types: TypeDeclarationMap,
258
+ aliasMap: {...NativeModuleAliasMap},
259
+ enumMap: {...NativeModuleEnumMap},
260
+ tryParse: ParserErrorCapturer,
261
+ cxxOnly: boolean,
262
+ ): Array<$FlowFixMe> {
263
+ return properties.map(prop => {
264
+ return {
265
+ name: prop.key.name,
266
+ optional: true,
267
+ typeAnnotation: typeScriptTranslateTypeAnnotation(
268
+ hasteModuleName,
269
+ prop.typeAnnotation.typeAnnotation,
270
+ types,
271
+ aliasMap,
272
+ enumMap,
273
+ tryParse,
274
+ cxxOnly,
275
+ this,
276
+ ),
277
+ };
278
+ });
279
+ }
280
+
281
+ functionTypeAnnotation(propertyValueType: string): boolean {
282
+ return (
283
+ propertyValueType === 'TSFunctionType' ||
284
+ propertyValueType === 'TSMethodSignature'
285
+ );
286
+ }
287
+
288
+ getTypeArgumentParamsFromDeclaration(declaration: $FlowFixMe): $FlowFixMe {
289
+ return declaration.typeParameters.params;
290
+ }
291
+
292
+ // This FlowFixMe is supposed to refer to typeArgumentParams and funcArgumentParams of generated AST.
293
+ getNativeComponentType(
294
+ typeArgumentParams: $FlowFixMe,
295
+ funcArgumentParams: $FlowFixMe,
296
+ ): {[string]: string} {
297
+ return {
298
+ propsTypeName: typeArgumentParams[0].typeName.name,
299
+ componentName: funcArgumentParams[0].value,
300
+ };
301
+ }
302
+
303
+ getAnnotatedElementProperties(annotatedElement: $FlowFixMe): $FlowFixMe {
304
+ return annotatedElement.typeAnnotation.members;
305
+ }
195
306
  }
307
+
196
308
  module.exports = {
197
309
  TypeScriptParser,
198
310
  };
@@ -13,36 +13,6 @@
13
13
  const _require = require('./parseTopLevelType'),
14
14
  parseTopLevelType = _require.parseTopLevelType;
15
15
 
16
- /**
17
- * TODO(T108222691): Use flow-types for @babel/parser
18
- */
19
- function getTypes(ast) {
20
- return ast.body.reduce((types, node) => {
21
- switch (node.type) {
22
- case 'ExportNamedDeclaration': {
23
- if (node.declaration) {
24
- switch (node.declaration.type) {
25
- case 'TSTypeAliasDeclaration':
26
- case 'TSInterfaceDeclaration':
27
- case 'TSEnumDeclaration': {
28
- types[node.declaration.id.name] = node.declaration;
29
- break;
30
- }
31
- }
32
- }
33
- break;
34
- }
35
- case 'TSTypeAliasDeclaration':
36
- case 'TSInterfaceDeclaration':
37
- case 'TSEnumDeclaration': {
38
- types[node.id.name] = node;
39
- break;
40
- }
41
- }
42
- return types;
43
- }, {});
44
- }
45
-
46
16
  // $FlowFixMe[unclear-type] Use flow-types for @babel/parser
47
17
 
48
18
  const invariant = require('invariant');
@@ -117,5 +87,4 @@ function resolveTypeAnnotation(
117
87
  }
118
88
  module.exports = {
119
89
  resolveTypeAnnotation,
120
- getTypes,
121
90
  };
@@ -14,36 +14,6 @@ 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
- function getTypes(ast: $FlowFixMe): TypeDeclarationMap {
21
- return ast.body.reduce((types, node) => {
22
- switch (node.type) {
23
- case 'ExportNamedDeclaration': {
24
- if (node.declaration) {
25
- switch (node.declaration.type) {
26
- case 'TSTypeAliasDeclaration':
27
- case 'TSInterfaceDeclaration':
28
- case 'TSEnumDeclaration': {
29
- types[node.declaration.id.name] = node.declaration;
30
- break;
31
- }
32
- }
33
- }
34
- break;
35
- }
36
- case 'TSTypeAliasDeclaration':
37
- case 'TSInterfaceDeclaration':
38
- case 'TSEnumDeclaration': {
39
- types[node.id.name] = node;
40
- break;
41
- }
42
- }
43
- return types;
44
- }, {});
45
- }
46
-
47
17
  // $FlowFixMe[unclear-type] Use flow-types for @babel/parser
48
18
  export type ASTNode = Object;
49
19
 
@@ -131,5 +101,4 @@ function resolveTypeAnnotation(
131
101
 
132
102
  module.exports = {
133
103
  resolveTypeAnnotation,
134
- getTypes,
135
104
  };
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native/codegen",
3
- "version": "0.72.2",
3
+ "version": "0.72.4",
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": {
@@ -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,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
- };