diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs index 9c0ef920c523cc..128bba2ef06c36 100644 --- a/cli/file_fetcher.rs +++ b/cli/file_fetcher.rs @@ -481,7 +481,9 @@ fn map_file_extension(path: &Path) -> msg::MediaType { None => msg::MediaType::Unknown, Some(os_str) => match os_str.to_str() { Some("ts") => msg::MediaType::TypeScript, + Some("tsx") => msg::MediaType::TSX, Some("js") => msg::MediaType::JavaScript, + Some("jsx") => msg::MediaType::JSX, Some("mjs") => msg::MediaType::JavaScript, Some("json") => msg::MediaType::Json, _ => msg::MediaType::Unknown, @@ -1342,6 +1344,10 @@ mod tests { map_file_extension(Path::new("foo/bar.ts")), msg::MediaType::TypeScript ); + assert_eq!( + map_file_extension(Path::new("foo/bar.tsx")), + msg::MediaType::TSX + ); assert_eq!( map_file_extension(Path::new("foo/bar.d.ts")), msg::MediaType::TypeScript @@ -1350,6 +1356,10 @@ mod tests { map_file_extension(Path::new("foo/bar.js")), msg::MediaType::JavaScript ); + assert_eq!( + map_file_extension(Path::new("foo/bar.jsx")), + msg::MediaType::JSX + ); assert_eq!( map_file_extension(Path::new("foo/bar.json")), msg::MediaType::Json @@ -1371,6 +1381,10 @@ mod tests { map_content_type(Path::new("foo/bar.ts"), None), msg::MediaType::TypeScript ); + assert_eq!( + map_content_type(Path::new("foo/bar.tsx"), None), + msg::MediaType::TSX + ); assert_eq!( map_content_type(Path::new("foo/bar.d.ts"), None), msg::MediaType::TypeScript @@ -1379,6 +1393,10 @@ mod tests { map_content_type(Path::new("foo/bar.js"), None), msg::MediaType::JavaScript ); + assert_eq!( + map_content_type(Path::new("foo/bar.jsx"), None), + msg::MediaType::JSX + ); assert_eq!( map_content_type(Path::new("foo/bar.json"), None), msg::MediaType::Json diff --git a/cli/msg.rs b/cli/msg.rs index 4416c7d71b67f2..20ab9db130408c 100644 --- a/cli/msg.rs +++ b/cli/msg.rs @@ -66,15 +66,19 @@ pub enum ErrorKind { #[derive(Clone, Copy, PartialEq, Debug)] pub enum MediaType { JavaScript = 0, - TypeScript = 1, - Json = 2, - Unknown = 3, + JSX = 1, + TypeScript = 2, + TSX = 3, + Json = 4, + Unknown = 5, } pub fn enum_name_media_type(mt: MediaType) -> &'static str { match mt { MediaType::JavaScript => "JavaScript", + MediaType::JSX => "JSX", MediaType::TypeScript => "TypeScript", + MediaType::TSX => "TSX", MediaType::Json => "Json", MediaType::Unknown => "Unknown", } diff --git a/cli/state.rs b/cli/state.rs index d7c6102048f4b0..ef870bef046c85 100644 --- a/cli/state.rs +++ b/cli/state.rs @@ -250,7 +250,9 @@ impl ThreadSafeState { msg::MediaType::Json => { state_.json_compiler.compile_async(state_.clone(), &out) } - msg::MediaType::TypeScript => { + msg::MediaType::TypeScript + | msg::MediaType::TSX + | msg::MediaType::JSX => { state_.ts_compiler.compile_async(state_.clone(), &out) } msg::MediaType::JavaScript => { diff --git a/cli/tests/046_jsx_test.tsx b/cli/tests/046_jsx_test.tsx new file mode 100644 index 00000000000000..4e9380eb8f6df5 --- /dev/null +++ b/cli/tests/046_jsx_test.tsx @@ -0,0 +1,9 @@ +const React = { + createElement(factory: any, props: any, ...children: any[]) { + return {factory, props, children} + } +} +const View = () => ( +