From f18e5644251d741d025c4e70a82487ee1853af70 Mon Sep 17 00:00:00 2001 From: Hongbo Zhang Date: Wed, 25 May 2016 10:38:32 -0400 Subject: [PATCH] provide attributes support for application [f a] --- jscomp/ppx_entry.ml | 39 +++++++++++++++++---------------------- jscomp/test/attr_test.ml | 2 +- jscomp/test/test_react.ml | 4 ++-- lib/js/test/attr_test.js | 3 +++ 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/jscomp/ppx_entry.ml b/jscomp/ppx_entry.ml index d53b167648..73e34b702b 100644 --- a/jscomp/ppx_entry.ml +++ b/jscomp/ppx_entry.ml @@ -679,23 +679,6 @@ let rec unsafe_mapper : Ast_mapper.mapper = | Pexp_extension ({txt = "bs.debugger"; loc} , payload) -> handle_debugger loc payload (** End rewriting *) - (* | Pexp_extension *) - (* ({txt = "uncurry";loc}, *) - (* PStr *) - (* [{ *) - (* pstr_desc = *) - (* Pstr_eval *) - (* ({pexp_desc = *) - (* Pexp_fun ("", None, pat , *) - (* body)}, *) - (* _)}]) *) - (* -> *) - (* begin match body.pexp_desc with *) - (* | Pexp_fun _ -> *) - (* Location.raise_errorf ~loc *) - (* "`fun %%uncurry (param0, param1) -> ` instead of `fun %%uncurry param0 param1 ->` " *) - (* | _ -> handle_uncurry_generation loc pat body e mapper *) - (* end *) | Pexp_fun ("", None, pat , body) -> let loc = e.pexp_loc in @@ -710,12 +693,12 @@ let rec unsafe_mapper : Ast_mapper.mapper = Location.raise_errorf ~loc {| `fun [@uncurry] (param0, param1) -> ` instead of `fun [@uncurry] param0 param1 ->` |} - | _ -> - handle_uncurry_generation loc pat body - {e with pexp_attributes = attrs } mapper - end - + | _ -> + handle_uncurry_generation loc pat body + {e with pexp_attributes = attrs } mapper + end end + | Pexp_apply ({pexp_desc = Pexp_ident {txt = Lident "#@"; loc}}, [("", fn); ("", pat)]) @@ -752,6 +735,18 @@ let rec unsafe_mapper : Ast_mapper.mapper = ) ) ]) -> handle_obj_property loc obj name e mapper + | Pexp_apply (fn, + [("", pat)]) -> + let loc = e.pexp_loc in + begin match Ext_list.exclude_with_fact (function + | {Location.txt = "uncurry"; _}, _ -> true + | _ -> false) e.pexp_attributes with + | None, _ -> Ast_mapper.default_mapper.expr mapper e + | Some _, attrs -> + handle_uncurry_application loc fn pat + {e with pexp_attributes = attrs} mapper + end + | Pexp_record (label_exprs, None) -> begin match (* exclude {[ u with ..]} syntax currently *) Ext_list.exclude_with_fact diff --git a/jscomp/test/attr_test.ml b/jscomp/test/attr_test.ml index d9fe8acb27..02768e1186 100644 --- a/jscomp/test/attr_test.ml +++ b/jscomp/test/attr_test.ml @@ -1,7 +1,7 @@ let u = fun [@uncurry] (x,y) -> x + y -(* let h = u (1,2) [@uncurry] *) +let h = u (1,2) [@uncurry] type u = < v : int ; y : int > [@uncurry] diff --git a/jscomp/test/test_react.ml b/jscomp/test/test_react.ml index f9d05d34d1..9bd551709a 100644 --- a/jscomp/test/test_react.ml +++ b/jscomp/test/test_react.ml @@ -12,8 +12,8 @@ type doc = document Js.t external doc : doc = "doc" [@@bs.val ] class type con = - object - method log : 'a -> unit [@uncurry] + object [@uncurry] + method log : 'a -> unit end type console = con Js.t diff --git a/lib/js/test/attr_test.js b/lib/js/test/attr_test.js index ffb10dc6f9..6ae47f4bcb 100644 --- a/lib/js/test/attr_test.js +++ b/lib/js/test/attr_test.js @@ -6,5 +6,8 @@ function u(x, y) { return x + y | 0; } +var h = u(1, 2); + exports.u = u; +exports.h = h; /* u Not a pure module */