mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Add input filter for stripping methods marked as NS_UNAVAILABLE (#55973)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/55973 Adds input filter for stripping methods marked as `NS_UNAVAILABLE` which shouldn't be part of the public API. Changelog: [Internal] Reviewed By: cipolleschi Differential Revision: D95552298 fbshipit-source-id: 2e5b33f047bfda259733b92b187ce86d9967cf93
This commit is contained in:
1 parent
c0ae52b74a
commit
d83bf7394b
10 files changed
+234
-91
No files matched your search
@@ -5,6 +5,7 @@ interface RCTTestMacros {
|
||||
public virtual instancetype initWithName:(NSString* name);
|
||||
public virtual static UIUserInterfaceStyle userInterfaceStyle();
|
||||
public virtual void deprecatedMethod();
|
||||
public virtual void start();
|
||||
}
|
||||
|
||||
protocol RCTTestProtocol {
|
||||
|
||||
@@ -11,14 +11,24 @@
|
||||
|
||||
- (instancetype)initWithDelegate:(id)delegate options:(NSDictionary *)options NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
|
||||
+ (instancetype)new NS_UNAVAILABLE;
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;
|
||||
|
||||
@property (nonatomic, strong, readonly) dispatch_queue_t methodQueue RCT_DEPRECATED;
|
||||
|
||||
@property (nonatomic, weak, readonly) id bridge RCT_DEPRECATED;
|
||||
|
||||
@property (nonatomic, copy, nullable) NSString *text NS_UNAVAILABLE;
|
||||
|
||||
- (void)deprecatedMethod RCT_DEPRECATED;
|
||||
|
||||
+ (UIUserInterfaceStyle)userInterfaceStyle API_AVAILABLE(ios(12));
|
||||
|
||||
- (void)start;
|
||||
|
||||
@end
|
||||
|
||||
RCT_EXTERN void RCTExternFunction(const char *input, NSString **output);
|
||||
@@ -33,4 +43,6 @@ RCT_EXTERN NSString *RCTParseType(const char **input);
|
||||
|
||||
@property (nonatomic, readonly) NSString *name RCT_DEPRECATED;
|
||||
|
||||
- (void)setSelectedTextRange:(nullable UITextRange *)selectedTextRange NS_UNAVAILABLE;
|
||||
|
||||
@end
|
||||
@@ -7,10 +7,9 @@ from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from ..input_filters.doxygen_strip_comments import (
|
||||
strip_block_comments,
|
||||
strip_deprecated_msg,
|
||||
)
|
||||
from ..input_filters.strip_block_comments import strip_block_comments
|
||||
from ..input_filters.strip_deprecated_msg import strip_deprecated_msg
|
||||
from ..input_filters.strip_ns_unavailable import strip_ns_unavailable
|
||||
|
||||
|
||||
class TestDoxygenStripComments(unittest.TestCase):
|
||||
@@ -116,5 +115,98 @@ class TestStripDeprecatedMsg(unittest.TestCase):
|
||||
self.assertEqual(result, "@interface RCTSurface : NSObject")
|
||||
|
||||
|
||||
class TestStripNSUnavailable(unittest.TestCase):
|
||||
def test_strips_single_line_init(self):
|
||||
content = "- (instancetype)init NS_UNAVAILABLE;"
|
||||
result = strip_ns_unavailable(content)
|
||||
self.assertEqual(result, "")
|
||||
|
||||
def test_strips_single_line_new(self):
|
||||
content = "+ (instancetype)new NS_UNAVAILABLE;"
|
||||
result = strip_ns_unavailable(content)
|
||||
self.assertEqual(result, "")
|
||||
|
||||
def test_strips_init_with_frame(self):
|
||||
content = "- (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;"
|
||||
result = strip_ns_unavailable(content)
|
||||
self.assertEqual(result, "")
|
||||
|
||||
def test_strips_property(self):
|
||||
content = "@property (nonatomic, copy, nullable) NSString *text NS_UNAVAILABLE;"
|
||||
result = strip_ns_unavailable(content)
|
||||
self.assertEqual(result, "")
|
||||
|
||||
def test_strips_method_with_params(self):
|
||||
content = (
|
||||
"- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index"
|
||||
" NS_UNAVAILABLE;"
|
||||
)
|
||||
result = strip_ns_unavailable(content)
|
||||
self.assertEqual(result, "")
|
||||
|
||||
def test_strips_multiline_declaration(self):
|
||||
content = (
|
||||
"- (instancetype)initWithSurface:(id<RCTSurfaceProtocol>)surface\n"
|
||||
" sizeMeasureMode:(RCTSurfaceSizeMeasureMode)"
|
||||
"sizeMeasureMode NS_UNAVAILABLE;"
|
||||
)
|
||||
result = strip_ns_unavailable(content)
|
||||
# Should preserve line count (2 lines -> 1 newline)
|
||||
self.assertEqual(result, "\n")
|
||||
|
||||
def test_preserves_normal_methods(self):
|
||||
content = "- (instancetype)initWithBridge:(RCTBridge *)bridge;"
|
||||
result = strip_ns_unavailable(content)
|
||||
self.assertEqual(result, content)
|
||||
|
||||
def test_preserves_normal_properties(self):
|
||||
content = "@property (nonatomic, strong) NSString *name;"
|
||||
result = strip_ns_unavailable(content)
|
||||
self.assertEqual(result, content)
|
||||
|
||||
def test_preserves_designated_initializer(self):
|
||||
content = (
|
||||
"- (instancetype)initWithName:(NSString *)name NS_DESIGNATED_INITIALIZER;"
|
||||
)
|
||||
result = strip_ns_unavailable(content)
|
||||
self.assertEqual(result, content)
|
||||
|
||||
def test_does_not_strip_across_semicolons(self):
|
||||
content = (
|
||||
"- (void)normalMethod;\n"
|
||||
"- (instancetype)init NS_UNAVAILABLE;\n"
|
||||
"- (void)anotherMethod;"
|
||||
)
|
||||
result = strip_ns_unavailable(content)
|
||||
self.assertEqual(result, "- (void)normalMethod;\n\n- (void)anotherMethod;")
|
||||
|
||||
def test_strips_multiple_unavailable_methods(self):
|
||||
content = (
|
||||
"- (instancetype)init NS_UNAVAILABLE;\n+ (instancetype)new NS_UNAVAILABLE;"
|
||||
)
|
||||
result = strip_ns_unavailable(content)
|
||||
self.assertEqual(result, "\n")
|
||||
|
||||
def test_handles_empty_content(self):
|
||||
result = strip_ns_unavailable("")
|
||||
self.assertEqual(result, "")
|
||||
|
||||
def test_preserves_line_count(self):
|
||||
content = (
|
||||
"@interface RCTHost : NSObject\n"
|
||||
"- (instancetype)init NS_UNAVAILABLE;\n"
|
||||
"+ (instancetype)new NS_UNAVAILABLE;\n"
|
||||
"- (void)start;\n"
|
||||
"@end"
|
||||
)
|
||||
result = strip_ns_unavailable(content)
|
||||
self.assertEqual(result.count("\n"), content.count("\n"))
|
||||
|
||||
def test_handles_leading_whitespace(self):
|
||||
content = " - (instancetype)init NS_UNAVAILABLE;"
|
||||
result = strip_ns_unavailable(content)
|
||||
self.assertEqual(result, "")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -106,9 +106,7 @@ def _make_case_test(case_dir: Traversable, tests_root: Traversable):
|
||||
|
||||
# Find the filter script in the package resources
|
||||
pkg_root = ir.files(__package__ if __package__ else "__main__")
|
||||
filter_script = (
|
||||
pkg_root.parent / "input_filters" / "doxygen_strip_comments.py"
|
||||
)
|
||||
filter_script = pkg_root.parent / "input_filters" / "main.py"
|
||||
|
||||
# Get real filesystem path for filter script if it exists
|
||||
# IMPORTANT: Keep the context manager active while Doxygen runs,
|
||||
|
||||
Reference in new issue
Block a user