@@ -136,7 +136,7 @@ let funExpr expr =
136
136
collectNewTypes (stringLoc :: acc) returnExpr
137
137
| returnExpr -> (List. rev acc, returnExpr)
138
138
in
139
- let rec collect n attrsBefore acc expr =
139
+ let rec collect attrsBefore acc expr =
140
140
match expr with
141
141
| {
142
142
pexp_desc =
@@ -147,48 +147,26 @@ let funExpr expr =
147
147
{pexp_desc = Pexp_apply _} );
148
148
} ->
149
149
(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
156
150
| {pexp_desc = Pexp_newtype (stringLoc , rest ); pexp_attributes = attrs } ->
157
151
let stringLocs, returnExpr = collectNewTypes [stringLoc] rest in
158
152
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
168
154
| {
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 = [] ;
173
157
} ->
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)
183
161
| expr -> (attrsBefore, List. rev acc, expr)
184
162
in
185
163
match expr with
186
164
| {
187
- pexp_desc = Pexp_fun (Nolabel , _defaultExpr, _pattern, _returnExpr);
165
+ pexp_desc = Pexp_fun (_ , _defaultExpr, _pattern, _returnExpr);
188
166
pexp_attributes = attrs;
189
167
} 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
192
170
193
171
let processBracesAttr expr =
194
172
match expr.pexp_attributes with
0 commit comments