Skip to content

Commit

Permalink
provide attributes support for application [f a]
Browse files Browse the repository at this point in the history
  • Loading branch information
Hongbo Zhang committed May 25, 2016
1 parent 16605ef commit f18e564
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 25 deletions.
39 changes: 17 additions & 22 deletions jscomp/ppx_entry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)])
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion jscomp/test/attr_test.ml
Original file line number Diff line number Diff line change
@@ -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]

Expand Down
4 changes: 2 additions & 2 deletions jscomp/test/test_react.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/js/test/attr_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit f18e564

Please sign in to comment.