Skip to content

Commit

Permalink
Fix indent in the generated js code (#6747)
Browse files Browse the repository at this point in the history
* Fix indent in the generated js code

* Update test's compiled files

* Update changelog

* Update changelog
  • Loading branch information
DZakh authored Apr 29, 2024
1 parent 4738476 commit 9bae27c
Show file tree
Hide file tree
Showing 364 changed files with 23,514 additions and 23,513 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- Remove redundant space for export in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6560
- Remove empty export blocks in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6744
- Fix indent for returned/thrown/wrapped in parentheses objects in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6746
- Fix indent in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6747

# 11.1.0

Expand Down
38 changes: 19 additions & 19 deletions jscomp/core/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ and pp_function ~return_unit ~async ~is_method cxt (f : P.t) ~fn_state
param_body ()
| No_name { single_arg } ->
(* see # 1692, add a paren for annoymous function for safety *)
P.cond_paren_group f (not single_arg) 1 (fun _ ->
P.cond_paren_group f (not single_arg) (fun _ ->
P.string f (L.function_async ~async);
P.space f;
param_body ())
Expand Down Expand Up @@ -526,7 +526,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
bool f b;
cxt
| Seq (e1, e2) ->
P.cond_paren_group f (level > 0) 1 (fun () ->
P.cond_paren_group f (level > 0) (fun () ->
let cxt = expression ~level:0 cxt f e1 in
comma_sp f;
expression ~level:0 cxt f e2)
Expand All @@ -544,12 +544,12 @@ and expression_desc cxt ~(level : int) f x : cxt =
]}
*)
| Call (e, el, info) ->
P.cond_paren_group f (level > 15) 1 (fun _ ->
P.group f 1 (fun _ ->
P.cond_paren_group f (level > 15) (fun _ ->
P.group f 0 (fun _ ->
match (info, el) with
| { arity = Full }, _ | _, [] ->
let cxt = expression ~level:15 cxt f e in
P.paren_group f 1 (fun _ ->
P.paren_group f 0 (fun _ ->
match el with
| [
{
Expand Down Expand Up @@ -580,13 +580,13 @@ and expression_desc cxt ~(level : int) f x : cxt =
let len = List.length el in
if 1 <= len && len <= 8 then (
Curry_gen.pp_app f len;
P.paren_group f 1 (fun _ -> arguments cxt f (e :: el)))
P.paren_group f 0 (fun _ -> arguments cxt f (e :: el)))
else (
Curry_gen.pp_app_any f;
P.paren_group f 1 (fun _ ->
P.paren_group f 0 (fun _ ->
arguments cxt f [ e; E.array Mutable el ]))))
| FlatCall (e, el) ->
P.group f 1 (fun _ ->
P.group f 0 (fun _ ->
let cxt = expression ~level:15 cxt f e in
P.string f L.dot;
P.string f L.apply;
Expand Down Expand Up @@ -676,15 +676,15 @@ and expression_desc cxt ~(level : int) f x : cxt =
if need_paren then P.paren f action else action ();
cxt
| Is_null_or_undefined e ->
P.cond_paren_group f (level > 0) 1 (fun _ ->
P.cond_paren_group f (level > 0) (fun _ ->
let cxt = expression ~level:1 cxt f e in
P.space f;
P.string f "==";
P.space f;
P.string f L.null;
cxt)
| Js_not e ->
P.cond_paren_group f (level > 13) 1 (fun _ ->
P.cond_paren_group f (level > 13) (fun _ ->
P.string f "!";
expression ~level:13 cxt f e)
| Typeof e ->
Expand All @@ -704,7 +704,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
{[ 0.00 - x ]}
{[ 0.000 - x ]}
*) ->
P.cond_paren_group f (level > 13) 1 (fun _ ->
P.cond_paren_group f (level > 13) (fun _ ->
P.string f (match desc with Float _ -> "- " | _ -> "-");
expression ~level:13 cxt f e)
| Bin (op, e1, e2) ->
Expand All @@ -714,7 +714,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
in
(* We are more conservative here, to make the generated code more readable
to the user *)
P.cond_paren_group f need_paren 1 (fun _ ->
P.cond_paren_group f need_paren (fun _ ->
let cxt = expression ~level:lft cxt f e1 in
P.space f;
P.string f (Js_op_util.op_str op);
Expand All @@ -726,7 +726,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
let need_paren =
level > out || match op with Lsl | Lsr | Asr -> true | _ -> false
in
P.cond_paren_group f need_paren 1 (fun _ ->
P.cond_paren_group f need_paren (fun _ ->
let cxt = expression ~level:lft cxt f e1 in
P.space f;
P.string f "+";
Expand Down Expand Up @@ -862,12 +862,12 @@ and expression_desc cxt ~(level : int) f x : cxt =
P.string f tag;
cxt)
| Array_index (e, p) ->
P.cond_paren_group f (level > 15) 1 (fun _ ->
P.cond_paren_group f (level > 15) (fun _ ->
P.group f 1 (fun _ ->
let cxt = expression ~level:15 cxt f e in
P.bracket_group f 1 (fun _ -> expression ~level:0 cxt f p)))
| Static_index (e, s, _) ->
P.cond_paren_group f (level > 15) 1 (fun _ ->
P.cond_paren_group f (level > 15) (fun _ ->
let cxt = expression ~level:15 cxt f e in
Js_dump_property.property_access f s;
(* See [ .obj_of_exports]
Expand All @@ -877,13 +877,13 @@ and expression_desc cxt ~(level : int) f x : cxt =
cxt)
| Length (e, _) ->
(*Todo: check parens *)
P.cond_paren_group f (level > 15) 1 (fun _ ->
P.cond_paren_group f (level > 15) (fun _ ->
let cxt = expression ~level:15 cxt f e in
P.string f L.dot;
P.string f L.length;
cxt)
| New (e, el) ->
P.cond_paren_group f (level > 15) 1 (fun _ ->
P.cond_paren_group f (level > 15) (fun _ ->
P.group f 1 (fun _ ->
P.string f L.new_;
P.space f;
Expand Down Expand Up @@ -916,14 +916,14 @@ and expression_desc cxt ~(level : int) f x : cxt =
var f = { x : 2 , y : 2}
]}
*)
P.cond_paren_group f (level > 1) 0 (fun _ ->
P.cond_paren_group f (level > 1) (fun _ ->
if lst = [] then (
P.string f "{}";
cxt)
else
P.brace_vgroup f 1 (fun _ -> property_name_and_value_list cxt f lst))
| Await e ->
P.cond_paren_group f (level > 13) 1 (fun _ ->
P.cond_paren_group f (level > 13) (fun _ ->
P.string f "await ";
expression ~level:13 cxt f e)

Expand Down
4 changes: 2 additions & 2 deletions jscomp/ext/ext_pp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ let paren_vgroup st n action =

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

let cond_paren_group st b n action =
if b then paren_group st n action else action ()
let cond_paren_group st b action =
if b then paren_group st 0 action else action ()

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

Expand Down
2 changes: 1 addition & 1 deletion jscomp/ext/ext_pp.mli
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ val brace : t -> (unit -> 'a) -> 'a

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

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

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

Expand Down
6 changes: 3 additions & 3 deletions jscomp/test/406_primitive_test.js

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

52 changes: 26 additions & 26 deletions jscomp/test/Import.js

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

10 changes: 5 additions & 5 deletions jscomp/test/SafePromises.js

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

18 changes: 9 additions & 9 deletions jscomp/test/UncurriedAlways.js

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

Loading

0 comments on commit 9bae27c

Please sign in to comment.