Skip to content

Commit

Permalink
refactor: Improvements to TsCompiler and its tests (denoland#6576)
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Jun 30, 2020
1 parent 6844c3a commit 062d1a4
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 148 deletions.
26 changes: 16 additions & 10 deletions cli/global_state.rs
Expand Up @@ -70,9 +70,8 @@ impl GlobalState {

let ts_compiler = TsCompiler::new(
file_fetcher.clone(),
flags.clone(),
dir.gen_cache.clone(),
!flags.reload,
flags.config_path.clone(),
)?;

// Note: reads lazily from disk on first call to lockfile.check()
Expand Down Expand Up @@ -155,7 +154,7 @@ impl GlobalState {
if should_compile {
self
.ts_compiler
.compile_module_graph(
.compile(
self.clone(),
&out,
target_lib,
Expand Down Expand Up @@ -245,12 +244,19 @@ impl GlobalState {
}

#[cfg(test)]
pub fn mock(argv: Vec<String>) -> GlobalState {
GlobalState::new(flags::Flags {
argv,
..flags::Flags::default()
})
.unwrap()
pub fn mock(
argv: Vec<String>,
maybe_flags: Option<flags::Flags>,
) -> GlobalState {
if let Some(in_flags) = maybe_flags {
GlobalState::new(flags::Flags { argv, ..in_flags }).unwrap()
} else {
GlobalState::new(flags::Flags {
argv,
..flags::Flags::default()
})
.unwrap()
}
}
}

Expand Down Expand Up @@ -312,7 +318,7 @@ fn needs_compilation(
#[test]
fn thread_safe() {
fn f<S: Send + Sync>(_: S) {}
f(GlobalState::mock(vec![]));
f(GlobalState::mock(vec![], None));
}

#[test]
Expand Down
14 changes: 4 additions & 10 deletions cli/main.rs
Expand Up @@ -425,8 +425,6 @@ async fn bundle_command(
}

debug!(">>>>> bundle START");
let compiler_config = tsc::CompilerConfig::load(flags.config_path.clone())?;

let global_state = GlobalState::new(flags)?;

info!(
Expand All @@ -435,14 +433,10 @@ async fn bundle_command(
module_specifier.to_string()
);

let output = tsc::bundle(
&global_state,
compiler_config,
module_specifier,
global_state.maybe_import_map.clone(),
global_state.flags.unstable,
)
.await?;
let output = global_state
.ts_compiler
.bundle(global_state.clone(), module_specifier)
.await?;

debug!(">>>>> bundle END");

Expand Down
2 changes: 1 addition & 1 deletion cli/state.rs
Expand Up @@ -499,7 +499,7 @@ impl State {
let module_specifier = ModuleSpecifier::resolve_url_or_path(main_module)
.expect("Invalid entry module");
State::new(
GlobalState::mock(vec!["deno".to_string()]),
GlobalState::mock(vec!["deno".to_string()], None),
None,
module_specifier,
None,
Expand Down

0 comments on commit 062d1a4

Please sign in to comment.