2021-04-21 12:11:50 +03:00
|
|
|
use serde_json::from_str;
|
|
|
|
use swc_common::ast_serde;
|
|
|
|
|
|
|
|
#[ast_serde]
|
2022-06-14 18:58:10 +03:00
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
2021-04-21 12:11:50 +03:00
|
|
|
pub enum Ambiguous {
|
|
|
|
#[tag("A")]
|
|
|
|
A(A),
|
|
|
|
#[tag("B")]
|
|
|
|
B(B),
|
|
|
|
}
|
|
|
|
#[ast_serde("B")]
|
2022-06-14 18:58:10 +03:00
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
2021-04-21 12:11:50 +03:00
|
|
|
pub struct A {}
|
|
|
|
|
|
|
|
#[ast_serde("B")]
|
2022-06-14 18:58:10 +03:00
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
2021-04-21 12:11:50 +03:00
|
|
|
pub struct B {}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn deserialize() {
|
|
|
|
assert_eq!(A {}, from_str(r#"{"type": "A"}"#).unwrap());
|
|
|
|
assert_eq!(B {}, from_str(r#"{"type": "B"}"#).unwrap());
|
|
|
|
}
|