From 2f6b2127d933094f864523749d13cfbb140b5b63 Mon Sep 17 00:00:00 2001 From: Gianluca Spada Date: Wed, 21 Sep 2022 04:13:12 -0700 Subject: [PATCH] Fix: Codegen template error in RCTThirdPartyFabricComponentsProvider (#34738) Summary: When `GenerateRCTThirdPartyFabricComponentsProviderCpp.js` generates `RCTThirdPartyFabricComponentsProvider.mm` an edge case happens in the following situation: - The same library exports multiple modules with one component each (i.e. one component per file); - The **first component** is excluded for iOS via the `excludedPlatforms` property in *codegenNativeComponent*. A "loose" comma appears in the generated template, breaking the code. ```c++ Class RCTThirdPartyFabricComponentsProvider(const char *name) { static std::unordered_map sFabricComponentsClassMap = { , // <-- the offending comma {"NativeComponent2", NativeComponent2Cls}, // rnmylibrary }; } ``` At some point, `GenerateRCTThirdPartyFabricComponentsProviderCpp.js` does not properly filter out empty arrays resulting from excluded components. This does not seem to be a problem when the excluded component is not the first being processed, as the comma gets added at the end of the previous line, after the comment with the name of the library. ## Changelog [iOS] [Fixed] - Fix error in the Codegen template for ThirdPartyFabricComponentsProvider Pull Request resolved: https://github.com/facebook/react-native/pull/34738 Test Plan: This is the schema that leads to the bug. Notice that the first component was excluded for iOS. ```json { "modules": { "ComponentFile1": { "type": "Component", "components": { "NativeComponent1": { "excludedPlatforms": ["iOS"] "extendsProps": [ { "type": "ReactNativeBuiltInType", "knownTypeName": "ReactNativeCoreViewProps" } ], "events": [], "props": [], "commands": [] } } }, "ComponentFile2": { "type": "Component", "components": { "NativeComponent2": { "extendsProps": [ { "type": "ReactNativeBuiltInType", "knownTypeName": "ReactNativeCoreViewProps" } ], "events": [], "props": [], "commands": [] } } } } ``` `GenerateRCTThirdPartyFabricComponentsProviderCpp.js` should generate a template without the comma in the wrong position (before NativeComponent2). I also added an additional test case to cover this problem. All the other tests passed. Reviewed By: sammy-SC Differential Revision: D39686573 Pulled By: cipolleschi fbshipit-source-id: 6054464d024218eb0b2e02974aa5cc7c8aebbbc9 --- ...hirdPartyFabricComponentsProviderObjCpp.js | 4 +- .../components/__test_fixtures__/fixtures.js | 48 ++++++++++++++ .../GenerateComponentDescriptorH-test.js.snap | 29 +++++++++ .../GenerateComponentHObjCpp-test.js.snap | 25 ++++++++ .../GenerateEventEmitterCpp-test.js.snap | 26 ++++++++ .../GenerateEventEmitterH-test.js.snap | 27 ++++++++ .../GeneratePropsCpp-test.js.snap | 40 ++++++++++++ .../__snapshots__/GeneratePropsH-test.js.snap | 46 ++++++++++++++ .../GeneratePropsJavaDelegate-test.js.snap | 63 +++++++++++++++++++ .../GeneratePropsJavaInterface-test.js.snap | 39 ++++++++++++ .../GeneratePropsJavaPojo-test.js.snap | 46 ++++++++++++++ .../GenerateShadowNodeCpp-test.js.snap | 26 ++++++++ .../GenerateShadowNodeH-test.js.snap | 45 +++++++++++++ .../__snapshots__/GenerateTests-test.js.snap | 61 ++++++++++++++++++ ...artyFabricComponentsProviderH-test.js.snap | 1 + ...abricComponentsProviderObjCpp-test.js.snap | 2 + .../GenerateViewConfigJs-test.js.snap | 44 +++++++++++++ 17 files changed, 571 insertions(+), 1 deletion(-) diff --git a/packages/react-native-codegen/src/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js b/packages/react-native-codegen/src/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js index 549633cd160428..fcd7b528192635 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js +++ b/packages/react-native-codegen/src/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js @@ -75,7 +75,7 @@ module.exports = { return null; } - return Object.keys(components) + const componentTemplates = Object.keys(components) .filter(componentName => { const component = components[componentName]; return !( @@ -91,6 +91,8 @@ module.exports = { return replacedTemplate; }); + + return componentTemplates.length > 0 ? componentTemplates : null; }) .filter(Boolean); }) diff --git a/packages/react-native-codegen/src/generators/components/__test_fixtures__/fixtures.js b/packages/react-native-codegen/src/generators/components/__test_fixtures__/fixtures.js index 1498da71273884..b38d07d189e61f 100644 --- a/packages/react-native-codegen/src/generators/components/__test_fixtures__/fixtures.js +++ b/packages/react-native-codegen/src/generators/components/__test_fixtures__/fixtures.js @@ -1594,6 +1594,53 @@ const EXCLUDE_ANDROID_IOS: SchemaType = { }, }; +const EXCLUDE_IOS_TWO_COMPONENTS_DIFFERENT_FILES: SchemaType = { + modules: { + ComponentFile1: { + type: 'Component', + components: { + ExcludedIosComponent: { + excludedPlatforms: ['iOS'], + extendsProps: [ + { + type: 'ReactNativeBuiltInType', + knownTypeName: 'ReactNativeCoreViewProps', + }, + ], + events: [], + props: [], + commands: [], + }, + }, + }, + ComponentFile2: { + type: 'Component', + components: { + MultiFileIncludedNativeComponent: { + extendsProps: [ + { + type: 'ReactNativeBuiltInType', + knownTypeName: 'ReactNativeCoreViewProps', + }, + ], + events: [], + props: [ + { + name: 'disabled', + optional: true, + typeAnnotation: { + type: 'BooleanTypeAnnotation', + default: true, + }, + }, + ], + commands: [], + }, + }, + }, + }, +}; + module.exports = { NO_PROPS_NO_EVENTS, INTERFACE_ONLY, @@ -1621,4 +1668,5 @@ module.exports = { COMMANDS_AND_PROPS, EXCLUDE_ANDROID, EXCLUDE_ANDROID_IOS, + EXCLUDE_IOS_TWO_COMPONENTS_DIFFERENT_FILES, }; diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateComponentDescriptorH-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateComponentDescriptorH-test.js.snap index 20ab6f69ffd131..7cf29170dec8d4 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateComponentDescriptorH-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateComponentDescriptorH-test.js.snap @@ -336,6 +336,35 @@ using ExcludedAndroidIosComponentComponentDescriptor = ConcreteComponentDescript } `; +exports[`GenerateComponentDescriptorH can generate fixture EXCLUDE_IOS_TWO_COMPONENTS_DIFFERENT_FILES 1`] = ` +Map { + "ComponentDescriptors.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateComponentDescriptorH.js + */ + +#pragma once + +#include +#include + +namespace facebook { +namespace react { + +using ExcludedIosComponentComponentDescriptor = ConcreteComponentDescriptor; +using MultiFileIncludedNativeComponentComponentDescriptor = ConcreteComponentDescriptor; + +} // namespace react +} // namespace facebook +", +} +`; + exports[`GenerateComponentDescriptorH can generate fixture FLOAT_PROPS 1`] = ` Map { "ComponentDescriptors.h" => " diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateComponentHObjCpp-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateComponentHObjCpp-test.js.snap index d21fa8930f0bcc..f7b45e6fc31e0f 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateComponentHObjCpp-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateComponentHObjCpp-test.js.snap @@ -430,6 +430,31 @@ NS_ASSUME_NONNULL_BEGIN +NS_ASSUME_NONNULL_END", +} +`; + +exports[`GenerateComponentHObjCpp can generate fixture EXCLUDE_IOS_TWO_COMPONENTS_DIFFERENT_FILES 1`] = ` +Map { + "RCTComponentViewHelpers.h" => "/** +* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). +* +* Do not edit this file as changes may cause incorrect behavior and will be lost +* once the code is regenerated. +* +* @generated by codegen project: GenerateComponentHObjCpp.js +*/ + +#import +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@protocol RCTMultiFileIncludedNativeComponentViewProtocol + +@end + NS_ASSUME_NONNULL_END", } `; diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateEventEmitterCpp-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateEventEmitterCpp-test.js.snap index 8d0858dc93bf99..9c58425980fe21 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateEventEmitterCpp-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateEventEmitterCpp-test.js.snap @@ -351,6 +351,32 @@ namespace react { +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateEventEmitterCpp can generate fixture EXCLUDE_IOS_TWO_COMPONENTS_DIFFERENT_FILES 1`] = ` +Map { + "EventEmitters.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateEventEmitterCpp.js + */ + +#include + +namespace facebook { +namespace react { + + + + } // namespace react } // namespace facebook ", diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateEventEmitterH-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateEventEmitterH-test.js.snap index 942ca4c88eadae..faacdff12be52a 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateEventEmitterH-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateEventEmitterH-test.js.snap @@ -390,6 +390,33 @@ namespace react { +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateEventEmitterH can generate fixture EXCLUDE_IOS_TWO_COMPONENTS_DIFFERENT_FILES 1`] = ` +Map { + "EventEmitters.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateEventEmitterH.js + */ +#pragma once + +#include +#include + +namespace facebook { +namespace react { + + + } // namespace react } // namespace facebook ", diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsCpp-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsCpp-test.js.snap index ceae8252ed004e..56ada8a6bffe13 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsCpp-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsCpp-test.js.snap @@ -412,6 +412,46 @@ ExcludedAndroidIosComponentProps::ExcludedAndroidIosComponentProps( } `; +exports[`GeneratePropsCpp can generate fixture EXCLUDE_IOS_TWO_COMPONENTS_DIFFERENT_FILES 1`] = ` +Map { + "Props.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GeneratePropsCpp.js + */ + +#include +#include +#include + +namespace facebook { +namespace react { + +ExcludedIosComponentProps::ExcludedIosComponentProps( + const PropsParserContext &context, + const ExcludedIosComponentProps &sourceProps, + const RawProps &rawProps): ViewProps(context, sourceProps, rawProps) + + + {} +MultiFileIncludedNativeComponentProps::MultiFileIncludedNativeComponentProps( + const PropsParserContext &context, + const MultiFileIncludedNativeComponentProps &sourceProps, + const RawProps &rawProps): ViewProps(context, sourceProps, rawProps), + + disabled(convertRawProp(context, rawProps, \\"disabled\\", sourceProps.disabled, {true})) + {} + +} // namespace react +} // namespace facebook +", +} +`; + exports[`GeneratePropsCpp can generate fixture FLOAT_PROPS 1`] = ` Map { "Props.cpp" => " diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsH-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsH-test.js.snap index bdede2c33e8793..7f8a84fe002064 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsH-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsH-test.js.snap @@ -660,6 +660,52 @@ class JSI_EXPORT ExcludedAndroidIosComponentProps final : public ViewProps { } `; +exports[`GeneratePropsH can generate fixture EXCLUDE_IOS_TWO_COMPONENTS_DIFFERENT_FILES 1`] = ` +Map { + "Props.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GeneratePropsH.js + */ +#pragma once + +#include +#include +#include + +namespace facebook { +namespace react { + +class JSI_EXPORT ExcludedIosComponentProps final : public ViewProps { + public: + ExcludedIosComponentProps() = default; + ExcludedIosComponentProps(const PropsParserContext& context, const ExcludedIosComponentProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + +}; + +class JSI_EXPORT MultiFileIncludedNativeComponentProps final : public ViewProps { + public: + MultiFileIncludedNativeComponentProps() = default; + MultiFileIncludedNativeComponentProps(const PropsParserContext& context, const MultiFileIncludedNativeComponentProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + bool disabled{true}; +}; + +} // namespace react +} // namespace facebook +", +} +`; + exports[`GeneratePropsH can generate fixture FLOAT_PROPS 1`] = ` Map { "Props.h" => " diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaDelegate-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaDelegate-test.js.snap index 9cd5fb54c8afbc..6c5dd2dbb4f79c 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaDelegate-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaDelegate-test.js.snap @@ -436,6 +436,69 @@ exports[`GeneratePropsJavaDelegate can generate fixture EXCLUDE_ANDROID 1`] = `M exports[`GeneratePropsJavaDelegate can generate fixture EXCLUDE_ANDROID_IOS 1`] = `Map {}`; +exports[`GeneratePropsJavaDelegate can generate fixture EXCLUDE_IOS_TWO_COMPONENTS_DIFFERENT_FILES 1`] = ` +Map { + "java/com/facebook/react/viewmanagers/ExcludedIosComponentManagerDelegate.java" => "/** +* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). +* +* Do not edit this file as changes may cause incorrect behavior and will be lost +* once the code is regenerated. +* +* @generated by codegen project: GeneratePropsJavaDelegate.js +*/ + +package com.facebook.react.viewmanagers; + +import android.view.View; +import androidx.annotation.Nullable; +import com.facebook.react.uimanager.BaseViewManagerDelegate; +import com.facebook.react.uimanager.BaseViewManagerInterface; + +public class ExcludedIosComponentManagerDelegate & ExcludedIosComponentManagerInterface> extends BaseViewManagerDelegate { + public ExcludedIosComponentManagerDelegate(U viewManager) { + super(viewManager); + } + @Override + public void setProperty(T view, String propName, @Nullable Object value) { + super.setProperty(view, propName, value); + } +} +", + "java/com/facebook/react/viewmanagers/MultiFileIncludedNativeComponentManagerDelegate.java" => "/** +* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). +* +* Do not edit this file as changes may cause incorrect behavior and will be lost +* once the code is regenerated. +* +* @generated by codegen project: GeneratePropsJavaDelegate.js +*/ + +package com.facebook.react.viewmanagers; + +import android.view.View; +import androidx.annotation.Nullable; +import com.facebook.react.uimanager.BaseViewManagerDelegate; +import com.facebook.react.uimanager.BaseViewManagerInterface; + +public class MultiFileIncludedNativeComponentManagerDelegate & MultiFileIncludedNativeComponentManagerInterface> extends BaseViewManagerDelegate { + public MultiFileIncludedNativeComponentManagerDelegate(U viewManager) { + super(viewManager); + } + @Override + public void setProperty(T view, String propName, @Nullable Object value) { + switch (propName) { + case \\"disabled\\": + mViewManager.setDisabled(view, value == null ? true : (boolean) value); + break; + default: + super.setProperty(view, propName, value); + } + } +} +", +} +`; + exports[`GeneratePropsJavaDelegate can generate fixture FLOAT_PROPS 1`] = ` Map { "java/com/facebook/react/viewmanagers/FloatPropNativeComponentManagerDelegate.java" => "/** diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaInterface-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaInterface-test.js.snap index 550da64c73b085..c4e652f19a38a4 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaInterface-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaInterface-test.js.snap @@ -249,6 +249,45 @@ exports[`GeneratePropsJavaInterface can generate fixture EXCLUDE_ANDROID 1`] = ` exports[`GeneratePropsJavaInterface can generate fixture EXCLUDE_ANDROID_IOS 1`] = `Map {}`; +exports[`GeneratePropsJavaInterface can generate fixture EXCLUDE_IOS_TWO_COMPONENTS_DIFFERENT_FILES 1`] = ` +Map { + "java/com/facebook/react/viewmanagers/ExcludedIosComponentManagerInterface.java" => "/** +* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). +* +* Do not edit this file as changes may cause incorrect behavior and will be lost +* once the code is regenerated. +* +* @generated by codegen project: GeneratePropsJavaInterface.js +*/ + +package com.facebook.react.viewmanagers; + +import android.view.View; + +public interface ExcludedIosComponentManagerInterface { + // No props +} +", + "java/com/facebook/react/viewmanagers/MultiFileIncludedNativeComponentManagerInterface.java" => "/** +* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). +* +* Do not edit this file as changes may cause incorrect behavior and will be lost +* once the code is regenerated. +* +* @generated by codegen project: GeneratePropsJavaInterface.js +*/ + +package com.facebook.react.viewmanagers; + +import android.view.View; + +public interface MultiFileIncludedNativeComponentManagerInterface { + void setDisabled(T view, boolean value); +} +", +} +`; + exports[`GeneratePropsJavaInterface can generate fixture FLOAT_PROPS 1`] = ` Map { "java/com/facebook/react/viewmanagers/FloatPropNativeComponentManagerInterface.java" => "/** diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaPojo-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaPojo-test.js.snap index 25f4abc590c274..9cb2b17fe2b341 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaPojo-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaPojo-test.js.snap @@ -474,6 +474,52 @@ exports[`GeneratePropsJavaPojo can generate fixture EXCLUDE_ANDROID 1`] = `Map { exports[`GeneratePropsJavaPojo can generate fixture EXCLUDE_ANDROID_IOS 1`] = `Map {}`; +exports[`GeneratePropsJavaPojo can generate fixture EXCLUDE_IOS_TWO_COMPONENTS_DIFFERENT_FILES 1`] = ` +Map { + "java/com/facebook/react/viewmanagers/ComponentFile1/ExcludedIosComponentProps.java" => "/** +* Copyright (c) Meta Platforms, Inc. and affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaPojo.js +*/ + +package com.facebook.react.viewmanagers.ComponentFile1; + +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public class ExcludedIosComponentProps { + + +} +", + "java/com/facebook/react/viewmanagers/ComponentFile2/MultiFileIncludedNativeComponentProps.java" => "/** +* Copyright (c) Meta Platforms, Inc. and affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaPojo.js +*/ + +package com.facebook.react.viewmanagers.ComponentFile2; + +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public class MultiFileIncludedNativeComponentProps { + private boolean mDisabled; + @DoNotStrip + public boolean getDisabled() { + return mDisabled; + } +} +", +} +`; + exports[`GeneratePropsJavaPojo can generate fixture FLOAT_PROPS 1`] = ` Map { "java/com/facebook/react/viewmanagers/Switch/FloatPropNativeComponentProps.java" => "/** diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeCpp-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeCpp-test.js.snap index 028d4fcbde9517..b09ab9ea8bebf3 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeCpp-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeCpp-test.js.snap @@ -300,6 +300,32 @@ extern const char ExcludedAndroidIosComponentComponentName[] = \\"ExcludedAndroi } `; +exports[`GenerateShadowNodeCpp can generate fixture EXCLUDE_IOS_TWO_COMPONENTS_DIFFERENT_FILES 1`] = ` +Map { + "ShadowNodes.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateShadowNodeCpp.js + */ + +#include + +namespace facebook { +namespace react { + +extern const char ExcludedIosComponentComponentName[] = \\"ExcludedIosComponent\\"; +extern const char MultiFileIncludedNativeComponentComponentName[] = \\"MultiFileIncludedNativeComponent\\"; + +} // namespace react +} // namespace facebook +", +} +`; + exports[`GenerateShadowNodeCpp can generate fixture FLOAT_PROPS 1`] = ` Map { "ShadowNodes.cpp" => " diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeH-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeH-test.js.snap index 25deb9ca84275e..fb4988800ad84b 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeH-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeH-test.js.snap @@ -429,6 +429,51 @@ using ExcludedAndroidIosComponentShadowNode = ConcreteViewShadowNode< } `; +exports[`GenerateShadowNodeH can generate fixture EXCLUDE_IOS_TWO_COMPONENTS_DIFFERENT_FILES 1`] = ` +Map { + "ShadowNodes.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateShadowNodeH.js + */ + +#pragma once + +#include +#include +#include + +namespace facebook { +namespace react { + +JSI_EXPORT extern const char ExcludedIosComponentComponentName[]; + +/* + * \`ShadowNode\` for component. + */ +using ExcludedIosComponentShadowNode = ConcreteViewShadowNode< + ExcludedIosComponentComponentName, + ExcludedIosComponentProps>; + +JSI_EXPORT extern const char MultiFileIncludedNativeComponentComponentName[]; + +/* + * \`ShadowNode\` for component. + */ +using MultiFileIncludedNativeComponentShadowNode = ConcreteViewShadowNode< + MultiFileIncludedNativeComponentComponentName, + MultiFileIncludedNativeComponentProps>; + +} // namespace react +} // namespace facebook +", +} +`; + exports[`GenerateShadowNodeH can generate fixture FLOAT_PROPS 1`] = ` Map { "ShadowNodes.h" => " diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateTests-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateTests-test.js.snap index 14a07e9534c015..e8f46ea1f10403 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateTests-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateTests-test.js.snap @@ -486,6 +486,67 @@ TEST(ExcludedAndroidIosComponentProps_DoesNotDie, etc) { } `; +exports[`GenerateTests can generate fixture EXCLUDE_IOS_TWO_COMPONENTS_DIFFERENT_FILES 1`] = ` +Map { + "Tests.cpp" => "/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateTests.js + * */ + +#include +#include +#include +#include +#include +#include + +using namespace facebook::react; + +TEST(ExcludedIosComponentProps_DoesNotDie, etc) { + auto propParser = RawPropsParser(); + propParser.prepare(); + auto const &sourceProps = ExcludedIosComponentProps(); + auto const &rawProps = RawProps(folly::dynamic::object(\\"xx_invalid_xx\\", \\"xx_invalid_xx\\")); + + ContextContainer contextContainer{}; + PropsParserContext parserContext{-1, contextContainer}; + + rawProps.parse(propParser, parserContext); + ExcludedIosComponentProps(parserContext, sourceProps, rawProps); +} + +TEST(MultiFileIncludedNativeComponentProps_DoesNotDie, etc) { + auto propParser = RawPropsParser(); + propParser.prepare(); + auto const &sourceProps = MultiFileIncludedNativeComponentProps(); + auto const &rawProps = RawProps(folly::dynamic::object(\\"xx_invalid_xx\\", \\"xx_invalid_xx\\")); + + ContextContainer contextContainer{}; + PropsParserContext parserContext{-1, contextContainer}; + + rawProps.parse(propParser, parserContext); + MultiFileIncludedNativeComponentProps(parserContext, sourceProps, rawProps); +} + +TEST(MultiFileIncludedNativeComponentProps_disabled, etc) { + auto propParser = RawPropsParser(); + propParser.prepare(); + auto const &sourceProps = MultiFileIncludedNativeComponentProps(); + auto const &rawProps = RawProps(folly::dynamic::object(\\"disabled\\", true)); + + ContextContainer contextContainer{}; + PropsParserContext parserContext{-1, contextContainer}; + + rawProps.parse(propParser, parserContext); + MultiFileIncludedNativeComponentProps(parserContext, sourceProps, rawProps); +}", +} +`; + exports[`GenerateTests can generate fixture FLOAT_PROPS 1`] = ` Map { "Tests.cpp" => "/** diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateThirdPartyFabricComponentsProviderH-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateThirdPartyFabricComponentsProviderH-test.js.snap index 46ad5bcb81a667..4cab36433d2411 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateThirdPartyFabricComponentsProviderH-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateThirdPartyFabricComponentsProviderH-test.js.snap @@ -51,6 +51,7 @@ Class CommandNativeComponentCls(void) __attribute__((u Class CommandNativeComponentCls(void) __attribute__((used)); // COMMANDS_AND_PROPS Class ExcludedAndroidComponentCls(void) __attribute__((used)); // EXCLUDE_ANDROID +Class MultiFileIncludedNativeComponentCls(void) __attribute__((used)); // EXCLUDE_IOS_TWO_COMPONENTS_DIFFERENT_FILES #ifdef __cplusplus } diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateThirdPartyFabricComponentsProviderObjCpp-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateThirdPartyFabricComponentsProviderObjCpp-test.js.snap index fd1ed66715440d..0fa2add3459f5b 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateThirdPartyFabricComponentsProviderObjCpp-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateThirdPartyFabricComponentsProviderObjCpp-test.js.snap @@ -74,6 +74,8 @@ Class RCTThirdPartyFabricComponentsProvider(const char {\\"ExcludedAndroidComponent\\", ExcludedAndroidComponentCls}, // EXCLUDE_ANDROID + + {\\"MultiFileIncludedNativeComponent\\", MultiFileIncludedNativeComponentCls}, // EXCLUDE_IOS_TWO_COMPONENTS_DIFFERENT_FILES }; auto p = sFabricComponentsClassMap.find(name); diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap index aeffa286b993d0..a48a2426a815e3 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap @@ -509,6 +509,50 @@ export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL } `; +exports[`GenerateViewConfigJs can generate fixture EXCLUDE_IOS_TWO_COMPONENTS_DIFFERENT_FILES 1`] = ` +Map { + "EXCLUDE_IOS_TWO_COMPONENTS_DIFFERENT_FILESNativeViewConfig.js" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @flow + * + * @generated by codegen project: GenerateViewConfigJs.js + */ + +'use strict'; + +const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); + +let nativeComponentName = 'ExcludedIosComponent'; + + +export const __INTERNAL_VIEW_CONFIG = { + uiViewClassName: 'ExcludedIosComponent', + validAttributes: {}, +}; + +export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL_VIEW_CONFIG); + +let nativeComponentName = 'MultiFileIncludedNativeComponent'; + + +export const __INTERNAL_VIEW_CONFIG = { + uiViewClassName: 'MultiFileIncludedNativeComponent', + + validAttributes: { + disabled: true, + }, +}; + +export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL_VIEW_CONFIG); +", +} +`; + exports[`GenerateViewConfigJs can generate fixture FLOAT_PROPS 1`] = ` Map { "FLOAT_PROPSNativeViewConfig.js" => "