Skip to content

Commit 06e79a8

Browse files
authored
fix(compiler): Apply list location to outer node (#1387)
1 parent 613d364 commit 06e79a8

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

compiler/src/parsing/ast_helper.re

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)