use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct JavaScriptAst {
pub module: swc_ecma_ast::Module,
}
#[cfg(test)]
mod tests {
use super::JavaScriptAst;
use crate::JavaScriptParser;
#[test]
fn modules_roundtrip_through_serde() {
let ast = JavaScriptParser::parse("const answer = 42;").expect("expected valid source");
let json = serde_json::to_string(&ast).expect("expected serialization");
let decoded: JavaScriptAst = serde_json::from_str(&json).expect("expected deserialization");
assert_eq!(decoded.module.body.len(), 1);
assert_eq!(
serde_json::to_string(&decoded).expect("expected re-serialization"),
json
);
}
}