Skip to content

Commit

Permalink
generated JS: improve indentation of switch cases (#1299)
Browse files Browse the repository at this point in the history
* generated JS: improve indentation of switch cases

* snapshot runtime tests

* fix blackbox tests, add changelog entries
  • Loading branch information
anmonteiro authored Jan 14, 2025
1 parent 82fc7dd commit 095eb8b
Show file tree
Hide file tree
Showing 72 changed files with 49,615 additions and 49,607 deletions.
8 changes: 8 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ Unreleased
([#1296](https://github.com/melange-re/melange/pull/1296))
- JS generation: add space before while loop condition
([#1297](https://github.com/melange-re/melange/pull/1297))
- JS generation: improve indentation of parenthesized blocks
([#1293](https://github.com/melange-re/melange/pull/1293))
- JS generation: add space after constructor comments
([#1294](https://github.com/melange-re/melange/pull/1294))
- JS generation: improve identation of `switch` cases
([#1299](https://github.com/melange-re/melange/pull/1299))
- JS generation: don't generate empty `default:` cases in `switch`
([#1300](https://github.com/melange-re/melange/pull/1300))

4.0.1 2024-06-07
---------------
Expand Down
4 changes: 2 additions & 2 deletions jscomp/core/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -478,15 +478,15 @@ and pp_one_case_clause : 'a. _ -> (_ -> 'a -> unit) -> 'a * J.case_clause -> _ =
(switch_case, ({ switch_body; should_break; comment } : J.case_clause)) ->
let cxt =
group cxt 1 (fun () ->
group cxt 1 (fun () ->
group cxt 0 (fun () ->
string cxt L.case;
space cxt;
pp_comment_option cxt comment;
pp_cond cxt switch_case;
(* could be integer or string *)
space cxt;
string cxt L.colon);
group cxt 1 (fun () ->
group cxt 0 (fun () ->
let cxt =
match switch_body with
| [] -> cxt
Expand Down
172 changes: 86 additions & 86 deletions jscomp/test/dist-es6/jscomp/test/mt.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,45 +52,45 @@ function close_enough(thresholdOpt, a, b) {
function handleCode(spec) {
switch (spec.TAG) {
case /* Eq */ 0 :
Assert.deepEqual(spec._0, spec._1);
return;
Assert.deepEqual(spec._0, spec._1);
return;
case /* Neq */ 1 :
Assert.notDeepEqual(spec._0, spec._1);
return;
Assert.notDeepEqual(spec._0, spec._1);
return;
case /* StrictEq */ 2 :
Assert.strictEqual(spec._0, spec._1);
return;
Assert.strictEqual(spec._0, spec._1);
return;
case /* StrictNeq */ 3 :
Assert.notStrictEqual(spec._0, spec._1);
return;
Assert.notStrictEqual(spec._0, spec._1);
return;
case /* Ok */ 4 :
Assert.ok(spec._0);
return;
Assert.ok(spec._0);
return;
case /* Approx */ 5 :
const b = spec._1;
const a = spec._0;
if (!close_enough(undefined, a, b)) {
Assert.deepEqual(a, b);
return;
} else {
return;
}
const b = spec._1;
const a = spec._0;
if (!close_enough(undefined, a, b)) {
Assert.deepEqual(a, b);
return;
} else {
return;
}
case /* ApproxThreshold */ 6 :
const b$1 = spec._2;
const a$1 = spec._1;
if (!close_enough(spec._0, a$1, b$1)) {
Assert.deepEqual(a$1, b$1);
return;
} else {
return;
}
case /* ThrowAny */ 7 :
Assert.throws(spec._0);
const b$1 = spec._2;
const a$1 = spec._1;
if (!close_enough(spec._0, a$1, b$1)) {
Assert.deepEqual(a$1, b$1);
return;
} else {
return;
}
case /* ThrowAny */ 7 :
Assert.throws(spec._0);
return;
case /* Fail */ 8 :
return assert_fail("failed");
return assert_fail("failed");
case /* FailWith */ 9 :
return assert_fail(spec._0);
return assert_fail(spec._0);

}
}
Expand Down Expand Up @@ -118,71 +118,71 @@ function from_pair_suites(name, suites) {
const _fn = Curry._1(param[1], undefined);
switch (_fn.TAG) {
case /* Eq */ 0 :
console.log([
name,
_fn._0,
"eq?",
_fn._1
]);
return;
console.log([
name,
_fn._0,
"eq?",
_fn._1
]);
return;
case /* Neq */ 1 :
console.log([
name,
_fn._0,
"neq?",
_fn._1
]);
return;
console.log([
name,
_fn._0,
"neq?",
_fn._1
]);
return;
case /* StrictEq */ 2 :
console.log([
name,
_fn._0,
"strict_eq?",
_fn._1
]);
return;
console.log([
name,
_fn._0,
"strict_eq?",
_fn._1
]);
return;
case /* StrictNeq */ 3 :
console.log([
name,
_fn._0,
"strict_neq?",
_fn._1
]);
return;
console.log([
name,
_fn._0,
"strict_neq?",
_fn._1
]);
return;
case /* Ok */ 4 :
console.log([
name,
_fn._0,
"ok?"
]);
return;
console.log([
name,
_fn._0,
"ok?"
]);
return;
case /* Approx */ 5 :
console.log([
name,
_fn._0,
"~",
_fn._1
]);
return;
console.log([
name,
_fn._0,
"~",
_fn._1
]);
return;
case /* ApproxThreshold */ 6 :
console.log([
name,
_fn._1,
"~",
_fn._2,
" (",
_fn._0,
")"
]);
return;
console.log([
name,
_fn._1,
"~",
_fn._2,
" (",
_fn._0,
")"
]);
return;
case /* ThrowAny */ 7 :
return;
return;
case /* Fail */ 8 :
console.log("failed");
return;
console.log("failed");
return;
case /* FailWith */ 9 :
console.log("failed: " + _fn._0);
return;
console.log("failed: " + _fn._0);
return;

}
}), suites);
Expand Down
Loading

0 comments on commit 095eb8b

Please sign in to comment.