Skip to content

Commit

Permalink
Correctly parse partial objects with optional value
Browse files Browse the repository at this point in the history
Summary:
The flow parser *always* returns if a property IS `optional` (true|false) OR not

The TypeScript one only emits `optional` if the prop is optional.

The current `partialProperty` UTs are not correct.

Changelog: [General][Fixed] -  Correctly parse partial objects with optional value

Differential Revision: D56689387
  • Loading branch information
christophpurrer authored and facebook-github-bot committed Apr 29, 2024
1 parent bb2c13a commit 1198f3f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ inline JS::NativeOptionalObjectTurboModule::Constants::Builder::Builder(Constant
inline NSString *JS::NativePartialAnnotationTurboModule::SpecGetSomeObjFromPartialSomeObjValue::a() const
{
id const p = _v[@\\"a\\"];
return RCTBridgingToOptionalString(p);
return RCTBridgingToString(p);
}
inline std::optional<bool> JS::NativePartialAnnotationTurboModule::SpecGetSomeObjFromPartialSomeObjValue::b() const
{
Expand All @@ -1211,7 +1211,7 @@ inline std::optional<bool> JS::NativePartialAnnotationTurboModule::SpecGetSomeOb
inline NSString *JS::NativePartialAnnotationTurboModule::SpecGetPartialPartialValue1::a() const
{
id const p = _v[@\\"a\\"];
return RCTBridgingToOptionalString(p);
return RCTBridgingToString(p);
}
inline std::optional<bool> JS::NativePartialAnnotationTurboModule::SpecGetPartialPartialValue1::b() const
{
Expand All @@ -1221,7 +1221,7 @@ inline std::optional<bool> JS::NativePartialAnnotationTurboModule::SpecGetPartia
inline NSString *JS::NativePartialAnnotationTurboModule::SpecGetPartialPartialValue2::a() const
{
id const p = _v[@\\"a\\"];
return RCTBridgingToOptionalString(p);
return RCTBridgingToString(p);
}
inline std::optional<bool> JS::NativePartialAnnotationTurboModule::SpecGetPartialPartialValue2::b() const
{
Expand Down Expand Up @@ -2553,7 +2553,7 @@ inline JS::NativeOptionalObjectTurboModule::Constants::Builder::Builder(Constant
inline NSString *JS::NativePartialAnnotationTurboModule::SpecGetSomeObjFromPartialSomeObjValue::a() const
{
id const p = _v[@\\"a\\"];
return RCTBridgingToOptionalString(p);
return RCTBridgingToString(p);
}
inline std::optional<bool> JS::NativePartialAnnotationTurboModule::SpecGetSomeObjFromPartialSomeObjValue::b() const
{
Expand All @@ -2563,7 +2563,7 @@ inline std::optional<bool> JS::NativePartialAnnotationTurboModule::SpecGetSomeOb
inline NSString *JS::NativePartialAnnotationTurboModule::SpecGetPartialPartialValue1::a() const
{
id const p = _v[@\\"a\\"];
return RCTBridgingToOptionalString(p);
return RCTBridgingToString(p);
}
inline std::optional<bool> JS::NativePartialAnnotationTurboModule::SpecGetPartialPartialValue1::b() const
{
Expand All @@ -2573,7 +2573,7 @@ inline std::optional<bool> JS::NativePartialAnnotationTurboModule::SpecGetPartia
inline NSString *JS::NativePartialAnnotationTurboModule::SpecGetPartialPartialValue2::a() const
{
id const p = _v[@\\"a\\"];
return RCTBridgingToOptionalString(p);
return RCTBridgingToString(p);
}
inline std::optional<bool> JS::NativePartialAnnotationTurboModule::SpecGetPartialPartialValue2::b() const
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ describe('FlowParser', () => {
const expected = [
{
name: 'a',
optional: true,
optional: false,
typeAnnotation: {type: 'StringTypeAnnotation'},
},
{
Expand Down Expand Up @@ -623,7 +623,7 @@ describe('TypeScriptParser', () => {
const expected = [
{
name: 'a',
optional: true,
optional: false,
typeAnnotation: {properties: [], type: 'ObjectTypeAnnotation'},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1760,7 +1760,7 @@ exports[`RN Codegen Flow Parser can generate fixture NATIVE_MODULE_WITH_PARTIALS
'properties': [
{
'name': 'a',
'optional': true,
'optional': false,
'typeAnnotation': {
'type': 'StringTypeAnnotation'
}
Expand Down Expand Up @@ -1795,7 +1795,7 @@ exports[`RN Codegen Flow Parser can generate fixture NATIVE_MODULE_WITH_PARTIALS
'properties': [
{
'name': 'a',
'optional': true,
'optional': false,
'typeAnnotation': {
'type': 'StringTypeAnnotation'
}
Expand Down Expand Up @@ -1868,7 +1868,7 @@ exports[`RN Codegen Flow Parser can generate fixture NATIVE_MODULE_WITH_PARTIALS
'properties': [
{
'name': 'a',
'optional': true,
'optional': false,
'typeAnnotation': {
'type': 'StringTypeAnnotation'
}
Expand All @@ -1891,7 +1891,7 @@ exports[`RN Codegen Flow Parser can generate fixture NATIVE_MODULE_WITH_PARTIALS
'properties': [
{
'name': 'a',
'optional': true,
'optional': false,
'typeAnnotation': {
'type': 'StringTypeAnnotation'
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-codegen/src/parsers/flow/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class FlowParser implements Parser {
return properties.map(prop => {
return {
name: prop.key.name,
optional: true,
optional: prop?.optional ?? false,
typeAnnotation: flowTranslateTypeAnnotation(
hasteModuleName,
prop.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2226,7 +2226,7 @@ exports[`RN Codegen TypeScript Parser can generate fixture NATIVE_MODULE_WITH_PA
'properties': [
{
'name': 'a',
'optional': true,
'optional': false,
'typeAnnotation': {
'type': 'StringTypeAnnotation'
}
Expand Down Expand Up @@ -2261,7 +2261,7 @@ exports[`RN Codegen TypeScript Parser can generate fixture NATIVE_MODULE_WITH_PA
'properties': [
{
'name': 'a',
'optional': true,
'optional': false,
'typeAnnotation': {
'type': 'StringTypeAnnotation'
}
Expand Down Expand Up @@ -2334,7 +2334,7 @@ exports[`RN Codegen TypeScript Parser can generate fixture NATIVE_MODULE_WITH_PA
'properties': [
{
'name': 'a',
'optional': true,
'optional': false,
'typeAnnotation': {
'type': 'StringTypeAnnotation'
}
Expand All @@ -2357,7 +2357,7 @@ exports[`RN Codegen TypeScript Parser can generate fixture NATIVE_MODULE_WITH_PA
'properties': [
{
'name': 'a',
'optional': true,
'optional': false,
'typeAnnotation': {
'type': 'StringTypeAnnotation'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class TypeScriptParser implements Parser {
return properties.map(prop => {
return {
name: prop.key.name,
optional: true,
optional: prop?.optional ?? false,
typeAnnotation: typeScriptTranslateTypeAnnotation(
hasteModuleName,
prop.typeAnnotation.typeAnnotation,
Expand Down

0 comments on commit 1198f3f

Please sign in to comment.