Skip to content

Commit

Permalink
improve code generation formatting of throw / return / JS Objects (
Browse files Browse the repository at this point in the history
…#1286)

* improve code generation formatting of throw / return

* better indentation of objects

* wip
  • Loading branch information
anmonteiro authored Jan 12, 2025
1 parent 08d7248 commit 0231b5a
Show file tree
Hide file tree
Showing 362 changed files with 76,360 additions and 76,362 deletions.
14 changes: 7 additions & 7 deletions flake.lock

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

8 changes: 3 additions & 5 deletions jscomp/core/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ module Curry_gen = struct
string cxt (Printf.sprintf "%d" len)
end

let return_indent = String.length L.return / Js_pp.indent_length
let throw_indent = String.length L.throw / Js_pp.indent_length
let semi cxt = string cxt L.semi
let comma cxt = string cxt L.comma

Expand Down Expand Up @@ -914,7 +912,7 @@ and expression_desc cxt ~(level : int) x : cxt =
var f = { x : 2 , y : 2}
]}
*)
cond_paren_group cxt (level > 1) 1 (fun () ->
cond_paren_group cxt (level > 1) 0 (fun () ->
if lst = [] then (
string cxt "{}";
cxt)
Expand Down Expand Up @@ -1195,7 +1193,7 @@ and statement_desc top cxt (s : J.statement_desc) : cxt =
| _ ->
return_sp cxt;
(* string cxt "return ";(\* ASI -- when there is a comment*\) *)
group cxt return_indent (fun () ->
group cxt 0 (fun () ->
let cxt = expression ~level:0 cxt e in
semi cxt;
cxt))
Expand Down Expand Up @@ -1255,7 +1253,7 @@ and statement_desc top cxt (s : J.statement_desc) : cxt =
in
string cxt L.throw;
space cxt;
group cxt throw_indent (fun () ->
group cxt 0 (fun () ->
let cxt = expression ~level:0 cxt e in
semi cxt;
cxt)
Expand Down
28 changes: 14 additions & 14 deletions jscomp/test/dist-es6/jscomp/test/es6_tests/es6_module_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@ Mt.from_pair_suites("Es6_module_test", {
"list_length",
(function (param) {
return {
TAG: /* Eq */0,
_0: Stdlib__List.length({
hd: 1,
tl: {
hd: 2,
tl: /* [] */0
}
}),
_1: 2
};
TAG: /* Eq */0,
_0: Stdlib__List.length({
hd: 1,
tl: {
hd: 2,
tl: /* [] */0
}
}),
_1: 2
};
})
],
tl: {
hd: [
"length",
(function (param) {
return {
TAG: /* Eq */0,
_0: 3,
_1: 3
};
TAG: /* Eq */0,
_0: 3,
_1: 3
};
})
],
tl: /* [] */0
Expand Down
200 changes: 100 additions & 100 deletions jscomp/test/dist-es6/jscomp/test/mt.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ function from_suites(name, suite) {
if (match && is_mocha(undefined)) {
describe(name, (function () {
return Stdlib__List.iter((function (param) {
const partial_arg = param[1];
it(param[0], (function () {
return Curry._1(partial_arg, undefined);
}));
}), suite);
const partial_arg = param[1];
it(param[0], (function () {
return Curry._1(partial_arg, undefined);
}));
}), suite);
}));
return ;
}
Expand Down Expand Up @@ -101,11 +101,11 @@ function from_pair_suites(name, suites) {
if (is_mocha(undefined)) {
describe(name, (function () {
return Stdlib__List.iter((function (param) {
const code = param[1];
it(param[0], (function () {
return handleCode(Curry._1(code, undefined));
}));
}), suites);
const code = param[1];
it(param[0], (function () {
return handleCode(Curry._1(code, undefined));
}));
}), suites);
}));
return ;
} else {
Expand All @@ -114,78 +114,78 @@ function from_pair_suites(name, suites) {
"testing"
]);
return Stdlib__List.iter((function (param) {
const name = param[0];
const _fn = Curry._1(param[1], undefined);
switch (_fn.TAG) {
case /* Eq */0 :
console.log([
name,
_fn._0,
"eq?",
_fn._1
]);
return ;
case /* Neq */1 :
console.log([
name,
_fn._0,
"neq?",
_fn._1
]);
return ;
case /* StrictEq */2 :
console.log([
name,
_fn._0,
"strict_eq?",
_fn._1
]);
return ;
case /* StrictNeq */3 :
console.log([
name,
_fn._0,
"strict_neq?",
_fn._1
]);
return ;
case /* Ok */4 :
console.log([
name,
_fn._0,
"ok?"
]);
return ;
case /* Approx */5 :
console.log([
name,
_fn._0,
"~",
_fn._1
]);
return ;
case /* ApproxThreshold */6 :
console.log([
name,
_fn._1,
"~",
_fn._2,
" (",
_fn._0,
")"
]);
return ;
case /* ThrowAny */7 :
return ;
case /* Fail */8 :
console.log("failed");
return ;
case /* FailWith */9 :
console.log("failed: " + _fn._0);
return ;
}
}), suites);
const name = param[0];
const _fn = Curry._1(param[1], undefined);
switch (_fn.TAG) {
case /* Eq */0 :
console.log([
name,
_fn._0,
"eq?",
_fn._1
]);
return ;
case /* Neq */1 :
console.log([
name,
_fn._0,
"neq?",
_fn._1
]);
return ;
case /* StrictEq */2 :
console.log([
name,
_fn._0,
"strict_eq?",
_fn._1
]);
return ;
case /* StrictNeq */3 :
console.log([
name,
_fn._0,
"strict_neq?",
_fn._1
]);
return ;
case /* Ok */4 :
console.log([
name,
_fn._0,
"ok?"
]);
return ;
case /* Approx */5 :
console.log([
name,
_fn._0,
"~",
_fn._1
]);
return ;
case /* ApproxThreshold */6 :
console.log([
name,
_fn._1,
"~",
_fn._2,
" (",
_fn._0,
")"
]);
return ;
case /* ThrowAny */7 :
return ;
case /* Fail */8 :
console.log("failed");
return ;
case /* FailWith */9 :
console.log("failed: " + _fn._0);
return ;

}
}), suites);
}
}

Expand All @@ -199,14 +199,14 @@ function from_promise_suites(name, suites) {
if (is_mocha(undefined)) {
describe(name, (function () {
return Stdlib__List.iter((function (param) {
const code = param[1];
it(param[0], (function () {
return code.then(function (x) {
handleCode(x);
return val_unit;
});
}));
}), suites);
const code = param[1];
it(param[0], (function () {
return code.then(function (x) {
handleCode(x);
return val_unit;
});
}));
}), suites);
}));
} else {
console.log("promise suites");
Expand All @@ -223,10 +223,10 @@ function eq_suites(test_id, suites, loc, x, y) {
loc + (" id " + String(test_id.contents)),
(function (param) {
return {
TAG: /* Eq */0,
_0: x,
_1: y
};
TAG: /* Eq */0,
_0: x,
_1: y
};
})
],
tl: suites.contents
Expand All @@ -240,9 +240,9 @@ function bool_suites(test_id, suites, loc, x) {
loc + (" id " + String(test_id.contents)),
(function (param) {
return {
TAG: /* Ok */4,
_0: x
};
TAG: /* Ok */4,
_0: x
};
})
],
tl: suites.contents
Expand All @@ -256,9 +256,9 @@ function throw_suites(test_id, suites, loc, x) {
loc + (" id " + String(test_id.contents)),
(function (param) {
return {
TAG: /* ThrowAny */7,
_0: x
};
TAG: /* ThrowAny */7,
_0: x
};
})
],
tl: suites.contents
Expand Down
6 changes: 3 additions & 3 deletions jscomp/test/dist/jscomp/test/406_primitive_test.js

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

8 changes: 4 additions & 4 deletions jscomp/test/dist/jscomp/test/a_filename_test.js

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

Loading

0 comments on commit 0231b5a

Please sign in to comment.