Skip to content

Fix sourcemap #1450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Compiler: fix simplification of js with let and const
* Compiler: reduce memory consumption when parsing js
* Compiler: parsing js can return a list of token, the list was sometime incorrect
* Sourcemap: stop producing sourcemaps mappings with negative lines or columns

# 5.1.1 (2023-03-15) - Lille
## Bug fixes
Expand Down
57 changes: 29 additions & 28 deletions compiler/lib/js_output.ml
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,17 @@ struct
match loc with
| N -> ()
| U | Pi { Parse_info.src = None | Some ""; _ } ->
push_mapping
(PP.pos f)
{ Source_map.gen_line = -1
; gen_col = -1
; ori_source = -1
; ori_line = -1
; ori_col = -1
; ori_name = None
}
push_mapping (PP.pos f) (Source_map.Gen { gen_line = -1; gen_col = -1 })
| Pi { Parse_info.src = Some file; line; col; _ } ->
push_mapping
(PP.pos f)
{ Source_map.gen_line = -1
; gen_col = -1
; ori_source = get_file_index file
; ori_line = line
; ori_col = col
; ori_name = None
}
(Source_map.Gen_Ori
{ gen_line = -1
; gen_col = -1
; ori_source = get_file_index file
; ori_line = line
; ori_col = col
})

let output_debug_info_ident f nm loc =
if source_map_enabled
Expand All @@ -115,13 +107,14 @@ struct
| Some { Parse_info.src = Some file; line; col; _ } ->
push_mapping
(PP.pos f)
{ Source_map.gen_line = -1
; gen_col = -1
; ori_source = get_file_index file
; ori_line = line
; ori_col = col
; ori_name = Some (get_name_index nm)
}
(Source_map.Gen_Ori_Name
{ gen_line = -1
; gen_col = -1
; ori_source = get_file_index file
; ori_line = line
; ori_col = col
; ori_name = get_name_index nm
})

let ident f = function
| S { name = Utf8 name; var = Some v; _ } ->
Expand Down Expand Up @@ -1632,11 +1625,19 @@ let program ?(accept_unnamed_var = false) f ?source_map p =
in
let mappings =
List.rev_append_map !temp_mappings sm.mappings ~f:(fun (pos, m) ->
{ m with
(* [p_line] starts at zero, [gen_line] at 1 *)
Source_map.gen_line = pos.PP.p_line + 1
; Source_map.gen_col = pos.PP.p_col
})
let gen_line = pos.PP.p_line + 1 in
let gen_col = pos.PP.p_col in
match m with
| Source_map.Gen { gen_col = _; gen_line = _ } ->
Source_map.Gen { gen_col; gen_line }
| Source_map.Gen_Ori
{ gen_line = _; gen_col = _; ori_source; ori_line; ori_col } ->
Source_map.Gen_Ori { gen_line; gen_col; ori_source; ori_line; ori_col }
| Source_map.Gen_Ori_Name
{ gen_line = _; gen_col = _; ori_source; ori_line; ori_col; ori_name }
->
Source_map.Gen_Ori_Name
{ gen_line; gen_col; ori_source; ori_line; ori_col; ori_name })
in
Some { sm with Source_map.sources; names; sources_content; mappings }
in
Expand Down
Loading