oxc_ecmascript/
private_bound_identifiers.rs

1use oxc_ast::ast::{
2    AccessorProperty, ClassElement, MethodDefinition, PrivateIdentifier, PropertyDefinition,
3    PropertyKey,
4};
5
6/// [`PrivateBoundIdentifiers`](https://tc39.es/ecma262/#sec-static-semantics-privateboundidentifiers)
7pub trait PrivateBoundIdentifiers {
8    fn private_bound_identifiers(&self) -> Option<PrivateIdentifier<'_>>;
9}
10
11impl PrivateBoundIdentifiers for ClassElement<'_> {
12    fn private_bound_identifiers(&self) -> Option<PrivateIdentifier<'_>> {
13        match self {
14            ClassElement::StaticBlock(_) | ClassElement::TSIndexSignature(_) => None,
15            ClassElement::MethodDefinition(def) => def.private_bound_identifiers(),
16            ClassElement::PropertyDefinition(def) => def.private_bound_identifiers(),
17            ClassElement::AccessorProperty(def) => def.private_bound_identifiers(),
18        }
19    }
20}
21
22impl PrivateBoundIdentifiers for MethodDefinition<'_> {
23    fn private_bound_identifiers(&self) -> Option<PrivateIdentifier<'_>> {
24        self.value.body.as_ref()?;
25        if let PropertyKey::PrivateIdentifier(ident) = &self.key {
26            return Some((*ident).clone());
27        }
28        None
29    }
30}
31
32impl PrivateBoundIdentifiers for PropertyDefinition<'_> {
33    fn private_bound_identifiers(&self) -> Option<PrivateIdentifier<'_>> {
34        if let PropertyKey::PrivateIdentifier(ident) = &self.key {
35            return Some((*ident).clone());
36        }
37        None
38    }
39}
40
41impl PrivateBoundIdentifiers for AccessorProperty<'_> {
42    fn private_bound_identifiers(&self) -> Option<PrivateIdentifier<'_>> {
43        if let PropertyKey::PrivateIdentifier(ident) = &self.key {
44            return Some((*ident).clone());
45        }
46        None
47    }
48}