Skip to main content

oak_typescript/ast/
class_nodes.rs

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