@@ -136,7 +136,7 @@ let funExpr expr =
136136 collectNewTypes (stringLoc :: acc) returnExpr
137137 | returnExpr -> (List. rev acc, returnExpr)
138138 in
139- let rec collect n attrsBefore acc expr =
139+ let rec collect attrsBefore acc expr =
140140 match expr with
141141 | {
142142 pexp_desc =
@@ -147,48 +147,26 @@ let funExpr expr =
147147 {pexp_desc = Pexp_apply _} );
148148 } ->
149149 (attrsBefore, List. rev acc, rewriteUnderscoreApply expr)
150- | {
151- pexp_desc = Pexp_fun (lbl, defaultExpr, pattern, returnExpr);
152- pexp_attributes = [] ;
153- } ->
154- let parameter = Parameter {attrs = [] ; lbl; defaultExpr; pat = pattern} in
155- collect (n + 1 ) attrsBefore (parameter :: acc) returnExpr
156150 | {pexp_desc = Pexp_newtype (stringLoc , rest ); pexp_attributes = attrs } ->
157151 let stringLocs, returnExpr = collectNewTypes [stringLoc] rest in
158152 let param = NewTypes {attrs; locs = stringLocs} in
159- collect (n + 1 ) attrsBefore (param :: acc) returnExpr
160- | {pexp_desc = Pexp_fun _; pexp_attributes}
161- when pexp_attributes
162- |> List. exists (fun ({Location. txt} , _ ) ->
163- txt = " bs" || txt = " res.async" )
164- && n > 0 ->
165- (* stop here, the uncurried or async attribute always indicates the beginning of an arrow function
166- * e.g. `(. a) => (. b)` instead of `(. a, . b)` *)
167- (attrsBefore, List. rev acc, expr)
153+ collect attrsBefore (param :: acc) returnExpr
168154 | {
169- pexp_desc =
170- Pexp_fun
171- (((Labelled _ | Optional _) as lbl), defaultExpr, pattern, returnExpr);
172- pexp_attributes = attrs;
155+ pexp_desc = Pexp_fun (lbl, defaultExpr, pattern, returnExpr);
156+ pexp_attributes = [] ;
173157 } ->
174- (* Normally attributes are attached to the labelled argument, e.g. (@foo ~x) => ...
175- In the case of `@res.async`, pass the attribute to the outside *)
176- let attrs_async, attrs_other =
177- attrs |> List. partition (fun ({Location. txt} , _ ) -> txt = " res.async" )
178- in
179- let parameter =
180- Parameter {attrs = attrs_other; lbl; defaultExpr; pat = pattern}
181- in
182- collect (n + 1 ) (attrs_async @ attrsBefore) (parameter :: acc) returnExpr
158+ let parameter = Parameter {attrs = [] ; lbl; defaultExpr; pat = pattern} in
159+ collect attrsBefore (parameter :: acc) returnExpr
160+ | {pexp_desc = Pexp_fun _ } -> (attrsBefore, List. rev acc, expr)
183161 | expr -> (attrsBefore, List. rev acc, expr)
184162 in
185163 match expr with
186164 | {
187- pexp_desc = Pexp_fun (Nolabel , _defaultExpr, _pattern, _returnExpr);
165+ pexp_desc = Pexp_fun (_ , _defaultExpr, _pattern, _returnExpr);
188166 pexp_attributes = attrs;
189167 } as expr ->
190- collect 0 attrs [] {expr with pexp_attributes = [] }
191- | expr -> collect 0 [] [] expr
168+ collect attrs [] {expr with pexp_attributes = [] }
169+ | expr -> collect [] [] expr
192170
193171let processBracesAttr expr =
194172 match expr.pexp_attributes with
0 commit comments