mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
refactor: strongly typed TSC ops (#20466)
Removes usage of `serde_json::Value` in several ops used in TSC, in favor of using strongly typed structs. This will unblock more changes in https://github.com/denoland/deno/pull/20462.
This commit is contained in:
parent
950e0e9cd6
commit
82c2864065
3 changed files with 83 additions and 57 deletions
|
@ -733,12 +733,9 @@ struct RespondArgs {
|
|||
}
|
||||
|
||||
#[op]
|
||||
fn op_respond(state: &mut OpState, args: Value) -> Result<Value, AnyError> {
|
||||
fn op_respond(state: &mut OpState, args: RespondArgs) {
|
||||
let state = state.borrow_mut::<State>();
|
||||
let v: RespondArgs = serde_json::from_value(args)
|
||||
.context("Error converting the result for \"op_respond\".")?;
|
||||
state.maybe_response = Some(v);
|
||||
Ok(json!(true))
|
||||
state.maybe_response = Some(args);
|
||||
}
|
||||
|
||||
/// Execute a request on the supplied snapshot, returning a response which
|
||||
|
@ -1160,21 +1157,18 @@ mod tests {
|
|||
#[tokio::test]
|
||||
async fn test_respond() {
|
||||
let mut state = setup(None, None, None).await;
|
||||
let actual = op_respond::call(
|
||||
&mut state,
|
||||
json!({
|
||||
"diagnostics": [
|
||||
{
|
||||
"messageText": "Unknown compiler option 'invalid'.",
|
||||
"category": 1,
|
||||
"code": 5023
|
||||
}
|
||||
],
|
||||
"stats": [["a", 12]]
|
||||
}),
|
||||
)
|
||||
.expect("should have invoked op");
|
||||
assert_eq!(actual, json!(true));
|
||||
let args = serde_json::from_value(json!({
|
||||
"diagnostics": [
|
||||
{
|
||||
"messageText": "Unknown compiler option 'invalid'.",
|
||||
"category": 1,
|
||||
"code": 5023
|
||||
}
|
||||
],
|
||||
"stats": [["a", 12]]
|
||||
}))
|
||||
.unwrap();
|
||||
op_respond::call(&mut state, args);
|
||||
let state = state.borrow::<State>();
|
||||
assert_eq!(
|
||||
state.maybe_response,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue