#![doc = include_str!("readme.md")]
use crate::ast::TypeScriptRoot;
use oak_core::{Language, LanguageCategory};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TypeScriptLanguage {
pub jsx: bool,
pub decorators: bool,
pub strict: bool,
pub target: EcmaVersion,
pub experimental: bool,
}
impl Default for TypeScriptLanguage {
fn default() -> Self {
Self::standard()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum EcmaVersion {
ES3,
ES5,
ES2015,
ES2016,
ES2017,
ES2018,
ES2019,
ES2020,
ES2021,
ES2022,
ESNext,
}
impl TypeScriptLanguage {
pub fn new() -> Self {
Self::default()
}
pub fn standard() -> Self {
Self { jsx: true, decorators: true, strict: false, target: EcmaVersion::ES2020, experimental: true }
}
pub fn with_jsx() -> Self {
Self { jsx: true, decorators: false, strict: false, target: EcmaVersion::ES2020, experimental: false }
}
pub fn with_decorators() -> Self {
Self { jsx: false, decorators: true, strict: false, target: EcmaVersion::ES2020, experimental: false }
}
pub fn strict() -> Self {
Self { jsx: false, decorators: false, strict: true, target: EcmaVersion::ES2020, experimental: false }
}
pub fn experimental() -> Self {
Self { jsx: true, decorators: true, strict: true, target: EcmaVersion::ESNext, experimental: true }
}
}
impl Language for TypeScriptLanguage {
const NAME: &'static str = "typescript";
const CATEGORY: LanguageCategory = LanguageCategory::Programming;
type TokenType = crate::lexer::token_type::TypeScriptTokenType;
type ElementType = crate::parser::element_type::TypeScriptElementType;
type TypedRoot = TypeScriptRoot;
}