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,
35 ES5,
37 ES2015,
39 ES2016,
41 ES2017,
43 ES2018,
45 ES2019,
47 ES2020,
49 ES2021,
51 ES2022,
53 ESNext,
55}
56
57impl TypeScriptLanguage {
58 pub fn new() -> Self {
60 Self::default()
61 }
62
63 pub fn standard() -> Self {
65 Self { jsx: true, decorators: true, strict: false, target: EcmaVersion::ES2020, experimental: true }
66 }
67
68 pub fn with_jsx() -> Self {
70 Self { jsx: true, decorators: false, strict: false, target: EcmaVersion::ES2020, experimental: false }
71 }
72
73 pub fn with_decorators() -> Self {
75 Self { jsx: false, decorators: true, strict: false, target: EcmaVersion::ES2020, experimental: false }
76 }
77
78 pub fn strict() -> Self {
80 Self { jsx: false, decorators: false, strict: true, target: EcmaVersion::ES2020, experimental: false }
81 }
82
83 pub fn experimental() -> Self {
85 Self { jsx: true, decorators: true, strict: true, target: EcmaVersion::ESNext, experimental: true }
86 }
87}
88
89impl Language for TypeScriptLanguage {
90 const NAME: &'static str = "typescript";
91 const CATEGORY: LanguageCategory = LanguageCategory::Programming;
92
93 type TokenType = crate::lexer::token_type::TypeScriptTokenType;
94 type ElementType = crate::parser::element_type::TypeScriptElementType;
95 type TypedRoot = TypeScriptRoot;
96}