mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 20:32:10 +00:00
refactor(coverage): avoid an String::from_utf8 over head during serialization (#3145)
This commit is contained in:
parent
67225a8091
commit
f5dccc96fd
2 changed files with 11 additions and 5 deletions
|
|
@ -28,11 +28,17 @@ impl serde_json::ser::Formatter for EcmaFormatter {
|
|||
impl<'a> Program<'a> {
|
||||
/// # Panics
|
||||
pub fn to_json(&self) -> String {
|
||||
let buf = std::vec::Vec::new();
|
||||
let mut ser = serde_json::Serializer::with_formatter(buf, crate::serialize::EcmaFormatter);
|
||||
self.serialize(&mut ser).unwrap();
|
||||
let ser = self.serializer();
|
||||
String::from_utf8(ser.into_inner()).unwrap()
|
||||
}
|
||||
|
||||
/// # Panics
|
||||
pub fn serializer(&self) -> serde_json::Serializer<std::vec::Vec<u8>, EcmaFormatter> {
|
||||
let buf = std::vec::Vec::new();
|
||||
let mut ser = serde_json::Serializer::with_formatter(buf, EcmaFormatter);
|
||||
self.serialize(&mut ser).unwrap();
|
||||
ser
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for RegExpFlags {
|
||||
|
|
|
|||
|
|
@ -322,8 +322,8 @@ pub trait Case: Sized + Sync + Send + UnwindSafe {
|
|||
return res;
|
||||
}
|
||||
|
||||
// Make sure serialization doesn't crash for ast and hir, also for code coverage.
|
||||
let _json = parser_ret.program.to_json();
|
||||
// Make sure serialization doesn't crash; also for code coverage.
|
||||
let _serializer = parser_ret.program.serializer();
|
||||
|
||||
let program = allocator.alloc(parser_ret.program);
|
||||
let semantic_ret = SemanticBuilder::new(source_text, source_type)
|
||||
|
|
|
|||
Loading…
Reference in a new issue