Skip to content

Commit 9bae27c

Browse files
authored
Fix indent in the generated js code (#6747)
* Fix indent in the generated js code * Update test's compiled files * Update changelog * Update changelog
1 parent 4738476 commit 9bae27c

File tree

364 files changed

+23514
-23513
lines changed

Some content is hidden

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

364 files changed

+23514
-23513
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
- Remove redundant space for export in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6560
3131
- Remove empty export blocks in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6744
3232
- Fix indent for returned/thrown/wrapped in parentheses objects in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6746
33+
- Fix indent in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6747
3334

3435
# 11.1.0
3536

jscomp/core/js_dump.ml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ and pp_function ~return_unit ~async ~is_method cxt (f : P.t) ~fn_state
393393
param_body ()
394394
| No_name { single_arg } ->
395395
(* see # 1692, add a paren for annoymous function for safety *)
396-
P.cond_paren_group f (not single_arg) 1 (fun _ ->
396+
P.cond_paren_group f (not single_arg) (fun _ ->
397397
P.string f (L.function_async ~async);
398398
P.space f;
399399
param_body ())
@@ -526,7 +526,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
526526
bool f b;
527527
cxt
528528
| Seq (e1, e2) ->
529-
P.cond_paren_group f (level > 0) 1 (fun () ->
529+
P.cond_paren_group f (level > 0) (fun () ->
530530
let cxt = expression ~level:0 cxt f e1 in
531531
comma_sp f;
532532
expression ~level:0 cxt f e2)
@@ -544,12 +544,12 @@ and expression_desc cxt ~(level : int) f x : cxt =
544544
]}
545545
*)
546546
| Call (e, el, info) ->
547-
P.cond_paren_group f (level > 15) 1 (fun _ ->
548-
P.group f 1 (fun _ ->
547+
P.cond_paren_group f (level > 15) (fun _ ->
548+
P.group f 0 (fun _ ->
549549
match (info, el) with
550550
| { arity = Full }, _ | _, [] ->
551551
let cxt = expression ~level:15 cxt f e in
552-
P.paren_group f 1 (fun _ ->
552+
P.paren_group f 0 (fun _ ->
553553
match el with
554554
| [
555555
{
@@ -580,13 +580,13 @@ and expression_desc cxt ~(level : int) f x : cxt =
580580
let len = List.length el in
581581
if 1 <= len && len <= 8 then (
582582
Curry_gen.pp_app f len;
583-
P.paren_group f 1 (fun _ -> arguments cxt f (e :: el)))
583+
P.paren_group f 0 (fun _ -> arguments cxt f (e :: el)))
584584
else (
585585
Curry_gen.pp_app_any f;
586-
P.paren_group f 1 (fun _ ->
586+
P.paren_group f 0 (fun _ ->
587587
arguments cxt f [ e; E.array Mutable el ]))))
588588
| FlatCall (e, el) ->
589-
P.group f 1 (fun _ ->
589+
P.group f 0 (fun _ ->
590590
let cxt = expression ~level:15 cxt f e in
591591
P.string f L.dot;
592592
P.string f L.apply;
@@ -676,15 +676,15 @@ and expression_desc cxt ~(level : int) f x : cxt =
676676
if need_paren then P.paren f action else action ();
677677
cxt
678678
| Is_null_or_undefined e ->
679-
P.cond_paren_group f (level > 0) 1 (fun _ ->
679+
P.cond_paren_group f (level > 0) (fun _ ->
680680
let cxt = expression ~level:1 cxt f e in
681681
P.space f;
682682
P.string f "==";
683683
P.space f;
684684
P.string f L.null;
685685
cxt)
686686
| Js_not e ->
687-
P.cond_paren_group f (level > 13) 1 (fun _ ->
687+
P.cond_paren_group f (level > 13) (fun _ ->
688688
P.string f "!";
689689
expression ~level:13 cxt f e)
690690
| Typeof e ->
@@ -704,7 +704,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
704704
{[ 0.00 - x ]}
705705
{[ 0.000 - x ]}
706706
*) ->
707-
P.cond_paren_group f (level > 13) 1 (fun _ ->
707+
P.cond_paren_group f (level > 13) (fun _ ->
708708
P.string f (match desc with Float _ -> "- " | _ -> "-");
709709
expression ~level:13 cxt f e)
710710
| Bin (op, e1, e2) ->
@@ -714,7 +714,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
714714
in
715715
(* We are more conservative here, to make the generated code more readable
716716
to the user *)
717-
P.cond_paren_group f need_paren 1 (fun _ ->
717+
P.cond_paren_group f need_paren (fun _ ->
718718
let cxt = expression ~level:lft cxt f e1 in
719719
P.space f;
720720
P.string f (Js_op_util.op_str op);
@@ -726,7 +726,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
726726
let need_paren =
727727
level > out || match op with Lsl | Lsr | Asr -> true | _ -> false
728728
in
729-
P.cond_paren_group f need_paren 1 (fun _ ->
729+
P.cond_paren_group f need_paren (fun _ ->
730730
let cxt = expression ~level:lft cxt f e1 in
731731
P.space f;
732732
P.string f "+";
@@ -862,12 +862,12 @@ and expression_desc cxt ~(level : int) f x : cxt =
862862
P.string f tag;
863863
cxt)
864864
| Array_index (e, p) ->
865-
P.cond_paren_group f (level > 15) 1 (fun _ ->
865+
P.cond_paren_group f (level > 15) (fun _ ->
866866
P.group f 1 (fun _ ->
867867
let cxt = expression ~level:15 cxt f e in
868868
P.bracket_group f 1 (fun _ -> expression ~level:0 cxt f p)))
869869
| Static_index (e, s, _) ->
870-
P.cond_paren_group f (level > 15) 1 (fun _ ->
870+
P.cond_paren_group f (level > 15) (fun _ ->
871871
let cxt = expression ~level:15 cxt f e in
872872
Js_dump_property.property_access f s;
873873
(* See [ .obj_of_exports]
@@ -877,13 +877,13 @@ and expression_desc cxt ~(level : int) f x : cxt =
877877
cxt)
878878
| Length (e, _) ->
879879
(*Todo: check parens *)
880-
P.cond_paren_group f (level > 15) 1 (fun _ ->
880+
P.cond_paren_group f (level > 15) (fun _ ->
881881
let cxt = expression ~level:15 cxt f e in
882882
P.string f L.dot;
883883
P.string f L.length;
884884
cxt)
885885
| New (e, el) ->
886-
P.cond_paren_group f (level > 15) 1 (fun _ ->
886+
P.cond_paren_group f (level > 15) (fun _ ->
887887
P.group f 1 (fun _ ->
888888
P.string f L.new_;
889889
P.space f;
@@ -916,14 +916,14 @@ and expression_desc cxt ~(level : int) f x : cxt =
916916
var f = { x : 2 , y : 2}
917917
]}
918918
*)
919-
P.cond_paren_group f (level > 1) 0 (fun _ ->
919+
P.cond_paren_group f (level > 1) (fun _ ->
920920
if lst = [] then (
921921
P.string f "{}";
922922
cxt)
923923
else
924924
P.brace_vgroup f 1 (fun _ -> property_name_and_value_list cxt f lst))
925925
| Await e ->
926-
P.cond_paren_group f (level > 13) 1 (fun _ ->
926+
P.cond_paren_group f (level > 13) (fun _ ->
927927
P.string f "await ";
928928
expression ~level:13 cxt f e)
929929

jscomp/ext/ext_pp.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ let paren_vgroup st n action =
160160

161161
let paren_group st n action = group st n (fun _ -> paren st action)
162162

163-
let cond_paren_group st b n action =
164-
if b then paren_group st n action else action ()
163+
let cond_paren_group st b action =
164+
if b then paren_group st 0 action else action ()
165165

166166
let brace_group st n action = group st n (fun _ -> brace st action)
167167

jscomp/ext/ext_pp.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ val brace : t -> (unit -> 'a) -> 'a
5656

5757
val paren_group : t -> int -> (unit -> 'a) -> 'a
5858

59-
val cond_paren_group : t -> bool -> int -> (unit -> 'a) -> 'a
59+
val cond_paren_group : t -> bool -> (unit -> 'a) -> 'a
6060

6161
val paren_vgroup : t -> int -> (unit -> 'a) -> 'a
6262

jscomp/test/406_primitive_test.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/Import.js

Lines changed: 26 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/SafePromises.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/UncurriedAlways.js

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)