From 1b0559859f365f791838f451ef983ea011dc5863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Tue, 22 Oct 2024 15:23:48 +0200 Subject: [PATCH] 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. --- compiler/lib/js_output.ml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/compiler/lib/js_output.ml b/compiler/lib/js_output.ml index 1d589b6e35..8a2b634cde 100644 --- a/compiler/lib/js_output.ml +++ b/compiler/lib/js_output.ml @@ -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;