use crate::parser::Span;
use crate::prelude::*;
use crate::value::JsString;
#[derive(Debug, Clone)]
pub struct Program {
pub body: Rc<[Statement]>,
pub source_type: SourceType,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SourceType {
Script,
Module,
}
#[derive(Debug, Clone)]
pub enum Statement {
VariableDeclaration(VariableDeclaration),
FunctionDeclaration(Box<FunctionDeclaration>),
ClassDeclaration(Box<ClassDeclaration>),
TypeAlias(Box<TypeAliasDeclaration>),
InterfaceDeclaration(Box<InterfaceDeclaration>),
EnumDeclaration(Box<EnumDeclaration>),
NamespaceDeclaration(Box<NamespaceDeclaration>),
Block(BlockStatement),
If(IfStatement),
Switch(SwitchStatement),
For(Box<ForStatement>),
ForIn(Box<ForInStatement>),
ForOf(Box<ForOfStatement>),
While(WhileStatement),
DoWhile(DoWhileStatement),
Try(Box<TryStatement>),
Return(ReturnStatement),
Break(BreakStatement),
Continue(ContinueStatement),
Throw(ThrowStatement),
Import(Box<ImportDeclaration>),
Export(Box<ExportDeclaration>),
Expression(ExpressionStatement),
Empty,
Debugger,
Labeled(LabeledStatement),
}
#[derive(Debug, Clone)]
pub struct ExpressionStatement {
pub expression: Rc<Expression>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct BlockStatement {
pub body: Rc<[Statement]>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct VariableDeclaration {
pub kind: VariableKind,
pub declarations: Rc<[VariableDeclarator]>,
pub span: Span,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum VariableKind {
Let,
Const,
Var,
}
#[derive(Debug, Clone)]
pub struct VariableDeclarator {
pub id: Pattern,
pub type_annotation: Option<Box<TypeAnnotation>>,
pub init: Option<Rc<Expression>>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct FunctionDeclaration {
pub id: Option<Identifier>,
pub params: Rc<[FunctionParam]>,
pub return_type: Option<Box<TypeAnnotation>>,
pub type_parameters: Option<TypeParameters>,
pub body: Rc<BlockStatement>,
pub generator: bool,
pub async_: bool,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct FunctionParam {
pub pattern: Pattern,
pub type_annotation: Option<Box<TypeAnnotation>>,
pub optional: bool,
pub decorators: Vec<Decorator>,
pub accessibility: Option<Accessibility>,
pub readonly: bool,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct ClassDeclaration {
pub id: Option<Identifier>,
pub type_parameters: Option<TypeParameters>,
pub super_class: Option<Rc<Expression>>,
pub implements: Vec<TypeReference>,
pub body: ClassBody,
pub decorators: Vec<Decorator>,
pub abstract_: bool,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct ClassBody {
pub members: Vec<ClassMember>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum ClassMember {
Method(Box<ClassMethod>),
Property(Box<ClassProperty>),
Constructor(Box<ClassConstructor>),
StaticBlock(BlockStatement),
}
#[derive(Debug, Clone)]
pub struct ClassMethod {
pub key: ObjectPropertyKey,
pub value: FunctionExpression,
pub kind: MethodKind,
pub computed: bool,
pub static_: bool,
pub accessibility: Option<Accessibility>,
pub decorators: Vec<Decorator>,
pub span: Span,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MethodKind {
Method,
Get,
Set,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Accessibility {
Public,
Private,
Protected,
}
#[derive(Debug, Clone)]
pub struct ClassProperty {
pub key: ObjectPropertyKey,
pub value: Option<Box<Expression>>,
pub type_annotation: Option<Box<TypeAnnotation>>,
pub computed: bool,
pub static_: bool,
pub readonly: bool,
pub optional: bool,
pub accessor: bool,
pub accessibility: Option<Accessibility>,
pub decorators: Vec<Decorator>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct ClassConstructor {
pub params: Vec<FunctionParam>,
pub body: BlockStatement,
pub accessibility: Option<Accessibility>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct Decorator {
pub expression: Expression,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct IfStatement {
pub test: Rc<Expression>,
pub consequent: Rc<Statement>,
pub alternate: Option<Rc<Statement>>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct SwitchStatement {
pub discriminant: Rc<Expression>,
pub cases: Rc<[SwitchCase]>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct SwitchCase {
pub test: Option<Rc<Expression>>, pub consequent: Rc<[Statement]>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct ForStatement {
pub init: Option<ForInit>,
pub test: Option<Rc<Expression>>,
pub update: Option<Rc<Expression>>,
pub body: Rc<Statement>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum ForInit {
Variable(VariableDeclaration),
Expression(Rc<Expression>),
}
#[derive(Debug, Clone)]
pub struct ForInStatement {
pub left: ForInOfLeft,
pub right: Rc<Expression>,
pub body: Rc<Statement>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct ForOfStatement {
pub left: ForInOfLeft,
pub right: Rc<Expression>,
pub body: Rc<Statement>,
pub await_: bool,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum ForInOfLeft {
Variable(VariableDeclaration),
Pattern(Pattern),
}
#[derive(Debug, Clone)]
pub struct WhileStatement {
pub test: Rc<Expression>,
pub body: Rc<Statement>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct DoWhileStatement {
pub body: Rc<Statement>,
pub test: Rc<Expression>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct TryStatement {
pub block: BlockStatement,
pub handler: Option<CatchClause>,
pub finalizer: Option<BlockStatement>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct CatchClause {
pub param: Option<Pattern>,
pub body: BlockStatement,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct ReturnStatement {
pub argument: Option<Rc<Expression>>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct BreakStatement {
pub label: Option<Identifier>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct ContinueStatement {
pub label: Option<Identifier>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct ThrowStatement {
pub argument: Rc<Expression>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct LabeledStatement {
pub label: Identifier,
pub body: Rc<Statement>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct TypeAliasDeclaration {
pub id: Identifier,
pub type_parameters: Option<TypeParameters>,
pub type_annotation: Box<TypeAnnotation>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct InterfaceDeclaration {
pub id: Identifier,
pub type_parameters: Option<TypeParameters>,
pub extends: Vec<TypeReference>,
pub body: Vec<TypeMember>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct EnumDeclaration {
pub id: Identifier,
pub members: Vec<EnumMember>,
pub const_: bool,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct EnumMember {
pub id: Identifier,
pub initializer: Option<Expression>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct NamespaceDeclaration {
pub id: Identifier,
pub body: Rc<[Statement]>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct ImportDeclaration {
pub specifiers: Vec<ImportSpecifier>,
pub source: StringLiteral,
pub type_only: bool,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum ImportSpecifier {
Named {
local: Identifier,
imported: Identifier,
span: Span,
},
Default {
local: Identifier,
span: Span,
},
Namespace {
local: Identifier,
span: Span,
},
}
#[derive(Debug, Clone)]
pub struct ExportDeclaration {
pub declaration: Option<Box<Statement>>,
pub specifiers: Vec<ExportSpecifier>,
pub source: Option<StringLiteral>,
pub namespace_export: Option<Identifier>,
pub default: bool,
pub type_only: bool,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct ExportSpecifier {
pub local: Identifier,
pub exported: Identifier,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum Expression {
Literal(Box<Literal>),
Array(ArrayExpression),
Object(ObjectExpression),
Function(Box<FunctionExpression>),
ArrowFunction(Box<ArrowFunctionExpression>),
Class(Box<ClassExpression>),
Template(Box<TemplateLiteral>),
TaggedTemplate(Box<TaggedTemplateExpression>),
Identifier(Identifier),
This(Span),
Super(Span),
Unary(UnaryExpression),
Binary(BinaryExpression),
Logical(LogicalExpression),
Conditional(ConditionalExpression),
Assignment(Box<AssignmentExpression>),
Update(UpdateExpression),
Sequence(SequenceExpression),
Member(Box<MemberExpression>),
OptionalChain(OptionalChainExpression),
Call(Box<CallExpression>),
New(Box<NewExpression>),
TypeAssertion(TypeAssertionExpression),
NonNull(NonNullExpression),
Spread(SpreadElement),
Yield(YieldExpression),
Await(AwaitExpression),
Parenthesized(Rc<Expression>, Span),
}
impl Expression {
pub fn span(&self) -> Span {
match self {
Expression::Literal(l) => l.span,
Expression::Array(a) => a.span,
Expression::Object(o) => o.span,
Expression::Function(f) => f.span,
Expression::ArrowFunction(a) => a.span,
Expression::Class(c) => c.span,
Expression::Template(t) => t.span,
Expression::TaggedTemplate(t) => t.span,
Expression::Identifier(i) => i.span,
Expression::This(s) | Expression::Super(s) => *s,
Expression::Unary(u) => u.span,
Expression::Binary(b) => b.span,
Expression::Logical(l) => l.span,
Expression::Conditional(c) => c.span,
Expression::Assignment(a) => a.span,
Expression::Update(u) => u.span,
Expression::Sequence(s) => s.span,
Expression::Member(m) => m.span,
Expression::OptionalChain(o) => o.span,
Expression::Call(c) => c.span,
Expression::New(n) => n.span,
Expression::TypeAssertion(t) => t.span,
Expression::NonNull(n) => n.span,
Expression::Spread(s) => s.span,
Expression::Yield(y) => y.span,
Expression::Await(a) => a.span,
Expression::Parenthesized(_, s) => *s,
}
}
}
#[derive(Debug, Clone)]
pub struct Literal {
pub value: LiteralValue,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq)]
pub enum LiteralValue {
Null,
Undefined,
Boolean(bool),
Number(f64),
String(JsString),
BigInt(String), RegExp { pattern: String, flags: String },
}
#[derive(Debug, Clone)]
pub struct StringLiteral {
pub value: JsString,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct Identifier {
pub name: JsString,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct ArrayExpression {
pub elements: Vec<Option<ArrayElement>>,
pub span: Span,
}
#[derive(Debug, Clone)]
#[allow(clippy::large_enum_variant)]
pub enum ArrayElement {
Expression(Expression),
Spread(SpreadElement),
}
#[derive(Debug, Clone)]
pub struct ObjectExpression {
pub properties: Vec<ObjectProperty>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum ObjectProperty {
Property(Box<Property>),
Spread(SpreadElement),
}
#[derive(Debug, Clone)]
pub struct Property {
pub key: ObjectPropertyKey,
pub value: Expression,
pub kind: PropertyKind,
pub computed: bool,
pub shorthand: bool,
pub method: bool,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum ObjectPropertyKey {
Identifier(Identifier),
String(StringLiteral),
Number(Literal),
Computed(Rc<Expression>),
PrivateIdentifier(Identifier),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PropertyKind {
Init,
Get,
Set,
}
#[derive(Debug, Clone)]
pub struct FunctionExpression {
pub id: Option<Identifier>,
pub params: Rc<[FunctionParam]>,
pub return_type: Option<Box<TypeAnnotation>>,
pub type_parameters: Option<TypeParameters>,
pub body: Rc<BlockStatement>,
pub generator: bool,
pub async_: bool,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct ArrowFunctionExpression {
pub params: Rc<[FunctionParam]>,
pub return_type: Option<Box<TypeAnnotation>>,
pub type_parameters: Option<TypeParameters>,
pub body: Box<ArrowFunctionBody>,
pub async_: bool,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum ArrowFunctionBody {
Expression(Rc<Expression>),
Block(Rc<BlockStatement>),
}
#[derive(Debug, Clone)]
pub struct ClassExpression {
pub id: Option<Identifier>,
pub type_parameters: Option<TypeParameters>,
pub super_class: Option<Rc<Expression>>,
pub implements: Vec<TypeReference>,
pub body: ClassBody,
pub decorators: Vec<Decorator>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct TemplateLiteral {
pub quasis: Vec<TemplateElement>,
pub expressions: Vec<Expression>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct TemplateElement {
pub value: JsString,
pub tail: bool,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct TaggedTemplateExpression {
pub tag: Rc<Expression>,
pub quasi: TemplateLiteral,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct UnaryExpression {
pub operator: UnaryOp,
pub argument: Rc<Expression>,
pub prefix: bool,
pub span: Span,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum UnaryOp {
Minus, Plus, Not, BitNot, Typeof, Void, Delete, }
#[derive(Debug, Clone)]
pub struct BinaryExpression {
pub operator: BinaryOp,
pub left: Rc<Expression>,
pub right: Rc<Expression>,
pub span: Span,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BinaryOp {
Add, Sub, Mul, Div, Mod, Exp,
Eq, NotEq, StrictEq, StrictNotEq, Lt, LtEq, Gt, GtEq,
BitAnd, BitOr, BitXor, LShift, RShift, URShift,
In, Instanceof, }
#[derive(Debug, Clone)]
pub struct LogicalExpression {
pub operator: LogicalOp,
pub left: Rc<Expression>,
pub right: Rc<Expression>,
pub span: Span,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LogicalOp {
And, Or, NullishCoalescing, }
#[derive(Debug, Clone)]
pub struct ConditionalExpression {
pub test: Rc<Expression>,
pub consequent: Rc<Expression>,
pub alternate: Rc<Expression>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct AssignmentExpression {
pub operator: AssignmentOp,
pub left: AssignmentTarget,
pub right: Rc<Expression>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum AssignmentTarget {
Identifier(Identifier),
Member(MemberExpression),
Pattern(Pattern),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AssignmentOp {
Assign, AddAssign, SubAssign, MulAssign, DivAssign, ModAssign, ExpAssign, BitAndAssign, BitOrAssign, BitXorAssign, LShiftAssign, RShiftAssign, URShiftAssign, AndAssign, OrAssign, NullishAssign, }
#[derive(Debug, Clone)]
pub struct UpdateExpression {
pub operator: UpdateOp,
pub argument: Rc<Expression>,
pub prefix: bool,
pub span: Span,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum UpdateOp {
Increment, Decrement, }
#[derive(Debug, Clone)]
pub struct SequenceExpression {
pub expressions: Vec<Expression>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct MemberExpression {
pub object: Rc<Expression>,
pub property: MemberProperty,
pub computed: bool,
pub optional: bool,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum MemberProperty {
Identifier(Identifier),
Expression(Rc<Expression>),
PrivateIdentifier(Identifier),
}
#[derive(Debug, Clone)]
pub struct OptionalChainExpression {
pub base: Rc<Expression>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct CallExpression {
pub callee: Rc<Expression>,
pub arguments: Vec<Argument>,
pub type_arguments: Option<TypeArguments>,
pub optional: bool,
pub span: Span,
}
#[derive(Debug, Clone)]
#[allow(clippy::large_enum_variant)]
pub enum Argument {
Expression(Expression),
Spread(SpreadElement),
}
#[derive(Debug, Clone)]
pub struct NewExpression {
pub callee: Rc<Expression>,
pub arguments: Vec<Argument>,
pub type_arguments: Option<TypeArguments>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct SpreadElement {
pub argument: Rc<Expression>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct YieldExpression {
pub argument: Option<Rc<Expression>>,
pub delegate: bool,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct AwaitExpression {
pub argument: Rc<Expression>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct TypeAssertionExpression {
pub expression: Rc<Expression>,
pub type_annotation: Box<TypeAnnotation>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct NonNullExpression {
pub expression: Rc<Expression>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum Pattern {
Identifier(Identifier),
Object(ObjectPattern),
Array(ArrayPattern),
Rest(RestElement),
Assignment(AssignmentPattern),
}
impl Pattern {
pub fn span(&self) -> Span {
match self {
Pattern::Identifier(i) => i.span,
Pattern::Object(o) => o.span,
Pattern::Array(a) => a.span,
Pattern::Rest(r) => r.span,
Pattern::Assignment(a) => a.span,
}
}
}
#[derive(Debug, Clone)]
pub struct ObjectPattern {
pub properties: Vec<ObjectPatternProperty>,
pub type_annotation: Option<Box<TypeAnnotation>>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum ObjectPatternProperty {
KeyValue {
key: ObjectPropertyKey,
value: Pattern,
shorthand: bool,
span: Span,
},
Rest(RestElement),
}
#[derive(Debug, Clone)]
pub struct ArrayPattern {
pub elements: Vec<Option<Pattern>>,
pub type_annotation: Option<Box<TypeAnnotation>>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct RestElement {
pub argument: Box<Pattern>,
pub type_annotation: Option<Box<TypeAnnotation>>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct AssignmentPattern {
pub left: Box<Pattern>,
pub right: Rc<Expression>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum TypeAnnotation {
Keyword(TypeKeyword),
Reference(TypeReference),
Literal(TypeLiteral),
Object(ObjectType),
Array(ArrayType),
Tuple(TupleType),
Union(UnionType),
Intersection(IntersectionType),
Function(FunctionType),
Conditional(ConditionalType),
Infer(InferType),
Mapped(MappedType),
Indexed(IndexedAccessType),
Typeof(TypeofType),
Keyof(KeyofType),
TemplateLiteral(TemplateLiteralType),
TypePredicate(TypePredicateType),
Parenthesized(Box<TypeAnnotation>),
This,
}
#[derive(Debug, Clone)]
pub struct TemplateLiteralType {
pub quasis: Vec<JsString>,
pub types: Vec<TypeAnnotation>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct TypePredicateType {
pub parameter_name: Identifier,
pub type_annotation: Option<Box<TypeAnnotation>>,
pub asserts: bool,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct TypeKeyword {
pub keyword: TypeKeywordKind,
pub span: Span,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TypeKeywordKind {
Any,
Unknown,
Never,
Void,
Null,
Undefined,
Boolean,
Number,
String,
Symbol,
BigInt,
Object,
}
#[derive(Debug, Clone)]
pub struct TypeReference {
pub name: Identifier,
pub type_arguments: Option<TypeArguments>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct TypeArguments {
pub params: Vec<TypeAnnotation>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct TypeParameters {
pub params: Vec<TypeParameter>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct TypeParameter {
pub name: Identifier,
pub constraint: Option<Box<TypeAnnotation>>,
pub default: Option<Box<TypeAnnotation>>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct TypeLiteral {
pub value: LiteralValue,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct ObjectType {
pub members: Vec<TypeMember>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum TypeMember {
Property(PropertySignature),
Method(MethodSignature),
Index(IndexSignature),
Call(CallSignature),
Construct(ConstructSignature),
}
#[derive(Debug, Clone)]
pub struct PropertySignature {
pub key: ObjectPropertyKey,
pub type_annotation: Option<Box<TypeAnnotation>>,
pub optional: bool,
pub readonly: bool,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct MethodSignature {
pub key: ObjectPropertyKey,
pub params: Vec<FunctionParam>,
pub return_type: Option<Box<TypeAnnotation>>,
pub type_parameters: Option<TypeParameters>,
pub optional: bool,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct IndexSignature {
pub key: Identifier,
pub key_type: Box<TypeAnnotation>,
pub value_type: Box<TypeAnnotation>,
pub readonly: bool,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct CallSignature {
pub params: Vec<FunctionParam>,
pub return_type: Option<Box<TypeAnnotation>>,
pub type_parameters: Option<TypeParameters>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct ConstructSignature {
pub params: Vec<FunctionParam>,
pub return_type: Option<Box<TypeAnnotation>>,
pub type_parameters: Option<TypeParameters>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct ArrayType {
pub element_type: Box<TypeAnnotation>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct TupleType {
pub element_types: Vec<TypeAnnotation>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct UnionType {
pub types: Vec<TypeAnnotation>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct IntersectionType {
pub types: Vec<TypeAnnotation>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct FunctionType {
pub params: Vec<FunctionParam>,
pub return_type: Box<TypeAnnotation>,
pub type_parameters: Option<TypeParameters>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct ConditionalType {
pub check_type: Box<TypeAnnotation>,
pub extends_type: Box<TypeAnnotation>,
pub true_type: Box<TypeAnnotation>,
pub false_type: Box<TypeAnnotation>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct InferType {
pub type_parameter: TypeParameter,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct MappedType {
pub type_parameter: TypeParameter,
pub name_type: Option<Box<TypeAnnotation>>,
pub type_annotation: Option<Box<TypeAnnotation>>,
pub readonly: Option<MappedTypeModifier>,
pub optional: Option<MappedTypeModifier>,
pub span: Span,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MappedTypeModifier {
Add,
Remove,
}
#[derive(Debug, Clone)]
pub struct IndexedAccessType {
pub object_type: Box<TypeAnnotation>,
pub index_type: Box<TypeAnnotation>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct TypeofType {
pub expression: Identifier,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct KeyofType {
pub type_annotation: Box<TypeAnnotation>,
pub span: Span,
}