From 47ef0e173f61c497c1a2ca7173be32d24476fb22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ma=C5=82ecki?= Date: Thu, 5 Mar 2026 07:21:42 -0800 Subject: [PATCH] Fix parsing of Objective-C block properties (#55776) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/55776 Doxygen splits block property types across `` and `` elements. For example: ```objc property (nonatomic, copy) void (^eventInterceptor)(NSString *eventName, NSDictionary *event, NSNumber *reactTag); ``` Produces XML like: ```xml void(^ eventInterceptor )(NSString *eventName, NSDictionary *event, NSNumber *reactTag) ``` This caused the parser to output incomplete types. The fix detects when the property type ends with `(^` and combines it with the property name and argsstring: ``` property (copy) void(^eventInterceptor)(NSString *eventName, NSDictionary *event, NSNumber *reactTag); ``` Changelog: [Internal] Reviewed By: cipolleschi Differential Revision: D94366205 fbshipit-source-id: 2d741401f63916284d453f1112ae0f349234308e --- scripts/cxx-api/parser/builders.py | 10 ++++++++++ scripts/cxx-api/parser/member.py | 6 +++++- .../snapshot.api | 5 +++++ .../test.h | 15 +++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 scripts/cxx-api/tests/snapshots/should_handle_interface_with_block_property/snapshot.api create mode 100644 scripts/cxx-api/tests/snapshots/should_handle_interface_with_block_property/test.h diff --git a/scripts/cxx-api/parser/builders.py b/scripts/cxx-api/parser/builders.py index 3361c25a35d..4dbd7466596 100644 --- a/scripts/cxx-api/parser/builders.py +++ b/scripts/cxx-api/parser/builders.py @@ -337,6 +337,16 @@ def get_property_member( is_readable = getattr(member_def, "readable", "no") == "yes" is_writable = getattr(member_def, "writable", "no") == "yes" + # Handle block properties: Doxygen splits the block type across and + # = "void(^" + # = ")(NSString *eventName, NSDictionary *event, NSNumber *reactTag)" + # We need to combine them: "void(^eventInterceptor)(NSString *, NSDictionary *, NSNumber *)" + if property_type.endswith("(^"): + argsstring = member_def.get_argsstring() + if argsstring: + property_type = f"{property_type}{property_name}{argsstring}" + property_name = "" + return PropertyMember( property_name, property_type, diff --git a/scripts/cxx-api/parser/member.py b/scripts/cxx-api/parser/member.py index 407fa078aec..2069aa80a84 100644 --- a/scripts/cxx-api/parser/member.py +++ b/scripts/cxx-api/parser/member.py @@ -404,7 +404,11 @@ class PropertyMember(Member): if self.is_static: result += "static " - result += f"@property {attrs_str}{self.type} {name};" + # For block properties, name is embedded in the type (e.g., "void(^eventInterceptor)(args)") + if name: + result += f"@property {attrs_str}{self.type} {name};" + else: + result += f"@property {attrs_str}{self.type};" return result diff --git a/scripts/cxx-api/tests/snapshots/should_handle_interface_with_block_property/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_interface_with_block_property/snapshot.api new file mode 100644 index 00000000000..01e1b9d3f9c --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_handle_interface_with_block_property/snapshot.api @@ -0,0 +1,5 @@ +interface RCTInterfaceWithBlockProperty : public NSObject { + public @property (copy) NSString *(^blockWithReturn)(int value); + public @property (copy) void(^eventInterceptor)(NSString *eventName, NSDictionary *event, NSNumber *reactTag); + public @property (copy) void(^simpleBlock)(void); +} diff --git a/scripts/cxx-api/tests/snapshots/should_handle_interface_with_block_property/test.h b/scripts/cxx-api/tests/snapshots/should_handle_interface_with_block_property/test.h new file mode 100644 index 00000000000..e9fc1c8b965 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_handle_interface_with_block_property/test.h @@ -0,0 +1,15 @@ +/* + * 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. + */ + +@interface RCTInterfaceWithBlockProperty : NSObject + +@property (nonatomic, copy, nullable) void (^eventInterceptor) + (NSString *eventName, NSDictionary *event, NSNumber *reactTag); +@property (nonatomic, copy) void (^simpleBlock)(void); +@property (nonatomic, copy) NSString * (^blockWithReturn)(int value); + +@end