oak_typescript/language/
mod.rs1#![doc = include_str!("readme.md")]
2use crate::ast::TypeScriptRoot;
3use oak_core::{Language, LanguageCategory};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub struct TypeScriptLanguage {
9 pub jsx: bool,
11 pub decorators: bool,
13 pub strict: bool,
15 pub target: EcmaVersion,
17 pub experimental: bool,
19}
20
21impl Default for TypeScriptLanguage {
22 fn default() -> Self {
23 Self::standard()
24 }
25}
26
27#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
29#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
30pub enum EcmaVersion {
31 ES3,
33 ES5,
35 ES2015,
37 ES2016,
39 ES2017,
41 ES2018,
43 ES2019,
45 ES2020,
47 ES2021,
49 ES2022,
51 ESNext,
53}
54
55impl TypeScriptLanguage {
56 pub fn new() -> Self {
58 Self::default()
59 }
60
61 pub fn standard() -> Self {
63 Self { jsx: true, decorators: true, strict: false, target: EcmaVersion::ES2020, experimental: true }
64 }
65
66 pub fn with_jsx() -> Self {
68 Self { jsx: true, decorators: false, strict: false, target: EcmaVersion::ES2020, experimental: false }
69 }
70
71 pub fn with_decorators() -> Self {
73 Self { jsx: false, decorators: true, strict: false, target: EcmaVersion::ES2020, experimental: false }
74 }
75
76 pub fn strict() -> Self {
78 Self { jsx: false, decorators: false, strict: true, target: EcmaVersion::ES2020, experimental: false }
79 }
80
81 pub fn experimental() -> Self {
83 Self { jsx: true, decorators: true, strict: true, target: EcmaVersion::ESNext, experimental: true }
84 }
85}
86
87impl Language for TypeScriptLanguage {
88 const NAME: &'static str = "typescript";
89 const CATEGORY: LanguageCategory = LanguageCategory::Programming;
90
91 type TokenType = crate::lexer::token_type::TypeScriptTokenType;
92 type ElementType = crate::parser::element_type::TypeScriptElementType;
93 type TypedRoot = TypeScriptRoot;
94}