diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-06-10 16:02:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-10 16:02:41 +0200 |
commit | 4b7d3b060e88c02bc0ca12664f52111a4666b167 (patch) | |
tree | 018968e67c8d34c5cffe73578643eb071fa103b0 /cli/tsc.rs | |
parent | f364a4c2b6dcce65959af2da3663f0b4a7338229 (diff) |
fix: several regressions in TS compiler (#6177)
This commit fixes several regressions in TS compiler:
* double compilation of same module during same process run
* compilation of JavaScript entry point with non-JS imports
* unexpected skip of emit during compilation
Additional checks were added to ensure "allowJs" setting is
used in TS compiler if JavaScript has non-JS dependencies.
Diffstat (limited to 'cli/tsc.rs')
-rw-r--r-- | cli/tsc.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/cli/tsc.rs b/cli/tsc.rs index 1b3208e75..8d0f0d5de 100644 --- a/cli/tsc.rs +++ b/cli/tsc.rs @@ -405,7 +405,6 @@ impl TsCompiler { }))) } - // TODO(bartlomieju): this method is no longer needed /// Mark given module URL as compiled to avoid multiple compilations of same /// module in single run. fn mark_compiled(&self, url: &Url) { @@ -413,6 +412,11 @@ impl TsCompiler { c.insert(url.clone()); } + fn has_compiled(&self, url: &Url) -> bool { + let c = self.compiled.lock().unwrap(); + c.contains(url) + } + /// Check if there is compiled source in cache that is valid /// and can be used again. // TODO(bartlomieju): there should be check that cached file actually exists @@ -459,10 +463,14 @@ impl TsCompiler { target: TargetLib, permissions: Permissions, module_graph: HashMap<String, ModuleGraphFile>, + allow_js: bool, ) -> Result<(), ErrBox> { let mut has_cached_version = false; - if self.use_disk_cache { + // Only use disk cache if `--reload` flag was not used or + // this file has already been compiled during current process + // lifetime. + if self.use_disk_cache || self.has_compiled(&source_file.url) { if let Some(metadata) = self.get_graph_metadata(&source_file.url) { has_cached_version = true; @@ -503,6 +511,7 @@ impl TsCompiler { let j = match (compiler_config.path, compiler_config.content) { (Some(config_path), Some(config_data)) => json!({ "type": msg::CompilerRequestType::Compile as i32, + "allowJs": allow_js, "target": target, "rootNames": root_names, "bundle": bundle, @@ -514,6 +523,7 @@ impl TsCompiler { }), _ => json!({ "type": msg::CompilerRequestType::Compile as i32, + "allowJs": allow_js, "target": target, "rootNames": root_names, "bundle": bundle, @@ -1151,6 +1161,7 @@ mod tests { TargetLib::Main, Permissions::allow_all(), module_graph, + false, ) .await; assert!(result.is_ok()); |