From 882dbe01184db422cd19f6d79b379ddae419b32c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ma=C5=82ecki?= Date: Wed, 18 Mar 2026 09:29:02 -0700 Subject: [PATCH] Handle template variables in the API snapshot (#56068) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/56068 Changelog: [Internal] Adds support for templates in variable declaration to the c++ API snapshot generator Reviewed By: cipolleschi Differential Revision: D96279463 fbshipit-source-id: eb68f97f926e4a407d6c7fa2dda6edf7e43e23ba --- scripts/cxx-api/parser/builders.py | 6 +++++- scripts/cxx-api/parser/member.py | 3 +++ .../snapshot.api | 7 +++++++ .../should_handle_template_variable/test.h | 20 +++++++++++++++++++ .../snapshot.api | 4 +++- 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 scripts/cxx-api/tests/snapshots/should_handle_template_variable/snapshot.api create mode 100644 scripts/cxx-api/tests/snapshots/should_handle_template_variable/test.h diff --git a/scripts/cxx-api/parser/builders.py b/scripts/cxx-api/parser/builders.py index 9beb9a93880..1122433b9c1 100644 --- a/scripts/cxx-api/parser/builders.py +++ b/scripts/cxx-api/parser/builders.py @@ -249,7 +249,7 @@ def get_variable_member( if initializer_type == InitializerType.BRACE: is_brace_initializer = True - return VariableMember( + member = VariableMember( variable_name, variable_type, visibility, @@ -263,6 +263,10 @@ def get_variable_member( is_brace_initializer, ) + member.add_template(get_template_params(member_def)) + + return member + def get_doxygen_params( function_def: compound.MemberdefType, diff --git a/scripts/cxx-api/parser/member.py b/scripts/cxx-api/parser/member.py index 7681b42dc1d..7c8290dad50 100644 --- a/scripts/cxx-api/parser/member.py +++ b/scripts/cxx-api/parser/member.py @@ -162,6 +162,9 @@ class VariableMember(Member): result = " " * indent + if self.template_list is not None: + result += self.template_list.to_string() + "\n" + " " * indent + if not hide_visibility: result += self.visibility + " " diff --git a/scripts/cxx-api/tests/snapshots/should_handle_template_variable/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_template_variable/snapshot.api new file mode 100644 index 00000000000..52711af8da3 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_handle_template_variable/snapshot.api @@ -0,0 +1,7 @@ +template +const test::Strct test::Strct::VALUE; + +template +struct test::Strct { + public static const test::Strct VALUE; +} diff --git a/scripts/cxx-api/tests/snapshots/should_handle_template_variable/test.h b/scripts/cxx-api/tests/snapshots/should_handle_template_variable/test.h new file mode 100644 index 00000000000..c1caf34d39d --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_handle_template_variable/test.h @@ -0,0 +1,20 @@ +/* + * 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 + +namespace test { + +template +struct Strct { + static const Strct VALUE; +}; + +template +const Strct Strct::VALUE = {}; + +} // namespace test diff --git a/scripts/cxx-api/tests/snapshots/should_qualify_variable_template_specialization/snapshot.api b/scripts/cxx-api/tests/snapshots/should_qualify_variable_template_specialization/snapshot.api index 2d598603d29..6248acdb5c7 100644 --- a/scripts/cxx-api/tests/snapshots/should_qualify_variable_template_specialization/snapshot.api +++ b/scripts/cxx-api/tests/snapshots/should_qualify_variable_template_specialization/snapshot.api @@ -1,5 +1,7 @@ -constexpr T test::default_value; constexpr test::MyType test::default_value; +template +constexpr T test::default_value; +template T* test::null_ptr; test::MyType* test::null_ptr;