@react-native/codegen 0.72.1
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/README.md +21 -0
- package/lib/CodegenSchema.js +11 -0
- package/lib/CodegenSchema.js.flow +351 -0
- package/lib/SchemaValidator.js +54 -0
- package/lib/SchemaValidator.js.flow +67 -0
- package/lib/cli/combine/combine-js-to-schema-cli.js +50 -0
- package/lib/cli/combine/combine-js-to-schema-cli.js.flow +49 -0
- package/lib/cli/combine/combine-js-to-schema.js +110 -0
- package/lib/cli/combine/combine-js-to-schema.js.flow +48 -0
- package/lib/cli/combine/combine-utils.js +118 -0
- package/lib/cli/combine/combine-utils.js.flow +85 -0
- package/lib/cli/generators/generate-all.js +65 -0
- package/lib/cli/generators/generate-all.js.flow +66 -0
- package/lib/cli/parser/parser-cli.js +55 -0
- package/lib/cli/parser/parser-cli.js.flow +18 -0
- package/lib/cli/parser/parser.js +35 -0
- package/lib/cli/parser/parser.js.flow +37 -0
- package/lib/cli/parser/parser.sh +15 -0
- package/lib/generators/RNCodegen.js +207 -0
- package/lib/generators/RNCodegen.js.flow +284 -0
- package/lib/generators/Utils.js +31 -0
- package/lib/generators/Utils.js.flow +33 -0
- package/lib/generators/__test_fixtures__/fixtures.js +79 -0
- package/lib/generators/__test_fixtures__/fixtures.js.flow +82 -0
- package/lib/generators/components/ComponentsGeneratorUtils.js +217 -0
- package/lib/generators/components/ComponentsGeneratorUtils.js.flow +304 -0
- package/lib/generators/components/CppHelpers.js +188 -0
- package/lib/generators/components/CppHelpers.js.flow +228 -0
- package/lib/generators/components/GenerateComponentDescriptorH.js +75 -0
- package/lib/generators/components/GenerateComponentDescriptorH.js.flow +95 -0
- package/lib/generators/components/GenerateComponentHObjCpp.js +327 -0
- package/lib/generators/components/GenerateComponentHObjCpp.js.flow +418 -0
- package/lib/generators/components/GenerateEventEmitterCpp.js +199 -0
- package/lib/generators/components/GenerateEventEmitterCpp.js.flow +273 -0
- package/lib/generators/components/GenerateEventEmitterH.js +224 -0
- package/lib/generators/components/GenerateEventEmitterH.js.flow +315 -0
- package/lib/generators/components/GeneratePropsCpp.js +126 -0
- package/lib/generators/components/GeneratePropsCpp.js.flow +161 -0
- package/lib/generators/components/GeneratePropsH.js +606 -0
- package/lib/generators/components/GeneratePropsH.js.flow +778 -0
- package/lib/generators/components/GeneratePropsJavaDelegate.js +287 -0
- package/lib/generators/components/GeneratePropsJavaDelegate.js.flow +348 -0
- package/lib/generators/components/GeneratePropsJavaInterface.js +237 -0
- package/lib/generators/components/GeneratePropsJavaInterface.js.flow +288 -0
- package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js +157 -0
- package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js.flow +187 -0
- package/lib/generators/components/GeneratePropsJavaPojo/index.js +66 -0
- package/lib/generators/components/GeneratePropsJavaPojo/index.js.flow +80 -0
- package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js +273 -0
- package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js.flow +296 -0
- package/lib/generators/components/GenerateShadowNodeCpp.js +73 -0
- package/lib/generators/components/GenerateShadowNodeCpp.js.flow +95 -0
- package/lib/generators/components/GenerateShadowNodeH.js +91 -0
- package/lib/generators/components/GenerateShadowNodeH.js.flow +124 -0
- package/lib/generators/components/GenerateStateCpp.js +70 -0
- package/lib/generators/components/GenerateStateCpp.js.flow +92 -0
- package/lib/generators/components/GenerateStateH.js +93 -0
- package/lib/generators/components/GenerateStateH.js.flow +111 -0
- package/lib/generators/components/GenerateTests.js +165 -0
- package/lib/generators/components/GenerateTests.js.flow +219 -0
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js +91 -0
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js.flow +107 -0
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js +89 -0
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js.flow +105 -0
- package/lib/generators/components/GenerateViewConfigJs.js +410 -0
- package/lib/generators/components/GenerateViewConfigJs.js.flow +484 -0
- package/lib/generators/components/JavaHelpers.js +87 -0
- package/lib/generators/components/JavaHelpers.js.flow +119 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js +1641 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js.flow +1672 -0
- package/lib/generators/modules/GenerateModuleCpp.js +299 -0
- package/lib/generators/modules/GenerateModuleCpp.js.flow +278 -0
- package/lib/generators/modules/GenerateModuleH.js +373 -0
- package/lib/generators/modules/GenerateModuleH.js.flow +355 -0
- package/lib/generators/modules/GenerateModuleJavaSpec.js +571 -0
- package/lib/generators/modules/GenerateModuleJavaSpec.js.flow +553 -0
- package/lib/generators/modules/GenerateModuleJniCpp.js +505 -0
- package/lib/generators/modules/GenerateModuleJniCpp.js.flow +523 -0
- package/lib/generators/modules/GenerateModuleJniH.js +138 -0
- package/lib/generators/modules/GenerateModuleJniH.js.flow +148 -0
- package/lib/generators/modules/GenerateModuleObjCpp/StructCollector.js +262 -0
- package/lib/generators/modules/GenerateModuleObjCpp/StructCollector.js.flow +208 -0
- package/lib/generators/modules/GenerateModuleObjCpp/Utils.js +25 -0
- package/lib/generators/modules/GenerateModuleObjCpp/Utils.js.flow +32 -0
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js +337 -0
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js.flow +288 -0
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js +330 -0
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js.flow +279 -0
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeStruct.js +25 -0
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeStruct.js.flow +35 -0
- package/lib/generators/modules/GenerateModuleObjCpp/index.js +185 -0
- package/lib/generators/modules/GenerateModuleObjCpp/index.js.flow +219 -0
- package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js +529 -0
- package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js.flow +510 -0
- package/lib/generators/modules/GenerateModuleObjCpp/source/serializeModule.js +96 -0
- package/lib/generators/modules/GenerateModuleObjCpp/source/serializeModule.js.flow +121 -0
- package/lib/generators/modules/Utils.js +34 -0
- package/lib/generators/modules/Utils.js.flow +53 -0
- package/lib/generators/modules/__test_fixtures__/fixtures.js +1658 -0
- package/lib/generators/modules/__test_fixtures__/fixtures.js.flow +1669 -0
- package/lib/parsers/consistency/compareSnaps.js +84 -0
- package/lib/parsers/error-utils.js +284 -0
- package/lib/parsers/error-utils.js.flow +295 -0
- package/lib/parsers/errors.js +350 -0
- package/lib/parsers/errors.js.flow +439 -0
- package/lib/parsers/flow/components/__test_fixtures__/failures.js +583 -0
- package/lib/parsers/flow/components/__test_fixtures__/failures.js.flow +600 -0
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +1001 -0
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +1016 -0
- package/lib/parsers/flow/components/commands.js +104 -0
- package/lib/parsers/flow/components/commands.js.flow +123 -0
- package/lib/parsers/flow/components/componentsUtils.js +446 -0
- package/lib/parsers/flow/components/componentsUtils.js.flow +496 -0
- package/lib/parsers/flow/components/events.js +233 -0
- package/lib/parsers/flow/components/events.js.flow +262 -0
- package/lib/parsers/flow/components/extends.js +52 -0
- package/lib/parsers/flow/components/extends.js.flow +66 -0
- package/lib/parsers/flow/components/index.js +267 -0
- package/lib/parsers/flow/components/index.js.flow +226 -0
- package/lib/parsers/flow/components/options.js +72 -0
- package/lib/parsers/flow/components/options.js.flow +87 -0
- package/lib/parsers/flow/components/props.js +47 -0
- package/lib/parsers/flow/components/props.js.flow +60 -0
- package/lib/parsers/flow/components/schema.js +106 -0
- package/lib/parsers/flow/components/schema.js.flow +62 -0
- package/lib/parsers/flow/index.js +80 -0
- package/lib/parsers/flow/index.js.flow +85 -0
- package/lib/parsers/flow/modules/__test_fixtures__/failures.js +215 -0
- package/lib/parsers/flow/modules/__test_fixtures__/failures.js.flow +223 -0
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js +724 -0
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js.flow +747 -0
- package/lib/parsers/flow/modules/index.js +528 -0
- package/lib/parsers/flow/modules/index.js.flow +420 -0
- package/lib/parsers/flow/parser.js +109 -0
- package/lib/parsers/flow/parser.js.flow +83 -0
- package/lib/parsers/flow/utils.js +108 -0
- package/lib/parsers/flow/utils.js.flow +123 -0
- package/lib/parsers/parser.js +11 -0
- package/lib/parsers/parser.js.flow +70 -0
- package/lib/parsers/parserMock.js +96 -0
- package/lib/parsers/parserMock.js.flow +68 -0
- package/lib/parsers/parsers-commons.js +448 -0
- package/lib/parsers/parsers-commons.js.flow +447 -0
- package/lib/parsers/parsers-primitives.js +387 -0
- package/lib/parsers/parsers-primitives.js.flow +383 -0
- package/lib/parsers/parsers-utils.js +18 -0
- package/lib/parsers/parsers-utils.js.flow +19 -0
- package/lib/parsers/schema/index.js +23 -0
- package/lib/parsers/schema/index.js.flow +26 -0
- package/lib/parsers/typescript/components/__test_fixtures__/failures.js +489 -0
- package/lib/parsers/typescript/components/__test_fixtures__/failures.js.flow +505 -0
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +1151 -0
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +1168 -0
- package/lib/parsers/typescript/components/commands.js +132 -0
- package/lib/parsers/typescript/components/commands.js.flow +151 -0
- package/lib/parsers/typescript/components/componentsUtils.js +471 -0
- package/lib/parsers/typescript/components/componentsUtils.js.flow +521 -0
- package/lib/parsers/typescript/components/events.js +240 -0
- package/lib/parsers/typescript/components/events.js.flow +262 -0
- package/lib/parsers/typescript/components/extends.js +88 -0
- package/lib/parsers/typescript/components/extends.js.flow +103 -0
- package/lib/parsers/typescript/components/index.js +277 -0
- package/lib/parsers/typescript/components/index.js.flow +239 -0
- package/lib/parsers/typescript/components/options.js +72 -0
- package/lib/parsers/typescript/components/options.js.flow +87 -0
- package/lib/parsers/typescript/components/props.js +39 -0
- package/lib/parsers/typescript/components/props.js.flow +48 -0
- package/lib/parsers/typescript/components/schema.js +106 -0
- package/lib/parsers/typescript/components/schema.js.flow +62 -0
- package/lib/parsers/typescript/index.js +85 -0
- package/lib/parsers/typescript/index.js.flow +94 -0
- package/lib/parsers/typescript/modules/__test_fixtures__/failures.js +160 -0
- package/lib/parsers/typescript/modules/__test_fixtures__/failures.js.flow +167 -0
- package/lib/parsers/typescript/modules/__test_fixtures__/fixtures.js +701 -0
- package/lib/parsers/typescript/modules/__test_fixtures__/fixtures.js.flow +727 -0
- package/lib/parsers/typescript/modules/index.js +543 -0
- package/lib/parsers/typescript/modules/index.js.flow +435 -0
- package/lib/parsers/typescript/parseTopLevelType.js +203 -0
- package/lib/parsers/typescript/parseTopLevelType.js.flow +243 -0
- package/lib/parsers/typescript/parser.js +105 -0
- package/lib/parsers/typescript/parser.js.flow +87 -0
- package/lib/parsers/typescript/utils.js +101 -0
- package/lib/parsers/typescript/utils.js.flow +115 -0
- package/lib/parsers/utils.js +273 -0
- package/lib/parsers/utils.js.flow +266 -0
- package/package.json +45 -0
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
// File path -> contents
|
|
14
|
+
|
|
15
|
+
const FileTemplate = ({libraryName, stateClasses}) => `
|
|
16
|
+
/**
|
|
17
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
18
|
+
*
|
|
19
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
20
|
+
* once the code is regenerated.
|
|
21
|
+
*
|
|
22
|
+
* ${'@'}generated by codegen project: GenerateStateCpp.js
|
|
23
|
+
*/
|
|
24
|
+
#include <react/renderer/components/${libraryName}/States.h>
|
|
25
|
+
|
|
26
|
+
namespace facebook {
|
|
27
|
+
namespace react {
|
|
28
|
+
|
|
29
|
+
${stateClasses}
|
|
30
|
+
|
|
31
|
+
} // namespace react
|
|
32
|
+
} // namespace facebook
|
|
33
|
+
`;
|
|
34
|
+
const StateTemplate = ({stateName}) => '';
|
|
35
|
+
module.exports = {
|
|
36
|
+
generate(libraryName, schema, packageName, assumeNonnull = false) {
|
|
37
|
+
const fileName = 'States.cpp';
|
|
38
|
+
const stateClasses = Object.keys(schema.modules)
|
|
39
|
+
.map(moduleName => {
|
|
40
|
+
const module = schema.modules[moduleName];
|
|
41
|
+
if (module.type !== 'Component') {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const components = module.components;
|
|
45
|
+
// No components in this module
|
|
46
|
+
if (components == null) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
return Object.keys(components)
|
|
50
|
+
.map(componentName => {
|
|
51
|
+
const component = components[componentName];
|
|
52
|
+
if (component.interfaceOnly === true) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
return StateTemplate({
|
|
56
|
+
stateName: `${componentName}State`,
|
|
57
|
+
});
|
|
58
|
+
})
|
|
59
|
+
.filter(Boolean)
|
|
60
|
+
.join('\n');
|
|
61
|
+
})
|
|
62
|
+
.filter(Boolean)
|
|
63
|
+
.join('\n');
|
|
64
|
+
const replacedTemplate = FileTemplate({
|
|
65
|
+
libraryName,
|
|
66
|
+
stateClasses,
|
|
67
|
+
});
|
|
68
|
+
return new Map([[fileName, replacedTemplate]]);
|
|
69
|
+
},
|
|
70
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
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 {SchemaType} from '../../CodegenSchema';
|
|
14
|
+
|
|
15
|
+
// File path -> contents
|
|
16
|
+
type FilesOutput = Map<string, string>;
|
|
17
|
+
|
|
18
|
+
const FileTemplate = ({
|
|
19
|
+
libraryName,
|
|
20
|
+
stateClasses,
|
|
21
|
+
}: {
|
|
22
|
+
libraryName: string,
|
|
23
|
+
stateClasses: string,
|
|
24
|
+
}) => `
|
|
25
|
+
/**
|
|
26
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
27
|
+
*
|
|
28
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
29
|
+
* once the code is regenerated.
|
|
30
|
+
*
|
|
31
|
+
* ${'@'}generated by codegen project: GenerateStateCpp.js
|
|
32
|
+
*/
|
|
33
|
+
#include <react/renderer/components/${libraryName}/States.h>
|
|
34
|
+
|
|
35
|
+
namespace facebook {
|
|
36
|
+
namespace react {
|
|
37
|
+
|
|
38
|
+
${stateClasses}
|
|
39
|
+
|
|
40
|
+
} // namespace react
|
|
41
|
+
} // namespace facebook
|
|
42
|
+
`;
|
|
43
|
+
|
|
44
|
+
const StateTemplate = ({stateName}: {stateName: string}) => '';
|
|
45
|
+
|
|
46
|
+
module.exports = {
|
|
47
|
+
generate(
|
|
48
|
+
libraryName: string,
|
|
49
|
+
schema: SchemaType,
|
|
50
|
+
packageName?: string,
|
|
51
|
+
assumeNonnull: boolean = false,
|
|
52
|
+
): FilesOutput {
|
|
53
|
+
const fileName = 'States.cpp';
|
|
54
|
+
|
|
55
|
+
const stateClasses = Object.keys(schema.modules)
|
|
56
|
+
.map(moduleName => {
|
|
57
|
+
const module = schema.modules[moduleName];
|
|
58
|
+
if (module.type !== 'Component') {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const {components} = module;
|
|
63
|
+
// No components in this module
|
|
64
|
+
if (components == null) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return Object.keys(components)
|
|
69
|
+
.map(componentName => {
|
|
70
|
+
const component = components[componentName];
|
|
71
|
+
if (component.interfaceOnly === true) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return StateTemplate({
|
|
76
|
+
stateName: `${componentName}State`,
|
|
77
|
+
});
|
|
78
|
+
})
|
|
79
|
+
.filter(Boolean)
|
|
80
|
+
.join('\n');
|
|
81
|
+
})
|
|
82
|
+
.filter(Boolean)
|
|
83
|
+
.join('\n');
|
|
84
|
+
|
|
85
|
+
const replacedTemplate = FileTemplate({
|
|
86
|
+
libraryName,
|
|
87
|
+
stateClasses,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
return new Map([[fileName, replacedTemplate]]);
|
|
91
|
+
},
|
|
92
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
// File path -> contents
|
|
14
|
+
|
|
15
|
+
const FileTemplate = ({libraryName, stateClasses}) =>
|
|
16
|
+
`
|
|
17
|
+
/**
|
|
18
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
19
|
+
*
|
|
20
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
21
|
+
* once the code is regenerated.
|
|
22
|
+
*
|
|
23
|
+
* ${'@'}generated by codegen project: GenerateStateH.js
|
|
24
|
+
*/
|
|
25
|
+
#pragma once
|
|
26
|
+
|
|
27
|
+
#ifdef ANDROID
|
|
28
|
+
#include <folly/dynamic.h>
|
|
29
|
+
#include <react/renderer/mapbuffer/MapBuffer.h>
|
|
30
|
+
#include <react/renderer/mapbuffer/MapBufferBuilder.h>
|
|
31
|
+
#endif
|
|
32
|
+
|
|
33
|
+
namespace facebook {
|
|
34
|
+
namespace react {
|
|
35
|
+
|
|
36
|
+
${stateClasses}
|
|
37
|
+
|
|
38
|
+
} // namespace react
|
|
39
|
+
} // namespace facebook
|
|
40
|
+
`.trim();
|
|
41
|
+
const StateTemplate = ({stateName}) =>
|
|
42
|
+
`
|
|
43
|
+
class ${stateName}State {
|
|
44
|
+
public:
|
|
45
|
+
${stateName}State() = default;
|
|
46
|
+
|
|
47
|
+
#ifdef ANDROID
|
|
48
|
+
${stateName}State(${stateName}State const &previousState, folly::dynamic data){};
|
|
49
|
+
folly::dynamic getDynamic() const {
|
|
50
|
+
return {};
|
|
51
|
+
};
|
|
52
|
+
MapBuffer getMapBuffer() const {
|
|
53
|
+
return MapBufferBuilder::EMPTY();
|
|
54
|
+
};
|
|
55
|
+
#endif
|
|
56
|
+
};
|
|
57
|
+
`.trim();
|
|
58
|
+
module.exports = {
|
|
59
|
+
generate(libraryName, schema, packageName, assumeNonnull = false) {
|
|
60
|
+
const fileName = 'States.h';
|
|
61
|
+
const stateClasses = Object.keys(schema.modules)
|
|
62
|
+
.map(moduleName => {
|
|
63
|
+
const module = schema.modules[moduleName];
|
|
64
|
+
if (module.type !== 'Component') {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const components = module.components;
|
|
68
|
+
// No components in this module
|
|
69
|
+
if (components == null) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
return Object.keys(components)
|
|
73
|
+
.map(componentName => {
|
|
74
|
+
const component = components[componentName];
|
|
75
|
+
if (component.interfaceOnly === true) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
return StateTemplate({
|
|
79
|
+
stateName: componentName,
|
|
80
|
+
});
|
|
81
|
+
})
|
|
82
|
+
.filter(Boolean)
|
|
83
|
+
.join('\n\n');
|
|
84
|
+
})
|
|
85
|
+
.filter(Boolean)
|
|
86
|
+
.join('\n\n');
|
|
87
|
+
const template = FileTemplate({
|
|
88
|
+
libraryName,
|
|
89
|
+
stateClasses,
|
|
90
|
+
});
|
|
91
|
+
return new Map([[fileName, template]]);
|
|
92
|
+
},
|
|
93
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
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 {SchemaType} from '../../CodegenSchema';
|
|
14
|
+
|
|
15
|
+
// File path -> contents
|
|
16
|
+
type FilesOutput = Map<string, string>;
|
|
17
|
+
|
|
18
|
+
const FileTemplate = ({
|
|
19
|
+
libraryName,
|
|
20
|
+
stateClasses,
|
|
21
|
+
}: {
|
|
22
|
+
libraryName: string,
|
|
23
|
+
stateClasses: string,
|
|
24
|
+
}) =>
|
|
25
|
+
`
|
|
26
|
+
/**
|
|
27
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
28
|
+
*
|
|
29
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
30
|
+
* once the code is regenerated.
|
|
31
|
+
*
|
|
32
|
+
* ${'@'}generated by codegen project: GenerateStateH.js
|
|
33
|
+
*/
|
|
34
|
+
#pragma once
|
|
35
|
+
|
|
36
|
+
#ifdef ANDROID
|
|
37
|
+
#include <folly/dynamic.h>
|
|
38
|
+
#include <react/renderer/mapbuffer/MapBuffer.h>
|
|
39
|
+
#include <react/renderer/mapbuffer/MapBufferBuilder.h>
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
namespace facebook {
|
|
43
|
+
namespace react {
|
|
44
|
+
|
|
45
|
+
${stateClasses}
|
|
46
|
+
|
|
47
|
+
} // namespace react
|
|
48
|
+
} // namespace facebook
|
|
49
|
+
`.trim();
|
|
50
|
+
|
|
51
|
+
const StateTemplate = ({stateName}: {stateName: string}) =>
|
|
52
|
+
`
|
|
53
|
+
class ${stateName}State {
|
|
54
|
+
public:
|
|
55
|
+
${stateName}State() = default;
|
|
56
|
+
|
|
57
|
+
#ifdef ANDROID
|
|
58
|
+
${stateName}State(${stateName}State const &previousState, folly::dynamic data){};
|
|
59
|
+
folly::dynamic getDynamic() const {
|
|
60
|
+
return {};
|
|
61
|
+
};
|
|
62
|
+
MapBuffer getMapBuffer() const {
|
|
63
|
+
return MapBufferBuilder::EMPTY();
|
|
64
|
+
};
|
|
65
|
+
#endif
|
|
66
|
+
};
|
|
67
|
+
`.trim();
|
|
68
|
+
|
|
69
|
+
module.exports = {
|
|
70
|
+
generate(
|
|
71
|
+
libraryName: string,
|
|
72
|
+
schema: SchemaType,
|
|
73
|
+
packageName?: string,
|
|
74
|
+
assumeNonnull: boolean = false,
|
|
75
|
+
): FilesOutput {
|
|
76
|
+
const fileName = 'States.h';
|
|
77
|
+
|
|
78
|
+
const stateClasses = Object.keys(schema.modules)
|
|
79
|
+
.map(moduleName => {
|
|
80
|
+
const module = schema.modules[moduleName];
|
|
81
|
+
if (module.type !== 'Component') {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const {components} = module;
|
|
86
|
+
// No components in this module
|
|
87
|
+
if (components == null) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return Object.keys(components)
|
|
92
|
+
.map(componentName => {
|
|
93
|
+
const component = components[componentName];
|
|
94
|
+
if (component.interfaceOnly === true) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
return StateTemplate({stateName: componentName});
|
|
98
|
+
})
|
|
99
|
+
.filter(Boolean)
|
|
100
|
+
.join('\n\n');
|
|
101
|
+
})
|
|
102
|
+
.filter(Boolean)
|
|
103
|
+
.join('\n\n');
|
|
104
|
+
|
|
105
|
+
const template = FileTemplate({
|
|
106
|
+
libraryName,
|
|
107
|
+
stateClasses,
|
|
108
|
+
});
|
|
109
|
+
return new Map([[fileName, template]]);
|
|
110
|
+
},
|
|
111
|
+
};
|
|
@@ -0,0 +1,165 @@
|
|
|
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('./CppHelpers'),
|
|
14
|
+
getImports = _require.getImports,
|
|
15
|
+
toSafeCppString = _require.toSafeCppString;
|
|
16
|
+
const FileTemplate = ({libraryName, imports, componentTests}) =>
|
|
17
|
+
`
|
|
18
|
+
/**
|
|
19
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
20
|
+
*
|
|
21
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
22
|
+
* once the code is regenerated.
|
|
23
|
+
*
|
|
24
|
+
* ${'@'}generated by codegen project: GenerateTests.js
|
|
25
|
+
* */
|
|
26
|
+
|
|
27
|
+
#include <gtest/gtest.h>
|
|
28
|
+
#include <react/renderer/core/PropsParserContext.h>
|
|
29
|
+
#include <react/renderer/components/${libraryName}/Props.h>
|
|
30
|
+
${imports}
|
|
31
|
+
|
|
32
|
+
using namespace facebook::react;
|
|
33
|
+
${componentTests}
|
|
34
|
+
`.trim();
|
|
35
|
+
const TestTemplate = ({componentName, testName, propName, propValue}) => `
|
|
36
|
+
TEST(${componentName}_${testName}, etc) {
|
|
37
|
+
auto propParser = RawPropsParser();
|
|
38
|
+
propParser.prepare<${componentName}>();
|
|
39
|
+
auto const &sourceProps = ${componentName}();
|
|
40
|
+
auto const &rawProps = RawProps(folly::dynamic::object("${propName}", ${propValue}));
|
|
41
|
+
|
|
42
|
+
ContextContainer contextContainer{};
|
|
43
|
+
PropsParserContext parserContext{-1, contextContainer};
|
|
44
|
+
|
|
45
|
+
rawProps.parse(propParser, parserContext);
|
|
46
|
+
${componentName}(parserContext, sourceProps, rawProps);
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
function getTestCasesForProp(propName, typeAnnotation) {
|
|
50
|
+
const cases = [];
|
|
51
|
+
if (typeAnnotation.type === 'StringEnumTypeAnnotation') {
|
|
52
|
+
typeAnnotation.options.forEach(option =>
|
|
53
|
+
cases.push({
|
|
54
|
+
propName,
|
|
55
|
+
testName: `${propName}_${toSafeCppString(option)}`,
|
|
56
|
+
propValue: option,
|
|
57
|
+
}),
|
|
58
|
+
);
|
|
59
|
+
} else if (typeAnnotation.type === 'StringTypeAnnotation') {
|
|
60
|
+
cases.push({
|
|
61
|
+
propName,
|
|
62
|
+
propValue:
|
|
63
|
+
typeAnnotation.default != null && typeAnnotation.default !== ''
|
|
64
|
+
? typeAnnotation.default
|
|
65
|
+
: 'foo',
|
|
66
|
+
});
|
|
67
|
+
} else if (typeAnnotation.type === 'BooleanTypeAnnotation') {
|
|
68
|
+
cases.push({
|
|
69
|
+
propName: propName,
|
|
70
|
+
propValue: typeAnnotation.default != null ? typeAnnotation.default : true,
|
|
71
|
+
});
|
|
72
|
+
// $FlowFixMe[incompatible-type]
|
|
73
|
+
} else if (typeAnnotation.type === 'IntegerTypeAnnotation') {
|
|
74
|
+
cases.push({
|
|
75
|
+
propName,
|
|
76
|
+
propValue: typeAnnotation.default || 10,
|
|
77
|
+
});
|
|
78
|
+
} else if (typeAnnotation.type === 'FloatTypeAnnotation') {
|
|
79
|
+
cases.push({
|
|
80
|
+
propName,
|
|
81
|
+
propValue: typeAnnotation.default != null ? typeAnnotation.default : 0.1,
|
|
82
|
+
});
|
|
83
|
+
} else if (typeAnnotation.type === 'ReservedPropTypeAnnotation') {
|
|
84
|
+
if (typeAnnotation.name === 'ColorPrimitive') {
|
|
85
|
+
cases.push({
|
|
86
|
+
propName,
|
|
87
|
+
propValue: 1,
|
|
88
|
+
});
|
|
89
|
+
} else if (typeAnnotation.name === 'PointPrimitive') {
|
|
90
|
+
cases.push({
|
|
91
|
+
propName,
|
|
92
|
+
propValue: 'folly::dynamic::object("x", 1)("y", 1)',
|
|
93
|
+
raw: true,
|
|
94
|
+
});
|
|
95
|
+
} else if (typeAnnotation.name === 'ImageSourcePrimitive') {
|
|
96
|
+
cases.push({
|
|
97
|
+
propName,
|
|
98
|
+
propValue: 'folly::dynamic::object("url", "testurl")',
|
|
99
|
+
raw: true,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return cases;
|
|
104
|
+
}
|
|
105
|
+
function generateTestsString(name, component) {
|
|
106
|
+
function createTest({testName, propName, propValue, raw = false}) {
|
|
107
|
+
const value =
|
|
108
|
+
!raw && typeof propValue === 'string' ? `"${propValue}"` : propValue;
|
|
109
|
+
return TestTemplate({
|
|
110
|
+
componentName: name,
|
|
111
|
+
testName: testName != null ? testName : propName,
|
|
112
|
+
propName,
|
|
113
|
+
propValue: String(value),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
const testCases = component.props.reduce((cases, prop) => {
|
|
117
|
+
return cases.concat(getTestCasesForProp(prop.name, prop.typeAnnotation));
|
|
118
|
+
}, []);
|
|
119
|
+
const baseTest = {
|
|
120
|
+
testName: 'DoesNotDie',
|
|
121
|
+
propName: 'xx_invalid_xx',
|
|
122
|
+
propValue: 'xx_invalid_xx',
|
|
123
|
+
};
|
|
124
|
+
return [baseTest, ...testCases].map(createTest).join('');
|
|
125
|
+
}
|
|
126
|
+
module.exports = {
|
|
127
|
+
generate(libraryName, schema, packageName, assumeNonnull = false) {
|
|
128
|
+
const fileName = 'Tests.cpp';
|
|
129
|
+
const allImports = new Set([
|
|
130
|
+
'#include <react/renderer/core/propsConversions.h>',
|
|
131
|
+
'#include <react/renderer/core/RawProps.h>',
|
|
132
|
+
'#include <react/renderer/core/RawPropsParser.h>',
|
|
133
|
+
]);
|
|
134
|
+
const componentTests = Object.keys(schema.modules)
|
|
135
|
+
.map(moduleName => {
|
|
136
|
+
const module = schema.modules[moduleName];
|
|
137
|
+
if (module.type !== 'Component') {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const components = module.components;
|
|
141
|
+
if (components == null) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
return Object.keys(components)
|
|
145
|
+
.map(componentName => {
|
|
146
|
+
const component = components[componentName];
|
|
147
|
+
const name = `${componentName}Props`;
|
|
148
|
+
const imports = getImports(component.props);
|
|
149
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
150
|
+
imports.forEach(allImports.add, allImports);
|
|
151
|
+
return generateTestsString(name, component);
|
|
152
|
+
})
|
|
153
|
+
.join('');
|
|
154
|
+
})
|
|
155
|
+
.filter(Boolean)
|
|
156
|
+
.join('');
|
|
157
|
+
const imports = Array.from(allImports).sort().join('\n').trim();
|
|
158
|
+
const replacedTemplate = FileTemplate({
|
|
159
|
+
imports,
|
|
160
|
+
libraryName,
|
|
161
|
+
componentTests,
|
|
162
|
+
});
|
|
163
|
+
return new Map([[fileName, replacedTemplate]]);
|
|
164
|
+
},
|
|
165
|
+
};
|