@@ -35,8 +35,8 @@ mod ts;
35
35
36
36
pub use ts:: EmitConfigOptions ;
37
37
pub use ts:: IgnoredCompilerOptions ;
38
- pub use ts:: JsxImportSourceConfig ;
39
38
pub use ts:: ParsedTsConfigOptions ;
39
+ pub use ts:: RawJsxCompilerOptions ;
40
40
pub use ts:: TsConfig ;
41
41
42
42
#[ derive( Clone , Debug , Default , Deserialize , Hash , PartialEq ) ]
@@ -834,17 +834,6 @@ pub enum ToInvalidConfigError {
834
834
} ,
835
835
}
836
836
837
- #[ derive( Debug , Error , JsError ) ]
838
- #[ class( type ) ]
839
- pub enum ToMaybeJsxImportSourceConfigError {
840
- #[ error( "'jsxImportSource' is only supported when 'jsx' is set to 'react-jsx' or 'react-jsxdev'.\n at {0}" ) ]
841
- InvalidJsxImportSourceJsxValue ( Url ) ,
842
- #[ error( "'jsxImportSourceTypes' is only supported when 'jsx' is set to 'react-jsx' or 'react-jsxdev'.\n at {0}" ) ]
843
- InvalidJjsxImportSourceTypessxValue ( Url ) ,
844
- #[ error( "Unsupported 'jsx' compiler option value '{value}'. Supported: 'react-jsx', 'react-jsxdev', 'react', 'precompile'\n at {specifier}" ) ]
845
- InvalidJsxCompilerOption { value : String , specifier : Url } ,
846
- }
847
-
848
837
#[ derive( Debug , Error , JsError ) ]
849
838
#[ class( type ) ]
850
839
pub enum ResolveTaskConfigError {
@@ -1626,60 +1615,18 @@ impl ConfigFile {
1626
1615
1627
1616
/// Based on the compiler options in the configuration file, return the
1628
1617
/// JSX import source configuration.
1629
- pub fn to_maybe_jsx_import_source_config (
1630
- & self ,
1631
- ) -> Result < Option < JsxImportSourceConfig > , ToMaybeJsxImportSourceConfigError >
1632
- {
1633
- #[ derive( Debug , Deserialize ) ]
1634
- #[ serde( rename_all = "camelCase" ) ]
1635
- struct JsxCompilerOptions {
1636
- pub jsx : Option < String > ,
1637
- pub jsx_import_source : Option < String > ,
1638
- pub jsx_import_source_types : Option < String > ,
1639
- }
1640
-
1641
- let Some ( compiler_options_value) = self . json . compiler_options . as_ref ( )
1642
- else {
1643
- return Ok ( None ) ;
1644
- } ;
1645
- let Some ( compiler_options) = serde_json:: from_value :: < JsxCompilerOptions > (
1646
- compiler_options_value. clone ( ) ,
1647
- )
1648
- . ok ( ) else {
1649
- return Ok ( None ) ;
1650
- } ;
1651
- let module = match compiler_options. jsx . as_deref ( ) {
1652
- Some ( "react-jsx" ) => "jsx-runtime" . to_string ( ) ,
1653
- Some ( "react-jsxdev" ) => "jsx-dev-runtime" . to_string ( ) ,
1654
- Some ( "react" ) | None => {
1655
- if compiler_options. jsx_import_source . is_some ( ) {
1656
- return Err (
1657
- ToMaybeJsxImportSourceConfigError :: InvalidJsxImportSourceJsxValue (
1658
- self . specifier . clone ( ) ,
1659
- ) ,
1660
- ) ;
1661
- }
1662
- if compiler_options. jsx_import_source_types . is_some ( ) {
1663
- return Err ( ToMaybeJsxImportSourceConfigError :: InvalidJjsxImportSourceTypessxValue ( self . specifier . clone ( ) ) ) ;
1664
- }
1665
- return Ok ( None ) ;
1666
- }
1667
- Some ( "precompile" ) => "jsx-runtime" . to_string ( ) ,
1668
- Some ( setting) => {
1669
- return Err (
1670
- ToMaybeJsxImportSourceConfigError :: InvalidJsxCompilerOption {
1671
- value : setting. to_string ( ) ,
1672
- specifier : self . specifier . clone ( ) ,
1673
- } ,
1618
+ pub fn to_raw_jsx_compiler_options ( & self ) -> RawJsxCompilerOptions {
1619
+ self
1620
+ . json
1621
+ . compiler_options
1622
+ . as_ref ( )
1623
+ . and_then ( |compiler_options_value| {
1624
+ serde_json:: from_value :: < RawJsxCompilerOptions > (
1625
+ compiler_options_value. clone ( ) ,
1674
1626
)
1675
- }
1676
- } ;
1677
- Ok ( Some ( JsxImportSourceConfig {
1678
- default_specifier : compiler_options. jsx_import_source ,
1679
- default_types_specifier : compiler_options. jsx_import_source_types ,
1680
- module,
1681
- base_url : self . specifier . clone ( ) ,
1682
- } ) )
1627
+ . ok ( )
1628
+ } )
1629
+ . unwrap_or_default ( )
1683
1630
}
1684
1631
1685
1632
pub fn resolve_tasks_config (
@@ -2238,92 +2185,6 @@ mod tests {
2238
2185
assert ! ( ConfigFile :: new( config_text, config_specifier, ) . is_err( ) ) ;
2239
2186
}
2240
2187
2241
- #[ test]
2242
- fn test_jsx_invalid_setting ( ) {
2243
- let config_text = r#"{ "compilerOptions": { "jsx": "preserve" } }"# ;
2244
- let config_specifier = Url :: parse ( "file:///deno/tsconfig.json" ) . unwrap ( ) ;
2245
- let config = ConfigFile :: new ( config_text, config_specifier) . unwrap ( ) ;
2246
- assert_eq ! (
2247
- config. to_maybe_jsx_import_source_config( ) . err( ) . unwrap( ) . to_string( ) ,
2248
- concat!(
2249
- "Unsupported 'jsx' compiler option value 'preserve'. Supported: 'react-jsx', 'react-jsxdev', 'react', 'precompile'\n " ,
2250
- " at file:///deno/tsconfig.json" ,
2251
- ) ,
2252
- ) ;
2253
- }
2254
-
2255
- #[ test]
2256
- fn test_jsx_import_source_only ( ) {
2257
- let config_specifier = Url :: parse ( "file:///deno/tsconfig.json" ) . unwrap ( ) ;
2258
- {
2259
- let config_text =
2260
- r#"{ "compilerOptions": { "jsxImportSource": "test" } }"# ;
2261
- let config =
2262
- ConfigFile :: new ( config_text, config_specifier. clone ( ) ) . unwrap ( ) ;
2263
- assert_eq ! (
2264
- config. to_maybe_jsx_import_source_config( ) . err( ) . unwrap( ) . to_string( ) ,
2265
- concat!(
2266
- "'jsxImportSource' is only supported when 'jsx' is set to 'react-jsx' or 'react-jsxdev'.\n " ,
2267
- " at file:///deno/tsconfig.json" ,
2268
- ) ,
2269
- ) ;
2270
- }
2271
- {
2272
- let config_text = r#"{ "compilerOptions": { "jsx": "react", "jsxImportSource": "test" } }"# ;
2273
- let config = ConfigFile :: new ( config_text, config_specifier) . unwrap ( ) ;
2274
- assert_eq ! (
2275
- config. to_maybe_jsx_import_source_config( ) . err( ) . unwrap( ) . to_string( ) ,
2276
- concat!(
2277
- "'jsxImportSource' is only supported when 'jsx' is set to 'react-jsx' or 'react-jsxdev'.\n " ,
2278
- " at file:///deno/tsconfig.json" ,
2279
- ) ,
2280
- ) ;
2281
- }
2282
- }
2283
-
2284
- #[ test]
2285
- fn test_jsx_import_source_types_only ( ) {
2286
- let config_specifier = Url :: parse ( "file:///deno/tsconfig.json" ) . unwrap ( ) ;
2287
- {
2288
- let config_text =
2289
- r#"{ "compilerOptions": { "jsxImportSourceTypes": "test" } }"# ;
2290
- let config =
2291
- ConfigFile :: new ( config_text, config_specifier. clone ( ) ) . unwrap ( ) ;
2292
- assert_eq ! (
2293
- config. to_maybe_jsx_import_source_config( ) . err( ) . unwrap( ) . to_string( ) ,
2294
- concat!(
2295
- "'jsxImportSourceTypes' is only supported when 'jsx' is set to 'react-jsx' or 'react-jsxdev'.\n " ,
2296
- " at file:///deno/tsconfig.json" ,
2297
- ) ,
2298
- ) ;
2299
- }
2300
- {
2301
- let config_text = r#"{ "compilerOptions": { "jsx": "react", "jsxImportSourceTypes": "test" } }"# ;
2302
- let config = ConfigFile :: new ( config_text, config_specifier) . unwrap ( ) ;
2303
- assert_eq ! (
2304
- config. to_maybe_jsx_import_source_config( ) . err( ) . unwrap( ) . to_string( ) ,
2305
- concat!(
2306
- "'jsxImportSourceTypes' is only supported when 'jsx' is set to 'react-jsx' or 'react-jsxdev'.\n " ,
2307
- " at file:///deno/tsconfig.json" ,
2308
- ) ,
2309
- ) ;
2310
- }
2311
- }
2312
-
2313
- #[ test]
2314
- fn test_jsx_import_source_valid ( ) {
2315
- let config_text = r#"{ "compilerOptions": { "jsx": "react" } }"# ;
2316
- let config_specifier = Url :: parse ( "file:///deno/tsconfig.json" ) . unwrap ( ) ;
2317
- assert ! ( ConfigFile :: new( config_text, config_specifier, ) . is_ok( ) ) ;
2318
- }
2319
-
2320
- #[ test]
2321
- fn test_jsx_precompile_skip_setting ( ) {
2322
- let config_text = r#"{ "compilerOptions": { "jsx": "precompile", "jsxPrecompileSkipElements": ["a", "p"] } }"# ;
2323
- let config_specifier = Url :: parse ( "file:///deno/tsconfig.json" ) . unwrap ( ) ;
2324
- assert ! ( ConfigFile :: new( config_text, config_specifier, ) . is_ok( ) ) ;
2325
- }
2326
-
2327
2188
#[ test]
2328
2189
fn task_name_invalid_chars ( ) {
2329
2190
run_task_error_test (
0 commit comments