Skip to content

Commit 06881d9

Browse files
committed
emit arrow syntax for non top level functions
1 parent 8a28daf commit 06881d9

File tree

349 files changed

+2875
-2865
lines changed

Some content is hidden

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

349 files changed

+2875
-2865
lines changed

jscomp/build_tests/react_ppx/src/gpr_3987_test.bs.js

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

jscomp/core/js_dump.ml

+14-8
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,12 @@ and pp_function ~return_unit ~async ~is_method ?directive cxt (f : P.t) ~fn_stat
360360
(* the context will be continued after this function *)
361361
let outer_cxt = Ext_pp_scope.merge cxt set_env in
362362

363+
(* whether the function output can use arrow syntax *)
364+
let arrow = match fn_state with
365+
| Name_top _ -> false
366+
| _ -> not is_method
367+
in
368+
363369
(* the context used to be printed inside this function
364370
365371
when printing a function,
@@ -388,6 +394,10 @@ and pp_function ~return_unit ~async ~is_method ?directive cxt (f : P.t) ~fn_stat
388394
P.paren_group f 1 (fun _ -> formal_parameter_list inner_cxt f l)
389395
in
390396
P.space f;
397+
if arrow then (
398+
P.string f (L.arrow);
399+
P.space f;
400+
);
391401
P.brace_vgroup f 1 (fun _ -> function_body ?directive ~return_unit cxt f b)
392402
in
393403
let enclose () =
@@ -396,24 +406,20 @@ and pp_function ~return_unit ~async ~is_method ?directive cxt (f : P.t) ~fn_stat
396406
match fn_state with
397407
| Is_return ->
398408
return_sp f;
399-
P.string f (L.function_async ~async);
400-
P.space f;
409+
P.string f (L.function_ ~async ~arrow);
401410
param_body ()
402411
| No_name { single_arg } ->
403412
(* see # 1692, add a paren for annoymous function for safety *)
404413
P.cond_paren_group f (not single_arg) (fun _ ->
405-
P.string f (L.function_async ~async);
406-
P.space f;
414+
P.string f (L.function_ ~async ~arrow);
407415
param_body ())
408416
| Name_non_top x ->
409417
ignore (pp_var_assign inner_cxt f x : cxt);
410-
P.string f (L.function_async ~async);
411-
P.space f;
418+
P.string f (L.function_ ~async ~arrow);
412419
param_body ();
413420
semi f
414421
| Name_top x ->
415-
P.string f (L.function_async ~async);
416-
P.space f;
422+
P.string f (L.function_ ~async ~arrow);
417423
ignore (Ext_pp_scope.ident inner_cxt f x : cxt);
418424
param_body ())
419425
in

jscomp/core/js_dump_lit.ml

+7-3
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25-
2625
let await = "await"
2726

28-
let function_ = "function"
27+
let function_ ~async ~arrow =
28+
match (async, arrow) with
29+
| (true, true) -> "async "
30+
| (false, true) -> ""
31+
| (true, false) -> "async function "
32+
| (false, false) -> "function "
2933

30-
let function_async ~async = if async then "async function" else "function"
34+
let arrow = "=>"
3135

3236
let let_ = "let"
3337

jscomp/test/Import.js

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

jscomp/test/PartialApplicationNoRuntimeCurry.js

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

jscomp/test/SafePromises.js

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

jscomp/test/UncurriedAlways.js

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

jscomp/test/UncurriedExternals.js

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

jscomp/test/UntaggedVariants.js

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

jscomp/test/a_filename_test.js

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

jscomp/test/a_list_test.js

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

jscomp/test/a_string_test.js

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

jscomp/test/and_or_tailcall_test.js

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

jscomp/test/ari_regress_test.js

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

0 commit comments

Comments
 (0)