parse union and fancy array types

Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
Nick Cameron
2025-03-13 14:56:30 +13:00
parent ce98218bf0
commit d7369d8a95
10 changed files with 212 additions and 74 deletions

View File

@ -939,9 +939,14 @@ impl RuntimeType {
Type::Primitive(pt) => {
PrimitiveType::from_parsed(pt, exec_state, source_range)?.map(RuntimeType::Primitive)
}
Type::Array(pt) => {
PrimitiveType::from_parsed(pt, exec_state, source_range)?.map(|t| RuntimeType::Array(t, ArrayLen::None))
Type::Array { ty, len } => {
PrimitiveType::from_parsed(ty, exec_state, source_range)?.map(|t| RuntimeType::Array(t, len))
}
Type::Union { tys } => tys
.into_iter()
.map(|t| PrimitiveType::from_parsed(t.inner, exec_state, source_range))
.collect::<Result<Option<Vec<_>>, CompilationError>>()?
.map(RuntimeType::Union),
Type::Object { properties } => properties
.into_iter()
.map(|p| {
@ -1034,7 +1039,7 @@ impl fmt::Display for RuntimeType {
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, ts_rs::TS, JsonSchema)]
pub enum ArrayLen {
None,
NonEmpty,