Skip to content

Commit 354f5cd

Browse files
committed
better error message when no label
1 parent 54499a5 commit 354f5cd

File tree

4 files changed

+60
-201
lines changed

4 files changed

+60
-201
lines changed

jscomp/syntax/reactjs_jsx_ppx.cppo.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,11 @@ let jsxMapper () =
716716
} -> ((fun a -> a), false, unerasableIgnoreExp expression)
717717
(* let make = (prop) => ... *)
718718
| {
719-
pexp_desc = Pexp_fun (_nolabel, _default, _pattern, _internalExpression)
720-
} -> raise (Invalid_argument "if your component doesn't take any props use () or _ instead of a name as your argument")
719+
pexp_desc = Pexp_fun (_nolabel, _default, _pattern, _internalExpression);
720+
pexp_loc
721+
} ->
722+
Location.raise_errorf ~loc:pexp_loc
723+
"Make sure to use labeled arguments for props, if your component doesn't take any props use () or _ instead of a name as your argument"
721724
(* let make = {let foo = bar in (~prop) => ...} *)
722725
| {
723726
pexp_desc = Pexp_let (recursive, vbs, internalExpression)

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -410387,8 +410387,11 @@ let jsxMapper () =
410387410387
} -> ((fun a -> a), false, unerasableIgnoreExp expression)
410388410388
(* let make = (prop) => ... *)
410389410389
| {
410390-
pexp_desc = Pexp_fun (_nolabel, _default, _pattern, _internalExpression)
410391-
} -> raise (Invalid_argument "if your component doesn't take any props use () or _ instead of a name as your argument")
410390+
pexp_desc = Pexp_fun (_nolabel, _default, _pattern, _internalExpression);
410391+
pexp_loc
410392+
} ->
410393+
Location.raise_errorf ~loc:pexp_loc
410394+
"Make sure to use labeled arguments for props, if your component doesn't take any props use () or _ instead of a name as your argument"
410392410395
(* let make = {let foo = bar in (~prop) => ...} *)
410393410396
| {
410394410397
pexp_desc = Pexp_let (recursive, vbs, internalExpression)
@@ -410601,11 +410604,11 @@ let jsxMapper () =
410601410604
| {loc; txt = Ldot (modulePath, ("createElement" | "make"))} ->
410602410605
(match !jsxVersion with
410603410606

410604-
# 933 "syntax/reactjs_jsx_ppx.cppo.ml"
410607+
# 936 "syntax/reactjs_jsx_ppx.cppo.ml"
410605410608
| None
410606410609
| Some 2 -> transformUppercaseCall modulePath mapper loc attrs callExpression callArguments
410607410610

410608-
# 939 "syntax/reactjs_jsx_ppx.cppo.ml"
410611+
# 942 "syntax/reactjs_jsx_ppx.cppo.ml"
410609410612
| Some 3 -> transformUppercaseCall3 modulePath mapper loc attrs callExpression callArguments
410610410613
| Some _ -> raise (Invalid_argument "JSX: the JSX version must be 2 or 3"))
410611410614

@@ -410615,11 +410618,11 @@ let jsxMapper () =
410615410618
| {loc; txt = Lident id} ->
410616410619
(match !jsxVersion with
410617410620

410618-
# 948 "syntax/reactjs_jsx_ppx.cppo.ml"
410621+
# 951 "syntax/reactjs_jsx_ppx.cppo.ml"
410619410622
| None
410620410623
| Some 2 -> transformLowercaseCall mapper loc attrs callArguments id
410621410624

410622-
# 954 "syntax/reactjs_jsx_ppx.cppo.ml"
410625+
# 957 "syntax/reactjs_jsx_ppx.cppo.ml"
410623410626
| Some 3 -> transformLowercaseCall3 mapper loc attrs callArguments id
410624410627
| Some _ -> raise (Invalid_argument "JSX: the JSX version must be 2 or 3"))
410625410628

@@ -411439,8 +411442,11 @@ let jsxMapper () =
411439411442
} -> ((fun a -> a), false, unerasableIgnoreExp expression)
411440411443
(* let make = (prop) => ... *)
411441411444
| {
411442-
pexp_desc = Pexp_fun (_nolabel, _default, _pattern, _internalExpression)
411443-
} -> raise (Invalid_argument "if your component doesn't take any props use () or _ instead of a name as your argument")
411445+
pexp_desc = Pexp_fun (_nolabel, _default, _pattern, _internalExpression);
411446+
pexp_loc
411447+
} ->
411448+
Location.raise_errorf ~loc:pexp_loc
411449+
"Make sure to use labeled arguments for props, if your component doesn't take any props use () or _ instead of a name as your argument"
411444411450
(* let make = {let foo = bar in (~prop) => ...} *)
411445411451
| {
411446411452
pexp_desc = Pexp_let (recursive, vbs, internalExpression)
@@ -411653,11 +411659,11 @@ let jsxMapper () =
411653411659
| {loc; txt = Ldot (modulePath, ("createElement" | "make"))} ->
411654411660
(match !jsxVersion with
411655411661

411656-
# 936 "syntax/reactjs_jsx_ppx.cppo.ml"
411662+
# 939 "syntax/reactjs_jsx_ppx.cppo.ml"
411657411663
| Some 2 -> transformUppercaseCall modulePath mapper loc attrs callExpression callArguments
411658411664
| None
411659411665

411660-
# 939 "syntax/reactjs_jsx_ppx.cppo.ml"
411666+
# 942 "syntax/reactjs_jsx_ppx.cppo.ml"
411661411667
| Some 3 -> transformUppercaseCall3 modulePath mapper loc attrs callExpression callArguments
411662411668
| Some _ -> raise (Invalid_argument "JSX: the JSX version must be 2 or 3"))
411663411669

@@ -411667,11 +411673,11 @@ let jsxMapper () =
411667411673
| {loc; txt = Lident id} ->
411668411674
(match !jsxVersion with
411669411675

411670-
# 951 "syntax/reactjs_jsx_ppx.cppo.ml"
411676+
# 954 "syntax/reactjs_jsx_ppx.cppo.ml"
411671411677
| Some 2 -> transformLowercaseCall mapper loc attrs callArguments id
411672411678
| None
411673411679

411674-
# 954 "syntax/reactjs_jsx_ppx.cppo.ml"
411680+
# 957 "syntax/reactjs_jsx_ppx.cppo.ml"
411675411681
| Some 3 -> transformLowercaseCall3 mapper loc attrs callArguments id
411676411682
| Some _ -> raise (Invalid_argument "JSX: the JSX version must be 2 or 3"))
411677411683

lib/4.06.1/unstable/js_refmt_compiler.ml

Lines changed: 19 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -384188,169 +384188,7 @@ let rec
384188384188
| _ -> false)
384189384189
| Lstaticraise(id,ls) ->
384190384190
(match l2 with Lstaticraise(id1,ls1) ->
384191-
id = id1 && eq_approx_list ls ls1
384192-
| _ -> false)
384193-
| Lprim info1 ->
384194-
(match l2 with
384195-
Lprim info2 ->
384196-
Lam_primitive.eq_primitive_approx info1.primitive info2.primitive &&
384197-
eq_approx_list info1.args info2.args
384198-
| _ -> false)
384199-
| Lstringswitch _ -> false
384200-
| Lfunction _
384201-
| Llet (_,_,_,_)
384202-
| Lletrec _
384203-
| Lswitch _
384204-
| Lstaticcatch _
384205-
| Ltrywith _
384206-
| Lfor (_,_,_,_,_)
384207-
| Lsend _
384208-
-> false
384209-
384210-
and eq_approx_list ls ls1 = Ext_list.for_all2_no_exn ls ls1 eq_approx
384211-
384212-
384213-
384214-
384215-
let switch lam (lam_switch : lambda_switch) : t =
384216-
match lam with
384217-
| Lconst ((Const_pointer (i,_) | (Const_int {value = i})))
384218-
->
384219-
Ext_list.assoc_by_int lam_switch.sw_consts i lam_switch.sw_failaction
384220-
| Lconst (Const_block (i,_,_)) ->
384221-
Ext_list.assoc_by_int lam_switch.sw_blocks i lam_switch.sw_failaction
384222-
| _ ->
384223-
Lswitch(lam,lam_switch)
384224-
384225-
let stringswitch (lam : t) cases default : t =
384226-
match lam with
384227-
| Lconst (Const_string a) ->
384228-
Ext_list.assoc_by_string cases a default
384229-
| _ -> Lstringswitch(lam, cases, default)
384230-
384231-
384232-
let true_ : t =
384233-
Lconst (Const_js_true)
384234-
384235-
let false_ : t =
384236-
Lconst (Const_js_false)
384237-
384238-
let unit : t = Lconst Const_js_undefined
384239-
384240-
384241-
384242-
384243-
384244-
let rec seq (a : t) b : t =
384245-
match a with
384246-
| Lprim
384247-
{primitive = Pmakeblock(_);
384248-
args= x::xs} ->
384249-
seq (Ext_list.fold_left xs x seq ) b
384250-
| Lprim {primitive = Pnull_to_opt | Pundefined_to_opt | Pnull_undefined_to_opt; args = [a]}
384251-
-> seq a b
384252-
| _ ->
384253-
Lsequence (a, b)
384254-
384255-
384256-
let var id : t = Lvar id
384257-
let global_module id = Lglobal_module id
384258-
let const ct : t = Lconst ct
384259-
let function_ ~arity ~params ~body : t =
384260-
Lfunction { arity; params ; body}
384261-
384262-
let let_ kind id e body : t
384263-
= Llet (kind,id,e,body)
384264-
let letrec bindings body : t =
384265-
Lletrec(bindings,body)
384266-
let while_ a b : t =
384267-
Lwhile(a,b)
384268-
384269-
let try_ body id handler : t =
384270-
Ltrywith(body,id,handler)
384271-
384272-
let for_ v e1 e2 dir e3 : t =
384273-
Lfor(v,e1,e2,dir,e3)
384274-
384275-
let assign v l : t = Lassign(v,l)
384276-
let send u m o ll v : t =
384277-
Lsend(u, m, o, ll, v)
384278-
let staticcatch a b c : t = Lstaticcatch(a,b,c)
384279-
let staticraise a b : t = Lstaticraise(a,b)
384280-
384281-
384282-
module Lift = struct
384283-
let int i : t =
384284-
Lconst ((Const_int {value = i; comment = None}))
384285-
384286-
384287-
(* let int32 i : t =
384288-
Lconst ((Const_int32 i)) *)
384289-
384290-
let bool b = if b then true_ else false_
384291-
384292-
(* ATTENTION: [float, nativeint] constant propogaton is not done
384293-
yet , due to cross platform problem
384294-
*)
384295-
(* let float b : t =
384296-
Lconst ((Const_float b)) *)
384297-
384298-
(* let nativeint b : t =
384299-
Lconst ((Const_nativeint b)) *)
384300-
384301-
let int32 b : t =
384302-
Lconst ((Const_int32 b))
384303-
384304-
let int64 b : t =
384305-
Lconst ((Const_int64 b))
384306-
let string b : t =
384307-
Lconst ((Const_string (b)))
384308-
let char b : t =
384309-
Lconst ((Const_char b))
384310-
end
384311-
384312-
384313-
384314-
let prim ~primitive:(prim : Lam_primitive.t) ~args loc : t =
384315-
let default () : t = Lprim { primitive = prim ;args; loc} in
384316-
match args with
384317-
| [Lconst a] ->
384318-
begin match prim, a with
384319-
| Pnegint, Const_int {value = a}
384320-
-> Lift.int (- a)
384321-
(* | Pfloatofint, ( (Const_int a)) *)
384322-
(* -> Lift.float (float_of_int a) *)
384323-
| Pintoffloat, ( (Const_float a))
384324-
->
384325-
Lift.int (int_of_float (float_of_string a))
384326-
(* | Pnegfloat -> Lift.float (-. a) *)
384327-
(* | Pabsfloat -> Lift.float (abs_float a) *)
384328-
| Pstringlength, Const_string a
384329-
->
384330-
Lift.int (String.length a)
384331-
(* | Pnegbint Pnativeint, ( (Const_nativeint i)) *)
384332-
(* -> *)
384333-
(* Lift.nativeint (Nativeint.neg i) *)
384334-
| Pnegbint Pint32, Const_int32 a
384335-
->
384336-
Lift.int32 (Int32.neg a)
384337-
| Pnegbint Pint64, Const_int64 a
384338-
->
384339-
Lift.int64 (Int64.neg a)
384340-
| Pnot, Const_js_true -> false_
384341-
| Pnot, Const_js_false -> true_
384342-
| Pnot , Const_pointer (a,_)
384343-
-> Lift.bool (a = 0 )
384344-
| _ -> default ()
384345-
end
384346-
384347-
384348-
| [Lconst a ; Lconst b] ->
384349-
begin match prim, a, b with
384350-
| Pbintcomp(_, cmp), (Const_int32 a), (Const_int32 b)
384351-
-> Lift.bool (Lam_compat.cmp_int32 cmp a b)
384352-
| Pbintcomp(_, cmp), (Const_int64 a), (Const_int64 b)
384353-
-> Lift.bool (Lam_compat.cmp_int64 cmp a b)
384191+
id = id1 t64 cmp a b)
384354384192
| Pbintcomp(_, cmp), (Const_nativeint a), (Const_nativeint b)
384355384193
-> Lift.bool (Lam_compat.cmp_nativeint cmp a b)
384356384194
| Pfloatcomp cmp, (Const_float a), (Const_float b)
@@ -410279,8 +410117,11 @@ let jsxMapper () =
410279410117
} -> ((fun a -> a), false, unerasableIgnoreExp expression)
410280410118
(* let make = (prop) => ... *)
410281410119
| {
410282-
pexp_desc = Pexp_fun (_nolabel, _default, _pattern, _internalExpression)
410283-
} -> raise (Invalid_argument "if your component doesn't take any props use () or _ instead of a name as your argument")
410120+
pexp_desc = Pexp_fun (_nolabel, _default, _pattern, _internalExpression);
410121+
pexp_loc
410122+
} ->
410123+
Location.raise_errorf ~loc:pexp_loc
410124+
"Make sure to use labeled arguments for props, if your component doesn't take any props use () or _ instead of a name as your argument"
410284410125
(* let make = {let foo = bar in (~prop) => ...} *)
410285410126
| {
410286410127
pexp_desc = Pexp_let (recursive, vbs, internalExpression)
@@ -410493,11 +410334,11 @@ let jsxMapper () =
410493410334
| {loc; txt = Ldot (modulePath, ("createElement" | "make"))} ->
410494410335
(match !jsxVersion with
410495410336

410496-
# 933 "syntax/reactjs_jsx_ppx.cppo.ml"
410337+
# 936 "syntax/reactjs_jsx_ppx.cppo.ml"
410497410338
| None
410498410339
| Some 2 -> transformUppercaseCall modulePath mapper loc attrs callExpression callArguments
410499410340

410500-
# 939 "syntax/reactjs_jsx_ppx.cppo.ml"
410341+
# 942 "syntax/reactjs_jsx_ppx.cppo.ml"
410501410342
| Some 3 -> transformUppercaseCall3 modulePath mapper loc attrs callExpression callArguments
410502410343
| Some _ -> raise (Invalid_argument "JSX: the JSX version must be 2 or 3"))
410503410344

@@ -410507,11 +410348,11 @@ let jsxMapper () =
410507410348
| {loc; txt = Lident id} ->
410508410349
(match !jsxVersion with
410509410350

410510-
# 948 "syntax/reactjs_jsx_ppx.cppo.ml"
410351+
# 951 "syntax/reactjs_jsx_ppx.cppo.ml"
410511410352
| None
410512410353
| Some 2 -> transformLowercaseCall mapper loc attrs callArguments id
410513410354

410514-
# 954 "syntax/reactjs_jsx_ppx.cppo.ml"
410355+
# 957 "syntax/reactjs_jsx_ppx.cppo.ml"
410515410356
| Some 3 -> transformLowercaseCall3 mapper loc attrs callArguments id
410516410357
| Some _ -> raise (Invalid_argument "JSX: the JSX version must be 2 or 3"))
410517410358

@@ -411331,8 +411172,11 @@ let jsxMapper () =
411331411172
} -> ((fun a -> a), false, unerasableIgnoreExp expression)
411332411173
(* let make = (prop) => ... *)
411333411174
| {
411334-
pexp_desc = Pexp_fun (_nolabel, _default, _pattern, _internalExpression)
411335-
} -> raise (Invalid_argument "if your component doesn't take any props use () or _ instead of a name as your argument")
411175+
pexp_desc = Pexp_fun (_nolabel, _default, _pattern, _internalExpression);
411176+
pexp_loc
411177+
} ->
411178+
Location.raise_errorf ~loc:pexp_loc
411179+
"Make sure to use labeled arguments for props, if your component doesn't take any props use () or _ instead of a name as your argument"
411336411180
(* let make = {let foo = bar in (~prop) => ...} *)
411337411181
| {
411338411182
pexp_desc = Pexp_let (recursive, vbs, internalExpression)
@@ -411545,11 +411389,11 @@ let jsxMapper () =
411545411389
| {loc; txt = Ldot (modulePath, ("createElement" | "make"))} ->
411546411390
(match !jsxVersion with
411547411391

411548-
# 936 "syntax/reactjs_jsx_ppx.cppo.ml"
411392+
# 939 "syntax/reactjs_jsx_ppx.cppo.ml"
411549411393
| Some 2 -> transformUppercaseCall modulePath mapper loc attrs callExpression callArguments
411550411394
| None
411551411395

411552-
# 939 "syntax/reactjs_jsx_ppx.cppo.ml"
411396+
# 942 "syntax/reactjs_jsx_ppx.cppo.ml"
411553411397
| Some 3 -> transformUppercaseCall3 modulePath mapper loc attrs callExpression callArguments
411554411398
| Some _ -> raise (Invalid_argument "JSX: the JSX version must be 2 or 3"))
411555411399

@@ -411559,11 +411403,11 @@ let jsxMapper () =
411559411403
| {loc; txt = Lident id} ->
411560411404
(match !jsxVersion with
411561411405

411562-
# 951 "syntax/reactjs_jsx_ppx.cppo.ml"
411406+
# 954 "syntax/reactjs_jsx_ppx.cppo.ml"
411563411407
| Some 2 -> transformLowercaseCall mapper loc attrs callArguments id
411564411408
| None
411565411409

411566-
# 954 "syntax/reactjs_jsx_ppx.cppo.ml"
411410+
# 957 "syntax/reactjs_jsx_ppx.cppo.ml"
411567411411
| Some 3 -> transformLowercaseCall3 mapper loc attrs callArguments id
411568411412
| Some _ -> raise (Invalid_argument "JSX: the JSX version must be 2 or 3"))
411569411413

0 commit comments

Comments
 (0)