diff --git a/cli/module_graph.rs b/cli/module_graph.rs index 8e423265cb..3a59a537d7 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); @@ -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 d3b2a9e4af..465fb9769e 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 0000000000..34208329bd --- /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 457a345dd3..b3f792b4e9 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 0000000000..44ba10b7ad --- /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 0000000000..4ea4308b1b --- /dev/null +++ b/cli/tests/tsx_imports.ts.out @@ -0,0 +1,2 @@ +Compile [WILDCARD]tsx_imports.ts +{ factory: [Function: View], props: null, children: [] }