summaryrefslogtreecommitdiff
path: root/cli/tsc.rs
diff options
context:
space:
mode:
authorAndreu Botella <andreu@andreubotella.com>2022-05-13 10:36:31 +0200
committerGitHub <noreply@github.com>2022-05-13 10:36:31 +0200
commit3e7afb8918fd0f6cedf839a7ebaae6aaee5e66ad (patch)
tree7fcc92da290889d3d2290f6e4902ac60685aae87 /cli/tsc.rs
parent0ee76da07b12fba38962634e65853d73adf9d4c0 (diff)
chore(runtime): Make some ops in ext and runtime infallible. (#14589)
Co-authored-by: Aaron O'Mullan <aaron.omullan@gmail.com>
Diffstat (limited to 'cli/tsc.rs')
-rw-r--r--cli/tsc.rs40
1 files changed, 20 insertions, 20 deletions
diff --git a/cli/tsc.rs b/cli/tsc.rs
index c39ed6c0d..aba289d8c 100644
--- a/cli/tsc.rs
+++ b/cli/tsc.rs
@@ -344,7 +344,7 @@ struct EmitArgs {
}
#[op]
-fn op_emit(state: &mut OpState, args: EmitArgs) -> Result<Value, AnyError> {
+fn op_emit(state: &mut OpState, args: EmitArgs) -> bool {
let state = state.borrow_mut::<State>();
match args.file_name.as_ref() {
"deno:///.tsbuildinfo" => state.maybe_tsbuildinfo = Some(args.data),
@@ -389,7 +389,7 @@ fn op_emit(state: &mut OpState, args: EmitArgs) -> Result<Value, AnyError> {
}
}
- Ok(json!(true))
+ true
}
#[derive(Debug, Deserialize)]
@@ -399,20 +399,20 @@ struct ExistsArgs {
}
#[op]
-fn op_exists(state: &mut OpState, args: ExistsArgs) -> Result<bool, AnyError> {
+fn op_exists(state: &mut OpState, args: ExistsArgs) -> bool {
let state = state.borrow_mut::<State>();
let graph_data = state.graph_data.read();
if let Ok(specifier) = normalize_specifier(&args.specifier) {
if specifier.scheme() == "asset" || specifier.scheme() == "data" {
- Ok(true)
+ true
} else {
- Ok(matches!(
+ matches!(
graph_data.get(&graph_data.follow_redirect(&specifier)),
Some(ModuleEntry::Module { .. })
- ))
+ )
}
} else {
- Ok(false)
+ false
}
}
@@ -510,7 +510,7 @@ pub struct ResolveArgs {
fn op_resolve(
state: &mut OpState,
args: ResolveArgs,
-) -> Result<Value, AnyError> {
+) -> Result<Vec<(String, String)>, AnyError> {
let state = state.borrow_mut::<State>();
let mut resolved: Vec<(String, String)> = Vec::new();
let referrer = if let Some(remapped_specifier) =
@@ -607,7 +607,7 @@ fn op_resolve(
}
}
- Ok(json!(resolved))
+ Ok(resolved)
}
#[derive(Debug, Deserialize, Eq, PartialEq)]
@@ -917,9 +917,8 @@ mod tests {
file_name: "cache:///some/file.js".to_string(),
maybe_specifiers: Some(vec!["file:///some/file.ts".to_string()]),
},
- )
- .expect("should have invoked op");
- assert_eq!(actual, json!(true));
+ );
+ assert!(actual);
let state = state.borrow::<State>();
assert_eq!(state.emitted_files.len(), 1);
assert!(state.maybe_tsbuildinfo.is_none());
@@ -948,9 +947,8 @@ mod tests {
vec!["file:///some/file.ts?q=.json".to_string()],
),
},
- )
- .expect("should have invoked op");
- assert_eq!(actual, json!(true));
+ );
+ assert!(actual);
let state = state.borrow::<State>();
assert_eq!(state.emitted_files.len(), 1);
assert!(state.maybe_tsbuildinfo.is_none());
@@ -977,9 +975,8 @@ mod tests {
file_name: "deno:///.tsbuildinfo".to_string(),
maybe_specifiers: None,
},
- )
- .expect("should have invoked op");
- assert_eq!(actual, json!(true));
+ );
+ assert!(actual);
let state = state.borrow::<State>();
assert_eq!(state.emitted_files.len(), 0);
assert_eq!(
@@ -1095,7 +1092,10 @@ mod tests {
},
)
.expect("should have invoked op");
- assert_eq!(actual, json!([["https://deno.land/x/b.ts", ".ts"]]));
+ assert_eq!(
+ actual,
+ vec![("https://deno.land/x/b.ts".into(), ".ts".into())]
+ );
}
#[tokio::test]
@@ -1116,7 +1116,7 @@ mod tests {
.expect("should have not errored");
assert_eq!(
actual,
- json!([["deno:///missing_dependency.d.ts", ".d.ts"]])
+ vec![("deno:///missing_dependency.d.ts".into(), ".d.ts".into())]
);
}