Skip to content

Commit acfbf91

Browse files
coadofacebook-github-bot
authored andcommitted
Fix parsing of Objective-C block properties (facebook#55776)
Summary: Doxygen splits block property types across `<type>` and `<argsstring>` elements. For example: ```objc property (nonatomic, copy) void (^eventInterceptor)(NSString *eventName, NSDictionary *event, NSNumber *reactTag); ``` Produces XML like: ```xml <type>void(^</type> <name>eventInterceptor</name> <argsstring>)(NSString *eventName, NSDictionary *event, NSNumber *reactTag)</argsstring> ``` 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); ``` Reviewed By: cipolleschi Differential Revision: D94366205
1 parent b500541 commit acfbf91

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

scripts/cxx-api/parser/builders.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,16 @@ def get_property_member(
343343
is_readable = getattr(member_def, "readable", "no") == "yes"
344344
is_writable = getattr(member_def, "writable", "no") == "yes"
345345

346+
# Handle block properties: Doxygen splits the block type across <type> and <argsstring>
347+
# <type> = "void(^"
348+
# <argsstring> = ")(NSString *eventName, NSDictionary *event, NSNumber *reactTag)"
349+
# We need to combine them: "void(^eventInterceptor)(NSString *, NSDictionary *, NSNumber *)"
350+
if property_type.endswith("(^"):
351+
argsstring = member_def.get_argsstring()
352+
if argsstring:
353+
property_type = f"{property_type}{property_name}{argsstring}"
354+
property_name = ""
355+
346356
return PropertyMember(
347357
property_name,
348358
property_type,

scripts/cxx-api/parser/member.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,11 @@ def to_string(
404404
if self.is_static:
405405
result += "static "
406406

407-
result += f"@property {attrs_str}{self.type} {name};"
407+
# For block properties, name is embedded in the type (e.g., "void(^eventInterceptor)(args)")
408+
if name:
409+
result += f"@property {attrs_str}{self.type} {name};"
410+
else:
411+
result += f"@property {attrs_str}{self.type};"
408412

409413
return result
410414

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
interface RCTInterfaceWithBlockProperty : public NSObject {
2+
public @property (copy) NSString *(^blockWithReturn)(int value);
3+
public @property (copy) void(^eventInterceptor)(NSString *eventName, NSDictionary *event, NSNumber *reactTag);
4+
public @property (copy) void(^simpleBlock)(void);
5+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
@interface RCTInterfaceWithBlockProperty : NSObject
9+
10+
@property (nonatomic, copy, nullable) void (^eventInterceptor)
11+
(NSString *eventName, NSDictionary *event, NSNumber *reactTag);
12+
@property (nonatomic, copy) void (^simpleBlock)(void);
13+
@property (nonatomic, copy) NSString * (^blockWithReturn)(int value);
14+
15+
@end

0 commit comments

Comments
 (0)