@@ -104,7 +104,8 @@ let init () =
104
104
let attr =
105
105
Ast_polyvar. map_row_fields_into_strings loc row_fields
106
106
in
107
-
107
+ let expConstantArray =
108
+ Exp. ident {loc; txt = Longident. Lident constantArray} in
108
109
begin match attr with
109
110
| NullString result ->
110
111
[
@@ -119,31 +120,29 @@ let init () =
119
120
]
120
121
) result));
121
122
(
122
- toJsBody
123
- (Exp. apply
124
- (Exp. ident ({loc;
125
- txt = Longident. parse " Js.MapperRt.search" })
126
- )
127
- [
128
- " " , exp_param;
129
- " " , Exp. ident {loc; txt = Longident. Lident constantArray}
130
- ]
131
- )
132
- );
133
-
134
- let string_arg = " str" in
123
+ toJsBody
124
+ (Exp. apply
125
+ (Exp. ident ({loc;
126
+ txt = Longident. parse " Js.MapperRt.search" })
127
+ )
128
+ [
129
+ " " , exp_param;
130
+ " " , expConstantArray
131
+ ]
132
+ )
133
+ );
135
134
Ast_comb. single_non_rec_value
136
- {loc; txt = fromJs}
135
+ patFromJs
137
136
(Exp. fun_ " " None
138
- (Pat. var {loc; txt = string_arg} )
137
+ (Pat. var pat_param )
139
138
(Exp. constraint_
140
139
(
141
140
Exp. apply
142
141
(Exp. ident {loc; txt = Longident. parse " Js.MapperRt.revSearch" })
143
142
[
144
143
" " , Exp. constant (Const_int (List. length result));
145
- " " , Exp. ident {loc; txt = Longident. Lident constantArray} ;
146
- " " , Exp. ident {loc; txt = Longident. Lident string_arg}
144
+ " " , expConstantArray ;
145
+ " " , exp_param
147
146
]
148
147
)
149
148
(Ast_core_type. lift_option_type core_type)
@@ -157,7 +156,6 @@ let init () =
157
156
)
158
157
159
158
| Ptype_variant ctors ->
160
- let loc = tdcl.ptype_loc in
161
159
if Ast_polyvar. is_enum_constructors ctors then
162
160
let xs = Ast_polyvar. map_constructor_declarations_into_ints ctors in
163
161
match xs with
@@ -167,31 +165,23 @@ let init () =
167
165
{loc; txt = constantArray}
168
166
(Exp. array (List. map (fun i -> Exp. constant (Const_int i)) xs ))
169
167
;
170
- (let variant_arg = " variant" in
171
- Ast_comb. single_non_rec_value
172
- {loc; txt = toJs}
173
- (Exp. fun_ " " None
174
- (Pat. constraint_
175
- (Pat. var {loc; txt = variant_arg } )
176
- core_type
177
- )
178
- (
179
- Exp. apply
180
- (Exp. ident {loc; txt = Longident. parse " Js.MapperRt.toInt" })
181
-
182
- [
183
- " " , Exp. ident {loc; txt = Lident variant_arg};
184
- " " , Exp. ident {loc; txt = Lident constantArray}
185
- ]
186
- )
187
- ))
168
+ (toJsBody
169
+ (
170
+ Exp. apply
171
+ (Exp. ident {loc; txt = Longident. parse " Js.MapperRt.toInt" })
172
+ [
173
+ " " , exp_param;
174
+ " " , Exp. ident {loc; txt = Lident constantArray}
175
+ ]
176
+ )
177
+ )
188
178
;
189
- let int_arg = " int " in
179
+
190
180
Ast_comb. single_non_rec_value
191
- {loc ; txt = fromJs}
181
+ patFromJs
192
182
(Exp. fun_ " " None
193
183
(Pat. constraint_
194
- (Pat. var {loc; txt = int_arg} )
184
+ (Pat. var pat_param )
195
185
(Ast_literal. type_int () )
196
186
)
197
187
(Exp. constraint_
@@ -200,45 +190,39 @@ let init () =
200
190
[
201
191
" " , Exp. constant(Const_int (List. length ctors));
202
192
" " , Exp. ident {loc; txt = Lident constantArray};
203
- " " , Exp. ident {loc; txt = Lident int_arg}
193
+ " " , exp_param
204
194
]
205
195
)
206
196
(Ast_core_type. lift_option_type core_type)
207
197
)
208
198
)
209
199
]
210
200
| `Offset offset ->
211
- let variant_arg = " variant" in
212
- [(Ast_comb. single_non_rec_value
213
- {loc; txt = toJs}
214
- (Exp. fun_ " " None
215
- (Pat. constraint_
216
- (Pat. var {loc; txt = variant_arg } )
217
- core_type
218
- )
219
- (Exp. apply
220
- (Exp. ident {loc; txt = Ldot (Lident " Pervasives" , " +" )})
221
- [
222
- " " ,
223
- (Exp. apply
224
- (Exp. ident {loc; txt = Ldot (Lident " Obj" , " magic" )})
225
- [" " ,(Exp. ident {loc; txt = Lident variant_arg})]);
226
- " " , Exp. constant (Const_int offset)
227
- ]
228
- )
229
- )
201
+
202
+ [(toJsBody
203
+ (Exp. apply
204
+ (Exp. ident {loc; txt = Ldot (Lident " Pervasives" , " +" )})
205
+ [
206
+ " " ,
207
+ (Exp. apply
208
+ (Exp. ident {loc; txt = Ldot (Lident " Obj" , " magic" )})
209
+ [" " ,
210
+ exp_param]);
211
+ " " , Exp. constant (Const_int offset)
212
+ ]
213
+ )
230
214
);
231
- let int_arg = " int " in
215
+
232
216
Ast_comb. single_non_rec_value
233
217
{loc ; txt = fromJs}
234
218
(Exp. fun_ " " None
235
219
(Pat. constraint_
236
- (Pat. var {loc; txt = int_arg} )
220
+ (Pat. var pat_param )
237
221
(Ast_literal. type_int () )
238
222
)
239
223
(Exp. constraint_
240
224
(
241
- let v = Exp. ident {loc; txt = Lident int_arg} in
225
+
242
226
let len = List. length ctors in
243
227
let range_low = Exp. constant (Const_int (offset + 0 )) in
244
228
let range_upper = Exp. constant (Const_int (offset + len - 1 )) in
@@ -251,16 +235,20 @@ let init () =
251
235
(Exp. ident {loc ; txt = Lident " &&" })
252
236
[" " ,
253
237
(Exp. apply (Exp. ident {loc; txt = Lident " <=" })
254
- [" " , v ; " " , range_upper] )
238
+ [" " , exp_param ; " " , range_upper] )
255
239
;
256
240
" " ,
257
241
(Exp. apply (Exp. ident {loc; txt = Lident " <=" })
258
- [" " , range_low; " " ,v ]
242
+ [" " , range_low; " " ,exp_param ]
259
243
)
260
244
]
261
245
)
262
- (Exp. construct {loc; txt = Lident " Some" } (Some v ))
263
-
246
+ (Exp. construct {loc; txt = Lident " Some" }
247
+ (Some
248
+ (Exp. apply
249
+ (Exp. ident {loc; txt = Ldot (Lident " Pervasives" ," -" )})
250
+ [" " ,exp_param ; " " , Exp. constant (Const_int offset)])
251
+ ))
264
252
(Some (Exp. construct {loc; txt = Lident " None" } None )))
265
253
]
266
254
)
0 commit comments