@@ -310,6 +310,20 @@ module E = struct
310310 | _ -> true )
311311 attrs
312312
313+ let extract_for_of_attribute attrs =
314+ List. find_map
315+ (function
316+ | {Location. txt = "res.for_of" } , Pt. PPat (_ , Some expr ) -> Some expr
317+ | _ -> None )
318+ attrs
319+
320+ let remove_for_of_attribute attrs =
321+ List. filter
322+ (function
323+ | {Location. txt = "res.for_of" } , _ -> false
324+ | _ -> true )
325+ attrs
326+
313327 let map_jsx_children sub (e : expression ) : Pt.jsx_children =
314328 let rec visit (e : expression ) : Pt.expression list =
315329 match e.pexp_desc with
@@ -524,9 +538,17 @@ module E = struct
524538 sequence ~loc ~attrs (sub.expr sub e1) (sub.expr sub e2)
525539 | Pexp_while (e1 , e2 ) ->
526540 while_ ~loc ~attrs (sub.expr sub e1) (sub.expr sub e2)
527- | Pexp_for (p , e1 , e2 , d , e3 ) ->
528- for_ ~loc ~attrs (sub.pat sub p) (sub.expr sub e1) (sub.expr sub e2) d
529- (sub.expr sub e3)
541+ | Pexp_for (p , e1 , e2 , d , e3 ) -> (
542+ let array_expr = extract_for_of_attribute attrs in
543+ let attrs = remove_for_of_attribute attrs in
544+ match array_expr with
545+ | Some array ->
546+ (* This is actually a for...of loop, decode it *)
547+ for_of ~loc ~attrs (sub.pat sub p) array (sub.expr sub e3)
548+ | None ->
549+ (* Regular for loop *)
550+ for_ ~loc ~attrs (sub.pat sub p) (sub.expr sub e1) (sub.expr sub e2) d
551+ (sub.expr sub e3))
530552 | Pexp_coerce (e , () , t2 ) ->
531553 coerce ~loc ~attrs (sub.expr sub e) (sub.typ sub t2)
532554 | Pexp_constraint (e , t ) ->
0 commit comments