Normalize template specialization angle bracket spacing (#55910)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/55910

Normalizes angle bracket spacing in scope names for template specializations.

Doxygen encodes template specializations with spaces around angle brackets in compound names (e.g., `CSSDataTypeParser< CSSMatrix >`). This caused inconsistent output in API snapshots.

The fix applies `normalize_angle_brackets()` to qualified paths when parsing scope names, ensuring consistent output:
- `CSSDataTypeParser< CSSMatrix >` → `CSSDataTypeParser<CSSMatrix>`
- `Callback< R(Args...)>` → `Callback<R(Args...)>`

Added a new test case `should_normalize_template_specialization_angle_brackets` to verify the fix.

Changelog:
[Internal]

Reviewed By: cipolleschi

Differential Revision: D95204780

fbshipit-source-id: d0d5fe7759a414b32630647f334b39e26da15108
This commit is contained in:
Dawid Małecki authored and meta-codesync[bot] committed 2026-03-05 07:21:42 -08:00
1 parent 78c8842f9e
commit dc8c442aa5
6 files changed
+76 -2

No files matched your search

+5
View File
@@ -201,6 +201,7 @@ def main():
"input_filters",
"doxygen_strip_comments.py",
)
input_filter = None
if os.path.exists(input_filter_path):
input_filter = f"python3 {input_filter_path}"
@@ -263,3 +264,7 @@ def main():
)
)
build_snapshots(output_dir, verbose=True)
if __name__ == "__main__":
main()
+2 -1
View File
@@ -33,6 +33,7 @@ from .utils import (
Argument,
extract_qualifiers,
InitializerType,
normalize_angle_brackets,
normalize_pointer_spacing,
parse_qualified_path,
resolve_linked_text_name,
@@ -59,7 +60,7 @@ def get_base_classes(
# - prot: protection level (public, protected, private)
# - virt: virtual inheritance (non-virtual, virtual, pure-virtual)
# - valueOf_: the name of the base class
base_name = base.valueOf_
base_name = normalize_angle_brackets(base.valueOf_)
base_prot = base.prot
base_virt = base.virt
base_refid = base.refid
@@ -5,6 +5,8 @@
from __future__ import annotations
from .text_resolution import normalize_angle_brackets
def parse_qualified_path(path: str) -> list[str]:
"""
@@ -19,7 +21,12 @@ def parse_qualified_path(path: str) -> list[str]:
- Comparison operators inside parentheses: "std::enable_if<(N > 0)>::type"
- Arrow operators: "decltype(ptr->member)::type"
- Bitshift operators: "std::integral_constant<int, (1 >> 2)>::value"
Normalizes angle bracket spacing (e.g., "Foo< Bar >" -> "Foo<Bar>").
"""
# Normalize angle bracket spacing before parsing
path = normalize_angle_brackets(path)
result = []
current = ""
angle_depth = 0
@@ -3,7 +3,7 @@ class test::Callback {
}
template <typename R, typename... Args>
class test::Callback< R(Args...)> {
class test::Callback<R(Args...)> {
public Callback(const test::Callback&) = delete;
public Callback(test::Callback&& other) noexcept;
public R call(Args... args) const;
@@ -0,0 +1,17 @@
class AndroidSwitchComponentDescriptor : public ConcreteComponentDescriptor<AndroidSwitchShadowNode> {
public AndroidSwitchComponentDescriptor(const ComponentDescriptorParameters& parameters);
public void adopt(ShadowNode& shadowNode) const;
}
struct CSSDataTypeParser<CSSMatrix> {
public static constexpr std::optional<CSSMatrix> consumeFunctionBlock(const CSSFunctionBlock& func, CSSValueParser& parser);
}
struct CSSMatrix {
public constexpr bool operator==(const CSSMatrix& rhs) const = default;
public std::array<float, 6> values;
}
template <typename ShadowNodeT>
class ConcreteComponentDescriptor {
}
@@ -0,0 +1,44 @@
/*
* 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.
*/
struct CSSMatrix {
std::array<float, 6> values{};
constexpr bool operator==(const CSSMatrix &rhs) const = default;
};
template <>
struct CSSDataTypeParser<CSSMatrix> {
static constexpr auto consumeFunctionBlock(const CSSFunctionBlock &func, CSSValueParser &parser)
-> std::optional<CSSMatrix>
{
if (!iequals(func.name, "matrix")) {
return {};
}
CSSMatrix matrix{};
for (int i = 0; i < 6; i++) {
auto value = parser.parseNextValue<CSSNumber>(i == 0 ? CSSDelimiter::None : CSSDelimiter::Comma);
if (std::holds_alternative<std::monostate>(value)) {
return {};
}
matrix.values[i] = std::get<CSSNumber>(value).value;
}
return matrix;
}
};
// Test base class inheritance with template angle brackets
template <typename ShadowNodeT>
class ConcreteComponentDescriptor {};
class AndroidSwitchComponentDescriptor : public ConcreteComponentDescriptor<AndroidSwitchShadowNode> {
public:
AndroidSwitchComponentDescriptor(const ComponentDescriptorParameters &parameters);
void adopt(ShadowNode &shadowNode) const;
};