Skip to content

Commit 03af145

Browse files
committed
1 parent e2877ca commit 03af145

File tree

8 files changed

+82
-187
lines changed

8 files changed

+82
-187
lines changed

jscomp/bin/bsdep.ml

+16-43
Original file line numberDiff line numberDiff line change
@@ -24477,8 +24477,11 @@ val assert_strings :
2447724477

2447824478
(** as a record or empty
2447924479
it will accept
24480+
2448024481
{[ [@@@bs.config ]]}
2448124482
or
24483+
{[ [@@@bs.config no_export ] ]}
24484+
or
2448224485
{[ [@@@bs.config { property .. } ]]}
2448324486
Note that we only
2448424487
{[
@@ -24489,9 +24492,6 @@ val assert_strings :
2448924492
{M.flat_property}
2449024493
]}
2449124494
*)
24492-
val record_as_config_and_process :
24493-
Location.t ->
24494-
t -> action list
2449524495

2449624496
val ident_or_record_as_config :
2449724497
Location.t ->
@@ -24608,40 +24608,6 @@ type action =
2460824608
{[ { x = exp }]}
2460924609
*)
2461024610

24611-
let record_as_config_and_process
24612-
loc
24613-
(x : Parsetree.payload)
24614-
: ( string Location.loc * Parsetree.expression option) list
24615-
=
24616-
match x with
24617-
| PStr
24618-
[ {pstr_desc = Pstr_eval
24619-
({pexp_desc = Pexp_record (label_exprs, with_obj) ; pexp_loc = loc}, _);
24620-
_
24621-
}]
24622-
->
24623-
begin match with_obj with
24624-
| None ->
24625-
List.map
24626-
(fun ((x,y) : (Longident.t Asttypes.loc * _) ) ->
24627-
match (x,y) with
24628-
| ({txt = Lident name; loc} ) ,
24629-
({Parsetree.pexp_desc = Pexp_ident{txt = Lident name2}} )
24630-
when name2 = name ->
24631-
({Asttypes.txt = name ; loc}, None)
24632-
| ({txt = Lident name; loc} ), y
24633-
->
24634-
({Asttypes.txt = name ; loc}, Some y)
24635-
| _ ->
24636-
Location.raise_errorf ~loc "Qualified label is not allood"
24637-
)
24638-
label_exprs
24639-
| Some _ ->
24640-
Location.raise_errorf ~loc "with is not supported"
24641-
end
24642-
| Parsetree.PStr [] -> []
24643-
| _ ->
24644-
Location.raise_errorf ~loc "this is not a valid record config"
2464524611

2464624612
let ident_or_record_as_config
2464724613
loc
@@ -25727,22 +25693,29 @@ let process_method_attributes_rev (attrs : t) =
2572725693
(fun
2572825694
(null, undefined)
2572925695
(({txt ; loc}, opt_expr) : Ast_payload.action) ->
25730-
if txt = "null" then
25696+
match txt with
25697+
| "null" ->
2573125698
(match opt_expr with
2573225699
| None -> true
2573325700
| Some e ->
2573425701
Ast_payload.assert_bool_lit e), undefined
2573525702

25736-
else if txt = "undefined" then
25703+
| "undefined" ->
2573725704
null,
2573825705
(match opt_expr with
2573925706
| None -> true
2574025707
| Some e ->
2574125708
Ast_payload.assert_bool_lit e)
25742-
25743-
else Bs_syntaxerr.err loc Unsupported_predicates
25709+
| "nullable" ->
25710+
begin match opt_expr with
25711+
| None -> true, true
25712+
| Some e ->
25713+
let v = Ast_payload.assert_bool_lit e in
25714+
v,v
25715+
end
25716+
| _ -> Bs_syntaxerr.err loc Unsupported_predicates
2574425717
) (false, false)
25745-
(Ast_payload.record_as_config_and_process loc payload) in
25718+
(Ast_payload.ident_or_record_as_config loc payload) in
2574625719

2574725720
({st with get = Some result}, acc )
2574825721

@@ -25759,7 +25732,7 @@ let process_method_attributes_rev (attrs : t) =
2575925732
`No_get
2576025733
else `Get
2576125734
else Bs_syntaxerr.err loc Unsupported_predicates
25762-
) `Get (Ast_payload.record_as_config_and_process loc payload) in
25735+
) `Get (Ast_payload.ident_or_record_as_config loc payload) in
2576325736
(* properties -- void
2576425737
[@@bs.set{only}]
2576525738
*)

jscomp/bin/bsppx.ml

+16-43
Original file line numberDiff line numberDiff line change
@@ -6426,8 +6426,11 @@ val assert_strings :
64266426

64276427
(** as a record or empty
64286428
it will accept
6429+
64296430
{[ [@@@bs.config ]]}
64306431
or
6432+
{[ [@@@bs.config no_export ] ]}
6433+
or
64316434
{[ [@@@bs.config { property .. } ]]}
64326435
Note that we only
64336436
{[
@@ -6438,9 +6441,6 @@ val assert_strings :
64386441
{M.flat_property}
64396442
]}
64406443
*)
6441-
val record_as_config_and_process :
6442-
Location.t ->
6443-
t -> action list
64446444

64456445
val ident_or_record_as_config :
64466446
Location.t ->
@@ -6557,40 +6557,6 @@ type action =
65576557
{[ { x = exp }]}
65586558
*)
65596559

6560-
let record_as_config_and_process
6561-
loc
6562-
(x : Parsetree.payload)
6563-
: ( string Location.loc * Parsetree.expression option) list
6564-
=
6565-
match x with
6566-
| PStr
6567-
[ {pstr_desc = Pstr_eval
6568-
({pexp_desc = Pexp_record (label_exprs, with_obj) ; pexp_loc = loc}, _);
6569-
_
6570-
}]
6571-
->
6572-
begin match with_obj with
6573-
| None ->
6574-
List.map
6575-
(fun ((x,y) : (Longident.t Asttypes.loc * _) ) ->
6576-
match (x,y) with
6577-
| ({txt = Lident name; loc} ) ,
6578-
({Parsetree.pexp_desc = Pexp_ident{txt = Lident name2}} )
6579-
when name2 = name ->
6580-
({Asttypes.txt = name ; loc}, None)
6581-
| ({txt = Lident name; loc} ), y
6582-
->
6583-
({Asttypes.txt = name ; loc}, Some y)
6584-
| _ ->
6585-
Location.raise_errorf ~loc "Qualified label is not allood"
6586-
)
6587-
label_exprs
6588-
| Some _ ->
6589-
Location.raise_errorf ~loc "with is not supported"
6590-
end
6591-
| Parsetree.PStr [] -> []
6592-
| _ ->
6593-
Location.raise_errorf ~loc "this is not a valid record config"
65946560

65956561
let ident_or_record_as_config
65966562
loc
@@ -7676,22 +7642,29 @@ let process_method_attributes_rev (attrs : t) =
76767642
(fun
76777643
(null, undefined)
76787644
(({txt ; loc}, opt_expr) : Ast_payload.action) ->
7679-
if txt = "null" then
7645+
match txt with
7646+
| "null" ->
76807647
(match opt_expr with
76817648
| None -> true
76827649
| Some e ->
76837650
Ast_payload.assert_bool_lit e), undefined
76847651

7685-
else if txt = "undefined" then
7652+
| "undefined" ->
76867653
null,
76877654
(match opt_expr with
76887655
| None -> true
76897656
| Some e ->
76907657
Ast_payload.assert_bool_lit e)
7691-
7692-
else Bs_syntaxerr.err loc Unsupported_predicates
7658+
| "nullable" ->
7659+
begin match opt_expr with
7660+
| None -> true, true
7661+
| Some e ->
7662+
let v = Ast_payload.assert_bool_lit e in
7663+
v,v
7664+
end
7665+
| _ -> Bs_syntaxerr.err loc Unsupported_predicates
76937666
) (false, false)
7694-
(Ast_payload.record_as_config_and_process loc payload) in
7667+
(Ast_payload.ident_or_record_as_config loc payload) in
76957668

76967669
({st with get = Some result}, acc )
76977670

@@ -7708,7 +7681,7 @@ let process_method_attributes_rev (attrs : t) =
77087681
`No_get
77097682
else `Get
77107683
else Bs_syntaxerr.err loc Unsupported_predicates
7711-
) `Get (Ast_payload.record_as_config_and_process loc payload) in
7684+
) `Get (Ast_payload.ident_or_record_as_config loc payload) in
77127685
(* properties -- void
77137686
[@@bs.set{only}]
77147687
*)

jscomp/bin/whole_compiler.ml

+16-43
Original file line numberDiff line numberDiff line change
@@ -103259,8 +103259,11 @@ val assert_strings :
103259103259

103260103260
(** as a record or empty
103261103261
it will accept
103262+
103262103263
{[ [@@@bs.config ]]}
103263103264
or
103265+
{[ [@@@bs.config no_export ] ]}
103266+
or
103264103267
{[ [@@@bs.config { property .. } ]]}
103265103268
Note that we only
103266103269
{[
@@ -103271,9 +103274,6 @@ val assert_strings :
103271103274
{M.flat_property}
103272103275
]}
103273103276
*)
103274-
val record_as_config_and_process :
103275-
Location.t ->
103276-
t -> action list
103277103277

103278103278
val ident_or_record_as_config :
103279103279
Location.t ->
@@ -103390,40 +103390,6 @@ type action =
103390103390
{[ { x = exp }]}
103391103391
*)
103392103392

103393-
let record_as_config_and_process
103394-
loc
103395-
(x : Parsetree.payload)
103396-
: ( string Location.loc * Parsetree.expression option) list
103397-
=
103398-
match x with
103399-
| PStr
103400-
[ {pstr_desc = Pstr_eval
103401-
({pexp_desc = Pexp_record (label_exprs, with_obj) ; pexp_loc = loc}, _);
103402-
_
103403-
}]
103404-
->
103405-
begin match with_obj with
103406-
| None ->
103407-
List.map
103408-
(fun ((x,y) : (Longident.t Asttypes.loc * _) ) ->
103409-
match (x,y) with
103410-
| ({txt = Lident name; loc} ) ,
103411-
({Parsetree.pexp_desc = Pexp_ident{txt = Lident name2}} )
103412-
when name2 = name ->
103413-
({Asttypes.txt = name ; loc}, None)
103414-
| ({txt = Lident name; loc} ), y
103415-
->
103416-
({Asttypes.txt = name ; loc}, Some y)
103417-
| _ ->
103418-
Location.raise_errorf ~loc "Qualified label is not allood"
103419-
)
103420-
label_exprs
103421-
| Some _ ->
103422-
Location.raise_errorf ~loc "with is not supported"
103423-
end
103424-
| Parsetree.PStr [] -> []
103425-
| _ ->
103426-
Location.raise_errorf ~loc "this is not a valid record config"
103427103393

103428103394
let ident_or_record_as_config
103429103395
loc
@@ -103651,22 +103617,29 @@ let process_method_attributes_rev (attrs : t) =
103651103617
(fun
103652103618
(null, undefined)
103653103619
(({txt ; loc}, opt_expr) : Ast_payload.action) ->
103654-
if txt = "null" then
103620+
match txt with
103621+
| "null" ->
103655103622
(match opt_expr with
103656103623
| None -> true
103657103624
| Some e ->
103658103625
Ast_payload.assert_bool_lit e), undefined
103659103626

103660-
else if txt = "undefined" then
103627+
| "undefined" ->
103661103628
null,
103662103629
(match opt_expr with
103663103630
| None -> true
103664103631
| Some e ->
103665103632
Ast_payload.assert_bool_lit e)
103666-
103667-
else Bs_syntaxerr.err loc Unsupported_predicates
103633+
| "nullable" ->
103634+
begin match opt_expr with
103635+
| None -> true, true
103636+
| Some e ->
103637+
let v = Ast_payload.assert_bool_lit e in
103638+
v,v
103639+
end
103640+
| _ -> Bs_syntaxerr.err loc Unsupported_predicates
103668103641
) (false, false)
103669-
(Ast_payload.record_as_config_and_process loc payload) in
103642+
(Ast_payload.ident_or_record_as_config loc payload) in
103670103643

103671103644
({st with get = Some result}, acc )
103672103645

@@ -103683,7 +103656,7 @@ let process_method_attributes_rev (attrs : t) =
103683103656
`No_get
103684103657
else `Get
103685103658
else Bs_syntaxerr.err loc Unsupported_predicates
103686-
) `Get (Ast_payload.record_as_config_and_process loc payload) in
103659+
) `Get (Ast_payload.ident_or_record_as_config loc payload) in
103687103660
(* properties -- void
103688103661
[@@bs.set{only}]
103689103662
*)

jscomp/syntax/ast_attributes.ml

+13-6
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,29 @@ let process_method_attributes_rev (attrs : t) =
4141
(fun
4242
(null, undefined)
4343
(({txt ; loc}, opt_expr) : Ast_payload.action) ->
44-
if txt = "null" then
44+
match txt with
45+
| "null" ->
4546
(match opt_expr with
4647
| None -> true
4748
| Some e ->
4849
Ast_payload.assert_bool_lit e), undefined
4950

50-
else if txt = "undefined" then
51+
| "undefined" ->
5152
null,
5253
(match opt_expr with
5354
| None -> true
5455
| Some e ->
5556
Ast_payload.assert_bool_lit e)
56-
57-
else Bs_syntaxerr.err loc Unsupported_predicates
57+
| "nullable" ->
58+
begin match opt_expr with
59+
| None -> true, true
60+
| Some e ->
61+
let v = Ast_payload.assert_bool_lit e in
62+
v,v
63+
end
64+
| _ -> Bs_syntaxerr.err loc Unsupported_predicates
5865
) (false, false)
59-
(Ast_payload.record_as_config_and_process loc payload) in
66+
(Ast_payload.ident_or_record_as_config loc payload) in
6067

6168
({st with get = Some result}, acc )
6269

@@ -73,7 +80,7 @@ let process_method_attributes_rev (attrs : t) =
7380
`No_get
7481
else `Get
7582
else Bs_syntaxerr.err loc Unsupported_predicates
76-
) `Get (Ast_payload.record_as_config_and_process loc payload) in
83+
) `Get (Ast_payload.ident_or_record_as_config loc payload) in
7784
(* properties -- void
7885
[@@bs.set{only}]
7986
*)

0 commit comments

Comments
 (0)