Skip to content

Commit 30fadda

Browse files
author
Hongbo Zhang
committed
clean up unused code
1 parent 0ebef3f commit 30fadda

16 files changed

+67
-121
lines changed

jscomp/syntax/ast_util.ml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,6 @@ let down_with_name ~loc obj name =
5959
~pval_type:(downgrade ~loc ())
6060
~local_fun_name:"cast"
6161
(fun down -> Exp.send ~loc (Exp.apply ~loc down ["", obj]) name )
62-
63-
let destruct_tuple_exp (exp : Parsetree.expression) : Parsetree.expression list =
64-
match exp with
65-
| {pexp_desc =
66-
Pexp_tuple [arg ; {pexp_desc = Pexp_ident{txt = Lident "__"; _}} ]
67-
; _} ->
68-
[arg]
69-
| {pexp_desc = Pexp_tuple args; _} -> args
70-
| {pexp_desc = Pexp_construct ({txt = Lident "()"}, None); _} -> []
71-
| v -> [v]
72-
73-
74-
75-
76-
7762

7863
let gen_fn_run loc arity fn args : Parsetree.expression_desc =
7964
let pval_prim = ["js_fn_run" ; string_of_int arity] in

jscomp/syntax/ast_util.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ val destruct_arrow_as_meth :
8383
Parsetree.core_type -> Ast_mapper.mapper -> Parsetree.core_type
8484

8585

86-
val destruct_tuple_exp :
87-
Parsetree.expression -> Parsetree.expression list
8886

8987
val lift_js_type :
9088
loc:Ast_helper.loc -> Parsetree.core_type -> Parsetree.core_type

jscomp/syntax/ppx_entry.ml

Lines changed: 34 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -230,53 +230,42 @@ let handle_class_obj_typ
230230

231231

232232

233-
234-
235-
236-
237-
let handle_obj_method loc (obj : Parsetree.expression)
238-
name (value : Parsetree.expression) e
233+
let handle_obj_fns loc (obj : Parsetree.expression)
234+
name (args : (string * Parsetree.expression) list ) e
239235
(mapper : Ast_mapper.mapper) : Parsetree.expression =
240-
let value = mapper.expr mapper value in
241-
let obj = mapper.expr mapper obj in
242-
let args = Ast_util.destruct_tuple_exp value in
243-
let len = List.length args in
244-
{e with pexp_desc =
245-
Ast_util.gen_method_run loc len
246-
(Exp.mk ~loc (Ast_util.down_with_name ~loc obj name )) (obj::args)
247-
}
248-
249-
let handle_obj_fn loc (obj : Parsetree.expression)
250-
name (value : Parsetree.expression) e
251-
(mapper : Ast_mapper.mapper) : Parsetree.expression =
252-
let obj = mapper.expr mapper obj in
253-
let value = mapper.expr mapper value in
236+
let obj = mapper.expr mapper obj in
237+
let args =
238+
List.map (fun (label,e) ->
239+
if label <> "" then
240+
Location.raise_errorf ~loc "label is not allowed here" ;
241+
mapper.expr mapper e
242+
) args in
243+
let len = List.length args in
254244
let method_kind =
255245
if name = Literals.case_set then Case_setter
256246
else if Ext_string.ends_with name Literals.setter_suffix then Setter
257247
else Normal name in
258-
let len, args =
259-
match method_kind with
260-
| Setter ->
261-
1, [value]
262-
| (Case_setter | Normal _) ->
263-
let args = Ast_util.destruct_tuple_exp value in
264-
let arity = List.length args in
265-
if method_kind = Case_setter && arity <> 2 then
266-
Location.raise_errorf ~loc "case_set would expect arity of 2 "
267-
else arity, args
248+
let () =
249+
if method_kind = Setter && len <> 1 then
250+
Location.raise_errorf ~loc "setter expect single argument"
251+
else if method_kind = Case_setter && len <> 2 then
252+
Location.raise_errorf ~loc "case_set would expect arity of 2 "
268253
in
269-
{e with pexp_desc =
270-
Ast_util.gen_fn_run loc len
271-
(Exp.mk ~loc @@ Ast_util.down_with_name ~loc obj name)
272-
args
273-
}
274-
(** TODO:
275-
More syntax sanity check for [case_set]
276-
case_set: arity 2
277-
_set : arity 1
278-
case:
279-
*)
254+
match args with
255+
| [ {pexp_desc = Pexp_construct ({txt = Lident "()"}, None)}]
256+
->
257+
{e with pexp_desc =
258+
Ast_util.gen_fn_run loc 0
259+
(Exp.mk ~loc @@ Ast_util.down_with_name ~loc obj name)
260+
[]
261+
}
262+
| _ ->
263+
{e with pexp_desc =
264+
Ast_util.gen_fn_run loc len
265+
(Exp.mk ~loc @@ Ast_util.down_with_name ~loc obj name)
266+
args
267+
}
268+
280269

281270

282271
(* ./dumpast -e ' (Js.Unsafe.(!) obj) # property ' *)
@@ -371,33 +360,24 @@ let rec unsafe_mapper : Ast_mapper.mapper =
371360
| {pexp_desc =
372361
Pexp_apply (
373362
{pexp_desc =
374-
Pexp_ident {txt = Lident ("##" | "#." as n) ; loc} ; _},
363+
Pexp_ident {txt = Lident "##" ; loc} ; _},
375364
[("", obj) ;
376365
("", {pexp_desc = Pexp_ident {txt = Lident name;_ } ; _} )
377366
]);
378367
_
379368
} ->
380-
begin match args with
381-
| [ "", value] ->
382-
if n = "##" then
383-
handle_obj_fn loc obj name value e mapper
384-
else
385-
handle_obj_method loc obj name value e mapper
386-
| _ ->
387-
Location.raise_errorf ~loc
388-
"Js object %s expect only one argument when it is a method " n
389-
end
369+
handle_obj_fns loc obj name args e mapper
390370
| {pexp_desc =
391371
Pexp_ident {txt = Lident "##" ; loc} ; _}
392372
->
393373
begin match args with
394374
| [("", obj) ;
395375
("", {pexp_desc = Pexp_apply(
396376
{pexp_desc = Pexp_ident {txt = Lident name;_ } ; _},
397-
["", value]
377+
args
398378
) })
399379
] -> (* f##(paint (1,2)) *)
400-
handle_obj_fn loc obj name value e mapper
380+
handle_obj_fns loc obj name args e mapper
401381
| [("", obj) ;
402382
("",
403383
{pexp_desc = Pexp_ident {txt = Lident name;_ } ; _}
@@ -407,21 +387,6 @@ let rec unsafe_mapper : Ast_mapper.mapper =
407387
Location.raise_errorf ~loc
408388
"Js object ## expect syntax like obj##(paint (a,b)) "
409389
end
410-
| {pexp_desc =
411-
Pexp_ident {txt = Lident "#." ; loc} ; _}
412-
->
413-
begin match args with
414-
| [("", obj) ; (* f#.(paint (1,2)) *)
415-
("", {pexp_desc = Pexp_apply(
416-
{pexp_desc = Pexp_ident {txt = Lident name;_ } ; _},
417-
["", value]
418-
) })
419-
] ->
420-
handle_obj_method loc obj name value e mapper
421-
| _ ->
422-
Location.raise_errorf ~loc
423-
"Js object #. expect syntax like obj#.(paint (a,b)) "
424-
end
425390
| _ ->
426391
begin match Ext_list.exclude_with_fact (function
427392
| {Location.txt = "uncurry"; _}, _ -> true

jscomp/test/chain_code_test.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ let f2 h =
1313
h##x##y##z
1414

1515
let f3 h x y =
16-
(h##paint(x,y))##draw(x,y)
16+
(h##paint x y)##draw x y
1717

1818
let f4 h x y =
19-
(h##paint_set(x,y))##draw_set(x,y)
19+
(h##paint_set (x,y))##draw_set (x,y)
2020

2121

2222
(* let g h = *)

jscomp/test/config2_test.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let hh2 ( x : vv) : vv2 = x
3030

3131

3232
let test_v (x : v Js.t) =
33-
x##hey(1,2)
33+
x##hey 1 2
3434

3535
let test_vv (h : vv) =
36-
h##hey(1,2)
36+
h##hey 1 2

jscomp/test/demo.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,12 @@ let ui_layout
201201

202202
button##text_set "update formula";
203203
button##minHeight_set 20;
204-
button##on ("click", (fun [@uncurry] _event -> (* FIXME both [_] and () should work*)
204+
button##on "click" begin fun [@uncurry] _event -> (* FIXME both [_] and () should work*)
205205
try
206206
let hot_function = compile inputCode##text in
207207
computeFunction := fun env -> hot_function (fun key -> lookup env key)
208-
with e -> ()));
208+
with e -> ()
209+
end;
209210
let fmt v = to_fixed v 2 in
210211
set_interval (fun [@uncurry] () ->
211212

jscomp/test/js_date_test.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ let d3 = d2 ~year:2016. ~day:1. ()
66

77

88
let suites = Mt.[
9-
"getMonth", (fun _ -> Eq(2., d ## getMonth () ));
9+
"getMonth", (fun _ -> Eq(2., d##getMonth () ));
1010
"getYear", (fun _ -> Eq((2016.,2.,1.),
11-
(d3 ## getFullYear() ,
12-
d3 ## getMonth(),
13-
d3 ## getDate()
11+
(d3##getFullYear() ,
12+
d3##getMonth(),
13+
d3##getDate()
1414
)))
1515
]
1616

jscomp/test/method_chain.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
let f obj x y=
33
obj
4-
##(paint (x,y))
5-
##(draw (x,y))
6-
##(bark (x,y))
4+
##(paint x y)
5+
##(draw x y )
6+
##(bark x y)

jscomp/test/method_name_test.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let eq loc x y =
88

99
let f x i file v =
1010
x##case i ;
11-
x##case_set (i,v);
11+
x##case_set i v;
1212
x##_open file;
1313
x##open_ file ;
1414
x##_MAX_LENGTH_

jscomp/test/obj_literal_ppx.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let b =
88
let f obj =
99
obj ## x + Array.length (obj ## y)
1010

11-
let h obj = obj##u (1,2)
11+
let h obj = obj##u 1 2
1212

1313
let u = f a
1414

jscomp/test/test_http_server.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
let port = 3000
55
let hostname = "127.0.0.1"
66
let create_server http =
7-
let server = http##createServer (fun [@uncurry] req resp ->
7+
let server = http##createServer begin fun [@uncurry] req resp ->
88
resp##statusCode_set 200;
9-
resp##setHeader("Content-Type", "text/plain");
10-
resp##end_("Hello world\n")
11-
)
9+
resp##setHeader "Content-Type" "text/plain";
10+
resp##end_ "Hello world\n"
11+
end
1212
in
13-
server##listen(port, hostname, fun [@uncurry] () ->
14-
Js.log ("Server running at http://"^ hostname ^ ":" ^ string_of_int port ^ "/")
15-
)
13+
server##listen port hostname begin fun [@uncurry] () ->
14+
Js.log ("Server running at http://"^ hostname ^ ":" ^ string_of_int port ^ "/")
15+
end
16+
1617
let () =
1718
create_server Http_types.http
1819

jscomp/test/test_index.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let f (x : [%bs.obj: < case : int -> 'a ;
88
case_set : int -> int -> unit ;
99
.. > [@uncurry] ] )
1010
=
11-
x ## case_set (3, 2) ;
11+
x ## case_set 3 2 ;
1212
x ## case 3
1313

1414
class type ['a] case = object [@uncurry]
@@ -18,7 +18,7 @@ end
1818

1919
let ff (x : int case Js.t)
2020
=
21-
x##case_set (3, 2) ;
21+
x##case_set 3 2 ;
2222
x##case 3
2323

2424

@@ -38,7 +38,7 @@ type x_obj =
3838
let f_ext
3939
(x : x_obj)
4040
=
41-
x ## case_set (3, 2) ;
41+
x ## case_set 3 2 ;
4242
x ## case 3
4343

4444

jscomp/test/test_obj_simple_ffi.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ type hh = < bark :( 'self -> int -> int [@meth_callback]) > Js.t as 'self
2424

2525
let ff (x : h) : hh = x
2626

27-
let f (u : x Js.t) =
28-
u#.tet (1,2)
27+
(* let f (u : x Js.t) = *)
28+
(* u#.tet (1,2) *)
2929

3030

3131
type 'a return = int -> 'a [@fn]

jscomp/test/test_unsafe_obj_ffi_ppx.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let chain x =
2121

2222
let g x =
2323
let () = x ## method1 3 in
24-
x ## method2 (3, 3 )
24+
x ## method2 3 3
2525

2626

2727

jscomp/test/unsafe_this.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let u : 'self =
1818
length : int > )
1919
]
2020

21-
let v = u##bark (u,1,2)
21+
let v = u##bark u 1 2
2222

2323

2424
(* let bark2 = fun [@bs.this] (this, x, y) -> Js.log (this##x,x+y) *)
@@ -88,10 +88,10 @@ let js_obj : 'self =
8888
length = 32
8989
}
9090
]
91-
let h = js_obj#.bark(1,2)
91+
(* let h = js_obj#.bark(1,2) *)
9292

9393
(* let h = run_method2 uuu##bark uuu 1 2 *)
94-
let hh = js_obj#.(bark (1,2))
94+
(* let hh = js_obj#.(bark (1,2)) *)
9595

9696

9797
(*

lib/js/test/unsafe_this.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,5 @@ var js_obj = {
3535
length: 32
3636
};
3737

38-
js_obj.bark(1, 2);
39-
40-
js_obj.bark(1, 2);
41-
4238
exports.js_obj = js_obj;
4339
/* u Not a pure module */

0 commit comments

Comments
 (0)