diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-06-19 12:27:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-19 12:27:15 +0200 |
commit | 826a3135b41bdaeb8c8cd27a4652563971b04baa (patch) | |
tree | e8baaca1b5560e5825e19f5b0c6872d781d767a3 /cli/global_state.rs | |
parent | 345a5b3dff3a333d156bf4aff9f7e2a355d59746 (diff) |
refactor(compiler): split code paths for compile and bundle (#6304)
* refactor "compile" and "runtimeCompile" in "compiler.ts" and factor out
separate methods for "compile" and "bundle" operations
* remove noisy debug output from "compiler.ts"
* provide "Serialize" implementations for enums in "msg.rs"
* rename "analyze_dependencies_and_references" to "pre_process_file" and
move it to "tsc.rs"
* refactor ModuleGraph to use more concrete types and properly annotate
locations where errors occur
* remove dead code from "file_fetcher.rs" - "SourceFile.types_url" is no
longer needed, as type reference parsing is done in "ModuleGraph"
* remove unneeded field "source_path" from ".meta" files stored for
compiled source file (towards #6080)
Diffstat (limited to 'cli/global_state.rs')
-rw-r--r-- | cli/global_state.rs | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/cli/global_state.rs b/cli/global_state.rs index 959d794ca..3c7f23435 100644 --- a/cli/global_state.rs +++ b/cli/global_state.rs @@ -260,9 +260,9 @@ impl GlobalState { /// - JSX import fn should_allow_js(module_graph_files: &[&ModuleGraphFile]) -> bool { module_graph_files.iter().any(|module_file| { - if module_file.media_type == (MediaType::JSX as i32) { + if module_file.media_type == MediaType::JSX { true - } else if module_file.media_type == (MediaType::JavaScript as i32) { + } else if module_file.media_type == MediaType::JavaScript { module_file.imports.iter().any(|import_desc| { let import_file = module_graph_files .iter() @@ -271,9 +271,9 @@ fn should_allow_js(module_graph_files: &[&ModuleGraphFile]) -> bool { }) .expect("Failed to find imported file"); let media_type = import_file.media_type; - media_type == (MediaType::TypeScript as i32) - || media_type == (MediaType::TSX as i32) - || media_type == (MediaType::JSX as i32) + media_type == MediaType::TypeScript + || media_type == MediaType::TSX + || media_type == MediaType::JSX }) } else { false @@ -301,9 +301,9 @@ fn needs_compilation( needs_compilation |= module_graph_files.iter().any(|module_file| { let media_type = module_file.media_type; - media_type == (MediaType::TypeScript as i32) - || media_type == (MediaType::TSX as i32) - || media_type == (MediaType::JSX as i32) + media_type == (MediaType::TypeScript) + || media_type == (MediaType::TSX) + || media_type == (MediaType::JSX) }); needs_compilation @@ -317,6 +317,7 @@ fn thread_safe() { #[test] fn test_should_allow_js() { + use crate::doc::Location; use crate::module_graph::ImportDescriptor; assert!(should_allow_js(&[ @@ -330,7 +331,7 @@ fn test_should_allow_js() { lib_directives: vec![], types_directives: vec![], type_headers: vec![], - media_type: MediaType::TypeScript as i32, + media_type: MediaType::TypeScript, source_code: "function foo() {}".to_string(), }, &ModuleGraphFile { @@ -346,12 +347,17 @@ fn test_should_allow_js() { .unwrap(), type_directive: None, resolved_type_directive: None, + location: Location { + filename: "file:///some/file1.js".to_string(), + line: 0, + col: 0, + }, }], referenced_files: vec![], lib_directives: vec![], types_directives: vec![], type_headers: vec![], - media_type: MediaType::JavaScript as i32, + media_type: MediaType::JavaScript, source_code: "function foo() {}".to_string(), }, ],)); @@ -367,7 +373,7 @@ fn test_should_allow_js() { lib_directives: vec![], types_directives: vec![], type_headers: vec![], - media_type: MediaType::JSX as i32, + media_type: MediaType::JSX, source_code: "function foo() {}".to_string(), }, &ModuleGraphFile { @@ -383,12 +389,17 @@ fn test_should_allow_js() { .unwrap(), type_directive: None, resolved_type_directive: None, + location: Location { + filename: "file:///some/file1.ts".to_string(), + line: 0, + col: 0, + }, }], referenced_files: vec![], lib_directives: vec![], types_directives: vec![], type_headers: vec![], - media_type: MediaType::TypeScript as i32, + media_type: MediaType::TypeScript, source_code: "function foo() {}".to_string(), }, ])); @@ -404,7 +415,7 @@ fn test_should_allow_js() { lib_directives: vec![], types_directives: vec![], type_headers: vec![], - media_type: MediaType::JavaScript as i32, + media_type: MediaType::JavaScript, source_code: "function foo() {}".to_string(), }, &ModuleGraphFile { @@ -420,12 +431,17 @@ fn test_should_allow_js() { .unwrap(), type_directive: None, resolved_type_directive: None, + location: Location { + filename: "file:///some/file.js".to_string(), + line: 0, + col: 0, + }, }], referenced_files: vec![], lib_directives: vec![], types_directives: vec![], type_headers: vec![], - media_type: MediaType::JavaScript as i32, + media_type: MediaType::JavaScript, source_code: "function foo() {}".to_string(), }, ],)); @@ -446,7 +462,7 @@ fn test_needs_compilation() { lib_directives: vec![], types_directives: vec![], type_headers: vec![], - media_type: MediaType::JavaScript as i32, + media_type: MediaType::JavaScript, source_code: "function foo() {}".to_string(), }], )); @@ -470,7 +486,7 @@ fn test_needs_compilation() { lib_directives: vec![], types_directives: vec![], type_headers: vec![], - media_type: MediaType::TypeScript as i32, + media_type: MediaType::TypeScript, source_code: "function foo() {}".to_string(), }, &ModuleGraphFile { @@ -483,7 +499,7 @@ fn test_needs_compilation() { lib_directives: vec![], types_directives: vec![], type_headers: vec![], - media_type: MediaType::JavaScript as i32, + media_type: MediaType::JavaScript, source_code: "function foo() {}".to_string(), }, ], |