Skip to content

Commit

Permalink
update loc attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
aspeddro committed Aug 15, 2023
1 parent da94a3c commit 5be09fb
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 34 deletions.
13 changes: 10 additions & 3 deletions jscomp/syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2005,7 +2005,6 @@ and parseBracketAccess p expr startPos =
Parser.eatBreadcrumb p;
let rbracket = p.prevEndPos in
let arrayLoc = mkLoc lbracket rbracket in
let attr = (Location.mkloc "res.syntaxSugar" arrayLoc, Parsetree.PStr []) in
match p.token with
| Equal ->
Parser.leaveBreadcrumb p ExprArrayMutation;
Expand All @@ -2015,15 +2014,23 @@ and parseBracketAccess p expr startPos =
Location.mkloc (Longident.Ldot (Lident "Array", "set")) arrayLoc
in
let endPos = p.prevEndPos in
let attr =
( Location.mkloc "res.syntaxSugar" (mkLoc startPos endPos),
Parsetree.PStr [] )
in
let arraySet =
Ast_helper.Exp.apply ~loc:(mkLoc startPos endPos) ~attrs:[attr]
(Ast_helper.Exp.ident ~loc:arrayLoc arraySet)
Ast_helper.Exp.apply ~loc:(mkLoc startPos endPos)
(Ast_helper.Exp.ident ~loc:arrayLoc arraySet ~attrs:[attr])
[(Nolabel, expr); (Nolabel, accessExpr); (Nolabel, rhsExpr)]
in
Parser.eatBreadcrumb p;
arraySet
| _ ->
let endPos = p.prevEndPos in
let attr =
( Location.mkloc "res.syntaxSugar" (mkLoc startPos endPos),
Parsetree.PStr [] )
in
let e =
Ast_helper.Exp.apply ~loc:(mkLoc startPos endPos)
(Ast_helper.Exp.ident ~loc:arrayLoc ~attrs:[attr]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
| _ -> ())
[@res.braces ]))[@res.namedArgLoc ][@res.braces ])
~children:[] ())[@JSX ])
;;if ((inclusions.(index) <- (uid, url))[@res.syntaxSugar ])
;;if ((Array.set)[@res.syntaxSugar ]) inclusions index (uid, url)
then onChange inclusions
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let e = ((if a |> computation then true else false)
let e = ((((Array.get)[@res.syntaxSugar ]) a 0)[@res.braces ])
let e = ((f b)[@res.braces ])
let e = (((a.b).c)[@res.braces ])
let e = ((arr.(x) <- 20)[@res.braces ][@res.syntaxSugar ])
let e = ((((Array.set)[@res.syntaxSugar ]) arr x 20)[@res.braces ])
let e = ((fun x -> (x + 1) |> (doStuff config))[@res.braces ])
let e = (((fun x -> x + 1) |> (doStuff config))[@res.braces ])
let e = ((if fun x -> x + 1 then true else false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let x =
let x =
((Array.get)[@res.syntaxSugar ])
(((Array.get)[@res.syntaxSugar ]) arr (x : int)) (y : int)
;;((arr.(0) <- (a + b))[@res.syntaxSugar ])
;;((Array.set)[@res.syntaxSugar ]) arr 0 (a + b)
;;f ()
;;(f ()) ()
;;f a
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(@res.syntaxSugar a[/* zz */ 0] = 7)
a[/* zz */ 0] = 7

let _ = /* zz */ a[0]

Expand Down
11 changes: 4 additions & 7 deletions jscomp/syntax/tests/printer/expr/expected/arraySet.res.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
(@res.syntaxSugar numbers[20] = 10)
numbers[20] = 10

(
@res.syntaxSugar
streetsAddressBookThisIsALongName[
streets->Belt.Array.length - 1
] = streetWithAVeryVeryVerrrrrrryVeeeeeeeeeryLongName
)
streetsAddressBookThisIsALongName[
streets->Belt.Array.length - 1
] = streetWithAVeryVeryVerrrrrrryVeeeeeeeeeryLongName
28 changes: 11 additions & 17 deletions jscomp/syntax/tests/printer/expr/expected/braced.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -220,24 +220,18 @@ let _ = {module(ME: MyMod)}
}[{
0
}]
(@res.syntaxSugar {myArray}[{0}] = {20})
(
@res.syntaxSugar
{
myArray
}[{
0
}] = {
20
}
)
{myArray}[{0}] = {20}
{
myArray
}[{
0
}] = {
20
}

(
@res.syntaxSugar
myArray[20] = {
a + b
}
)
myArray[20] = {
a + b
}

{jsObject}["foo"]
{jsObject}["foo"] = {"bar"}
Expand Down
2 changes: 1 addition & 1 deletion jscomp/syntax/tests/printer/expr/expected/if.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let x =
sideEffect()
}

if @res.syntaxSugar inclusions[index] = (uid, url) {
if inclusions[index] = (uid, url) {
onChange(inclusions)
}

Expand Down
2 changes: 1 addition & 1 deletion jscomp/syntax/tests/printer/expr/expected/unary.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ let () = {
}

let x = (!truths)[0]
(@res.syntaxSugar (!streets)[0] = "foo-street")
(!streets)[0] = "foo-street"
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ f(a, b, _) ? g(x, y, _) : h(alpha, beta, _)
<div> {f(a, b, _)} </div>

f(a, b, _)[ix]
(@res.syntaxSugar f(a, b, _)[ix] = 2)
f(a, b, _)[ix] = 2

getDirector(a, b, _).name = "Steve"

Expand Down

0 comments on commit 5be09fb

Please sign in to comment.