Fix handling of unnamed template arguments (#55646)

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

Changelog: [Internal]

Updates the C++ API snapshot generator script to correctly handle unnamed template arguments.

Reviewed By: cipolleschi

Differential Revision: D93407624

fbshipit-source-id: 50928b596fe64fa3549cde5d69da7146b452d784
This commit is contained in:
Jakub Piasecki
2026-02-25 11:16:36 -08:00
committed by meta-codesync[bot]
parent 269a2ee0cb
commit 5e4da8410e
6 changed files with 96 additions and 3 deletions
+10 -2
View File
@@ -152,8 +152,16 @@ def get_template_params(
template_type = " ".join(parts[:-1])
template_name = parts[-1]
elif len(parts) == 1:
# Just a name like "T" with no type keyword
template_name = parts[0]
# Check if this is an unnamed template parameter
# (just "typename" or "class" with or without a default value)
# In this case, we leave name as None/empty
if parts[0] in ("typename", "class"):
# Unnamed template parameter
# e.g., "typename" or "typename = std::enable_if_t<...>"
template_name = None
else:
# Just a name like "T" with no type keyword
template_name = parts[0]
template_params.append(
Template(template_type, template_name, template_value)
+19 -1
View File
@@ -3,14 +3,32 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import re
def _normalize_whitespace(text: str) -> str:
"""
Normalize whitespace by collapsing multiple consecutive whitespace
characters into a single space.
"""
return re.sub(r"\s+", " ", text).strip()
class Template:
def __init__(self, type: str, name: str, value: str | None) -> None:
self.type: str = type
self.name: str = name
self.value: str | None = value
self.value: str | None = _normalize_whitespace(value) if value else value
def to_string(self) -> str:
# Handle unnamed template parameters (e.g., "typename = std::enable_if_t<...>")
# When the name is empty or None, we just output "type = value" or "type"
if not self.name:
if self.value is None:
return self.type
else:
return f"{self.type} = {self.value}"
if self.value is None:
return f"{self.type} {self.name}"
else:
@@ -0,0 +1,3 @@
template <typename>
struct test::is_optional : public std::false_type {
}
@@ -0,0 +1,18 @@
/*
* 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.
*/
#pragma once
#include <type_traits>
namespace test {
// Unnamed template parameter without default value
template <typename>
struct is_optional : std::false_type {};
} // namespace test
@@ -0,0 +1,16 @@
class test::BigInt {
}
class test::Object {
}
class test::String {
}
class test::Symbol {
}
struct test::Value {
template <typename T, typename = std::enable_if_t< std::is_base_of<Symbol, T>::value || std::is_base_of<BigInt, T>::value || std::is_base_of<String, T>::value || std::is_base_of<Object, T>::value>>
public Value(T && other);
}
@@ -0,0 +1,30 @@
/*
* 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.
*/
#pragma once
#include <type_traits>
namespace test {
class Symbol {};
class BigInt {};
class String {};
class Object {};
struct Value {
template <
typename T,
typename = std::enable_if_t<
std::is_base_of<Symbol, T>::value || std::is_base_of<BigInt, T>::value || std::is_base_of<String, T>::value ||
std::is_base_of<Object, T>::value>>
/* implicit */ Value(T &&other)
{
}
};
} // namespace test