#![warn(missing_docs)]
use std::hash::Hash;
#[derive(Debug, Clone, Default)]
pub struct TypeScriptLanguage {
pub features: std::collections::HashSet<TypeScriptFeature>,
}
impl TypeScriptLanguage {
pub fn new() -> Self {
Self::default()
}
pub fn standard() -> Self {
let mut language = Self::new();
language.add_feature(TypeScriptFeature::TypeAnnotations);
language.add_feature(TypeScriptFeature::Interfaces);
language.add_feature(TypeScriptFeature::Generics);
language.add_feature(TypeScriptFeature::Enums);
language.add_feature(TypeScriptFeature::TypeAliases);
language.add_feature(TypeScriptFeature::UnionTypes);
language.add_feature(TypeScriptFeature::IntersectionTypes);
language.add_feature(TypeScriptFeature::LiteralTypes);
language.add_feature(TypeScriptFeature::TupleTypes);
language.add_feature(TypeScriptFeature::FunctionTypes);
language.add_feature(TypeScriptFeature::ObjectTypes);
language.add_feature(TypeScriptFeature::ArrayTypes);
language.add_feature(TypeScriptFeature::IndexedAccessTypes);
language.add_feature(TypeScriptFeature::KeyofTypes);
language.add_feature(TypeScriptFeature::TypeofTypes);
language.add_feature(TypeScriptFeature::InferredTypes);
language.add_feature(TypeScriptFeature::RecursiveTypes);
language.add_feature(TypeScriptFeature::GenericConstraints);
language.add_feature(TypeScriptFeature::TypeParameterDefaults);
language.add_feature(TypeScriptFeature::RestTypeParameters);
language.add_feature(TypeScriptFeature::OptionalTypeParameters);
language.add_feature(TypeScriptFeature::OverloadedFunctionTypes);
language.add_feature(TypeScriptFeature::ConstructorTypes);
language.add_feature(TypeScriptFeature::AccessModifiers);
language.add_feature(TypeScriptFeature::StaticMembers);
language.add_feature(TypeScriptFeature::AbstractClasses);
language.add_feature(TypeScriptFeature::Inheritance);
language.add_feature(TypeScriptFeature::InterfaceImplementation);
language.add_feature(TypeScriptFeature::ModuleSystem);
language.add_feature(TypeScriptFeature::EsModules);
language.add_feature(TypeScriptFeature::CommonJsModules);
language.add_feature(TypeScriptFeature::ExternalModuleDeclarations);
language.add_feature(TypeScriptFeature::AsyncAwait);
language.add_feature(TypeScriptFeature::OptionalChaining);
language.add_feature(TypeScriptFeature::NullishCoalescing);
language.add_feature(TypeScriptFeature::TemplateLiteralTypes);
language.add_feature(TypeScriptFeature::MappedTypes);
language.add_feature(TypeScriptFeature::ConditionalTypes);
language.add_feature(TypeScriptFeature::Namespaces);
language.add_feature(TypeScriptFeature::Decorators);
language.add_feature(TypeScriptFeature::StrictMode);
language.add_feature(TypeScriptFeature::StrictNullChecks);
language.add_feature(TypeScriptFeature::StrictFunctionTypes);
language.add_feature(TypeScriptFeature::StrictBindCallApply);
language.add_feature(TypeScriptFeature::StrictPropertyInitialization);
language.add_feature(TypeScriptFeature::NoImplicitAny);
language.add_feature(TypeScriptFeature::NoImplicitThis);
language.add_feature(TypeScriptFeature::AlwaysStrict);
language.add_feature(TypeScriptFeature::NoUnusedVariables);
language.add_feature(TypeScriptFeature::NoUnusedParameters);
language.add_feature(TypeScriptFeature::NoEmptyFunctions);
language.add_feature(TypeScriptFeature::NoEmptyInterfaces);
language.add_feature(TypeScriptFeature::NoDuplicateImports);
language.add_feature(TypeScriptFeature::NoDuplicateClassMembers);
language.add_feature(TypeScriptFeature::NoDuplicateParameters);
language.add_feature(TypeScriptFeature::NoDuplicateCaseLabels);
language.add_feature(TypeScriptFeature::NoUnreachableCode);
language.add_feature(TypeScriptFeature::NoImplicitReturns);
language.add_feature(TypeScriptFeature::TripleSlashDirectives);
language.add_feature(TypeScriptFeature::JsDocComments);
language
}
pub fn add_feature(&mut self, feature: TypeScriptFeature) {
self.features.insert(feature);
}
pub fn supports(&self, feature: TypeScriptFeature) -> bool {
self.features.contains(&feature)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum TypeScriptFeature {
TypeAnnotations,
Interfaces,
Generics,
Enums,
Namespaces,
Decorators,
AsyncAwait,
OptionalChaining,
NullishCoalescing,
TemplateLiteralTypes,
MappedTypes,
ConditionalTypes,
TypeAliases,
UnionTypes,
IntersectionTypes,
LiteralTypes,
TupleTypes,
FunctionTypes,
ObjectTypes,
ArrayTypes,
IndexedAccessTypes,
KeyofTypes,
TypeofTypes,
InferredTypes,
RecursiveTypes,
GenericConstraints,
TypeParameterDefaults,
RestTypeParameters,
OptionalTypeParameters,
OverloadedFunctionTypes,
ConstructorTypes,
AccessModifiers,
StaticMembers,
AbstractClasses,
Inheritance,
InterfaceImplementation,
ModuleSystem,
EsModules,
CommonJsModules,
ExternalModuleDeclarations,
TripleSlashDirectives,
JsDocComments,
StrictMode,
StrictNullChecks,
StrictFunctionTypes,
StrictBindCallApply,
StrictPropertyInitialization,
NoImplicitAny,
NoImplicitThis,
AlwaysStrict,
NoUnusedVariables,
NoUnusedParameters,
NoEmptyFunctions,
NoEmptyInterfaces,
NoDuplicateImports,
NoDuplicateClassMembers,
NoDuplicateParameters,
NoDuplicateCaseLabels,
NoUnreachableCode,
NoImplicitReturns,
NoImplicitCoercion,
NoEval,
NoWith,
NoArguments,
NoDelete,
NoVoid,
NoUndefined,
NoNull,
NoAny,
NoNever,
NoObject,
NoUnknown,
NoSymbol,
NoBigInt,
NoNumber,
NoString,
NoBoolean,
NoArray,
NoTuple,
NoEnum,
NoInterface,
NoType,
NoClass,
NoFunction,
NoConst,
NoLet,
NoVar,
NoAsync,
NoAwait,
NoYield,
NoReturn,
NoThrow,
NoTry,
NoCatch,
NoFinally,
NoIf,
NoElse,
NoSwitch,
NoCase,
NoDefault,
NoFor,
NoWhile,
NoDo,
NoBreak,
NoContinue,
NoWithStatement,
NoDebugger,
NoImport,
NoExport,
NoFrom,
NoAs,
NoIn,
NoInstanceOf,
NoNew,
NoThis,
NoSuper,
NoStatic,
NoPublic,
NoPrivate,
NoProtected,
NoAbstract,
NoReadonly,
NoOptional,
NoRest,
NoSpread,
NoDestructuring,
NoArrowFunctions,
NoGeneratorFunctions,
NoAsyncFunctions,
NoMethodSyntax,
NoComputedProperties,
NoShorthandProperties,
NoRestProperties,
NoSpreadProperties,
NoTemplateLiterals,
NoRegexLiterals,
NoNumericLiterals,
NoStringLiterals,
NoBooleanLiterals,
NoNullLiterals,
NoUndefinedLiterals,
NoBigIntLiterals,
NoSymbolLiterals,
NoObjectLiterals,
NoArrayLiterals,
NoFunctionLiterals,
NoClassLiterals,
NoNamespaceLiterals,
NoModuleLiterals,
NoEnumLiterals,
NoTypeLiterals,
NoInterfaceLiterals,
NoUnionLiterals,
NoIntersectionLiterals,
NoLiteralTypes,
NoTupleTypes,
NoFunctionTypes,
NoObjectTypes,
NoArrayTypes,
NoIndexedAccessTypes,
NoKeyofTypes,
NoTypeofTypes,
NoInferredTypes,
NoRecursiveTypes,
NoGenericConstraints,
NoTypeParameterDefaults,
NoRestTypeParameters,
NoOptionalTypeParameters,
NoOverloadedFunctionTypes,
NoConstructorTypes,
NoAccessModifiers,
NoStaticMembers,
NoAbstractClasses,
NoInheritance,
NoInterfaceImplementation,
NoModuleSystem,
NoEsModules,
NoCommonJsModules,
NoExternalModuleDeclarations,
NoTripleSlashDirectives,
NoJsDocComments,
NoStrictMode,
NoStrictNullChecks,
NoStrictFunctionTypes,
NoStrictBindCallApply,
NoStrictPropertyInitialization,
NoNoImplicitAny,
NoNoImplicitThis,
NoAlwaysStrict,
NoNoUnusedVariables,
NoNoUnusedParameters,
NoNoEmptyFunctions,
NoNoEmptyInterfaces,
NoNoDuplicateImports,
NoNoDuplicateClassMembers,
NoNoDuplicateParameters,
NoNoDuplicateCaseLabels,
NoNoUnreachableCode,
NoNoImplicitReturns,
NoNoImplicitCoercion,
NoNoEval,
NoNoWith,
NoNoArguments,
NoNoDelete,
NoNoVoid,
NoNoUndefined,
NoNoNull,
NoNoAny,
NoNoNever,
NoNoObject,
NoNoUnknown,
NoNoSymbol,
NoNoBigInt,
NoNoNumber,
NoNoString,
NoNoBoolean,
NoNoArray,
NoNoTuple,
NoNoEnum,
NoNoInterface,
NoNoType,
NoNoClass,
NoNoFunction,
NoNoConst,
NoNoLet,
NoNoVar,
NoNoAsync,
NoNoAwait,
NoNoYield,
NoNoReturn,
NoNoThrow,
NoNoTry,
NoNoCatch,
NoNoFinally,
NoNoIf,
NoNoElse,
NoNoSwitch,
NoNoCase,
NoNoDefault,
NoNoFor,
NoNoWhile,
NoNoDo,
NoNoBreak,
NoNoContinue,
NoNoWithStatement,
NoNoDebugger,
NoNoImport,
NoNoExport,
NoNoFrom,
NoNoAs,
NoNoIn,
NoNoInstanceOf,
NoNoNew,
NoNoThis,
NoNoSuper,
NoNoStatic,
NoNoPublic,
NoNoPrivate,
NoNoProtected,
NoNoAbstract,
NoNoReadonly,
NoNoOptional,
NoNoRest,
NoNoSpread,
NoNoDestructuring,
NoNoArrowFunctions,
NoNoGeneratorFunctions,
NoNoAsyncFunctions,
NoNoMethodSyntax,
NoNoComputedProperties,
NoNoShorthandProperties,
NoNoRestProperties,
NoNoSpreadProperties,
NoNoTemplateLiterals,
NoNoRegexLiterals,
NoNoNumericLiterals,
NoNoStringLiterals,
NoNoBooleanLiterals,
NoNoNullLiterals,
NoNoUndefinedLiterals,
NoNoBigIntLiterals,
NoNoSymbolLiterals,
NoNoObjectLiterals,
NoNoArrayLiterals,
NoNoFunctionLiterals,
NoNoClassLiterals,
NoNoNamespaceLiterals,
NoNoModuleLiterals,
NoNoEnumLiterals,
NoNoTypeLiterals,
NoNoInterfaceLiterals,
NoNoUnionLiterals,
NoNoIntersectionLiterals,
NoNoLiteralTypes,
NoNoTupleTypes,
NoNoFunctionTypes,
NoNoObjectTypes,
NoNoArrayTypes,
NoNoIndexedAccessTypes,
NoNoKeyofTypes,
NoNoTypeofTypes,
NoNoInferredTypes,
NoNoRecursiveTypes,
NoNoGenericConstraints,
NoNoTypeParameterDefaults,
NoNoRestTypeParameters,
NoNoOptionalTypeParameters,
NoNoOverloadedFunctionTypes,
NoNoConstructorTypes,
NoNoAccessModifiers,
NoNoStaticMembers,
NoNoAbstractClasses,
NoNoInheritance,
NoNoInterfaceImplementation,
NoNoModuleSystem,
NoNoEsModules,
NoNoCommonJsModules,
NoNoExternalModuleDeclarations,
NoNoTripleSlashDirectives,
NoNoJsDocComments,
}