fallow_extract/
js_text.rs1use std::borrow::Cow;
4
5use oxc_ast::StaticPropertyName;
6use oxc_str::JSStr;
7
8pub trait JsText<'a> {
15 fn text(self) -> Cow<'a, str>;
17}
18
19impl<'a> JsText<'a> for JSStr<'a> {
20 fn text(self) -> Cow<'a, str> {
21 self.as_str()
22 .map_or_else(|| Cow::Owned(self.display().to_string()), Cow::Borrowed)
23 }
24}
25
26impl<'b> JsText<'b> for &'b StaticPropertyName<'_> {
27 fn text(self) -> Cow<'b, str> {
28 self.as_js_str().text()
29 }
30}
31
32#[must_use]
35pub fn static_name_text(name: StaticPropertyName<'_>) -> Cow<'_, str> {
36 match name {
37 StaticPropertyName::Borrowed(name) => name.text(),
38 StaticPropertyName::Owned(name) => Cow::Owned(name.into_string()),
39 }
40}