Skip to content

Fix returning object in nested Some #7013

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

Merged
merged 2 commits into from
Sep 6, 2024
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: 5 additions & 3 deletions jscomp/core/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ let raw_snippet_exp_simple_enough (s : string) =

(* e = function(x){...}(x); is good
*)
let exp_need_paren (e : J.expression) =
let rec exp_need_paren ?(arrow=false) (e : J.expression) =
match e.expression_desc with
(* | Caml_uninitialized_obj _ *)
| Call ({ expression_desc = Raw_js_code _ }, _, _) -> true
Expand All @@ -178,11 +178,13 @@ let exp_need_paren (e : J.expression) =
| Length _ | Call _ | Caml_block_tag _ | Seq _ | Static_index _ | Cond _
| Bin _ | Is_null_or_undefined _ | String_index _ | Array_index _
| String_append _ | Var _ | Undefined _ | Null | Str _ | Array _
| Optional_block _ | Caml_block _ | FlatCall _ | Typeof _ | Number _
| Caml_block _ | FlatCall _ | Typeof _ | Number _
| Js_not _ | Bool _ | New _ ->
false
| Await _ -> false
| Tagged_template _ -> false
| Optional_block (e, true) when arrow -> exp_need_paren ~arrow e
| Optional_block _ -> false

(** Print as underscore for unused vars, may not be
needed in the future *)
Expand Down Expand Up @@ -411,7 +413,7 @@ and pp_function ~return_unit ~async ~is_method ?directive cxt (f : P.t) ~fn_stat

| [ { statement_desc = Return e } ] | [ { statement_desc = Exp e } ]
when arrow && directive == None
-> (if exp_need_paren e then P.paren_group f 0 else P.group f 0)
-> (if exp_need_paren ~arrow e then P.paren_group f 0 else P.group f 0)
(fun _ -> ignore (expression ~level:0 cxt f e))

| _ ->
Expand Down
3 changes: 2 additions & 1 deletion jscomp/test/build.ninja

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions jscomp/test/gpr_7012_test.js

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

5 changes: 5 additions & 0 deletions jscomp/test/gpr_7012_test.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type t = {a: int, b: int}

let f1 = () => () => Some({a: 1, b: 2})

let f2 = () => Some(Some(Some({a: 1, b: 2})))