@@ -282,32 +282,33 @@ module Exp = {
282282 let list = (~loc=?, ~attributes=?, a) => {
283283 let empty = ident(~loc? , ident_empty);
284284 let cons = ident(ident_cons);
285- let a = List . rev(a);
286- switch (a) {
287- | [] => empty
288- | [ base , ... rest ] =>
289- let base =
290- switch (base) {
291- | ListItem (expr ) => apply(~attributes? , cons, [ expr, empty] )
292- | ListSpread (expr , _ ) => expr
293- };
294- List . fold_left(
295- (acc, expr) => {
296- switch (expr) {
297- | ListItem (expr ) => apply(~attributes? , cons, [ expr, acc] )
298- | ListSpread (_ , loc ) =>
299- raise (
300- SyntaxError (
301- loc,
302- "A list spread can only appear at the end of a list." ,
303- ),
304- )
305- }
306- },
307- base,
308- rest,
309- );
310- };
285+ let list =
286+ switch (List . rev(a)) {
287+ | [] => empty
288+ | [ base , ... rest ] =>
289+ let base =
290+ switch (base) {
291+ | ListItem (expr ) => apply(~attributes? , cons, [ expr, empty] )
292+ | ListSpread (expr , _ ) => expr
293+ };
294+ List . fold_left(
295+ (acc, expr) => {
296+ switch (expr) {
297+ | ListItem (expr ) => apply(~attributes? , cons, [ expr, acc] )
298+ | ListSpread (_ , loc ) =>
299+ raise (
300+ SyntaxError (
301+ loc,
302+ "A list spread can only appear at the end of a list." ,
303+ ),
304+ )
305+ }
306+ },
307+ base,
308+ rest,
309+ );
310+ };
311+ Option . fold(~none= list, ~some= loc => {... list, pexp_loc: loc}, loc);
311312 };
312313 let null = (~loc=?, ~attributes=?, () ) =>
313314 mk(~loc? , ~attributes? , PExpNull );
0 commit comments