oak_typescript/language/
mod.rs1use crate::ast::TypeScriptRoot;
2use oak_core::{Language, LanguageCategory};
3
4pub struct TypeScriptLanguage {
6 pub jsx: bool,
8 pub decorators: bool,
10 pub strict: bool,
12 pub target: EcmaVersion,
14 pub experimental: bool,
16}
17
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20pub enum EcmaVersion {
21 ES3,
22 ES5,
23 ES2015,
24 ES2016,
25 ES2017,
26 ES2018,
27 ES2019,
28 ES2020,
29 ES2021,
30 ES2022,
31 ESNext,
32}
33
34impl TypeScriptLanguage {
35 pub fn standard() -> Self {
37 Self { jsx: false, decorators: false, strict: false, target: EcmaVersion::ES2020, experimental: false }
38 }
39
40 pub fn with_jsx() -> Self {
42 Self { jsx: true, decorators: false, strict: false, target: EcmaVersion::ES2020, experimental: false }
43 }
44
45 pub fn with_decorators() -> Self {
47 Self { jsx: false, decorators: true, strict: false, target: EcmaVersion::ES2020, experimental: false }
48 }
49
50 pub fn strict() -> Self {
52 Self { jsx: false, decorators: false, strict: true, target: EcmaVersion::ES2020, experimental: false }
53 }
54
55 pub fn experimental() -> Self {
57 Self { jsx: true, decorators: true, strict: true, target: EcmaVersion::ESNext, experimental: true }
58 }
59}
60
61impl Language for TypeScriptLanguage {
62 const NAME: &'static str = "typescript";
63 const CATEGORY: LanguageCategory = LanguageCategory::Programming;
64
65 type TokenType = crate::kind::TypeScriptSyntaxKind;
66 type ElementType = crate::kind::TypeScriptSyntaxKind;
67 type TypedRoot = TypeScriptRoot;
68}