summaryrefslogtreecommitdiff
path: root/cli/global_state.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/global_state.rs')
-rw-r--r--cli/global_state.rs50
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(),
},
],