@@ -58,6 +58,8 @@ let handle_config (config : Parsetree.expression option) =
58
58
}
59
59
],None )
60
60
-> not (x = " false" )
61
+ | Pexp_ident {txt = Lident (" jsType" )}
62
+ -> true
61
63
| _ -> invalid_config config)
62
64
| None -> false
63
65
let noloc = Location. none
@@ -110,11 +112,12 @@ let revSearch len constantArray exp =
110
112
constantArray
111
113
exp
112
114
113
- let revSearchAssert constantArray exp =
114
- app2
115
+ let revSearchAssert len constantArray exp =
116
+ app3
115
117
(Exp. ident
116
118
{loc= noloc;
117
119
txt = Longident. Ldot (jsMapperRt, " revSearchAssert" )})
120
+ len
118
121
constantArray
119
122
exp
120
123
@@ -134,14 +137,24 @@ let fromInt len array exp =
134
137
array
135
138
exp
136
139
137
- let fromIntAssert array exp =
138
- app2
140
+ let fromIntAssert len array exp =
141
+ app3
139
142
(Exp. ident
140
143
{loc = noloc;
141
144
txt = Longident. Ldot (jsMapperRt," fromIntAssert" )})
145
+ len
142
146
array
143
147
exp
144
148
149
+
150
+ let assertExp e =
151
+ Exp. extension
152
+ ({Asttypes. loc = noloc; txt = " assert" },
153
+ (PStr
154
+ [Str. eval e ]
155
+ )
156
+ )
157
+
145
158
let init () =
146
159
Ast_derive. register
147
160
" jsMapper"
@@ -267,6 +280,7 @@ let init () =
267
280
(Pat. var pat_param)
268
281
(if createType then
269
282
revSearchAssert
283
+ exp_len
270
284
expConstantArray
271
285
(exp_param +: newType)
272
286
+>
@@ -295,6 +309,7 @@ let init () =
295
309
match xs with
296
310
| `New xs ->
297
311
let constantArrayExp = Exp. ident {loc; txt = Lident constantArray} in
312
+ let exp_len = const_int (List. length ctors) in
298
313
let v = [
299
314
eraseTypeStr;
300
315
Ast_comb. single_non_rec_value
@@ -316,13 +331,14 @@ let init () =
316
331
(
317
332
if createType then
318
333
fromIntAssert
334
+ exp_len
319
335
constantArrayExp
320
336
(exp_param +: newType)
321
337
+>
322
338
core_type
323
339
else
324
340
fromInt
325
- (const_int ( List. length ctors))
341
+ exp_len
326
342
constantArrayExp
327
343
exp_param
328
344
+>
@@ -340,18 +356,30 @@ let init () =
340
356
(eraseType exp_param +~ const_int offset)
341
357
)
342
358
;
359
+ let len = List. length ctors in
360
+ let range_low = const_int (offset + 0 ) in
361
+ let range_upper = const_int (offset + len - 1 ) in
362
+
343
363
Ast_comb. single_non_rec_value
344
364
{loc ; txt = fromJs}
345
365
(Exp. fun_ " " None
346
366
(Pat. var pat_param)
347
367
(if createType then
348
- (( exp_param +: newType) -~ const_int offset)
368
+ (Exp. let_ Nonrecursive
369
+ [Vb. mk
370
+ (Pat. var pat_param)
371
+ (exp_param +: newType)
372
+ ]
373
+ (
374
+ Exp. sequence
375
+ (assertExp
376
+ ((exp_param < =~ range_upper) &&~ (range_low < =~ exp_param))
377
+ )
378
+ (exp_param -~ const_int offset))
379
+ )
349
380
+>
350
381
core_type
351
382
else
352
- let len = List. length ctors in
353
- let range_low = const_int (offset + 0 ) in
354
- let range_upper = const_int (offset + len - 1 ) in
355
383
(Exp. ifthenelse
356
384
( (exp_param < =~ range_upper) &&~ (range_low < =~ exp_param))
357
385
(Exp. construct {loc; txt = Lident " Some" }
0 commit comments