Skip to content

Commit 34e20f8

Browse files
committed
1 parent f303d04 commit 34e20f8

9 files changed

+465
-251
lines changed

Diff for: jscomp/bin/bsdep.ml

+114-63
Original file line numberDiff line numberDiff line change
@@ -24493,6 +24493,10 @@ val as_config_record_and_process :
2449324493
Location.t ->
2449424494
t -> action list
2449524495

24496+
val ident_or_record_as_config :
24497+
Location.t ->
24498+
t -> action list
24499+
2449624500
val assert_bool_lit : Parsetree.expression -> bool
2449724501

2449824502
val empty : t
@@ -24569,7 +24573,7 @@ let as_core_type loc x =
2456924573
match x with
2457024574
| Parsetree.PTyp x -> x
2457124575
| _ -> Location.raise_errorf ~loc "except a core type"
24572-
24576+
2457324577
let as_ident (x : t ) =
2457424578
match x with
2457524579
| PStr [
@@ -24578,7 +24582,7 @@ let as_ident (x : t ) =
2457824582
{
2457924583
pexp_desc =
2458024584
Pexp_ident ident
24581-
24585+
2458224586
} , _)
2458324587
}
2458424588
] -> Some ident
@@ -24587,7 +24591,7 @@ open Ast_helper
2458724591

2458824592
let raw_string_payload loc (s : string) : t =
2458924593
PStr [ Str.eval ~loc (Exp.constant ~loc (Const_string (s,None) ))]
24590-
24594+
2459124595
let as_empty_structure (x : t ) =
2459224596
match x with
2459324597
| PStr ([]) -> true
@@ -24597,7 +24601,7 @@ type lid = string Asttypes.loc
2459724601
type label_expr = lid * Parsetree.expression
2459824602

2459924603
type action =
24600-
lid * Parsetree.expression option
24604+
lid * Parsetree.expression option
2460124605
(** None means punning is hit
2460224606
{[ { x } ]}
2460324607
otherwise it comes with a payload
@@ -24607,6 +24611,7 @@ type action =
2460724611
let as_config_record_and_process
2460824612
loc
2460924613
(x : Parsetree.payload)
24614+
: ( string Location.loc * Parsetree.expression option) list
2461024615
=
2461124616
match x with
2461224617
| PStr
@@ -24616,32 +24621,77 @@ let as_config_record_and_process
2461624621
}]
2461724622
->
2461824623
begin match with_obj with
24619-
| None ->
24620-
List.map
24621-
(fun (x,y) ->
24622-
match (x,y) with
24623-
| ({Asttypes.txt = Longident.Lident name; loc} ) ,
24624-
({Parsetree.pexp_desc = Pexp_ident{txt = Lident name2}} )
24625-
when name2 = name ->
24626-
({Asttypes.txt = name ; loc}, None)
24627-
| ({Asttypes.txt = Longident.Lident name; loc} ), y
24628-
->
24629-
({Asttypes.txt = name ; loc}, Some y)
24630-
| _ ->
24631-
Location.raise_errorf ~loc "Qualified label is not allood"
24632-
)
24633-
label_exprs
24634-
| Some _ ->
24635-
Location.raise_errorf ~loc "with is not supported"
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"
2463624641
end
2463724642
| Parsetree.PStr [] -> []
2463824643
| _ ->
2463924644
Location.raise_errorf ~loc "this is not a valid record config"
2464024645

24646+
let ident_or_record_as_config
24647+
loc
24648+
(x : Parsetree.payload)
24649+
: ( string Location.loc * Parsetree.expression option) list
24650+
=
24651+
match x with
24652+
| PStr
24653+
[ {pstr_desc = Pstr_eval
24654+
({pexp_desc = Pexp_record (label_exprs, with_obj) ; pexp_loc = loc}, _);
24655+
_
24656+
}]
24657+
->
24658+
begin match with_obj with
24659+
| None ->
24660+
List.map
24661+
(fun ((x,y) : (Longident.t Asttypes.loc * _) ) ->
24662+
match (x,y) with
24663+
| ({txt = Lident name; loc} ) ,
24664+
({Parsetree.pexp_desc = Pexp_ident{txt = Lident name2}} )
24665+
when name2 = name ->
24666+
({Asttypes.txt = name ; loc}, None)
24667+
| ({txt = Lident name; loc} ), y
24668+
->
24669+
({Asttypes.txt = name ; loc}, Some y)
24670+
| _ ->
24671+
Location.raise_errorf ~loc "Qualified label is not allood"
24672+
)
24673+
label_exprs
24674+
| Some _ ->
24675+
Location.raise_errorf ~loc "with is not supported"
24676+
end
24677+
| PStr [
24678+
{pstr_desc =
24679+
Pstr_eval (
24680+
{
24681+
pexp_desc =
24682+
Pexp_ident ({loc = lloc; txt = Lident txt});
24683+
24684+
} , _)
24685+
}
24686+
] -> [ {Asttypes.txt ; loc = lloc}, None]
24687+
| PStr [] -> []
24688+
| _ ->
24689+
Location.raise_errorf ~loc "this is not a valid record config"
24690+
2464124691

2464224692

2464324693
let assert_strings loc (x : t) : string list
24644-
=
24694+
=
2464524695
let module M = struct exception Not_str end in
2464624696
match x with
2464724697
| PStr [ {pstr_desc =
@@ -24652,7 +24702,7 @@ let assert_strings loc (x : t) : string list
2465224702
pstr_loc = loc ;
2465324703
_}] ->
2465424704
(try
24655-
strs |> List.map (fun e ->
24705+
strs |> List.map (fun e ->
2465624706
match (e : Parsetree.expression) with
2465724707
| {pexp_desc = Pexp_constant (Const_string (name,_)); _} ->
2465824708
name
@@ -24687,7 +24737,7 @@ let empty : t = Parsetree.PStr []
2468724737

2468824738

2468924739
let table_dispatch table (action : action)
24690-
=
24740+
=
2469124741
match action with
2469224742
| {txt = name; loc }, y ->
2469324743
begin match String_map.find_exn name table with
@@ -25674,44 +25724,45 @@ let process_method_attributes_rev (attrs : t) =
2567425724
->
2567525725
let result =
2567625726
List.fold_left
25677-
(fun
25678-
(null, undefined)
25679-
(({txt ; loc}, opt_expr) : Ast_payload.action) ->
25680-
if txt = "null" then
25681-
(match opt_expr with
25682-
| None -> true
25683-
| Some e ->
25684-
Ast_payload.assert_bool_lit e), undefined
25685-
25686-
else if txt = "undefined" then
25687-
null,
25688-
(match opt_expr with
25689-
| None -> true
25690-
| Some e ->
25691-
Ast_payload.assert_bool_lit e)
25692-
25693-
else Bs_syntaxerr.err loc Unsupported_predicates
25694-
) (false, false) (Ast_payload.as_config_record_and_process loc payload) in
25727+
(fun
25728+
(null, undefined)
25729+
(({txt ; loc}, opt_expr) : Ast_payload.action) ->
25730+
if txt = "null" then
25731+
(match opt_expr with
25732+
| None -> true
25733+
| Some e ->
25734+
Ast_payload.assert_bool_lit e), undefined
25735+
25736+
else if txt = "undefined" then
25737+
null,
25738+
(match opt_expr with
25739+
| None -> true
25740+
| Some e ->
25741+
Ast_payload.assert_bool_lit e)
25742+
25743+
else Bs_syntaxerr.err loc Unsupported_predicates
25744+
) (false, false)
25745+
(Ast_payload.as_config_record_and_process loc payload) in
2569525746

2569625747
({st with get = Some result}, acc )
2569725748

2569825749
| "bs.set"
2569925750
->
2570025751
let result =
2570125752
List.fold_left
25702-
(fun st (({txt ; loc}, opt_expr) : Ast_payload.action) ->
25703-
if txt = "no_get" then
25704-
match opt_expr with
25705-
| None -> `No_get
25706-
| Some e ->
25707-
if Ast_payload.assert_bool_lit e then
25708-
`No_get
25709-
else `Get
25710-
else Bs_syntaxerr.err loc Unsupported_predicates
25711-
) `Get (Ast_payload.as_config_record_and_process loc payload) in
25753+
(fun st (({txt ; loc}, opt_expr) : Ast_payload.action) ->
25754+
if txt = "no_get" then
25755+
match opt_expr with
25756+
| None -> `No_get
25757+
| Some e ->
25758+
if Ast_payload.assert_bool_lit e then
25759+
`No_get
25760+
else `Get
25761+
else Bs_syntaxerr.err loc Unsupported_predicates
25762+
) `Get (Ast_payload.as_config_record_and_process loc payload) in
2571225763
(* properties -- void
2571325764
[@@bs.set{only}]
25714-
*)
25765+
*)
2571525766
{st with set = Some result }, acc
2571625767
| _ ->
2571725768
(st, attr::acc )
@@ -25777,7 +25828,7 @@ let process_derive_type attrs =
2577725828
->
2577825829
{st with
2577925830
bs_deriving = `Has_deriving
25780-
(Ast_payload.as_config_record_and_process loc payload)}, acc
25831+
(Ast_payload.ident_or_record_as_config loc payload)}, acc
2578125832
| {bs_deriving = `Has_deriving _}, "bs.deriving"
2578225833
->
2578325834
Bs_syntaxerr.err loc Duplicated_bs_deriving
@@ -25807,10 +25858,10 @@ let process_bs_string_int_unwrap_uncurry attrs =
2580725858
-> `Unwrap, attrs
2580825859
| "bs.uncurry", `Nothing
2580925860
->
25810-
`Uncurry (Ast_payload.is_single_int payload), attrs
25811-
(* Don't allow duplicated [bs.uncurry] since
25812-
it may introduce inconsistency in arity
25813-
*)
25861+
`Uncurry (Ast_payload.is_single_int payload), attrs
25862+
(* Don't allow duplicated [bs.uncurry] since
25863+
it may introduce inconsistency in arity
25864+
*)
2581425865
| "bs.int", _
2581525866
| "bs.string", _
2581625867
| "bs.ignore", _
@@ -25834,7 +25885,7 @@ let process_bs_string_as attrs =
2583425885
end
2583525886
| "bs.as", _
2583625887
->
25837-
Bs_syntaxerr.err loc Duplicated_bs_as
25888+
Bs_syntaxerr.err loc Duplicated_bs_as
2583825889
| _ , _ -> (st, attr::attrs)
2583925890
) (None, []) attrs
2584025891

@@ -25866,10 +25917,10 @@ let process_bs_string_or_int_as attrs =
2586625917
begin match Ast_payload.is_single_int payload with
2586725918
| None ->
2586825919
begin match Ast_payload.is_single_string payload with
25869-
| Some (s,None) -> (Some (`Str (s)), attrs)
25870-
| Some (s, Some "json") -> (Some (`Json_str s ), attrs)
25871-
| None | Some (_, Some _) ->
25872-
Bs_syntaxerr.err loc Expect_int_or_string_or_json_literal
25920+
| Some (s,None) -> (Some (`Str (s)), attrs)
25921+
| Some (s, Some "json") -> (Some (`Json_str s ), attrs)
25922+
| None | Some (_, Some _) ->
25923+
Bs_syntaxerr.err loc Expect_int_or_string_or_json_literal
2587325924

2587425925
end
2587525926
| Some v-> (Some (`Int v), attrs)

0 commit comments

Comments
 (0)