oak_typescript/language/
mod.rs

1use crate::{ast::TypeScriptRoot, kind::TypeScriptSyntaxKind};
2use oak_core::Language;
3
4/// TypeScript 语言配置
5pub struct TypeScriptLanguage {
6    /// 是否支持 JSX 语法
7    pub jsx: bool,
8    /// 是否支持装饰器
9    pub decorators: bool,
10    /// 是否启用严格模式
11    pub strict: bool,
12    /// 目标 ECMAScript 版本
13    pub target: EcmaVersion,
14    /// 是否允许实验性语法
15    pub experimental: bool,
16}
17
18/// ECMAScript 版本
19#[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    /// 创建标准 TypeScript 配置
36    pub fn standard() -> Self {
37        Self { jsx: false, decorators: false, strict: false, target: EcmaVersion::ES2020, experimental: false }
38    }
39
40    /// 创建支持 JSX TypeScript 配置
41    pub fn with_jsx() -> Self {
42        Self { jsx: true, decorators: false, strict: false, target: EcmaVersion::ES2020, experimental: false }
43    }
44
45    /// 创建支持装饰器的 TypeScript 配置
46    pub fn with_decorators() -> Self {
47        Self { jsx: false, decorators: true, strict: false, target: EcmaVersion::ES2020, experimental: false }
48    }
49
50    /// 创建严格模式TypeScript 配置
51    pub fn strict() -> Self {
52        Self { jsx: false, decorators: false, strict: true, target: EcmaVersion::ES2020, experimental: false }
53    }
54
55    /// 创建实验性语法的 TypeScript 配置
56    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    type SyntaxKind = TypeScriptSyntaxKind;
63    type TypedRoot = TypeScriptRoot;
64}