use std::collections::BTreeMap;
use std::path::PathBuf;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedFile {
pub path: PathBuf,
pub classes: Vec<ParsedClass>,
pub type_aliases: Vec<ParsedTypeAlias>,
pub local_type_bindings: Vec<String>,
pub local_value_bindings: Vec<String>,
pub imports: Vec<ParsedImport>,
pub exports: Vec<ParsedExport>,
pub diagnostics: Vec<ParseDiagnostic>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedTypeAlias {
pub name: String,
pub type_text: String,
pub span: SourceSpan,
pub type_span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedImport {
pub source: String,
pub specifiers: Vec<ParsedImportSpecifier>,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedImportSpecifier {
pub imported: String,
pub local: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedExport {
pub kind: ParsedExportKind,
pub source: Option<String>,
pub specifiers: Vec<ParsedExportSpecifier>,
pub span: SourceSpan,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ParsedExportKind {
Named,
Default,
All,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedExportSpecifier {
pub local: Option<String>,
pub exported: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedClass {
pub name: String,
pub span: SourceSpan,
pub heritage: Option<ParsedClassHeritage>,
pub decorators: Vec<ParsedDecorator>,
pub properties: Vec<ParsedProperty>,
pub methods: Vec<ParsedMethod>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedClassHeritage {
pub base: String,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedDecorator {
pub name: String,
pub is_invoked: bool,
pub arguments: Vec<Option<String>>,
pub argument: Option<String>,
pub argument_count: usize,
pub argument_spans: Vec<SourceSpan>,
pub static_member_argument: Option<ParsedStaticMemberDesignator>,
pub this_member_argument: Option<ParsedThisMemberDesignator>,
pub validation_rule_expression: Option<ParsedValidationRuleExpression>,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedValidationRuleExpression {
pub kind: ParsedValidationRuleExpressionKind,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ParsedValidationRuleExpressionKind {
Call {
callee: Option<String>,
arguments: Vec<ParsedValidationRuleArgument>,
},
Identifier(String),
Unsupported,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedValidationRuleArgument {
pub kind: ParsedValidationRuleArgumentKind,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ParsedValidationRuleArgumentKind {
StringLiteral(String),
Constant(ParsedConstantExpression),
ThisMember(ParsedThisMemberDesignator),
Unsupported,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedThisMemberDesignator {
pub member: String,
pub span: SourceSpan,
pub this_span: SourceSpan,
pub member_span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedStaticMemberDesignator {
pub object: String,
pub member: String,
pub span: SourceSpan,
pub object_span: SourceSpan,
pub member_span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedProperty {
pub name: String,
pub is_identifier_name: bool,
pub decorators: Vec<ParsedDecorator>,
pub initializer: Option<String>,
pub initializer_literal: Option<ParsedSerializableValue>,
pub initializer_expression: Option<ParsedComputedExpression>,
pub initializer_constant_expression: Option<ParsedConstantExpression>,
pub initializer_span: Option<SourceSpan>,
pub state_initial_value: Option<ParsedSerializableValue>,
pub state_initial_expression: Option<ParsedConstantExpression>,
pub state_type_annotation: Option<ParsedTypeAnnotation>,
pub type_annotation: Option<ParsedTypeAnnotation>,
pub name_span: SourceSpan,
pub is_static: bool,
pub is_definite_assignment: bool,
pub is_declare: bool,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedTypeAnnotation {
pub text: String,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ParsedSerializableValue {
Null,
Number(String),
String(String),
Boolean(bool),
Array(Vec<ParsedSerializableValue>),
Object(BTreeMap<String, ParsedSerializableValue>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedArithmeticExpression {
pub kind: ParsedArithmeticExpressionKind,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ParsedArithmeticExpressionKind {
Number(String),
Binary {
operator: ParsedArithmeticOperator,
left: Box<ParsedArithmeticExpression>,
right: Box<ParsedArithmeticExpression>,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ParsedArithmeticOperator {
Add,
Subtract,
Multiply,
Divide,
Remainder,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedConstantExpression {
pub kind: ParsedConstantExpressionKind,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ParsedConstantExpressionKind {
Primitive(ParsedSerializableValue),
Boolean(bool),
Arithmetic(ParsedArithmeticExpression),
Comparison {
operator: ParsedComparisonOperator,
left: ParsedArithmeticExpression,
right: ParsedArithmeticExpression,
},
Logical {
operator: ParsedLogicalOperator,
left: Box<ParsedConstantExpression>,
right: Box<ParsedConstantExpression>,
},
NullishCoalescing {
left: Box<ParsedConstantExpression>,
right: Box<ParsedConstantExpression>,
},
Unary {
operator: ParsedUnaryOperator,
operand: Box<ParsedConstantExpression>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedComputedExpression {
pub kind: ParsedComputedExpressionKind,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ParsedComputedExpressionKind {
Literal(ParsedSerializableValue),
ThisMember(String),
MemberAccess {
object: Box<ParsedComputedExpression>,
property: String,
optional: bool,
},
IndexAccess {
object: Box<ParsedComputedExpression>,
index: Box<ParsedComputedExpression>,
},
Conditional {
condition: Box<ParsedComputedExpression>,
when_true: Box<ParsedComputedExpression>,
when_false: Box<ParsedComputedExpression>,
},
Template {
quasis: Vec<String>,
expressions: Vec<ParsedComputedExpression>,
},
Call {
callee: String,
arguments: Vec<ParsedComputedExpression>,
},
Arithmetic {
left: Box<ParsedComputedExpression>,
right: Box<ParsedComputedExpression>,
operator: ParsedArithmeticOperator,
},
Comparison {
left: Box<ParsedComputedExpression>,
right: Box<ParsedComputedExpression>,
operator: ParsedComparisonOperator,
},
Logical {
left: Box<ParsedComputedExpression>,
right: Box<ParsedComputedExpression>,
operator: ParsedLogicalOperator,
},
NullishCoalescing {
left: Box<ParsedComputedExpression>,
right: Box<ParsedComputedExpression>,
},
Unary {
operand: Box<ParsedComputedExpression>,
operator: ParsedUnaryOperator,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ParsedComparisonOperator {
Equal,
NotEqual,
LessThan,
LessThanOrEqual,
GreaterThan,
GreaterThanOrEqual,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ParsedLogicalOperator {
And,
Or,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ParsedUnaryOperator {
Not,
Plus,
Minus,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedMethod {
pub name: String,
pub span: SourceSpan,
pub decorators: Vec<ParsedDecorator>,
pub is_getter: bool,
pub is_setter: bool,
pub is_async: bool,
pub is_static: bool,
pub jsx_roots: Vec<ParsedJsxNode>,
pub bindings: Vec<String>,
pub state_updates: Vec<ParsedStateUpdate>,
pub local_variables: Vec<ParsedLocalVariable>,
pub parameters: Vec<ParsedMethodParameter>,
pub return_type_annotation: Option<ParsedTypeAnnotation>,
pub return_values: Vec<ParsedSerializableValue>,
pub computed_expression: Option<ParsedComputedExpression>,
pub effect_body: Option<ParsedEffectBody>,
pub calls: Vec<ParsedMethodCall>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedEffectBody {
pub statements: Vec<ParsedEffectStatement>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedEffectStatement {
pub kind: ParsedEffectStatementKind,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ParsedEffectStatementKind {
StaticMemberAssignment {
target: ParsedEffectExpression,
value: ParsedEffectExpression,
},
CapabilityCall {
callee: ParsedEffectExpression,
arguments: Vec<ParsedEffectExpression>,
},
EffectReturn {
value: Option<ParsedEffectExpression>,
},
Empty,
Unsupported(ParsedUnsupportedEffectStatementKind),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ParsedUnsupportedEffectStatementKind {
LocalDeclaration,
Branch,
Loop,
NestedBlock,
ExceptionHandling,
AsyncOperation,
CompoundAssignment,
CleanupReturnCandidate,
UnsupportedExpression,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedEffectExpression {
pub kind: ParsedEffectExpressionKind,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ParsedEffectExpressionKind {
Literal(ParsedSerializableValue),
Identifier(String),
ThisMember(String),
MemberAccess {
object: Box<ParsedEffectExpression>,
property: String,
},
Arithmetic {
left: Box<ParsedEffectExpression>,
right: Box<ParsedEffectExpression>,
operator: ParsedArithmeticOperator,
},
Comparison {
left: Box<ParsedEffectExpression>,
right: Box<ParsedEffectExpression>,
operator: ParsedComparisonOperator,
},
Logical {
left: Box<ParsedEffectExpression>,
right: Box<ParsedEffectExpression>,
operator: ParsedLogicalOperator,
},
NullishCoalescing {
left: Box<ParsedEffectExpression>,
right: Box<ParsedEffectExpression>,
},
Unary {
operand: Box<ParsedEffectExpression>,
operator: ParsedUnaryOperator,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedMethodCall {
pub callee: String,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedMethodParameter {
pub name: String,
pub decorators: Vec<ParsedDecorator>,
pub span: SourceSpan,
pub type_annotation: Option<ParsedTypeAnnotation>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedLocalVariable {
pub name: String,
pub value: ParsedSerializableValue,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedStateUpdate {
pub field: String,
pub operation: ParsedStateOperation,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ParsedStateOperation {
Increment,
Decrement,
AddAssign(ParsedSerializableValue),
SubtractAssign(ParsedSerializableValue),
Assign(ParsedSerializableValue),
AssignParameter(String),
Toggle,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ParsedJsxChild {
Text {
value: String,
span: SourceSpan,
},
Binding {
expression: String,
span: SourceSpan,
},
Element(ParsedJsxElement),
Fragment(ParsedJsxFragment),
Conditional(ParsedJsxConditional),
List(ParsedJsxList),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ParsedJsxNode {
Element(ParsedJsxElement),
Fragment(ParsedJsxFragment),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedJsxElement {
pub name: String,
pub name_span: SourceSpan,
pub span: SourceSpan,
pub attributes: Vec<ParsedJsxAttribute>,
pub event_handlers: Vec<ParsedEventHandler>,
pub children: Vec<ParsedJsxChild>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedJsxFragment {
pub span: SourceSpan,
pub children: Vec<ParsedJsxChild>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedJsxConditional {
pub condition: String,
pub span: SourceSpan,
pub when_true: ParsedJsxNode,
pub when_false: Option<ParsedJsxNode>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedJsxList {
pub iterable: String,
pub item_variable: String,
pub index_variable: Option<String>,
pub key_expression: String,
pub span: SourceSpan,
pub item_template: ParsedJsxNode,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedJsxAttribute {
pub name: String,
pub value: ParsedJsxAttributeValue,
pub name_span: SourceSpan,
pub value_span: Option<SourceSpan>,
pub expression_span: Option<SourceSpan>,
pub this_member: Option<ParsedThisMemberDesignator>,
pub constant_value: Option<ParsedSerializableValue>,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ParsedJsxAttributeValue {
Boolean,
Static(String),
Expression(Option<String>),
Spread(Option<String>),
Unsupported,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedEventHandler {
pub event: String,
pub handler: String,
pub arguments: Vec<ParsedSerializableValue>,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParseDiagnostic {
pub message: String,
pub severity: ParseSeverity,
pub labels: Vec<ParseLabel>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ParseSeverity {
Info,
Warning,
Error,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParseLabel {
pub span: SourceSpan,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SourceSpan {
pub start: usize,
pub end: usize,
pub line: usize,
pub column: usize,
}