use std::borrow::Cow;
use swc_atoms::{Atom, Wtf8Atom};
use swc_ecma_ast::Str;
#[inline]
pub(crate) fn normalize_wtf8_atom(value: &Wtf8Atom) -> Atom {
value
.as_str()
.map(Atom::from)
.unwrap_or_else(|| Atom::from(value.to_string_lossy()))
}
#[inline]
pub(crate) fn str_to_atom(value: &Str) -> Atom {
normalize_wtf8_atom(&value.value)
}
pub(crate) fn wtf8_to_cow_str(value: &Wtf8Atom) -> Cow<'_, str> {
value
.as_str()
.map(Cow::Borrowed)
.unwrap_or_else(|| Cow::Owned(value.to_string_lossy().into_owned()))
}