typedshell 0.1.0

A typed TypeScript subset compiled to standalone Bash or other shell targets
Documentation
use miette::{Diagnostic, NamedSource, SourceSpan};
use thiserror::Error;

#[derive(Debug, Error, Diagnostic)]
#[error("{message}")]
pub struct CompileError {
    pub message: String,
    #[source_code]
    pub source_code: NamedSource<String>,
    #[label("{message}")]
    pub span: SourceSpan,
}
impl CompileError {
    pub fn new(
        name: impl Into<String>,
        source: &str,
        start: usize,
        len: usize,
        message: impl Into<String>,
    ) -> Self {
        Self {
            message: message.into(),
            source_code: NamedSource::new(name.into(), source.to_owned()),
            span: (
                start.min(source.len()),
                len.min(source.len().saturating_sub(start)),
            )
                .into(),
        }
    }
    pub fn plain(message: impl Into<String>) -> Self {
        Self::new("tsh", "", 0, 0, message)
    }
}