From 82c28640658df400e5bed2e208912247b1e83d0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 12 Sep 2023 02:55:57 +0200 Subject: 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. --- cli/tsc/mod.rs | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'cli/tsc') diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs index 22f9d3290..af4c67c0d 100644 --- a/cli/tsc/mod.rs +++ b/cli/tsc/mod.rs @@ -733,12 +733,9 @@ struct RespondArgs { } #[op] -fn op_respond(state: &mut OpState, args: Value) -> Result { +fn op_respond(state: &mut OpState, args: RespondArgs) { let state = state.borrow_mut::(); - 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::(); assert_eq!( state.maybe_response, -- cgit v1.2.3