Skip to content

Commit

Permalink
code generation: remove redundant switch cases branches in generated …
Browse files Browse the repository at this point in the history
…JS (#1295)

* Fix redundant branches in generated switch body, fixes #6671 (#6672)

* Fix redundant branches in generated switch body, fixes #6671

Signed-Off-By: Vincenzo Pellegrini <[email protected]>

* Updated changelog

---------

Signed-off-by: Vincenzo Pellegrini <[email protected]>

* fmt

* snapshot runtime tests

* chore: add changelog entry

---------

Signed-off-by: Vincenzo Pellegrini <[email protected]>
Co-authored-by: Vincenzo Pellegrini <[email protected]>
  • Loading branch information
anmonteiro and friedbyalice authored Jan 14, 2025
1 parent 94a1fd6 commit 9669dc8
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 77 deletions.
14 changes: 8 additions & 6 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,17 @@ Unreleased
- BREAKING: ppx: print the `deprecated` alert for `@@deriving abstract` at the
declaration site rather than at (all) usages
([#1269](https://github.com/melange-re/melange/pull/1269))
- core: prettify melange code generation for `for` loops
- JS generation: prettify `for` loops
([#1275](https://github.com/melange-re/melange/pull/1275))
- core: improve generated code formatting for `throw` and `return` statements,
JS objects ([#1286](https://github.com/melange-re/melange/pull/1286),
- JS generation: improve formatting for `throw` and `return` statements, JS
objects ([#1286](https://github.com/melange-re/melange/pull/1286),
[#1289](https://github.com/melange-re/melange/pull/1289))
- core: improve generated code formatting for empty return and continue
statements ([#1288](https://github.com/melange-re/melange/pull/1288))
- core: in generated code, remove trailing spaces before commas in `export`
- JS generation: improve formatting for empty return and continue statements
([#1288](https://github.com/melange-re/melange/pull/1288))
- JS generation: remove trailing spaces before commas in `export`
([#1287](https://github.com/melange-re/melange/pull/1287))
- JS generation: remove redundant switch cases branches
([#1295](https://github.com/melange-re/melange/pull/1295))

4.0.1 2024-06-07
---------------
Expand Down
9 changes: 9 additions & 0 deletions jscomp/core/lam_compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,15 @@ and compile_general_cases :
break still should not be printed (it will be continuned)
TOOD: disabled temporarily since it's not perfect yet *)
morph_declare_to_assign cxt (fun cxt declaration ->
(* Exclude cases that are the same as the default if the default is defined *)
let cases =
match default with
| Default lam ->
List.filter
~f:(fun (_, lam1) -> not (Lam.eq_approx lam lam1))
cases
| _ -> cases
in
let default =
match default with
| Complete -> None
Expand Down
2 changes: 0 additions & 2 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.

16 changes: 0 additions & 16 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.

2 changes: 0 additions & 2 deletions jscomp/test/dist/jscomp/test/gpr_1698_test.js

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

19 changes: 0 additions & 19 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.

17 changes: 0 additions & 17 deletions jscomp/test/dist/jscomp/test/ocaml_re_test.js

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

2 changes: 0 additions & 2 deletions jscomp/test/dist/jscomp/test/ocaml_typedtree_test.js

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

5 changes: 0 additions & 5 deletions jscomp/test/dist/jscomp/test/string_test.js

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

5 changes: 0 additions & 5 deletions jscomp/test/dist/jscomp/test/tscanf_test.js

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

3 changes: 0 additions & 3 deletions jscomp/test/dist/jscomp/test/typeof_test.js

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

0 comments on commit 9669dc8

Please sign in to comment.