Skip to content

Commit

Permalink
fix: source_map = True, allow_js = True outputs source maps for JS …
Browse files Browse the repository at this point in the history
…inputs
  • Loading branch information
jfirebaugh committed Dec 12, 2024
1 parent dff5194 commit 8dba016
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion examples/jsx/expected_outputs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ examples/jsx/out/b.d.ts
examples/jsx/out/b.d.ts.map
examples/jsx/out/a.jsx
examples/jsx/out/a.jsx.map
examples/jsx/out/b.jsx
examples/jsx/out/b.jsx
examples/jsx/out/b.jsx.map
4 changes: 3 additions & 1 deletion examples/module_ext/expected_outputs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ examples/module_ext/out/d.d.cts.map
examples/module_ext/out/a.mjs
examples/module_ext/out/a.mjs.map
examples/module_ext/out/b.mjs
examples/module_ext/out/b.mjs.map
examples/module_ext/out/c.cjs
examples/module_ext/out/c.cjs.map
examples/module_ext/out/d.cjs
examples/module_ext/out/d.cjs
examples/module_ext/out/d.cjs.map
2 changes: 1 addition & 1 deletion ts/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def ts_project(
tsc_map_outs = []
if emit_tsc_js:
tsc_js_outs = _lib.calculate_js_outs(srcs, out_dir, root_dir, allow_js, resolve_json_module, preserve_jsx, emit_declaration_only)
tsc_map_outs = _lib.calculate_map_outs(srcs, out_dir, root_dir, source_map, preserve_jsx, emit_declaration_only)
tsc_map_outs = _lib.calculate_map_outs(srcs, out_dir, root_dir, source_map, allow_js, preserve_jsx, emit_declaration_only)

# Custom typing transpiler
if emit_transpiler_dts:
Expand Down
6 changes: 4 additions & 2 deletions ts/private/ts_lib.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def _calculate_js_outs(srcs, out_dir, root_dir, allow_js, resolve_json_module, p

return _to_js_out_paths(srcs, out_dir, root_dir, allow_js, resolve_json_module, exts, ".js")

def _calculate_map_outs(srcs, out_dir, root_dir, source_map, preserve_jsx, emit_declaration_only):
def _calculate_map_outs(srcs, out_dir, root_dir, source_map, allow_js, preserve_jsx, emit_declaration_only):
if not source_map or emit_declaration_only:
return []

Expand All @@ -281,8 +281,10 @@ def _calculate_map_outs(srcs, out_dir, root_dir, source_map, preserve_jsx, emit_
}
if preserve_jsx:
exts[".tsx"] = ".jsx.map"
if allow_js:
exts[".jsx"] = ".jsx.map"

return _to_js_out_paths(srcs, out_dir, root_dir, False, False, exts, ".js.map")
return _to_js_out_paths(srcs, out_dir, root_dir, allow_js, False, exts, ".js.map")

def _calculate_typings_outs(srcs, typings_out_dir, root_dir, declaration, composite, allow_js):
if not (declaration or composite):
Expand Down
2 changes: 1 addition & 1 deletion ts/private/ts_project.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _ts_project_impl(ctx):
map_outs = []
if not ctx.attr.no_emit and ctx.attr.transpile != 0:
js_outs = _lib.declare_outputs(ctx, _lib.calculate_js_outs(srcs, ctx.attr.out_dir, ctx.attr.root_dir, ctx.attr.allow_js, ctx.attr.resolve_json_module, ctx.attr.preserve_jsx, ctx.attr.emit_declaration_only))
map_outs = _lib.declare_outputs(ctx, _lib.calculate_map_outs(srcs, ctx.attr.out_dir, ctx.attr.root_dir, ctx.attr.source_map, ctx.attr.preserve_jsx, ctx.attr.emit_declaration_only))
map_outs = _lib.declare_outputs(ctx, _lib.calculate_map_outs(srcs, ctx.attr.out_dir, ctx.attr.root_dir, ctx.attr.source_map, ctx.attr.allow_js, ctx.attr.preserve_jsx, ctx.attr.emit_declaration_only))

# dts+map file outputs
typings_outs = []
Expand Down
2 changes: 1 addition & 1 deletion ts/test/mock_transpiler.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ def mock(name, srcs, source_map = False, **kwargs):
# Calculate pre-declared outputs so they can be referenced as targets.
# This is an optional transpiler feature aligning with the default tsc transpiler.
js_outs = lib.calculate_js_outs(srcs, ".", ".", False, False, False, False),
map_outs = lib.calculate_map_outs(srcs, ".", ".", True, False, False) if source_map else [],
map_outs = lib.calculate_map_outs(srcs, ".", ".", True, False, False, False) if source_map else [],
**kwargs
)

0 comments on commit 8dba016

Please sign in to comment.