2323 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424
2525type attr = Parsetree .attribute
26-
2726type t = attr list
28-
2927type ('a, 'b) st = { get : 'a option ; set : 'b option }
3028
3129let process_method_attributes_rev (attrs : t ) =
@@ -164,14 +162,13 @@ let is_inline : attr -> bool =
164162let has_inline_payload (attrs : t ) = Ext_list. find_first attrs is_inline
165163
166164let is_await : attr -> bool =
167- fun ({ txt } , _ ) -> txt = " await" || txt = " res.await"
165+ fun ({ txt } , _ ) -> txt = " await" || txt = " res.await"
168166
169167let is_async : attr -> bool =
170- fun ({ txt } , _ ) -> txt = " async" || txt = " res.async"
168+ fun ({ txt } , _ ) -> txt = " async" || txt = " res.async"
171169
172170let has_await_payload (attrs : t ) = Ext_list. find_first attrs is_await
173171let has_async_payload (attrs : t ) = Ext_list. find_first attrs is_async
174-
175172
176173type derive_attr = { bs_deriving : Ast_payload .action list option } [@@ unboxed]
177174
@@ -281,10 +278,16 @@ let iter_process_bs_int_as (attrs : t) =
281278 | _ -> () );
282279 ! st
283280
284- type as_const_payload = Int of int | Str of string * string option
281+ type as_const_payload = Int of int | Str of string * J .delim
285282
286283let iter_process_bs_string_or_int_as (attrs : Parsetree.attributes ) =
287284 let st = ref None in
285+ let process_delim = function
286+ | None -> Some J. Nothing
287+ | Some "json" -> Some Json
288+ | Some "*j" -> Some StarJ
289+ | _ -> None
290+ in
288291 Ext_list. iter attrs (fun (({ txt; loc } , payload ) as attr ) ->
289292 match txt with
290293 | "bs.as" | "as" ->
@@ -300,32 +303,34 @@ let iter_process_bs_string_or_int_as (attrs : Parsetree.attributes) =
300303 Pstr_eval
301304 ( {
302305 pexp_desc =
303- Pexp_constant
304- (Pconst_string
305- (s, ((None | Some " json" | Some " *j" ) as delim)));
306+ Pexp_constant (Pconst_string (s, delim_));
306307 pexp_loc;
307308 _;
308309 },
309310 _ );
310311 _;
311312 };
312313 ]
313- ->
314+ when process_delim delim_ <> None -> (
315+ let delim =
316+ match process_delim delim_ with
317+ | None -> assert false
318+ | Some delim -> delim
319+ in
314320 st := Some (Str (s, delim));
315- if delim = Some " json " then (
321+ if delim = Json then
316322 (* check that it is a valid object literal *)
317323 match
318- Classify_function. classify
319- ~check:
320- (pexp_loc, Bs_flow_ast_utils. flow_deli_offset delim )
321- s
322- with
324+ Classify_function. classify
325+ ~check:
326+ (pexp_loc, Bs_flow_ast_utils. flow_deli_offset delim_ )
327+ s
328+ with
323329 | Js_literal _ -> ()
324330 | _ ->
325331 Location. raise_errorf ~loc: pexp_loc
326- " an object literal expected"
327- )
328- | _ -> Bs_syntaxerr. err loc (Expect_int_or_string_or_json_literal )
332+ " an object literal expected" )
333+ | _ -> Bs_syntaxerr. err loc Expect_int_or_string_or_json_literal
329334 )
330335 | Some v -> st := Some (Int v))
331336 else Bs_syntaxerr. err loc Duplicated_bs_as
0 commit comments