@@ -1486,6 +1486,10 @@ impl WorkspaceDirectory {
1486
1486
. map ( |r| r. to_raw_jsx_compiler_options ( ) )
1487
1487
. unwrap_or_default ( ) ;
1488
1488
let member = config. member . to_raw_jsx_compiler_options ( ) ;
1489
+ let is_jsx_automatic = matches ! (
1490
+ member. jsx. as_deref( ) . or( base. jsx. as_deref( ) ) ,
1491
+ Some ( "react-jsx" | "react-jsxdev" | "precompile" ) ,
1492
+ ) ;
1489
1493
let import_source = member
1490
1494
. jsx_import_source
1491
1495
. map ( |specifier| JsxImportSourceSpecifierConfig {
@@ -1499,6 +1503,12 @@ impl WorkspaceDirectory {
1499
1503
specifier,
1500
1504
} )
1501
1505
} )
1506
+ } )
1507
+ . or_else ( || {
1508
+ is_jsx_automatic. then ( || JsxImportSourceSpecifierConfig {
1509
+ base : config. member . specifier . clone ( ) ,
1510
+ specifier : "react" . to_string ( ) ,
1511
+ } )
1502
1512
} ) ;
1503
1513
let import_source_types = member
1504
1514
. jsx_import_source_types
@@ -1513,7 +1523,8 @@ impl WorkspaceDirectory {
1513
1523
specifier,
1514
1524
} )
1515
1525
} )
1516
- } ) ;
1526
+ } )
1527
+ . or_else ( || import_source. clone ( ) ) ;
1517
1528
let module = match member. jsx . as_deref ( ) . or ( base. jsx . as_deref ( ) ) {
1518
1529
Some ( "react-jsx" ) => "jsx-runtime" . to_string ( ) ,
1519
1530
Some ( "react-jsxdev" ) => "jsx-dev-runtime" . to_string ( ) ,
@@ -5712,6 +5723,32 @@ pub mod test {
5712
5723
assert ! ( member. to_maybe_jsx_import_source_config( ) . is_ok( ) ) ;
5713
5724
}
5714
5725
5726
+ #[ test]
5727
+ fn test_jsx_import_source_defaults ( ) {
5728
+ let member = workspace_for_root_and_member (
5729
+ json ! ( {
5730
+ "compilerOptions" : { "jsx" : "react-jsx" }
5731
+ } ) ,
5732
+ json ! ( { } ) ,
5733
+ ) ;
5734
+ let config = member. to_maybe_jsx_import_source_config ( ) . unwrap ( ) . unwrap ( ) ;
5735
+ assert_eq ! ( config. import_source. unwrap( ) . specifier, "react" ) ;
5736
+ assert_eq ! ( config. import_source_types. unwrap( ) . specifier, "react" ) ;
5737
+ }
5738
+
5739
+ #[ test]
5740
+ fn test_jsx_import_source_types_defaults_import_source ( ) {
5741
+ let member = workspace_for_root_and_member (
5742
+ json ! ( {
5743
+ "compilerOptions" : { "jsx" : "react-jsx" , "jsxImportSource" : "jsx" }
5744
+ } ) ,
5745
+ json ! ( { } ) ,
5746
+ ) ;
5747
+ let config = member. to_maybe_jsx_import_source_config ( ) . unwrap ( ) . unwrap ( ) ;
5748
+ assert_eq ! ( config. import_source. unwrap( ) . specifier, "jsx" ) ;
5749
+ assert_eq ! ( config. import_source_types. unwrap( ) . specifier, "jsx" ) ;
5750
+ }
5751
+
5715
5752
#[ test]
5716
5753
fn test_jsx_precompile_skip_setting ( ) {
5717
5754
let member = workspace_for_root_and_member (
0 commit comments