Skip to content

Commit 8654d30

Browse files
vouillonhhugo
authored andcommitted
Change strategy to avoid ambiguity after a return statement
When pretty-printing, there is no ambiguity since we always have a space after the return statement. In compact mode, use a newline instead.
1 parent 6dcc384 commit 8654d30

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

compiler/lib/js_output.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,8 +1407,14 @@ struct
14071407
let last_semi ?(ret = false) () =
14081408
if can_omit_semi
14091409
then ()
1410-
else if ret && source_map_enabled
1411-
then PP.string f "; "
1410+
else if ret && source_map_enabled && PP.compact f
1411+
then
1412+
(* In Chrome, the debugger will stop right after a return
1413+
statement. We want a whitespace between this statement and
1414+
the next one to avoid confusing this location and the
1415+
location of the next statement. When pretty-printing, this
1416+
is already the case. In compact mode, we add a newline. *)
1417+
PP.string f ";\n"
14121418
else PP.string f ";"
14131419
in
14141420
if stop_on_statement s then output_debug_info f loc;

compiler/tests-compiler/sourcemap.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ let%expect_test _ =
7575
3: (function(globalThis){
7676
4: "use strict";
7777
5: var runtime = globalThis.jsoo_runtime;
78-
6: function id(x){return x; }
78+
6: function id(x){return x;}
7979
7: var Test = [0, id];
8080
8: runtime.caml_register_global(0, Test, "Test");
8181
9: return;
@@ -89,7 +89,7 @@ let%expect_test _ =
8989
/dune-root/test.ml:1:4 -> 6:12
9090
/dune-root/test.ml:1:7 -> 6:15
9191
/dune-root/test.ml:1:11 -> 6:18
92-
/dune-root/test.ml:1:12 -> 6:28
92+
/dune-root/test.ml:1:12 -> 6:27
9393
/dune-root/test.ml:1:12 -> 7:0
9494
/dune-root/test.ml:1:12 -> 7:7
9595
/builtin/blackbox.ml:1:0 -> 7:14
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
sourcemap for test.bc.js
2-
/my/sourceRoot#b.ml:1:4 -> 12: function <>f(x){return x - 1 | 0; }
3-
/my/sourceRoot#b.ml:1:6 -> 14: function f(<>x){return x - 1 | 0; }
4-
/my/sourceRoot#b.ml:1:10 -> 17: function f(x){<>return x - 1 | 0; }
5-
/my/sourceRoot#b.ml:1:15 -> 35: function f(x){return x - 1 | 0; <>}
2+
/my/sourceRoot#b.ml:1:4 -> 12: function <>f(x){return x - 1 | 0;}
3+
/my/sourceRoot#b.ml:1:6 -> 14: function f(<>x){return x - 1 | 0;}
4+
/my/sourceRoot#b.ml:1:10 -> 17: function f(x){<>return x - 1 | 0;}
5+
/my/sourceRoot#b.ml:1:15 -> 34: function f(x){return x - 1 | 0;<>}
66
/my/sourceRoot#b.ml:1:15 -> 0:<> var Testlib_B = [0, f];
77
/my/sourceRoot#b.ml:1:15 -> 7: var <>Testlib_B = [0, f];

0 commit comments

Comments
 (0)