1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

Cleanup compiler API (#2466)

This commit is contained in:
Kitson Kelly 2019-06-07 10:37:26 +10:00 committed by Ryan Dahl
parent cbcb78f188
commit e3b2205eba
2 changed files with 12 additions and 31 deletions

View file

@ -84,21 +84,19 @@ pub fn get_compiler_config(
pub fn compile_async(
state: ThreadSafeState,
specifier: &str,
referrer: &str,
module_meta_data: &ModuleMetaData,
) -> impl Future<Item = ModuleMetaData, Error = Diagnostic> {
let module_name = module_meta_data.module_name.clone();
debug!(
"Running rust part of compile_sync. specifier: {}, referrer: {}",
&specifier, &referrer
"Running rust part of compile_sync. module_name: {}",
&module_name
);
let root_names = vec![module_meta_data.module_name.clone()];
let root_names = vec![module_name.clone()];
let compiler_config = get_compiler_config(&state, "typescript");
let req_msg = req(root_names, compiler_config);
let module_meta_data_ = module_meta_data.clone();
// Count how many times we start the compiler worker.
state.metrics.compiler_starts.fetch_add(1, Ordering::SeqCst);
@ -113,9 +111,7 @@ pub fn compile_async(
js_check(worker.execute("workerMain()"));
js_check(worker.execute("compilerMain()"));
let compiling_job = state
.progress
.add(format!("Compiling {}", module_meta_data_.module_name));
let compiling_job = state.progress.add(format!("Compiling {}", module_name));
let resource = worker.state.resource.clone();
let compiler_rid = resource.rid;
@ -146,12 +142,9 @@ pub fn compile_async(
}
}
let r = state.dir.fetch_module_meta_data(
&module_meta_data_.module_name,
".",
true,
true,
);
let r = state
.dir
.fetch_module_meta_data(&module_name, ".", true, true);
let module_meta_data_after_compile = r.unwrap();
// Explicit drop to keep reference alive until future completes.
@ -167,16 +160,9 @@ pub fn compile_async(
pub fn compile_sync(
state: ThreadSafeState,
specifier: &str,
referrer: &str,
module_meta_data: &ModuleMetaData,
) -> Result<ModuleMetaData, Diagnostic> {
tokio_util::block_on(compile_async(
state,
specifier,
referrer,
module_meta_data,
))
tokio_util::block_on(compile_async(state, module_meta_data))
}
#[cfg(test)]
@ -186,11 +172,7 @@ mod tests {
#[test]
fn test_compile_sync() {
tokio_util::init(|| {
let cwd = std::env::current_dir().unwrap();
let cwd_string = cwd.to_str().unwrap().to_owned();
let specifier = "./tests/002_hello.ts";
let referrer = cwd_string + "/";
use crate::worker;
let module_name = worker::root_specifier_to_url(specifier)
.unwrap()
@ -208,8 +190,7 @@ mod tests {
maybe_source_map: None,
};
out = compile_sync(ThreadSafeState::mock(), specifier, &referrer, &out)
.unwrap();
out = compile_sync(ThreadSafeState::mock(), &out).unwrap();
assert!(
out
.maybe_output_code

View file

@ -127,7 +127,7 @@ fn fetch_module_meta_data_and_maybe_compile_async(
{
debug!(">>>>> compile_sync START");
Either::A(
compile_async(state_.clone(), &specifier, &referrer, &out)
compile_async(state_.clone(), &out)
.map_err(|e| {
debug!("compiler error exiting!");
eprintln!("\n{}", e.to_string());