From 9c2a37098e5edcf66714032867417c06e2d8f18e Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Fri, 7 Mar 2025 03:16:12 +0000 Subject: [PATCH] feat(ast): add `AstBuilder::atom_from_strs_array` (#9400) --- crates/oxc_ast/src/ast_builder_impl.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/oxc_ast/src/ast_builder_impl.rs b/crates/oxc_ast/src/ast_builder_impl.rs index bfc55fe74f921..d8d388e62dab1 100644 --- a/crates/oxc_ast/src/ast_builder_impl.rs +++ b/crates/oxc_ast/src/ast_builder_impl.rs @@ -2,7 +2,7 @@ use std::{borrow::Cow, mem}; -use oxc_allocator::{Allocator, Box, FromIn, IntoIn, Vec}; +use oxc_allocator::{Allocator, Box, FromIn, IntoIn, String, Vec}; use oxc_span::{Atom, SPAN, Span}; use oxc_syntax::{number::NumberBase, operator::UnaryOperator, scope::ScopeId}; @@ -80,6 +80,13 @@ impl<'a> AstBuilder<'a> { Atom::from_in(value, self.allocator) } + /// Allocate an [`Atom`] from an array of string slices. + #[inline] + pub fn atom_from_strs_array(self, array: [&str; N]) -> Atom<'a> { + let string = String::from_strs_array_in(array, self.allocator); + Atom::from(string) + } + /// Convert a [`Cow<'a, str>`] to an [`Atom<'a>`]. /// /// If the `Cow` borrows a string from arena, returns an `Atom` which references that same string,