summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-05-23 19:04:29 +0200
committerGitHub <noreply@github.com>2020-05-23 19:04:29 +0200
commitc3c16f025ca6f30f3faaa70481a125494ddcea87 (patch)
tree1c2f4ba66838f1177ce01546426c5fea7e73869c
parent94f1de5f805638b7bc06ac36b7fb8adb568c7a25 (diff)
fix: TSX analysis in module graph loader (#5785)
-rw-r--r--cli/module_graph.rs11
-rw-r--r--cli/swc_util.rs1
-rw-r--r--cli/tests/Component.tsx1
-rw-r--r--cli/tests/integration_tests.rs5
-rw-r--r--cli/tests/tsx_imports.ts1
-rw-r--r--cli/tests/tsx_imports.ts.out2
6 files changed, 18 insertions, 3 deletions
diff --git a/cli/module_graph.rs b/cli/module_graph.rs
index 8e423265c..3a59a537d 100644
--- a/cli/module_graph.rs
+++ b/cli/module_graph.rs
@@ -48,6 +48,13 @@ where
}
}
+const SUPPORTED_MEDIA_TYPES: [MediaType; 4] = [
+ MediaType::JavaScript,
+ MediaType::TypeScript,
+ MediaType::JSX,
+ MediaType::TSX,
+];
+
#[derive(Debug, Serialize)]
pub struct ModuleGraph(HashMap<String, ModuleGraphFile>);
@@ -384,9 +391,7 @@ impl ModuleGraphLoader {
let module_specifier = ModuleSpecifier::from(source_file.url.clone());
let source_code = String::from_utf8(source_file.source_code)?;
- if source_file.media_type == MediaType::JavaScript
- || source_file.media_type == MediaType::TypeScript
- {
+ if SUPPORTED_MEDIA_TYPES.contains(&source_file.media_type) {
if let Some(types_specifier) = source_file.types_header {
let type_header = ReferenceDescriptor {
specifier: types_specifier.to_string(),
diff --git a/cli/swc_util.rs b/cli/swc_util.rs
index d3b2a9e4a..465fb9769 100644
--- a/cli/swc_util.rs
+++ b/cli/swc_util.rs
@@ -147,6 +147,7 @@ impl AstParser {
let mut ts_config = TsConfig::default();
ts_config.dynamic_import = true;
ts_config.decorators = true;
+ ts_config.tsx = true;
let syntax = Syntax::Typescript(ts_config);
let lexer = Lexer::new(
diff --git a/cli/tests/Component.tsx b/cli/tests/Component.tsx
new file mode 100644
index 000000000..34208329b
--- /dev/null
+++ b/cli/tests/Component.tsx
@@ -0,0 +1 @@
+import "./046_jsx_test.tsx"; \ No newline at end of file
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index 457a345dd..b3f792b4e 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -1723,6 +1723,11 @@ itest!(disallow_http_from_https_ts {
exit_code: 1,
});
+itest!(tsx_imports {
+ args: "run --reload tsx_imports.ts",
+ output: "tsx_imports.ts.out",
+});
+
itest!(fix_js_import_js {
args: "run --quiet --reload fix_js_import_js.ts",
output: "fix_js_import_js.ts.out",
diff --git a/cli/tests/tsx_imports.ts b/cli/tests/tsx_imports.ts
new file mode 100644
index 000000000..44ba10b7a
--- /dev/null
+++ b/cli/tests/tsx_imports.ts
@@ -0,0 +1 @@
+import "./Component.tsx";
diff --git a/cli/tests/tsx_imports.ts.out b/cli/tests/tsx_imports.ts.out
new file mode 100644
index 000000000..4ea4308b1
--- /dev/null
+++ b/cli/tests/tsx_imports.ts.out
@@ -0,0 +1,2 @@
+Compile [WILDCARD]tsx_imports.ts
+{ factory: [Function: View], props: null, children: [] }