@@ -269,6 +269,7 @@ def _validate_options_impl(ctx):
269
269
allow_js = ctx .attr .allow_js ,
270
270
declaration = ctx .attr .declaration ,
271
271
declaration_map = ctx .attr .declaration_map ,
272
+ preserve_jsx = ctx .attr .preserve_jsx ,
272
273
composite = ctx .attr .composite ,
273
274
emit_declaration_only = ctx .attr .emit_declaration_only ,
274
275
source_map = ctx .attr .source_map ,
@@ -299,6 +300,7 @@ validate_options = rule(
299
300
"emit_declaration_only" : attr .bool (),
300
301
"extends" : attr .label (allow_files = [".json" ]),
301
302
"incremental" : attr .bool (),
303
+ "preserve_jsx" : attr .bool (),
302
304
"source_map" : attr .bool (),
303
305
"target" : attr .string (),
304
306
"ts_build_info_file" : attr .string (),
@@ -312,10 +314,20 @@ def _is_ts_src(src, allow_js):
312
314
return True
313
315
return allow_js and (src .endswith (".js" ) or src .endswith (".jsx" ))
314
316
315
- def _out_paths (srcs , outdir , rootdir , allow_js , ext ):
317
+ def _replace_ext (f , ext_map ):
318
+ cur_ext = f [f .rindex ("." ):]
319
+ new_ext = ext_map .get (cur_ext )
320
+ if new_ext != None :
321
+ return new_ext
322
+ new_ext = ext_map .get ("*" )
323
+ if new_ext != None :
324
+ return new_ext
325
+ return None
326
+
327
+ def _out_paths (srcs , outdir , rootdir , allow_js , ext_map ):
316
328
rootdir_replace_pattern = rootdir + "/" if rootdir else ""
317
329
return [
318
- _join (outdir , f [:f .rindex ("." )].replace (rootdir_replace_pattern , "" ) + ext )
330
+ _join (outdir , f [:f .rindex ("." )].replace (rootdir_replace_pattern , "" ) + _replace_ext ( f , ext_map ) )
319
331
for f in srcs
320
332
if _is_ts_src (f , allow_js )
321
333
]
@@ -331,6 +343,7 @@ def ts_project_macro(
331
343
declaration = False ,
332
344
source_map = False ,
333
345
declaration_map = False ,
346
+ preserve_jsx = False ,
334
347
composite = False ,
335
348
incremental = False ,
336
349
emit_declaration_only = False ,
@@ -551,6 +564,8 @@ def ts_project_macro(
551
564
Instructs Bazel to expect a `.js.map` output for each `.ts` source.
552
565
declaration_map: if the `declarationMap` bit is set in the tsconfig.
553
566
Instructs Bazel to expect a `.d.ts.map` output for each `.ts` source.
567
+ preserve_jsx: if the `jsx` value is set to "preserve" in the tsconfig.
568
+ Instructs Bazel to expect a `.jsx` or `.jsx.map` output for each `.tsx` source.
554
569
composite: if the `composite` bit is set in the tsconfig.
555
570
Instructs Bazel to expect a `.tsbuildinfo` output and a `.d.ts` output for each `.ts` source.
556
571
incremental: if the `incremental` bit is set in the tsconfig.
@@ -620,6 +635,7 @@ def ts_project_macro(
620
635
declaration = declaration ,
621
636
source_map = source_map ,
622
637
declaration_map = declaration_map ,
638
+ preserve_jsx = preserve_jsx ,
623
639
composite = composite ,
624
640
incremental = incremental ,
625
641
ts_build_info_file = ts_build_info_file ,
@@ -660,13 +676,22 @@ def ts_project_macro(
660
676
typing_maps_outs = []
661
677
662
678
if not emit_declaration_only :
663
- js_outs .extend (_out_paths (srcs , out_dir , root_dir , allow_js , ".js" ))
679
+ exts = {
680
+ "*" : ".js" ,
681
+ ".jsx" : ".jsx" ,
682
+ ".tsx" : ".jsx" ,
683
+ } if preserve_jsx else {"*" : ".js" }
684
+ js_outs .extend (_out_paths (srcs , out_dir , root_dir , allow_js , exts ))
664
685
if source_map and not emit_declaration_only :
665
- map_outs .extend (_out_paths (srcs , out_dir , root_dir , False , ".js.map" ))
686
+ exts = {
687
+ "*" : ".js.map" ,
688
+ ".tsx" : ".jsx.map" ,
689
+ } if preserve_jsx else {"*" : ".js.map" }
690
+ map_outs .extend (_out_paths (srcs , out_dir , root_dir , False , exts ))
666
691
if declaration or composite :
667
- typings_outs .extend (_out_paths (srcs , typings_out_dir , root_dir , allow_js , " .d.ts" ))
692
+ typings_outs .extend (_out_paths (srcs , typings_out_dir , root_dir , allow_js , { "*" : " .d.ts"} ))
668
693
if declaration_map :
669
- typing_maps_outs .extend (_out_paths (srcs , typings_out_dir , root_dir , allow_js , " .d.ts.map" ))
694
+ typing_maps_outs .extend (_out_paths (srcs , typings_out_dir , root_dir , allow_js , { "*" : " .d.ts.map"} ))
670
695
671
696
if not len (js_outs ) and not len (typings_outs ):
672
697
fail ("""ts_project target "//{}:{}" is configured to produce no outputs.
0 commit comments