Skip to content

Commit

Permalink
Generated JS: don't generate empty default: cases in switch (#1300)
Browse files Browse the repository at this point in the history
* Generated JS: don't generate empty `default:` cases in `switch`

* chore: snapshot runtime tests
  • Loading branch information
anmonteiro authored Jan 14, 2025
1 parent 2de72a2 commit 82fc7dd
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 171 deletions.
5 changes: 2 additions & 3 deletions jscomp/core/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,8 @@ and pp_function ~return_unit ~is_method cxt ~fn_state (l : Ident.t list)
param_body ());
outer_cxt

(* Assume the cond would not change the context,
since it can be either [int] or [string]
*)
(* Assume the cond would not change the context, since it can be either [int]
or [string] *)
and pp_one_case_clause : 'a. _ -> (_ -> 'a -> unit) -> 'a * J.case_clause -> _ =
fun cxt pp_cond
(switch_case, ({ switch_body; should_break; comment } : J.case_clause)) ->
Expand Down
6 changes: 4 additions & 2 deletions jscomp/core/lam_compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,10 @@ and compile_general_cases :
match default with
| Complete -> None
| NonComplete -> None
| Default lam ->
Some (Js_output.output_as_block (compile_lambda cxt lam))
| Default lam -> (
match Js_output.output_as_block (compile_lambda cxt lam) with
| [] -> None
| xs -> Some xs)
in
let make_comment i =
match get_cstr_name i with
Expand Down
81 changes: 27 additions & 54 deletions jscomp/test/dist/jscomp/test/flow_parser_reg_test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions jscomp/test/dist/jscomp/test/gpr_1438.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions jscomp/test/dist/jscomp/test/gpr_2931_test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions jscomp/test/dist/jscomp/test/mario_game.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 6 additions & 12 deletions jscomp/test/dist/jscomp/test/ocaml_parsetree_test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions jscomp/test/dist/jscomp/test/ocaml_proto_test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 82fc7dd

Please sign in to comment.