1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use is_macro::Is;
use serde::{Deserialize, Serialize};
use stc_visit::Visit;
use swc_common::{EqIgnoreSpan, Span, Spanned, TypeEq};

use crate::{StringMappingMetadata, TypeParamInstantiation};

#[derive(Debug, Clone, PartialEq, Spanned, EqIgnoreSpan, TypeEq, Visit, Serialize, Deserialize)]
pub struct StringMapping {
    pub span: Span,
    pub kind: IntrinsicKind,
    pub type_args: TypeParamInstantiation,
    pub metadata: StringMappingMetadata,
}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Is, EqIgnoreSpan, TypeEq, Visit, Serialize, Deserialize)]
pub enum IntrinsicKind {
    Uppercase,
    Lowercase,
    Capitalize,
    Uncapitalize,
}

impl From<&'_ str> for IntrinsicKind {
    fn from(s: &str) -> Self {
        match s {
            "Uppercase" => Self::Uppercase,
            "Lowercase" => Self::Lowercase,
            "Capitalize" => Self::Capitalize,
            "Uncapitalize" => Self::Uncapitalize,
            _ => {
                unreachable!("unknown intrinsic type `{}`", s)
            }
        }
    }
}