Skip to content

Commit e547f46

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Improve codegen to add getDebugProps to components (#53135)
Summary: Pull Request resolved: #53135 Our Codegenerated components are not generating code for `getDebugProps`. This change modifies Codegen to add those functions for all the codegen components. ## Changelog: [General][Added] - Added getDebugProps to codegen ## Facebook: `getDebugProps` are required by Fantom to write tests. However, we can't generate these function for third party components, because codegen can generate arbitrary structs and we don't have a generic `toString()` method that can be used or automatically generated by C++. By generating this function only for Core Components, we can ensure that we can write Fantom tests without breaking all the users of React Native. Reviewed By: rubennorte Differential Revision: D79805145 fbshipit-source-id: 0e41c65fc30eaa886a05557ca233fb0a9cb18a71
1 parent 8363a4c commit e547f46

24 files changed

Lines changed: 349 additions & 29 deletions

packages/react-native-codegen/e2e/deep_imports/__tests__/components/__snapshots__/GeneratePropsCpp-test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ InterfaceOnlyNativeComponentViewProps::InterfaceOnlyNativeComponentViewProps(
717717
const InterfaceOnlyNativeComponentViewProps &sourceProps,
718718
const RawProps &rawProps): ViewProps(context, sourceProps, rawProps),
719719
720-
title(convertRawProp(context, rawProps, \\"title\\", sourceProps.title, {\\"\\"})) {}
720+
title(convertRawProp(context, rawProps, \\"title\\", sourceProps.title, {std::string{\\"\\"}})) {}
721721
722722
#ifdef RN_SERIALIZABLE_STATE
723723
ComponentName InterfaceOnlyNativeComponentViewProps::getDiffPropsImplementationTarget() const {
@@ -1060,7 +1060,7 @@ StringPropNativeComponentViewProps::StringPropNativeComponentViewProps(
10601060
const StringPropNativeComponentViewProps &sourceProps,
10611061
const RawProps &rawProps): ViewProps(context, sourceProps, rawProps),
10621062
1063-
placeholder(convertRawProp(context, rawProps, \\"placeholder\\", sourceProps.placeholder, {\\"\\"})),
1063+
placeholder(convertRawProp(context, rawProps, \\"placeholder\\", sourceProps.placeholder, {std::string{\\"\\"}})),
10641064
defaultValue(convertRawProp(context, rawProps, \\"defaultValue\\", sourceProps.defaultValue, {})) {}
10651065
10661066
#ifdef RN_SERIALIZABLE_STATE

packages/react-native-codegen/e2e/deep_imports/__tests__/components/__snapshots__/GeneratePropsH-test.js.snap

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Object {
1818
#include <react/renderer/core/PropsParserContext.h>
1919
#include <react/renderer/core/graphicsConversions.h>
2020
#include <react/renderer/core/propsConversions.h>
21+
#include <react/renderer/debug/DebugStringConvertible.h>
2122
#include <react/renderer/graphics/Color.h>
2223
#include <react/renderer/graphics/Point.h>
2324
#include <react/renderer/graphics/RectangleEdges.h>
@@ -89,6 +90,7 @@ static inline std::string toString(const ArrayPropsNativeComponentViewSizesMaskW
8990
struct ArrayPropsNativeComponentViewObjectStruct {
9091
std::string prop{};
9192
93+
9294
#ifdef RN_SERIALIZABLE_STATE
9395
bool operator==(const ArrayPropsNativeComponentViewObjectStruct&) const = default;
9496
@@ -133,6 +135,7 @@ struct ArrayPropsNativeComponentViewArrayOfObjectsStruct {
133135
Float prop1{0.0};
134136
int prop2{0};
135137
138+
136139
#ifdef RN_SERIALIZABLE_STATE
137140
bool operator==(const ArrayPropsNativeComponentViewArrayOfObjectsStruct&) const = default;
138141
@@ -203,6 +206,8 @@ class ArrayPropsNativeComponentViewProps final : public ViewProps {
203206
204207
folly::dynamic getDiffProps(const Props* prevProps) const override;
205208
#endif
209+
210+
206211
};
207212
208213
} // namespace facebook::react
@@ -225,6 +230,7 @@ Object {
225230
226231
#include <react/renderer/components/view/ViewProps.h>
227232
#include <react/renderer/core/PropsParserContext.h>
233+
#include <react/renderer/debug/DebugStringConvertible.h>
228234
229235
namespace facebook::react {
230236
@@ -243,6 +249,8 @@ class BooleanPropNativeComponentViewProps final : public ViewProps {
243249
244250
folly::dynamic getDiffProps(const Props* prevProps) const override;
245251
#endif
252+
253+
246254
};
247255
248256
} // namespace facebook::react
@@ -265,6 +273,7 @@ Object {
265273
266274
#include <react/renderer/components/view/ViewProps.h>
267275
#include <react/renderer/core/PropsParserContext.h>
276+
#include <react/renderer/debug/DebugStringConvertible.h>
268277
#include <react/renderer/graphics/Color.h>
269278
270279
namespace facebook::react {
@@ -283,6 +292,8 @@ class ColorPropNativeComponentViewProps final : public ViewProps {
283292
284293
folly::dynamic getDiffProps(const Props* prevProps) const override;
285294
#endif
295+
296+
286297
};
287298
288299
} // namespace facebook::react
@@ -306,6 +317,7 @@ Object {
306317
#include <react/renderer/components/view/ViewProps.h>
307318
#include <react/renderer/core/PropsParserContext.h>
308319
#include <react/renderer/core/graphicsConversions.h>
320+
#include <react/renderer/debug/DebugStringConvertible.h>
309321
#include <yoga/Yoga.h>
310322
311323
namespace facebook::react {
@@ -324,6 +336,8 @@ class DimensionPropNativeComponentViewProps final : public ViewProps {
324336
325337
folly::dynamic getDiffProps(const Props* prevProps) const override;
326338
#endif
339+
340+
327341
};
328342
329343
} // namespace facebook::react
@@ -346,6 +360,7 @@ Object {
346360
347361
#include <react/renderer/components/view/ViewProps.h>
348362
#include <react/renderer/core/PropsParserContext.h>
363+
#include <react/renderer/debug/DebugStringConvertible.h>
349364
350365
namespace facebook::react {
351366
@@ -363,6 +378,8 @@ class EdgeInsetsPropNativeComponentViewProps final : public ViewProps {
363378
364379
folly::dynamic getDiffProps(const Props* prevProps) const override;
365380
#endif
381+
382+
366383
};
367384
368385
} // namespace facebook::react
@@ -385,6 +402,7 @@ Object {
385402
386403
#include <react/renderer/components/view/ViewProps.h>
387404
#include <react/renderer/core/PropsParserContext.h>
405+
#include <react/renderer/debug/DebugStringConvertible.h>
388406
389407
namespace facebook::react {
390408
@@ -468,6 +486,8 @@ class EnumPropNativeComponentViewProps final : public ViewProps {
468486
469487
folly::dynamic getDiffProps(const Props* prevProps) const override;
470488
#endif
489+
490+
471491
};
472492
473493
} // namespace facebook::react
@@ -490,6 +510,7 @@ Object {
490510
491511
#include <react/renderer/components/view/ViewProps.h>
492512
#include <react/renderer/core/PropsParserContext.h>
513+
#include <react/renderer/debug/DebugStringConvertible.h>
493514
494515
namespace facebook::react {
495516
@@ -507,6 +528,8 @@ class EventNestedObjectPropsNativeComponentViewProps final : public ViewProps {
507528
508529
folly::dynamic getDiffProps(const Props* prevProps) const override;
509530
#endif
531+
532+
510533
};
511534
512535
} // namespace facebook::react
@@ -529,6 +552,7 @@ Object {
529552
530553
#include <react/renderer/components/view/ViewProps.h>
531554
#include <react/renderer/core/PropsParserContext.h>
555+
#include <react/renderer/debug/DebugStringConvertible.h>
532556
533557
namespace facebook::react {
534558
@@ -546,6 +570,8 @@ class EventPropsNativeComponentViewProps final : public ViewProps {
546570
547571
folly::dynamic getDiffProps(const Props* prevProps) const override;
548572
#endif
573+
574+
549575
};
550576
551577
} // namespace facebook::react
@@ -568,6 +594,7 @@ Object {
568594
569595
#include <react/renderer/components/view/ViewProps.h>
570596
#include <react/renderer/core/PropsParserContext.h>
597+
#include <react/renderer/debug/DebugStringConvertible.h>
571598
572599
namespace facebook::react {
573600
@@ -591,6 +618,8 @@ class FloatPropsNativeComponentViewProps final : public ViewProps {
591618
592619
folly::dynamic getDiffProps(const Props* prevProps) const override;
593620
#endif
621+
622+
594623
};
595624
596625
} // namespace facebook::react
@@ -613,6 +642,7 @@ Object {
613642
614643
#include <react/renderer/components/view/ViewProps.h>
615644
#include <react/renderer/core/PropsParserContext.h>
645+
#include <react/renderer/debug/DebugStringConvertible.h>
616646
#include <react/renderer/imagemanager/primitives.h>
617647
618648
namespace facebook::react {
@@ -631,6 +661,8 @@ class ImagePropNativeComponentViewProps final : public ViewProps {
631661
632662
folly::dynamic getDiffProps(const Props* prevProps) const override;
633663
#endif
664+
665+
634666
};
635667
636668
} // namespace facebook::react
@@ -653,6 +685,7 @@ Object {
653685
654686
#include <react/renderer/components/view/ViewProps.h>
655687
#include <react/renderer/core/PropsParserContext.h>
688+
#include <react/renderer/debug/DebugStringConvertible.h>
656689
657690
namespace facebook::react {
658691
@@ -672,6 +705,8 @@ class IntegerPropNativeComponentViewProps final : public ViewProps {
672705
673706
folly::dynamic getDiffProps(const Props* prevProps) const override;
674707
#endif
708+
709+
675710
};
676711
677712
} // namespace facebook::react
@@ -694,6 +729,7 @@ Object {
694729
695730
#include <react/renderer/components/view/ViewProps.h>
696731
#include <react/renderer/core/PropsParserContext.h>
732+
#include <react/renderer/debug/DebugStringConvertible.h>
697733
698734
namespace facebook::react {
699735
@@ -704,13 +740,15 @@ class InterfaceOnlyNativeComponentViewProps final : public ViewProps {
704740
705741
#pragma mark - Props
706742
707-
std::string title{\\"\\"};
743+
std::string title{std::string{\\"\\"}};
708744
709745
#ifdef RN_SERIALIZABLE_STATE
710746
ComponentName getDiffPropsImplementationTarget() const override;
711747
712748
folly::dynamic getDiffProps(const Props* prevProps) const override;
713749
#endif
750+
751+
714752
};
715753
716754
} // namespace facebook::react
@@ -733,6 +771,7 @@ Object {
733771
734772
#include <react/renderer/components/view/ViewProps.h>
735773
#include <react/renderer/core/PropsParserContext.h>
774+
#include <react/renderer/debug/DebugStringConvertible.h>
736775
737776
namespace facebook::react {
738777
@@ -750,6 +789,8 @@ class MixedPropNativeComponentViewProps final : public ViewProps {
750789
751790
folly::dynamic getDiffProps(const Props* prevProps) const override;
752791
#endif
792+
793+
753794
};
754795
755796
} // namespace facebook::react
@@ -772,6 +813,7 @@ Object {
772813
773814
#include <react/renderer/components/view/ViewProps.h>
774815
#include <react/renderer/core/PropsParserContext.h>
816+
#include <react/renderer/debug/DebugStringConvertible.h>
775817
#include <react/renderer/graphics/Color.h>
776818
#include <react/renderer/graphics/Point.h>
777819
#include <react/renderer/imagemanager/primitives.h>
@@ -795,6 +837,8 @@ class MultiNativePropNativeComponentViewProps final : public ViewProps {
795837
796838
folly::dynamic getDiffProps(const Props* prevProps) const override;
797839
#endif
840+
841+
798842
};
799843
800844
} // namespace facebook::react
@@ -817,6 +861,7 @@ Object {
817861
818862
#include <react/renderer/components/view/ViewProps.h>
819863
#include <react/renderer/core/PropsParserContext.h>
864+
#include <react/renderer/debug/DebugStringConvertible.h>
820865
821866
namespace facebook::react {
822867
@@ -834,6 +879,8 @@ class NoPropsNoEventsNativeComponentViewProps final : public ViewProps {
834879
835880
folly::dynamic getDiffProps(const Props* prevProps) const override;
836881
#endif
882+
883+
837884
};
838885
839886
} // namespace facebook::react
@@ -858,6 +905,7 @@ Object {
858905
#include <react/renderer/components/view/ViewProps.h>
859906
#include <react/renderer/core/PropsParserContext.h>
860907
#include <react/renderer/core/propsConversions.h>
908+
#include <react/renderer/debug/DebugStringConvertible.h>
861909
#include <react/renderer/graphics/Color.h>
862910
#include <react/renderer/graphics/Point.h>
863911
#include <react/renderer/imagemanager/primitives.h>
@@ -918,13 +966,14 @@ static inline folly::dynamic toDynamic(const ObjectPropsNativeComponentIntEnumPr
918966
}
919967
#endif
920968
struct ObjectPropsNativeComponentObjectPropStruct {
921-
std::string stringProp{\\"\\"};
969+
std::string stringProp{std::string{\\"\\"}};
922970
bool booleanProp{false};
923971
Float floatProp{0.0};
924972
int intProp{0};
925973
ObjectPropsNativeComponentStringEnumProp stringEnumProp{ObjectPropsNativeComponentStringEnumProp::Small};
926974
ObjectPropsNativeComponentIntEnumProp intEnumProp{ObjectPropsNativeComponentIntEnumProp::IntEnumProp0};
927975
976+
928977
#ifdef RN_SERIALIZABLE_STATE
929978
bool operator==(const ObjectPropsNativeComponentObjectPropStruct&) const = default;
930979
@@ -983,6 +1032,7 @@ static inline folly::dynamic toDynamic(const ObjectPropsNativeComponentObjectPro
9831032
struct ObjectPropsNativeComponentObjectArrayPropStruct {
9841033
std::vector<std::string> array{};
9851034
1035+
9861036
#ifdef RN_SERIALIZABLE_STATE
9871037
bool operator==(const ObjectPropsNativeComponentObjectArrayPropStruct&) const = default;
9881038
@@ -1018,6 +1068,7 @@ struct ObjectPropsNativeComponentObjectPrimitiveRequiredPropStruct {
10181068
SharedColor color{};
10191069
Point point{};
10201070
1071+
10211072
#ifdef RN_SERIALIZABLE_STATE
10221073
bool operator==(const ObjectPropsNativeComponentObjectPrimitiveRequiredPropStruct&) const = default;
10231074
@@ -1073,6 +1124,8 @@ class ObjectPropsNativeComponentProps final : public ViewProps {
10731124
10741125
folly::dynamic getDiffProps(const Props* prevProps) const override;
10751126
#endif
1127+
1128+
10761129
};
10771130
10781131
} // namespace facebook::react
@@ -1095,6 +1148,7 @@ Object {
10951148
10961149
#include <react/renderer/components/view/ViewProps.h>
10971150
#include <react/renderer/core/PropsParserContext.h>
1151+
#include <react/renderer/debug/DebugStringConvertible.h>
10981152
#include <react/renderer/graphics/Point.h>
10991153
11001154
namespace facebook::react {
@@ -1113,6 +1167,8 @@ class PointPropNativeComponentViewProps final : public ViewProps {
11131167
11141168
folly::dynamic getDiffProps(const Props* prevProps) const override;
11151169
#endif
1170+
1171+
11161172
};
11171173
11181174
} // namespace facebook::react
@@ -1135,6 +1191,7 @@ Object {
11351191
11361192
#include <react/renderer/components/view/ViewProps.h>
11371193
#include <react/renderer/core/PropsParserContext.h>
1194+
#include <react/renderer/debug/DebugStringConvertible.h>
11381195
11391196
namespace facebook::react {
11401197
@@ -1145,14 +1202,16 @@ class StringPropNativeComponentViewProps final : public ViewProps {
11451202
11461203
#pragma mark - Props
11471204
1148-
std::string placeholder{\\"\\"};
1205+
std::string placeholder{std::string{\\"\\"}};
11491206
std::string defaultValue{};
11501207
11511208
#ifdef RN_SERIALIZABLE_STATE
11521209
ComponentName getDiffPropsImplementationTarget() const override;
11531210
11541211
folly::dynamic getDiffProps(const Props* prevProps) const override;
11551212
#endif
1213+
1214+
11561215
};
11571216
11581217
} // namespace facebook::react

0 commit comments

Comments
 (0)