@react-native/codegen 0.72.5 → 0.73.0-nightly-20230605-5062553c6

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 (72) hide show
  1. package/README.md +2 -2
  2. package/lib/CodegenSchema.d.ts +15 -4
  3. package/lib/CodegenSchema.js.flow +33 -21
  4. package/lib/generators/components/CppHelpers.js +39 -2
  5. package/lib/generators/components/CppHelpers.js.flow +54 -5
  6. package/lib/generators/components/GenerateEventEmitterCpp.js +238 -55
  7. package/lib/generators/components/GenerateEventEmitterCpp.js.flow +233 -55
  8. package/lib/generators/components/GenerateEventEmitterH.js +77 -28
  9. package/lib/generators/components/GenerateEventEmitterH.js.flow +87 -32
  10. package/lib/generators/components/GeneratePropsH.js +1 -2
  11. package/lib/generators/components/GeneratePropsH.js.flow +1 -2
  12. package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js +0 -1
  13. package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js.flow +3 -5
  14. package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js +4 -0
  15. package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js.flow +4 -0
  16. package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js +2 -0
  17. package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js.flow +2 -0
  18. package/lib/generators/components/__test_fixtures__/fixtures.js +114 -1
  19. package/lib/generators/components/__test_fixtures__/fixtures.js.flow +114 -1
  20. package/lib/generators/modules/GenerateModuleCpp.js +3 -3
  21. package/lib/generators/modules/GenerateModuleCpp.js.flow +3 -3
  22. package/lib/generators/modules/GenerateModuleJavaSpec.js +1 -2
  23. package/lib/generators/modules/GenerateModuleJavaSpec.js.flow +1 -2
  24. package/lib/parsers/error-utils.js +44 -0
  25. package/lib/parsers/error-utils.js.flow +59 -0
  26. package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +51 -0
  27. package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +51 -0
  28. package/lib/parsers/flow/components/componentsUtils.js +12 -19
  29. package/lib/parsers/flow/components/componentsUtils.js.flow +16 -27
  30. package/lib/parsers/flow/components/events.js +157 -83
  31. package/lib/parsers/flow/components/events.js.flow +158 -82
  32. package/lib/parsers/flow/components/index.js +10 -129
  33. package/lib/parsers/flow/components/index.js.flow +10 -150
  34. package/lib/parsers/flow/modules/index.js +39 -49
  35. package/lib/parsers/flow/modules/index.js.flow +22 -31
  36. package/lib/parsers/flow/parser.d.ts +9 -2
  37. package/lib/parsers/flow/parser.js +177 -16
  38. package/lib/parsers/flow/parser.js.flow +220 -6
  39. package/lib/parsers/flow/utils.js +0 -63
  40. package/lib/parsers/flow/utils.js.flow +1 -77
  41. package/lib/parsers/parser.js.flow +143 -1
  42. package/lib/parsers/parserMock.js +175 -2
  43. package/lib/parsers/parserMock.js.flow +227 -2
  44. package/lib/parsers/parsers-commons.js +169 -9
  45. package/lib/parsers/parsers-commons.js.flow +233 -12
  46. package/lib/parsers/parsers-primitives.js +94 -35
  47. package/lib/parsers/parsers-primitives.js.flow +124 -35
  48. package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +51 -0
  49. package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +51 -0
  50. package/lib/parsers/typescript/components/componentsUtils.js +44 -46
  51. package/lib/parsers/typescript/components/componentsUtils.js.flow +44 -51
  52. package/lib/parsers/typescript/components/events.js +142 -72
  53. package/lib/parsers/typescript/components/events.js.flow +149 -73
  54. package/lib/parsers/typescript/components/extends.js +2 -49
  55. package/lib/parsers/typescript/components/extends.js.flow +1 -55
  56. package/lib/parsers/typescript/components/index.js +11 -134
  57. package/lib/parsers/typescript/components/index.js.flow +11 -156
  58. package/lib/parsers/typescript/modules/index.js +43 -51
  59. package/lib/parsers/typescript/modules/index.js.flow +25 -32
  60. package/lib/parsers/typescript/parser.d.ts +9 -2
  61. package/lib/parsers/typescript/parser.js +224 -7
  62. package/lib/parsers/typescript/parser.js.flow +262 -6
  63. package/lib/parsers/utils.js.flow +6 -0
  64. package/package.json +16 -5
  65. package/lib/parsers/flow/components/extends.js +0 -52
  66. package/lib/parsers/flow/components/extends.js.flow +0 -66
  67. package/lib/parsers/flow/components/props.js +0 -47
  68. package/lib/parsers/flow/components/props.js.flow +0 -60
  69. package/lib/parsers/typescript/components/props.js +0 -39
  70. package/lib/parsers/typescript/components/props.js.flow +0 -48
  71. package/lib/parsers/typescript/utils.js +0 -90
  72. package/lib/parsers/typescript/utils.js.flow +0 -104
@@ -1,66 +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 {ExtendsPropsShape} from '../../../CodegenSchema.js';
14
- import type {TypeDeclarationMap} from '../../utils';
15
-
16
- function extendsForProp(prop: PropsAST, types: TypeDeclarationMap) {
17
- if (!prop.argument) {
18
- console.log('null', prop);
19
- }
20
- const name = prop.argument.id.name;
21
-
22
- if (types[name] != null) {
23
- // This type is locally defined in the file
24
- return null;
25
- }
26
-
27
- switch (name) {
28
- case 'ViewProps':
29
- return {
30
- type: 'ReactNativeBuiltInType',
31
- knownTypeName: 'ReactNativeCoreViewProps',
32
- };
33
- default: {
34
- throw new Error(`Unable to handle prop spread: ${name}`);
35
- }
36
- }
37
- }
38
-
39
- function removeKnownExtends(
40
- typeDefinition: $ReadOnlyArray<PropsAST>,
41
- types: TypeDeclarationMap,
42
- ): $ReadOnlyArray<PropsAST> {
43
- return typeDefinition.filter(
44
- prop =>
45
- prop.type !== 'ObjectTypeSpreadProperty' ||
46
- extendsForProp(prop, types) === null,
47
- );
48
- }
49
-
50
- // $FlowFixMe[unclear-type] there's no flowtype for ASTs
51
- type PropsAST = Object;
52
-
53
- function getExtendsProps(
54
- typeDefinition: $ReadOnlyArray<PropsAST>,
55
- types: TypeDeclarationMap,
56
- ): $ReadOnlyArray<ExtendsPropsShape> {
57
- return typeDefinition
58
- .filter(prop => prop.type === 'ObjectTypeSpreadProperty')
59
- .map(prop => extendsForProp(prop, types))
60
- .filter(Boolean);
61
- }
62
-
63
- module.exports = {
64
- getExtendsProps,
65
- removeKnownExtends,
66
- };
@@ -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
- *
8
- * @format
9
- */
10
-
11
- 'use strict';
12
-
13
- const _require = require('./componentsUtils.js'),
14
- flattenProperties = _require.flattenProperties,
15
- getSchemaInfo = _require.getSchemaInfo,
16
- getTypeAnnotation = _require.getTypeAnnotation;
17
- function buildPropSchema(property, types) {
18
- const info = getSchemaInfo(property, types);
19
- if (info == null) {
20
- return null;
21
- }
22
- const name = info.name,
23
- optional = info.optional,
24
- typeAnnotation = info.typeAnnotation,
25
- defaultValue = info.defaultValue,
26
- withNullDefault = info.withNullDefault;
27
- return {
28
- name,
29
- optional,
30
- typeAnnotation: getTypeAnnotation(
31
- name,
32
- typeAnnotation,
33
- defaultValue,
34
- withNullDefault,
35
- types,
36
- buildPropSchema,
37
- ),
38
- };
39
- }
40
- function getProps(typeDefinition, types) {
41
- return flattenProperties(typeDefinition, types)
42
- .map(property => buildPropSchema(property, types))
43
- .filter(Boolean);
44
- }
45
- module.exports = {
46
- getProps,
47
- };
@@ -1,60 +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 {
14
- flattenProperties,
15
- getSchemaInfo,
16
- getTypeAnnotation,
17
- } = require('./componentsUtils.js');
18
-
19
- import type {NamedShape, PropTypeAnnotation} from '../../../CodegenSchema.js';
20
- import type {TypeDeclarationMap} from '../../utils';
21
-
22
- // $FlowFixMe[unclear-type] there's no flowtype for ASTs
23
- type PropAST = Object;
24
-
25
- function buildPropSchema(
26
- property: PropAST,
27
- types: TypeDeclarationMap,
28
- ): ?NamedShape<PropTypeAnnotation> {
29
- const info = getSchemaInfo(property, types);
30
- if (info == null) {
31
- return null;
32
- }
33
- const {name, optional, typeAnnotation, defaultValue, withNullDefault} = info;
34
-
35
- return {
36
- name,
37
- optional,
38
- typeAnnotation: getTypeAnnotation(
39
- name,
40
- typeAnnotation,
41
- defaultValue,
42
- withNullDefault,
43
- types,
44
- buildPropSchema,
45
- ),
46
- };
47
- }
48
-
49
- function getProps(
50
- typeDefinition: $ReadOnlyArray<PropAST>,
51
- types: TypeDeclarationMap,
52
- ): $ReadOnlyArray<NamedShape<PropTypeAnnotation>> {
53
- return flattenProperties(typeDefinition, types)
54
- .map(property => buildPropSchema(property, types))
55
- .filter(Boolean);
56
- }
57
-
58
- module.exports = {
59
- getProps,
60
- };
@@ -1,39 +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('./componentsUtils.js'),
14
- getSchemaInfo = _require.getSchemaInfo,
15
- getTypeAnnotation = _require.getTypeAnnotation;
16
- function buildPropSchema(property, types) {
17
- const info = getSchemaInfo(property, types);
18
- const name = info.name,
19
- optional = info.optional,
20
- typeAnnotation = info.typeAnnotation,
21
- defaultValue = info.defaultValue;
22
- return {
23
- name,
24
- optional,
25
- typeAnnotation: getTypeAnnotation(
26
- name,
27
- typeAnnotation,
28
- defaultValue,
29
- types,
30
- buildPropSchema,
31
- ),
32
- };
33
- }
34
- function getProps(typeDefinition, types) {
35
- return typeDefinition.map(property => buildPropSchema(property, types));
36
- }
37
- module.exports = {
38
- getProps,
39
- };
@@ -1,48 +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
- const {getSchemaInfo, getTypeAnnotation} = require('./componentsUtils.js');
13
-
14
- import type {NamedShape, PropTypeAnnotation} from '../../../CodegenSchema.js';
15
- import type {TypeDeclarationMap} from '../../utils';
16
-
17
- // $FlowFixMe[unclear-type] there's no flowtype for ASTs
18
- type PropAST = Object;
19
-
20
- function buildPropSchema(
21
- property: PropAST,
22
- types: TypeDeclarationMap,
23
- ): NamedShape<PropTypeAnnotation> {
24
- const info = getSchemaInfo(property, types);
25
- const {name, optional, typeAnnotation, defaultValue} = info;
26
- return {
27
- name,
28
- optional,
29
- typeAnnotation: getTypeAnnotation(
30
- name,
31
- typeAnnotation,
32
- defaultValue,
33
- types,
34
- buildPropSchema,
35
- ),
36
- };
37
- }
38
-
39
- function getProps(
40
- typeDefinition: $ReadOnlyArray<PropAST>,
41
- types: TypeDeclarationMap,
42
- ): $ReadOnlyArray<NamedShape<PropTypeAnnotation>> {
43
- return typeDefinition.map(property => buildPropSchema(property, types));
44
- }
45
-
46
- module.exports = {
47
- getProps,
48
- };
@@ -1,90 +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('./parseTopLevelType'),
14
- parseTopLevelType = _require.parseTopLevelType;
15
-
16
- // $FlowFixMe[unclear-type] Use flow-types for @babel/parser
17
-
18
- const invariant = require('invariant');
19
- function resolveTypeAnnotation(
20
- // TODO(T108222691): Use flow-types for @babel/parser
21
- typeAnnotation,
22
- types,
23
- ) {
24
- invariant(
25
- typeAnnotation != null,
26
- 'resolveTypeAnnotation(): typeAnnotation cannot be null',
27
- );
28
- let node =
29
- typeAnnotation.type === 'TSTypeAnnotation'
30
- ? typeAnnotation.typeAnnotation
31
- : typeAnnotation;
32
- let nullable = false;
33
- let typeResolutionStatus = {
34
- successful: false,
35
- };
36
- for (;;) {
37
- const topLevelType = parseTopLevelType(node);
38
- nullable = nullable || topLevelType.optional;
39
- node = topLevelType.type;
40
- if (node.type !== 'TSTypeReference') {
41
- break;
42
- }
43
- const resolvedTypeAnnotation = types[node.typeName.name];
44
- if (resolvedTypeAnnotation == null) {
45
- break;
46
- }
47
- switch (resolvedTypeAnnotation.type) {
48
- case 'TSTypeAliasDeclaration': {
49
- typeResolutionStatus = {
50
- successful: true,
51
- type: 'alias',
52
- name: node.typeName.name,
53
- };
54
- node = resolvedTypeAnnotation.typeAnnotation;
55
- break;
56
- }
57
- case 'TSInterfaceDeclaration': {
58
- typeResolutionStatus = {
59
- successful: true,
60
- type: 'alias',
61
- name: node.typeName.name,
62
- };
63
- node = resolvedTypeAnnotation;
64
- break;
65
- }
66
- case 'TSEnumDeclaration': {
67
- typeResolutionStatus = {
68
- successful: true,
69
- type: 'enum',
70
- name: node.typeName.name,
71
- };
72
- node = resolvedTypeAnnotation;
73
- break;
74
- }
75
- default: {
76
- throw new TypeError(
77
- `A non GenericTypeAnnotation must be a type declaration ('TSTypeAliasDeclaration'), an interface ('TSInterfaceDeclaration'), or enum ('TSEnumDeclaration'). Instead, got the unsupported ${resolvedTypeAnnotation.type}.`,
78
- );
79
- }
80
- }
81
- }
82
- return {
83
- nullable: nullable,
84
- typeAnnotation: node,
85
- typeResolutionStatus,
86
- };
87
- }
88
- module.exports = {
89
- resolveTypeAnnotation,
90
- };
@@ -1,104 +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 {TypeResolutionStatus, TypeDeclarationMap} from '../utils';
14
-
15
- const {parseTopLevelType} = require('./parseTopLevelType');
16
-
17
- // $FlowFixMe[unclear-type] Use flow-types for @babel/parser
18
- export type ASTNode = Object;
19
-
20
- const invariant = require('invariant');
21
-
22
- function resolveTypeAnnotation(
23
- // TODO(T108222691): Use flow-types for @babel/parser
24
- typeAnnotation: $FlowFixMe,
25
- types: TypeDeclarationMap,
26
- ): {
27
- nullable: boolean,
28
- typeAnnotation: $FlowFixMe,
29
- typeResolutionStatus: TypeResolutionStatus,
30
- } {
31
- invariant(
32
- typeAnnotation != null,
33
- 'resolveTypeAnnotation(): typeAnnotation cannot be null',
34
- );
35
-
36
- let node =
37
- typeAnnotation.type === 'TSTypeAnnotation'
38
- ? typeAnnotation.typeAnnotation
39
- : typeAnnotation;
40
- let nullable = false;
41
- let typeResolutionStatus: TypeResolutionStatus = {
42
- successful: false,
43
- };
44
-
45
- for (;;) {
46
- const topLevelType = parseTopLevelType(node);
47
- nullable = nullable || topLevelType.optional;
48
- node = topLevelType.type;
49
-
50
- if (node.type !== 'TSTypeReference') {
51
- break;
52
- }
53
-
54
- const resolvedTypeAnnotation = types[node.typeName.name];
55
- if (resolvedTypeAnnotation == null) {
56
- break;
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
- }
93
- }
94
-
95
- return {
96
- nullable: nullable,
97
- typeAnnotation: node,
98
- typeResolutionStatus,
99
- };
100
- }
101
-
102
- module.exports = {
103
- resolveTypeAnnotation,
104
- };