@@ -60,7 +60,12 @@ let () =
60
60
Ast_derive_js_mapper. init ()
61
61
62
62
63
-
63
+ let succeed attr attrs =
64
+ match attrs with
65
+ | [ _ ] -> ()
66
+ | _ ->
67
+ Bs_ast_invariant. mark_used_bs_attribute attr;
68
+ Bs_ast_invariant. warn_discarded_unused_attributes attrs
64
69
65
70
type mapper = Bs_ast_mapper .mapper
66
71
let default_mapper = Bs_ast_mapper. default_mapper
@@ -243,14 +248,14 @@ let signature_item_mapper (self : mapper) (sigi : Parsetree.signature_item) =
243
248
Ast_external. handleExternalInSig self value_desc sigi
244
249
else
245
250
(match
246
- Ast_attributes. has_inline_payload_in_sig
251
+ Ast_attributes. has_inline_payload
247
252
pval_attributes with
248
- | Some ({loc} ,PStr [{pstr_desc = Pstr_eval ({pexp_desc } ,_ )} ]) ->
253
+ | Some (( _ ,PStr [{pstr_desc = Pstr_eval ({pexp_desc } ,_ )} ]) as attr ) ->
249
254
begin match pexp_desc with
250
255
| Pexp_constant (
251
256
Pconst_string
252
257
(s,dec)) ->
253
- Bs_ast_invariant. warn_discarded_unused_attributes pval_attributes;
258
+ succeed attr pval_attributes;
254
259
{ sigi with
255
260
psig_desc = Psig_value
256
261
{
@@ -260,8 +265,8 @@ let signature_item_mapper (self : mapper) (sigi : Parsetree.signature_item) =
260
265
}}
261
266
| Pexp_constant (
262
267
Pconst_integer (s,None )
263
- ) ->
264
- Bs_ast_invariant. warn_discarded_unused_attributes pval_attributes;
268
+ ) ->
269
+ succeed attr pval_attributes;
265
270
let s = Int32. of_string s in
266
271
{ sigi with
267
272
psig_desc = Psig_value
@@ -273,22 +278,22 @@ let signature_item_mapper (self : mapper) (sigi : Parsetree.signature_item) =
273
278
| Pexp_constant (Pconst_integer (s, Some 'L' ))
274
279
->
275
280
let s = Int64. of_string s in
276
- Bs_ast_invariant. warn_discarded_unused_attributes pval_attributes;
281
+ succeed attr pval_attributes;
277
282
{sigi with psig_desc = Psig_value {
278
283
value_desc with
279
284
pval_prim = External_ffi_types. inline_int64_primitive s;
280
285
pval_attributes = [] ;
281
286
} }
282
287
| Pexp_constant (Pconst_float(s ,None)) ->
283
- Bs_ast_invariant. warn_discarded_unused_attributes pval_attributes;
288
+ succeed attr pval_attributes;
284
289
{sigi with psig_desc = Psig_value {
285
290
value_desc with
286
291
pval_prim = External_ffi_types. inline_float_primitive s;
287
292
pval_attributes = [] ;
288
293
} }
289
294
| Pexp_construct ({txt = Lident (" true" | " false" as txt)}, None )
290
295
->
291
- Bs_ast_invariant. warn_discarded_unused_attributes pval_attributes;
296
+ succeed attr pval_attributes;
292
297
{ sigi with
293
298
psig_desc = Psig_value
294
299
{
@@ -297,12 +302,11 @@ let signature_item_mapper (self : mapper) (sigi : Parsetree.signature_item) =
297
302
pval_attributes = []
298
303
}}
299
304
| _ ->
300
- Location. raise_errorf ~loc " invalid payload in bs.inline "
305
+ default_mapper.signature_item self sigi
301
306
end
302
- | Some ({loc} , _ ) ->
303
- Location. raise_errorf ~loc " invalid payload in bs.inline"
307
+ | Some _
304
308
| None ->
305
- default_mapper.signature_item self sigi
309
+ default_mapper.signature_item self sigi
306
310
)
307
311
| _ -> default_mapper.signature_item self sigi
308
312
@@ -327,66 +331,64 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) =
327
331
->
328
332
let pvb_expr = self.expr self pvb_expr in
329
333
let pvb_attributes = self.attributes self pvb_attributes in
330
- let has_inline_property = Ast_attributes. has_inline_in_stru pvb_attributes in
331
- if has_inline_property then
332
- begin match pvb_expr.pexp_desc with
333
- | Pexp_constant (
334
- Pconst_string
335
- (s,dec))
336
- ->
337
- Bs_ast_invariant. warn_discarded_unused_attributes pvb_attributes;
338
- {str with pstr_desc = Pstr_primitive {
339
- pval_name = pval_name ;
340
- pval_type = Ast_literal. type_string () ;
341
- pval_loc = pvb_loc;
342
- pval_attributes = [] ;
343
- pval_prim = External_ffi_types. inline_string_primitive s dec
344
- } }
345
- | Pexp_constant (Pconst_integer (s,None ))
346
- ->
347
- let s = Int32. of_string s in
348
- Bs_ast_invariant. warn_discarded_unused_attributes pvb_attributes;
349
- {str with pstr_desc = Pstr_primitive {
350
- pval_name = pval_name ;
351
- pval_type = Ast_literal. type_int () ;
352
- pval_loc = pvb_loc;
353
- pval_attributes = [] ;
354
- pval_prim = External_ffi_types. inline_int_primitive s
355
- } }
356
- | Pexp_constant (Pconst_integer (s, Some 'L' ))
357
- ->
358
- let s = Int64. of_string s in
359
- Bs_ast_invariant. warn_discarded_unused_attributes pvb_attributes;
360
- {str with pstr_desc = Pstr_primitive {
361
- pval_name = pval_name ;
362
- pval_type = Ast_literal. type_int64;
363
- pval_loc = pvb_loc;
364
- pval_attributes = [] ;
365
- pval_prim = External_ffi_types. inline_int64_primitive s
366
- } }
367
- | Pexp_constant (Pconst_float (s, None ))
368
- ->
369
- Bs_ast_invariant. warn_discarded_unused_attributes pvb_attributes;
370
- {str with pstr_desc = Pstr_primitive {
371
- pval_name = pval_name ;
372
- pval_type = Ast_literal. type_float;
373
- pval_loc = pvb_loc;
374
- pval_attributes = [] ;
375
- pval_prim = External_ffi_types. inline_float_primitive s
376
- } }
377
- | Pexp_construct ({txt = Lident ("true" | "false" as txt ) } ,None ) ->
378
- Bs_ast_invariant. warn_discarded_unused_attributes pvb_attributes;
379
- {str with pstr_desc = Pstr_primitive {
380
- pval_name = pval_name ;
381
- pval_type = Ast_literal. type_bool () ;
382
- pval_loc = pvb_loc;
383
- pval_attributes = [] ;
384
- pval_prim = External_ffi_types. inline_bool_primitive (txt = " true" )
385
- } }
386
- | _ -> Location. raise_errorf ~loc: pvb_loc " invalid payload in bs.inline"
387
- end
388
- else
389
- { str with pstr_desc = Pstr_value (Nonrecursive , [{pvb_pat ; pvb_expr; pvb_attributes; pvb_loc}])}
334
+ let has_inline_property = Ast_attributes. has_inline_payload pvb_attributes in
335
+ begin match has_inline_property, pvb_expr.pexp_desc with
336
+ | Some attr, Pexp_constant (
337
+ Pconst_string
338
+ (s,dec))
339
+ ->
340
+ succeed attr pvb_attributes;
341
+ {str with pstr_desc = Pstr_primitive {
342
+ pval_name = pval_name ;
343
+ pval_type = Ast_literal. type_string () ;
344
+ pval_loc = pvb_loc;
345
+ pval_attributes = [] ;
346
+ pval_prim = External_ffi_types. inline_string_primitive s dec
347
+ } }
348
+ | Some attr, Pexp_constant (Pconst_integer (s,None ))
349
+ ->
350
+ let s = Int32. of_string s in
351
+ succeed attr pvb_attributes;
352
+ {str with pstr_desc = Pstr_primitive {
353
+ pval_name = pval_name ;
354
+ pval_type = Ast_literal. type_int () ;
355
+ pval_loc = pvb_loc;
356
+ pval_attributes = [] ;
357
+ pval_prim = External_ffi_types. inline_int_primitive s
358
+ } }
359
+ | Some attr, Pexp_constant (Pconst_integer (s, Some 'L' ))
360
+ ->
361
+ let s = Int64. of_string s in
362
+ succeed attr pvb_attributes;
363
+ {str with pstr_desc = Pstr_primitive {
364
+ pval_name = pval_name ;
365
+ pval_type = Ast_literal. type_int64;
366
+ pval_loc = pvb_loc;
367
+ pval_attributes = [] ;
368
+ pval_prim = External_ffi_types. inline_int64_primitive s
369
+ } }
370
+ | Some attr, Pexp_constant (Pconst_float (s, None ))
371
+ ->
372
+ succeed attr pvb_attributes;
373
+ {str with pstr_desc = Pstr_primitive {
374
+ pval_name = pval_name ;
375
+ pval_type = Ast_literal. type_float;
376
+ pval_loc = pvb_loc;
377
+ pval_attributes = [] ;
378
+ pval_prim = External_ffi_types. inline_float_primitive s
379
+ } }
380
+ | Some attr , Pexp_construct ({txt = Lident ("true" | "false" as txt ) } ,None ) ->
381
+ succeed attr pvb_attributes;
382
+ {str with pstr_desc = Pstr_primitive {
383
+ pval_name = pval_name ;
384
+ pval_type = Ast_literal. type_bool () ;
385
+ pval_loc = pvb_loc;
386
+ pval_attributes = [] ;
387
+ pval_prim = External_ffi_types. inline_bool_primitive (txt = " true" )
388
+ } }
389
+ | _ ->
390
+ { str with pstr_desc = Pstr_value (Nonrecursive , [{pvb_pat ; pvb_expr; pvb_attributes; pvb_loc}])}
391
+ end
390
392
| Pstr_attribute ({txt = "bs.config" } ,_ ) -> str
391
393
| _ -> default_mapper.structure_item self str
392
394
@@ -431,10 +433,6 @@ let rec
431
433
| [] -> []
432
434
| item ::rest ->
433
435
match item.pstr_desc with
434
- | Pstr_extension (({txt = (" bs.debugger.chrome" | " debugger.chrome" ) ;loc}, _),_)
435
- ->
436
- Location. prerr_warning loc (Preprocessor " this extension can be safely removed" );
437
- structure_mapper self rest
438
436
| Pstr_extension ( ({txt = (" bs.raw" | " raw" ) ; loc}, payload), _attrs)
439
437
->
440
438
Ast_exp_handle_external. handle_raw_structure loc payload :: structure_mapper self rest
0 commit comments