Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
68c516b
introduce linked external source map
mununki Apr 27, 2026
d0ed388
Remove marker entries after lookup
mununki Apr 27, 2026
b021c2f
Preserve relative source paths in maps
mununki Apr 27, 2026
cdea1ce
Change sourceMap field schema to false or object
mununki Apr 28, 2026
879cd69
sourcemap schema in rescript.json
mununki Apr 28, 2026
f7ca25e
Add source map enabled policy
mununki Apr 28, 2026
e258af0
Preserve source map markers across package targets
mununki Apr 29, 2026
f941252
Add comments
mununki Apr 30, 2026
fdebf10
Add mapping %debugger statement
mununki Apr 30, 2026
0778383
Refactor source maps to use JS IR source locations
mununki May 1, 2026
1892e2f
Add inline and hidden source map modes
mununki May 3, 2026
32ef222
Reject sourceMap true during config parsing
mununki May 3, 2026
a15148e
Merge remote-tracking branch 'origin/master' into sourcemap
mununki May 4, 2026
5238b01
Expand source map coverage across modes
mununki May 4, 2026
c5f6258
Merge remote-tracking branch 'origin/master' into sourcemap
mununki Jun 15, 2026
52839e8
Expand source map test coverage
mununki Jun 15, 2026
986a544
format
mununki Jun 15, 2026
1a3e662
Invalidate dependency builds on sourcemap changes
mununki Jun 28, 2026
9855b62
fix test in windows
mununki Jun 28, 2026
02f9d5c
Merge remote-tracking branch 'upstream/master' into resolve-pr-8393
mununki Jul 6, 2026
c932800
Merge branch 'master' of github.com:rescript-lang/rescript into sourc…
mununki Jul 17, 2026
edfc89e
Avoid source map work when disabled
mununki Jul 17, 2026
904d705
Remove direct internal source map flag test
mununki Jul 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions compiler/bsc/rescript_compiler_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,25 @@ let[@inline] string_optional_set s : Bsc_args.spec =
let[@inline] unit_call s : Bsc_args.spec = Unit (Unit_call s)
let[@inline] string_list_add s : Bsc_args.spec = String (String_list_add s)

let parse_source_map value =
Js_config.source_map :=
match String.lowercase_ascii value with
| "linked" -> Linked
| "inline" -> Inline
| "hidden" -> Hidden
| "false" | "none" -> No_source_map
| value ->
Bsc_args.bad_arg
("Unsupported sourceMap value: " ^ value
^ ". Expected linked, inline, hidden, false, or none")

let parse_bool_ref target value =
target :=
match String.lowercase_ascii value with
| "true" -> true
| "false" -> false
| value -> Bsc_args.bad_arg ("Expected true or false, got: " ^ value)

(* mostly common used to list in the beginning to make search fast
*)
let command_line_flags : (string * Bsc_args.spec * string) array =
Expand Down Expand Up @@ -259,6 +278,15 @@ let command_line_flags : (string * Bsc_args.spec * string) array =
string_call ignore,
"*internal* Set jsx mode, this is no longer used and is a no-op." );
("-bs-jsx-preserve", set Js_config.jsx_preserve, "*internal* Preserve jsx");
( "-bs-source-map",
string_call parse_source_map,
"*internal* Configure source map output" );
( "-bs-source-map-sources-content",
string_call (parse_bool_ref Js_config.source_map_sources_content),
"*internal* Include original source text in source maps" );
( "-bs-source-map-root",
string_call (fun value -> Js_config.source_map_root := value),
"*internal* Set sourceRoot in source maps" );
( "-bs-package-output",
string_call Js_packages_state.update_npm_package_path,
"*internal* Set npm-output-path: [opt_module]:path, for example: \
Expand Down
4 changes: 4 additions & 0 deletions compiler/common/js_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

type jsx_version = Jsx_v4
type jsx_module = React | Generic of {module_name: string}
type source_map = No_source_map | Linked | Inline | Hidden

let no_version_header = ref false

Expand Down Expand Up @@ -53,6 +54,9 @@ let jsx_version = ref None
let jsx_module = ref React
let jsx_preserve = ref false
let js_stdout = ref true
let source_map = ref No_source_map
let source_map_sources_content = ref false
let source_map_root = ref ""
let all_module_aliases = ref false
let no_stdlib = ref false
let no_export = ref false
Expand Down
7 changes: 7 additions & 0 deletions compiler/common/js_config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

type jsx_version = Jsx_v4
type jsx_module = React | Generic of {module_name: string}
type source_map = No_source_map | Linked | Inline | Hidden

(* val get_packages_info :
unit -> Js_packages_info.t *)
Expand Down Expand Up @@ -86,6 +87,12 @@ val jsx_preserve : bool ref

val js_stdout : bool ref

val source_map : source_map ref

val source_map_sources_content : bool ref

val source_map_root : string ref

val all_module_aliases : bool ref

val no_stdlib : bool ref
Expand Down
2 changes: 1 addition & 1 deletion compiler/core/dune
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
(backend bisect_ppx))
(flags
(:standard -w +a-4-9-27-30-40-41-42-48-70))
(libraries depends ext flow_parser frontend gentype))
(libraries depends ext flow_parser frontend gentype yojson))

(rule
(target js_name_of_module_id.ml)
Expand Down
14 changes: 12 additions & 2 deletions compiler/core/j.ml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ and case_clause = {
should_break: bool;
(* true means break *)
comment: string option;
source_loc: Location.t option;
}

and string_clause = Ast_untagged_variants.tag_type * case_clause
Expand Down Expand Up @@ -295,8 +296,17 @@ and statement_desc =
| Try of block * (exception_ident * block) option * block option
| Debugger

and expression = {expression_desc: expression_desc; comment: string option}
and statement = {statement_desc: statement_desc; comment: string option}
and expression = {
expression_desc: expression_desc;
comment: string option;
source_loc: Location.t option;
}

and statement = {
statement_desc: statement_desc;
comment: string option;
source_loc: Location.t option;
}

and variable_declaration = {
ident: ident;
Expand Down
2 changes: 1 addition & 1 deletion compiler/core/js_analyzer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ let rev_flatten_seq (x : J.expression) =
let rec aux acc (x : J.expression) : J.block =
match x.expression_desc with
| Seq (a, b) -> aux (aux acc a) b
| _ -> {statement_desc = Exp x; comment = None} :: acc
| _ -> {statement_desc = Exp x; comment = None; source_loc = None} :: acc
in
aux [] x

Expand Down
11 changes: 9 additions & 2 deletions compiler/core/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -463,14 +463,16 @@ and pp_function ~return_unit ~async ~is_method ?directive cxt (f : P.t)
and pp_one_case_clause :
'a. _ -> P.t -> (P.t -> 'a -> unit) -> 'a * J.case_clause -> _ =
fun cxt f pp_cond
(switch_case, ({switch_body; should_break; comment} : J.case_clause)) ->
( switch_case,
({switch_body; should_break; comment; source_loc} : J.case_clause) ) ->
P.newline f;
let cxt =
P.group f 1 (fun _ ->
P.group f 0 (fun _ ->
P.string f L.case;
P.space f;
pp_comment_option f comment;
Js_source_map.mark_source_loc f source_loc;
pp_cond f switch_case;
(* could be integer or string *)
P.space f;
Expand Down Expand Up @@ -517,6 +519,7 @@ and vident cxt f (v : J.vident) =
(* The higher the level, the more likely that inner has to add parens *)
and expression ~level:l cxt f (exp : J.expression) : cxt =
pp_comment_option f exp.comment;
Js_source_map.mark_source_loc f exp.source_loc;
expression_desc cxt ~level:l f exp.expression_desc

and expression_desc cxt ~(level : int) f x : cxt =
Expand Down Expand Up @@ -1367,6 +1370,8 @@ and variable_declaration top cxt f (variable : J.variable_declaration) : cxt =
| _ -> (
match e.expression_desc with
| Fun {is_method; params; body; env; return_unit; async; directive} ->
pp_comment_option f e.comment;
Js_source_map.mark_source_loc f e.source_loc;
pp_function ?directive ~is_method ~return_unit ~async
~fn_state:(if top then Name_top name else Name_non_top name)
cxt f params body env
Expand Down Expand Up @@ -1407,8 +1412,10 @@ and pp_comment_option f comment =
| None -> ()
| Some x -> pp_comment f x

and statement top cxt f ({statement_desc = s; comment; _} : J.statement) : cxt =
and statement top cxt f
({statement_desc = s; comment; source_loc} : J.statement) : cxt =
pp_comment_option f comment;
Js_source_map.mark_source_loc f source_loc;
statement_desc top cxt f s

and statement_desc top cxt f (s : J.statement_desc) : cxt =
Expand Down
Loading
Loading