oak_typescript/language/
mod.rs1use crate::ast::TypeScriptRoot;
2use oak_core::{Language, LanguageCategory};
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
7pub struct TypeScriptLanguage {
8 pub jsx: bool,
10 pub decorators: bool,
12 pub strict: bool,
14 pub target: EcmaVersion,
16 pub experimental: bool,
18}
19
20impl Default for TypeScriptLanguage {
21 fn default() -> Self {
22 Self::standard()
23 }
24}
25
26#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
28pub enum EcmaVersion {
29 ES3,
30 ES5,
31 ES2015,
32 ES2016,
33 ES2017,
34 ES2018,
35 ES2019,
36 ES2020,
37 ES2021,
38 ES2022,
39 ESNext,
40}
41
42impl TypeScriptLanguage {
43 pub fn new() -> Self {
45 Self::default()
46 }
47
48 pub fn standard() -> Self {
50 Self { jsx: false, decorators: false, strict: false, target: EcmaVersion::ES2020, experimental: false }
51 }
52
53 pub fn with_jsx() -> Self {
55 Self { jsx: true, decorators: false, strict: false, target: EcmaVersion::ES2020, experimental: false }
56 }
57
58 pub fn with_decorators() -> Self {
60 Self { jsx: false, decorators: true, strict: false, target: EcmaVersion::ES2020, experimental: false }
61 }
62
63 pub fn strict() -> Self {
65 Self { jsx: false, decorators: false, strict: true, target: EcmaVersion::ES2020, experimental: false }
66 }
67
68 pub fn experimental() -> Self {
70 Self { jsx: true, decorators: true, strict: true, target: EcmaVersion::ESNext, experimental: true }
71 }
72}
73
74impl Language for TypeScriptLanguage {
75 const NAME: &'static str = "typescript";
76 const CATEGORY: LanguageCategory = LanguageCategory::Programming;
77
78 type TokenType = crate::kind::TypeScriptSyntaxKind;
79 type ElementType = crate::kind::TypeScriptSyntaxKind;
80 type TypedRoot = TypeScriptRoot;
81}