mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
feat(ast): allow conversion from TSAccessibility into &'static str (#4711)
This commit is contained in:
parent
4b7dfd6c7c
commit
e12bd1e21a
2 changed files with 32 additions and 10 deletions
|
|
@ -126,8 +126,29 @@ impl<'a> TSType<'a> {
|
|||
}
|
||||
|
||||
impl TSAccessibility {
|
||||
pub fn is_private(&self) -> bool {
|
||||
matches!(self, TSAccessibility::Private)
|
||||
#[inline]
|
||||
pub fn is_private(self) -> bool {
|
||||
matches!(self, Self::Private)
|
||||
}
|
||||
|
||||
pub fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::Public => "public",
|
||||
Self::Private => "private",
|
||||
Self::Protected => "protected",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TSAccessibility> for &'static str {
|
||||
fn from(accessibility: TSAccessibility) -> Self {
|
||||
accessibility.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for TSAccessibility {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str(self.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -242,12 +242,13 @@ impl<'a> IsolatedDeclarations<'a> {
|
|||
let mut elements = self.ast.vec();
|
||||
for (index, param) in function.params.items.iter().enumerate() {
|
||||
if param.accessibility.is_some() || param.readonly {
|
||||
let type_annotation = if param.accessibility.is_some_and(|a| a.is_private()) {
|
||||
None
|
||||
} else {
|
||||
// transformed params will definitely have type annotation
|
||||
self.ast.copy(¶ms.items[index].pattern.type_annotation)
|
||||
};
|
||||
let type_annotation =
|
||||
if param.accessibility.is_some_and(oxc_ast::ast::TSAccessibility::is_private) {
|
||||
None
|
||||
} else {
|
||||
// transformed params will definitely have type annotation
|
||||
self.ast.copy(¶ms.items[index].pattern.type_annotation)
|
||||
};
|
||||
if let Some(new_element) =
|
||||
self.transform_formal_parameter_to_class_property(param, type_annotation)
|
||||
{
|
||||
|
|
@ -270,7 +271,7 @@ impl<'a> IsolatedDeclarations<'a> {
|
|||
for element in &decl.body.body {
|
||||
if let ClassElement::MethodDefinition(method) = element {
|
||||
if method.key.is_private_identifier()
|
||||
|| method.accessibility.is_some_and(|a| a.is_private())
|
||||
|| method.accessibility.is_some_and(oxc_ast::ast::TSAccessibility::is_private)
|
||||
|| (method.computed && !self.is_literal_key(&method.key))
|
||||
{
|
||||
continue;
|
||||
|
|
@ -359,7 +360,7 @@ impl<'a> IsolatedDeclarations<'a> {
|
|||
if self.report_property_key(&method.key, method.computed) {
|
||||
continue;
|
||||
}
|
||||
if method.accessibility.is_some_and(|a| a.is_private()) {
|
||||
if method.accessibility.is_some_and(oxc_ast::ast::TSAccessibility::is_private) {
|
||||
elements.push(self.transform_private_modifier_method(method));
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue