Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generated JS: improve indentation of switch cases #1299

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading