Skip to content

Commit 53f40b6

Browse files
committed
Merge branch 'master' into js-exn-fix
2 parents 286c097 + 6077950 commit 53f40b6

File tree

410 files changed

+24902
-25347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

410 files changed

+24902
-25347
lines changed

Diff for: CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@
1212
1313
# 12.0.0-alpha.2 (Unreleased)
1414

15+
#### :nail_care: Polish
16+
17+
- Improve formatting in the generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6932
18+
- `}\ncatch{` -> `} catch {`
19+
- `for(let i = 0 ,i_finish = r.length; i < i_finish; ++i){` -> `for (let i = 0, i_finish = r.length; i < i_finish; ++i) {`
20+
- `while(true) {` -> `while (true) {`
21+
- Fixed tabulation for `switch case` bodies
22+
- Fixed tabulation for `throw new Error` bodies
23+
- Removed empty line at the end of `switch` statement
24+
- Removed empty `default` case from `switch` statement in the generated code
25+
1526
# 12.0.0-alpha.1
1627

1728
#### :rocket: New Feature

Diff for: jscomp/core/js_dump.ml

+17-12
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ let debugger_nl f =
248248

249249
let break_nl f =
250250
P.string f L.break;
251-
P.space f;
252251
semi f;
253252
P.newline f
254253

@@ -430,17 +429,18 @@ and pp_one_case_clause :
430429
'a. _ -> P.t -> (P.t -> 'a -> unit) -> 'a * J.case_clause -> _ =
431430
fun cxt f pp_cond
432431
(switch_case, ({ switch_body; should_break; comment } : J.case_clause)) ->
432+
P.newline f;
433433
let cxt =
434434
P.group f 1 (fun _ ->
435-
P.group f 1 (fun _ ->
435+
P.group f 0 (fun _ ->
436436
P.string f L.case;
437437
P.space f;
438438
pp_comment_option f comment;
439439
pp_cond f switch_case;
440440
(* could be integer or string *)
441441
P.space f;
442442
P.string f L.colon);
443-
P.group f 1 (fun _ ->
443+
P.group f 0 (fun _ ->
444444
let cxt =
445445
match switch_body with
446446
| [] -> cxt
@@ -454,7 +454,6 @@ and pp_one_case_clause :
454454
semi f);
455455
cxt))
456456
in
457-
P.newline f;
458457
cxt
459458

460459
and loop_case_clauses :
@@ -858,11 +857,11 @@ and expression_desc cxt ~(level : int) f x : cxt =
858857
cxt)
859858
| New (e, el) ->
860859
P.cond_paren_group f (level > 15) (fun _ ->
861-
P.group f 1 (fun _ ->
860+
P.group f 0 (fun _ ->
862861
P.string f L.new_;
863862
P.space f;
864863
let cxt = expression ~level:16 cxt f e in
865-
P.paren_group f 1 (fun _ ->
864+
P.paren_group f 0 (fun _ ->
866865
match el with Some el -> arguments cxt f el | None -> cxt)))
867866
| Cond (e, e1, e2) ->
868867
let action () =
@@ -1045,13 +1044,15 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
10451044
match e.expression_desc with
10461045
| Number (Int { i = 1l }) ->
10471046
P.string f L.while_;
1047+
P.space f;
10481048
P.string f L.lparen;
10491049
P.string f L.true_;
10501050
P.string f L.rparen;
10511051
P.space f;
10521052
cxt
10531053
| _ ->
10541054
P.string f L.while_;
1055+
P.space f;
10551056
let cxt =
10561057
P.paren_group f 1 (fun _ -> expression ~level:0 cxt f e)
10571058
in
@@ -1068,7 +1069,8 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
10681069
P.group f 0 (fun _ ->
10691070
(* The only place that [semi] may have semantics here *)
10701071
P.string f L.for_;
1071-
P.paren_group f 1 (fun _ ->
1072+
P.space f;
1073+
let ctx = P.paren_group f 1 (fun _ ->
10721074
let cxt, new_id =
10731075
match
10741076
(for_ident_expression, finish.expression_desc)
@@ -1081,8 +1083,8 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
10811083
let cxt =
10821084
expression ~level:1 cxt f ident_expression
10831085
in
1084-
P.space f;
10851086
comma f;
1087+
P.space f;
10861088
let id =
10871089
Ext_ident.create (Ident.name id ^ "_finish")
10881090
in
@@ -1128,7 +1130,9 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
11281130
semi f;
11291131
P.space f;
11301132
pp_direction f direction;
1131-
Ext_pp_scope.ident cxt f id))
1133+
Ext_pp_scope.ident cxt f id) in
1134+
P.space f;
1135+
ctx)
11321136
in
11331137
brace_block cxt f s)
11341138
in
@@ -1177,6 +1181,7 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
11771181
match def with
11781182
| None -> cxt
11791183
| Some def ->
1184+
P.newline f;
11801185
P.group f 1 (fun _ ->
11811186
P.string f L.default;
11821187
P.string f L.colon;
@@ -1195,6 +1200,7 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
11951200
match def with
11961201
| None -> cxt
11971202
| Some def ->
1203+
P.newline f;
11981204
P.group f 1 (fun _ ->
11991205
P.string f L.default;
12001206
P.string f L.colon;
@@ -1224,10 +1230,9 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
12241230
match ctch with
12251231
| None -> cxt
12261232
| Some (i, b) ->
1227-
P.newline f;
1228-
P.string f "catch (";
1233+
P.string f " catch (";
12291234
let cxt = Ext_pp_scope.ident cxt f i in
1230-
P.string f ")";
1235+
P.string f ") ";
12311236
brace_block cxt f b
12321237
in
12331238
match fin with

Diff for: jscomp/core/lam_compile.ml

+4-1
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,10 @@ and compile_general_cases :
584584
| Complete -> None
585585
| NonComplete -> None
586586
| Default lam ->
587-
Some (Js_output.output_as_block (compile_lambda cxt lam))
587+
let statements = Js_output.output_as_block (compile_lambda cxt lam) in
588+
match statements with
589+
| [] -> None
590+
| _ -> Some statements
588591
in
589592
let body =
590593
group_apply ~merge_cases cases (fun last (switch_case, lam) ->

Diff for: jscomp/gentype_tests/typescript-react-example/src/NestedVariants.res.js

+15-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: jscomp/gentype_tests/typescript-react-example/src/VariantsWithPayload.res.js

+9-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: jscomp/others/belt_HashSetInt.resi

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
2424

2525
/***
26-
This module is [`Belt.HashSet`]() specialized with key type to be a primitive type.
26+
This module is [`Belt.HashSet`]() specialized with key type to be a primitive type.
2727

28-
It is more efficient in general, the API is the same with [`Belt.HashSet`]() except its key type is fixed,
29-
and identity is not needed(using the built-in one)
28+
It is more efficient in general, the API is the same with [`Belt.HashSet`]() except its key type is fixed,
29+
and identity is not needed(using the built-in one)
3030

31-
**See** [`Belt.HashSet`]()
31+
**See** [`Belt.HashSet`]()
3232
*/
3333

3434
type key = int

Diff for: jscomp/others/belt_HashSetString.resi

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
2424

2525
/***
26-
This module is [`Belt.HashSet`]() specialized with key type to be a primitive type.
26+
This module is [`Belt.HashSet`]() specialized with key type to be a primitive type.
2727

28-
It is more efficient in general, the API is the same with [`Belt.HashSet`]() except its key type is fixed,
29-
and identity is not needed(using the built-in one)
28+
It is more efficient in general, the API is the same with [`Belt.HashSet`]() except its key type is fixed,
29+
and identity is not needed(using the built-in one)
3030

31-
**See** [`Belt.HashSet`]()
31+
**See** [`Belt.HashSet`]()
3232
*/
3333

3434
type key = string

Diff for: jscomp/others/belt_SetInt.resi

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
2424

2525
/***
26-
This module is [`Belt.Set`]() specialized with value type to be a primitive type.
27-
It is more efficient in general, the API is the same with [`Belt_Set`]() except its value type is fixed,
28-
and identity is not needed(using the built-in one)
26+
This module is [`Belt.Set`]() specialized with value type to be a primitive type.
27+
It is more efficient in general, the API is the same with [`Belt_Set`]() except its value type is fixed,
28+
and identity is not needed(using the built-in one)
2929

30-
**See** [`Belt.Set`]()
30+
**See** [`Belt.Set`]()
3131
*/
3232

3333
/** The type of the set elements. */
@@ -77,7 +77,7 @@ of sets.
7777
*/
7878
let cmp: (t, t) => int
7979

80-
/**
80+
/**
8181
`eq(s1, s2)` tests whether the sets `s1` and `s2` are equal, that is, contain
8282
equal elements.
8383
*/
@@ -105,7 +105,7 @@ let every: (t, value => bool) => bool
105105

106106
let someU: (t, (. value) => bool) => bool
107107

108-
/**
108+
/**
109109
`some(p, s)` checks if at least one element of the set satisfies the predicate
110110
`p`. Oder unspecified.
111111
*/

Diff for: jscomp/others/belt_SetString.resi

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
2424

2525
/***
26-
This module is [`Belt.Set`]() specialized with value type to be a primitive type.
27-
It is more efficient in general, the API is the same with [`Belt_Set`]() except its value type is fixed,
28-
and identity is not needed(using the built-in one)
26+
This module is [`Belt.Set`]() specialized with value type to be a primitive type.
27+
It is more efficient in general, the API is the same with [`Belt_Set`]() except its value type is fixed,
28+
and identity is not needed(using the built-in one)
2929

30-
**See** [`Belt.Set`]()
30+
**See** [`Belt.Set`]()
3131
*/
3232

3333
/** The type of the set elements. */
@@ -77,7 +77,7 @@ of sets.
7777
*/
7878
let cmp: (t, t) => int
7979

80-
/**
80+
/**
8181
`eq(s1, s2)` tests whether the sets `s1` and `s2` are equal, that is, contain
8282
equal elements.
8383
*/
@@ -105,7 +105,7 @@ let every: (t, value => bool) => bool
105105

106106
let someU: (t, (. value) => bool) => bool
107107

108-
/**
108+
/**
109109
`some(p, s)` checks if at least one element of the set satisfies the predicate
110110
`p`. Oder unspecified.
111111
*/
File renamed without changes.

Diff for: jscomp/others/belt_Set.cppo.resi renamed to jscomp/others_cppo/belt_Set.cppo.resi

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
2424

2525
/***
26-
This module is [`Belt.Set`]() specialized with value type to be a primitive type.
27-
It is more efficient in general, the API is the same with [`Belt_Set`]() except its value type is fixed,
28-
and identity is not needed(using the built-in one)
26+
This module is [`Belt.Set`]() specialized with value type to be a primitive type.
27+
It is more efficient in general, the API is the same with [`Belt_Set`]() except its value type is fixed,
28+
and identity is not needed(using the built-in one)
2929

30-
**See** [`Belt.Set`]()
30+
**See** [`Belt.Set`]()
3131
*/
3232

3333
#ifdef TYPE_STRING
@@ -84,7 +84,7 @@ of sets.
8484
*/
8585
let cmp: (t, t) => int
8686

87-
/**
87+
/**
8888
`eq(s1, s2)` tests whether the sets `s1` and `s2` are equal, that is, contain
8989
equal elements.
9090
*/
@@ -112,7 +112,7 @@ let every: (t, value => bool) => bool
112112

113113
let someU: (t, (. value) => bool) => bool
114114

115-
/**
115+
/**
116116
`some(p, s)` checks if at least one element of the set satisfies the predicate
117117
`p`. Oder unspecified.
118118
*/
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: jscomp/others/hashset.cppo.resi renamed to jscomp/others_cppo/hashset.cppo.resi

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
2424

2525
/***
26-
This module is [`Belt.HashSet`]() specialized with key type to be a primitive type.
26+
This module is [`Belt.HashSet`]() specialized with key type to be a primitive type.
2727

28-
It is more efficient in general, the API is the same with [`Belt.HashSet`]() except its key type is fixed,
29-
and identity is not needed(using the built-in one)
28+
It is more efficient in general, the API is the same with [`Belt.HashSet`]() except its key type is fixed,
29+
and identity is not needed(using the built-in one)
3030

31-
**See** [`Belt.HashSet`]()
31+
**See** [`Belt.HashSet`]()
3232
*/
3333

3434
#ifdef TYPE_STRING
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)