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