Skip to content

Commit

Permalink
Change strategy to avoid ambiguity after a return statement
Browse files Browse the repository at this point in the history
When pretty-printing, there is no ambiguity since we always have a space
after the return statement. In compact mode, use a newline instead.
  • Loading branch information
vouillon committed Oct 22, 2024
1 parent a6a78b7 commit fb9eae8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
10 changes: 8 additions & 2 deletions compiler/lib/js_output.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1407,8 +1407,14 @@ struct
let last_semi ?(ret = false) () =
if can_omit_semi
then ()
else if ret && source_map_enabled
then PP.string f "; "
else if ret && source_map_enabled && PP.compact f
then
(* In Chrome, the debugger will stop right after a return
statement. We want a whitespace between this statement and
the next one to avoid confusing this location and the
location of the next statement. When pretty-printing, this
is already the case. In compact mode, we add a newline. *)
PP.string f ";\n"
else PP.string f ";"
in
if stop_on_statement s then output_debug_info f loc;
Expand Down
4 changes: 2 additions & 2 deletions compiler/tests-compiler/sourcemap.ml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ let%expect_test _ =
3: (function(globalThis){
4: "use strict";
5: var runtime = globalThis.jsoo_runtime;
6: function id(x){return x; }
6: function id(x){return x;}
7: var Test = [0, id];
8: runtime.caml_register_global(0, Test, "Test");
9: return;
Expand All @@ -89,7 +89,7 @@ let%expect_test _ =
/dune-root/test.ml:1:4 -> 6:12
/dune-root/test.ml:1:7 -> 6:15
/dune-root/test.ml:1:11 -> 6:18
/dune-root/test.ml:1:12 -> 6:28
/dune-root/test.ml:1:12 -> 6:27
/dune-root/test.ml:1:12 -> 7:0
/dune-root/test.ml:1:12 -> 7:7
/builtin/blackbox.ml:1:0 -> 7:14
Expand Down
8 changes: 4 additions & 4 deletions compiler/tests-sourcemap/dump.reference
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sourcemap for test.bc.js
/my/sourceRoot#b.ml:1:4 -> 12: function <>f(x){return x - 1 | 0; }
/my/sourceRoot#b.ml:1:6 -> 14: function f(<>x){return x - 1 | 0; }
/my/sourceRoot#b.ml:1:10 -> 17: function f(x){<>return x - 1 | 0; }
/my/sourceRoot#b.ml:1:15 -> 35: function f(x){return x - 1 | 0; <>}
/my/sourceRoot#b.ml:1:4 -> 12: function <>f(x){return x - 1 | 0;}
/my/sourceRoot#b.ml:1:6 -> 14: function f(<>x){return x - 1 | 0;}
/my/sourceRoot#b.ml:1:10 -> 17: function f(x){<>return x - 1 | 0;}
/my/sourceRoot#b.ml:1:15 -> 34: function f(x){return x - 1 | 0;<>}
/my/sourceRoot#b.ml:1:15 -> 0:<> var Testlib_B = [0, f];
/my/sourceRoot#b.ml:1:15 -> 7: var <>Testlib_B = [0, f];

0 comments on commit fb9eae8

Please sign in to comment.