1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//! Includes type annotations + syntax added by TypeScript (and Ezno) such as `declare` declarations

pub mod declares;
pub mod enum_declaration;
pub mod interface;
pub mod namespace;
pub mod type_alias;
pub mod type_annotations;
pub mod type_declarations;

pub use interface::InterfaceDeclaration;

// [See](https://www.typescriptlang.org/docs/handbook/2/classes.html#member-visibility)
// #[derive(Debug, Clone, PartialEq, Eq)]
// pub enum Visibility {
// 	Private,
// 	Public,
// 	Protected,
// }

// impl Visibility {
// 	pub fn as_str(&self) -> &'static str {
// 		match self {
// 			Visibility::Private => "private ",
// 			Visibility::Public => "public ",
// 			Visibility::Protected => "protected ",
// 		}
// 	}
// }

#[cfg(feature = "extras")]
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "self-rust-tokenize", derive(self_rust_tokenize::SelfRustTokenize))]
#[cfg_attr(feature = "serde-serialize", derive(serde::Serialize))]
pub enum AnnotationPerforms {
	PerformsStatements {
		performs_keyword: crate::Keyword<crate::tsx_keywords::Performs>,
		statements: crate::Block,
	},
	PerformsConst {
		performs_keyword: crate::Keyword<crate::tsx_keywords::Performs>,
		identifier: String,
	},
}

#[cfg(feature = "extras")]
impl crate::ASTNode for AnnotationPerforms {
	fn get_position(&self) -> &source_map::Span {
		todo!()
	}

	fn from_reader(
		reader: &mut impl tokenizer_lib::TokenReader<crate::TSXToken, crate::TokenStart>,
		state: &mut crate::ParsingState,
		settings: &crate::ParseOptions,
	) -> crate::ParseResult<Self> {
		let performs_keyword = crate::Keyword::from_reader(reader)?;
		if let Some(tokenizer_lib::Token(crate::TSXToken::OpenBrace, _)) = reader.peek() {
			// let expression = Expression::from_reader(reader, state, settings)?;
			// reader.expect_next(TSXToken::CloseParentheses)?;
			// Some(Box::new(expression))

			let body = crate::Block::from_reader(reader, state, settings)?;
			Ok(AnnotationPerforms::PerformsStatements { performs_keyword, statements: body })
		} else {
			reader.expect_next(crate::TSXToken::Keyword(crate::TSXKeyword::Const))?;
			let (identifier, _) =
				crate::tokens::token_as_identifier(reader.next().unwrap(), "performs const")?;
			Ok(AnnotationPerforms::PerformsConst { performs_keyword, identifier })
		}
	}

	fn to_string_from_buffer<T: source_map::ToString>(
		&self,
		_buf: &mut T,
		_settings: &crate::ToStringOptions,
		_depth: u8,
	) {
		todo!()
	}
}