mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
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:
1 parent
269a2ee0cb
commit
5e4da8410e
6 files changed
+96
-3
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user