Skip to content

Commit bfde01a

Browse files
committed
fix arbitrary
1 parent 183f2e5 commit bfde01a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/swc_common/src/unknown.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,24 @@ impl<'de> serde::Deserialize<'de> for Unknown {
116116
}
117117
}
118118

119+
#[cfg(feature = "arbitrary")]
120+
impl<'a> arbitrary::Arbitrary<'a> for Unknown {
121+
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
122+
use cbor4ii::core::{ Value, BoxedRawValue };
123+
124+
let len = u.arbitrary_len::<u64>()?;
125+
let mut list = Vec::new();
126+
for _ in 0..len() {
127+
let n = u.int_in_range::<u64>(0..=102410241024)?;
128+
list.push(Value::Integer(n.into()));
129+
}
130+
let value = Value::Array(list);
131+
let value = BoxedRawValue::from_value(&value)
132+
.map_err(|_| arbitrary::Error::IncorrectFormat)?;
133+
Ok(Unknown(value))
134+
}
135+
}
136+
119137
#[track_caller]
120138
pub fn unknown() -> ! {
121139
panic!("unknown node")

0 commit comments

Comments
 (0)