@@ -69536,8 +69536,8 @@ let fn_method = "fn_method"
69536
69536
let fn_mk = "fn_mk"
69537
69537
(*let js_fn_runmethod = "js_fn_runmethod"*)
69538
69538
69539
- let bs_deriving = "bs.deriving"
69540
- let bs_deriving_dot = "bs.deriving."
69539
+
69540
+
69541
69541
69542
69542
69543
69543
(** nodejs *)
@@ -400907,21 +400907,21 @@ let external_needs_to_be_encoded (attrs : t)=
400907
400907
(fun {txt} ->
400908
400908
Ext_string.starts_with txt "bs." || txt = Literals.gentype_import)
400909
400909
400910
+ let is_inline : attr -> bool =
400911
+ (fun
400912
+ (({txt;},_) as attr) ->
400913
+ let b = txt = "bs.inline" || txt = "inline" in
400914
+ (if b then
400915
+ Bs_ast_invariant.mark_used_bs_attribute attr);
400916
+ b
400917
+ ) (* still needs to be marked, since we are going to drop it right now *)
400918
+
400910
400919
let has_inline_in_stru (attrs : t) : bool =
400911
- Ext_list.exists attrs (fun
400912
- ({txt;},_) ->
400913
- if txt = "bs.inline" then
400914
- true
400915
- else false)
400920
+ Ext_list.exists attrs is_inline
400916
400921
400917
400922
let has_inline_payload_in_sig (attrs : t) =
400918
- Ext_list.find_first attrs
400919
- (fun
400920
- ({txt},_) ->
400921
- if txt = "bs.inline" then
400922
- true
400923
- else false
400924
- )
400923
+ Ext_list.find_first attrs is_inline
400924
+
400925
400925
400926
400926
type derive_attr = {
400927
400927
bs_deriving : Ast_payload.action list option
@@ -403063,12 +403063,6 @@ val gen_signature:
403063
403063
Ast_signature.t
403064
403064
403065
403065
403066
- val gen_expression :
403067
- string Asttypes.loc ->
403068
- Parsetree.core_type ->
403069
- Parsetree.expression
403070
-
403071
-
403072
403066
403073
403067
val gen_structure_signature :
403074
403068
Location.t ->
@@ -403145,15 +403139,7 @@ let gen_signature
403145
403139
(Ast_payload.table_dispatch !derive_table action).signature_gen
403146
403140
tdcls explict_nonrec)
403147
403141
403148
- (** used for cases like [%sexp] *)
403149
- let gen_expression ({Asttypes.txt ; loc}) typ =
403150
- let txt = Ext_string.tail_from txt (String.length Literals.bs_deriving_dot) in
403151
- match (Ast_payload.table_dispatch !derive_table
403152
- ({txt ; loc}, None)).expression_gen with
403153
- | None ->
403154
- Bs_syntaxerr.err loc (Unregistered txt)
403155
403142
403156
- | Some f -> f typ
403157
403143
403158
403144
open Ast_helper
403159
403145
let gen_structure_signature
@@ -406838,7 +406824,7 @@ open Ast_helper
406838
406824
406839
406825
406840
406826
let handle_extension record_as_js_object e (self : Bs_ast_mapper.mapper)
406841
- (({txt ; loc} as lid , payload) : Parsetree.extension) =
406827
+ (({txt ; loc} , payload) : Parsetree.extension) =
406842
406828
begin match txt with
406843
406829
| "bs.raw" | "raw" ->
406844
406830
Ast_exp_handle_external.handle_raw ~kind:Raw_exp loc payload
@@ -406951,10 +406937,6 @@ let handle_extension record_as_js_object e (self : Bs_ast_mapper.mapper)
406951
406937
| _ -> Location.raise_errorf ~loc "Expect an expression here"
406952
406938
end
406953
406939
| _ ->
406954
- match payload with
406955
- | PTyp typ when Ext_string.starts_with txt Literals.bs_deriving_dot ->
406956
- self.expr self (Ast_derive.gen_expression lid typ)
406957
- | _ ->
406958
406940
e (* For an unknown extension, we don't really need to process further*)
406959
406941
(* Exp.extension ~loc ~attrs:e.pexp_attributes (
406960
406942
self.extension self extension) *)
@@ -408022,7 +408004,7 @@ let signature_item_mapper (self : mapper) (sigi : Parsetree.signature_item) =
408022
408004
(match
408023
408005
Ast_attributes.has_inline_payload_in_sig
408024
408006
pval_attributes with
408025
- | Some ({loc} ,PStr [{pstr_desc = Pstr_eval ({pexp_desc },_)}]) ->
408007
+ | Some (_ ,PStr [{pstr_desc = Pstr_eval ({pexp_desc },_)}]) ->
408026
408008
begin match pexp_desc with
408027
408009
| Pexp_constant (
408028
408010
Pconst_string
@@ -408074,12 +408056,11 @@ let signature_item_mapper (self : mapper) (sigi : Parsetree.signature_item) =
408074
408056
pval_attributes = []
408075
408057
}}
408076
408058
| _ ->
408077
- Location.raise_errorf ~loc "invalid payload in bs.inline"
408059
+ default_mapper.signature_item self sigi
408078
408060
end
408079
- | Some ({loc}, _) ->
408080
- Location.raise_errorf ~loc "invalid payload in bs.inline"
408061
+ | Some _
408081
408062
| None ->
408082
- default_mapper.signature_item self sigi
408063
+ default_mapper.signature_item self sigi
408083
408064
)
408084
408065
| _ -> default_mapper.signature_item self sigi
408085
408066
@@ -408105,65 +408086,63 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) =
408105
408086
let pvb_expr = self.expr self pvb_expr in
408106
408087
let pvb_attributes = self.attributes self pvb_attributes in
408107
408088
let has_inline_property = Ast_attributes.has_inline_in_stru pvb_attributes in
408108
- if has_inline_property then
408109
- begin match pvb_expr.pexp_desc with
408110
- | Pexp_constant(
408111
- Pconst_string
408112
- (s,dec))
408113
- ->
408114
- Bs_ast_invariant.warn_discarded_unused_attributes pvb_attributes;
408115
- {str with pstr_desc = Pstr_primitive {
408116
- pval_name = pval_name ;
408117
- pval_type = Ast_literal.type_string ();
408118
- pval_loc = pvb_loc;
408119
- pval_attributes = [];
408120
- pval_prim = External_ffi_types.inline_string_primitive s dec
408121
- } }
408122
- | Pexp_constant(Pconst_integer (s,None))
408123
- ->
408124
- let s = Int32.of_string s in
408125
- Bs_ast_invariant.warn_discarded_unused_attributes pvb_attributes;
408126
- {str with pstr_desc = Pstr_primitive {
408127
- pval_name = pval_name ;
408128
- pval_type = Ast_literal.type_int ();
408129
- pval_loc = pvb_loc;
408130
- pval_attributes = [];
408131
- pval_prim = External_ffi_types.inline_int_primitive s
408132
- } }
408133
- | Pexp_constant(Pconst_integer (s, Some 'L'))
408134
- ->
408135
- let s = Int64.of_string s in
408136
- Bs_ast_invariant.warn_discarded_unused_attributes pvb_attributes;
408137
- {str with pstr_desc = Pstr_primitive {
408138
- pval_name = pval_name ;
408139
- pval_type = Ast_literal.type_int64;
408140
- pval_loc = pvb_loc;
408141
- pval_attributes = [];
408142
- pval_prim = External_ffi_types.inline_int64_primitive s
408143
- } }
408144
- | Pexp_constant(Pconst_float (s, None))
408145
- ->
408146
- Bs_ast_invariant.warn_discarded_unused_attributes pvb_attributes;
408147
- {str with pstr_desc = Pstr_primitive {
408148
- pval_name = pval_name ;
408149
- pval_type = Ast_literal.type_float;
408150
- pval_loc = pvb_loc;
408151
- pval_attributes = [];
408152
- pval_prim = External_ffi_types.inline_float_primitive s
408153
- } }
408154
- | Pexp_construct ({txt = Lident ("true" | "false" as txt) },None) ->
408155
- Bs_ast_invariant.warn_discarded_unused_attributes pvb_attributes;
408156
- {str with pstr_desc = Pstr_primitive {
408157
- pval_name = pval_name ;
408158
- pval_type = Ast_literal.type_bool ();
408159
- pval_loc = pvb_loc;
408160
- pval_attributes = [];
408161
- pval_prim = External_ffi_types.inline_bool_primitive (txt = "true")
408162
- } }
408163
- | _ -> Location.raise_errorf ~loc:pvb_loc "invalid payload in bs.inline"
408164
- end
408165
- else
408166
- { str with pstr_desc = Pstr_value(Nonrecursive, [{pvb_pat ; pvb_expr; pvb_attributes; pvb_loc}])}
408089
+ begin match has_inline_property, pvb_expr.pexp_desc with
408090
+ | true, Pexp_constant(
408091
+ Pconst_string
408092
+ (s,dec))
408093
+ ->
408094
+ Bs_ast_invariant.warn_discarded_unused_attributes pvb_attributes;
408095
+ {str with pstr_desc = Pstr_primitive {
408096
+ pval_name = pval_name ;
408097
+ pval_type = Ast_literal.type_string ();
408098
+ pval_loc = pvb_loc;
408099
+ pval_attributes = [];
408100
+ pval_prim = External_ffi_types.inline_string_primitive s dec
408101
+ } }
408102
+ | true, Pexp_constant(Pconst_integer (s,None))
408103
+ ->
408104
+ let s = Int32.of_string s in
408105
+ Bs_ast_invariant.warn_discarded_unused_attributes pvb_attributes;
408106
+ {str with pstr_desc = Pstr_primitive {
408107
+ pval_name = pval_name ;
408108
+ pval_type = Ast_literal.type_int ();
408109
+ pval_loc = pvb_loc;
408110
+ pval_attributes = [];
408111
+ pval_prim = External_ffi_types.inline_int_primitive s
408112
+ } }
408113
+ | true, Pexp_constant(Pconst_integer (s, Some 'L'))
408114
+ ->
408115
+ let s = Int64.of_string s in
408116
+ Bs_ast_invariant.warn_discarded_unused_attributes pvb_attributes;
408117
+ {str with pstr_desc = Pstr_primitive {
408118
+ pval_name = pval_name ;
408119
+ pval_type = Ast_literal.type_int64;
408120
+ pval_loc = pvb_loc;
408121
+ pval_attributes = [];
408122
+ pval_prim = External_ffi_types.inline_int64_primitive s
408123
+ } }
408124
+ | true, Pexp_constant(Pconst_float (s, None))
408125
+ ->
408126
+ Bs_ast_invariant.warn_discarded_unused_attributes pvb_attributes;
408127
+ {str with pstr_desc = Pstr_primitive {
408128
+ pval_name = pval_name ;
408129
+ pval_type = Ast_literal.type_float;
408130
+ pval_loc = pvb_loc;
408131
+ pval_attributes = [];
408132
+ pval_prim = External_ffi_types.inline_float_primitive s
408133
+ } }
408134
+ | true, Pexp_construct ({txt = Lident ("true" | "false" as txt) },None) ->
408135
+ Bs_ast_invariant.warn_discarded_unused_attributes pvb_attributes;
408136
+ {str with pstr_desc = Pstr_primitive {
408137
+ pval_name = pval_name ;
408138
+ pval_type = Ast_literal.type_bool ();
408139
+ pval_loc = pvb_loc;
408140
+ pval_attributes = [];
408141
+ pval_prim = External_ffi_types.inline_bool_primitive (txt = "true")
408142
+ } }
408143
+ | _ ->
408144
+ { str with pstr_desc = Pstr_value(Nonrecursive, [{pvb_pat ; pvb_expr; pvb_attributes; pvb_loc}])}
408145
+ end
408167
408146
| Pstr_attribute({txt = "bs.config" },_) -> str
408168
408147
| _ -> default_mapper.structure_item self str
408169
408148
0 commit comments