Skip to main content

oak_typescript/ast/
class_nodes.rs

1use crate::ast::{Decorator, Expression, FunctionParam, Statement, TypeAnnotation, TypeParameter};
2use core::range::Range;
3
4/// Represents the visibility of a class member.
5#[derive(Debug, Clone)]
6#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7pub enum Visibility {
8    /// Public visibility.
9    Public,
10    /// Private visibility.
11    Private,
12    /// Protected visibility.
13    Protected,
14}
15
16/// Represents a member of a class.
17#[derive(Debug, Clone)]
18#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
19pub enum ClassMember {
20    /// A property member.
21    Property {
22        /// Decorators associated with the property.
23        decorators: Vec<Decorator>,
24        /// Name of the property.
25        name: String,
26        /// Type annotation of the property.
27        ty: Option<TypeAnnotation>,
28        /// Initializer expression of the property.
29        initializer: Option<Expression>,
30        /// Visibility of the property.
31        visibility: Option<Visibility>,
32        /// Whether the property is static.
33        is_static: bool,
34        /// Whether the property is readonly.
35        is_readonly: bool,
36        /// Whether the property is abstract.
37        is_abstract: bool,
38        /// Whether the property is optional.
39        is_optional: bool,
40        /// Source span of the property.
41        #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
42        span: Range<usize>,
43    },
44    /// A method member.
45    Method {
46        /// Decorators associated with the method.
47        decorators: Vec<Decorator>,
48        /// Name of the method.
49        name: String,
50        /// Type parameters of the method.
51        type_params: Vec<TypeParameter>,
52        /// Parameters of the method.
53        params: Vec<FunctionParam>,
54        /// Return type of the method.
55        return_type: Option<TypeAnnotation>,
56        /// Body of the method.
57        body: Vec<Statement>,
58        /// Visibility of the method.
59        visibility: Option<Visibility>,
60        /// Whether the method is static.
61        is_static: bool,
62        /// Whether the method is abstract.
63        is_abstract: bool,
64        /// Whether the method is a getter.
65        is_getter: bool,
66        /// Whether the method is a setter.
67        is_setter: bool,
68        /// Whether the method is optional.
69        is_optional: bool,
70        /// Source span of the method.
71        #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
72        span: Range<usize>,
73    },
74}