Skip to content

Commit efc3069

Browse files
cristianoccknitt
authored andcommitted
Fix location of let bindings with attributes
The location of let bindings did not include annotations attached to the binding (for the first binding in a sequence). This would show up in actions for dead code elimination in the editor tooling, which would remove everything but the annotation: rescript-lang/rescript-vscode#991
1 parent 5a6f6fa commit efc3069

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
1313
# 11.1.2
1414

15+
#### :bug: Bug Fix
16+
17+
- Fix location of let bindings with attributes. https://github.com/rescript-lang/rescript-compiler/pull/6791
18+
1519
# 11.1.1
1620

1721
#### :bug: Bug Fix

jscomp/syntax/src/res_core.ml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,8 +2555,7 @@ and parseAttributesAndBinding (p : Parser.t) =
25552555
| _ -> []
25562556

25572557
(* definition ::= let [rec] let-binding { and let-binding } *)
2558-
and parseLetBindings ~attrs p =
2559-
let startPos = p.Parser.startPos in
2558+
and parseLetBindings ~attrs ~startPos p =
25602559
Parser.optional p Let |> ignore;
25612560
let recFlag =
25622561
if Parser.optional p Token.Rec then Asttypes.Recursive
@@ -3222,7 +3221,7 @@ and parseExprBlockItem p =
32223221
let loc = mkLoc startPos p.prevEndPos in
32233222
Ast_helper.Exp.open_ ~loc od.popen_override od.popen_lid blockExpr
32243223
| Let ->
3225-
let recFlag, letBindings = parseLetBindings ~attrs p in
3224+
let recFlag, letBindings = parseLetBindings ~attrs ~startPos p in
32263225
parseNewlineOrSemicolonExprBlock p;
32273226
let next =
32283227
if Grammar.isBlockExprStart p.Parser.token then parseExprBlock p
@@ -5639,7 +5638,7 @@ and parseStructureItemRegion p =
56395638
let loc = mkLoc startPos p.prevEndPos in
56405639
Some (Ast_helper.Str.open_ ~loc openDescription)
56415640
| Let ->
5642-
let recFlag, letBindings = parseLetBindings ~attrs p in
5641+
let recFlag, letBindings = parseLetBindings ~attrs ~startPos p in
56435642
parseNewlineOrSemicolonStructure p;
56445643
let loc = mkLoc startPos p.prevEndPos in
56455644
Some (Ast_helper.Str.value ~loc recFlag letBindings)

0 commit comments

Comments
 (0)