px-wsdom-ts-parse 0.0.6

for the wsdom crate, and potentially other uses
Documentation
use winnow::{
    combinator::{delimited, opt, preceded, separated_pair},
    Parser,
};

use super::{
    generic::GenericsDeclaration,
    ts_type::TsType,
    util::{token, token_word, word1, Parsable},
};

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TypeAlias<'a> {
    pub name: &'a str,
    pub generics: GenericsDeclaration<'a>,
    pub ty: TsType<'a>,
}

impl<'a> Parsable<'a> for TypeAlias<'a> {
    fn parse(input: &mut &'a str) -> winnow::PResult<Self> {
        delimited(
            preceded(opt(token_word("declare")), token_word("type")),
            separated_pair(
                (word1, opt(GenericsDeclaration::parse)),
                token('='),
                TsType::parse,
            ),
            token(';'),
        )
        .map(|((name, generics), ty)| Self {
            name,
            generics: generics.unwrap_or_default(),
            ty,
        })
        .parse_next(input)
    }
}