From 5be09fbe1e648f059e64ec07b42f58555b0b0661 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Tue, 15 Aug 2023 20:57:07 -0300 Subject: [PATCH] update loc attrs --- jscomp/syntax/src/res_core.ml | 13 +++++++-- .../expected/binaryNoEs6Arrow.res.txt | 2 +- .../expected/bracedOrRecord.res.txt | 2 +- .../expressions/expected/primary.res.txt | 2 +- .../printer/comments/expected/array.res.txt | 2 +- .../printer/expr/expected/arraySet.res.txt | 11 +++----- .../printer/expr/expected/braced.res.txt | 28 ++++++++----------- .../tests/printer/expr/expected/if.res.txt | 2 +- .../tests/printer/expr/expected/unary.res.txt | 2 +- .../expr/expected/underscoreApply.res.txt | 2 +- 10 files changed, 32 insertions(+), 34 deletions(-) diff --git a/jscomp/syntax/src/res_core.ml b/jscomp/syntax/src/res_core.ml index 7118aa0e99..1ce02cfc74 100644 --- a/jscomp/syntax/src/res_core.ml +++ b/jscomp/syntax/src/res_core.ml @@ -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; @@ -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] diff --git a/jscomp/syntax/tests/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt b/jscomp/syntax/tests/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt index 95e400abf5..be3e32f71a 100644 --- a/jscomp/syntax/tests/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt +++ b/jscomp/syntax/tests/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt @@ -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 \ No newline at end of file diff --git a/jscomp/syntax/tests/parsing/grammar/expressions/expected/bracedOrRecord.res.txt b/jscomp/syntax/tests/parsing/grammar/expressions/expected/bracedOrRecord.res.txt index 1e42aa2b6a..1f35ee8e20 100644 --- a/jscomp/syntax/tests/parsing/grammar/expressions/expected/bracedOrRecord.res.txt +++ b/jscomp/syntax/tests/parsing/grammar/expressions/expected/bracedOrRecord.res.txt @@ -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) diff --git a/jscomp/syntax/tests/parsing/grammar/expressions/expected/primary.res.txt b/jscomp/syntax/tests/parsing/grammar/expressions/expected/primary.res.txt index 4b79cab514..ef0892f23f 100644 --- a/jscomp/syntax/tests/parsing/grammar/expressions/expected/primary.res.txt +++ b/jscomp/syntax/tests/parsing/grammar/expressions/expected/primary.res.txt @@ -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 diff --git a/jscomp/syntax/tests/printer/comments/expected/array.res.txt b/jscomp/syntax/tests/printer/comments/expected/array.res.txt index 9a212b06cd..90ed9ed5c8 100644 --- a/jscomp/syntax/tests/printer/comments/expected/array.res.txt +++ b/jscomp/syntax/tests/printer/comments/expected/array.res.txt @@ -1,4 +1,4 @@ -(@res.syntaxSugar a[/* zz */ 0] = 7) +a[/* zz */ 0] = 7 let _ = /* zz */ a[0] diff --git a/jscomp/syntax/tests/printer/expr/expected/arraySet.res.txt b/jscomp/syntax/tests/printer/expr/expected/arraySet.res.txt index eaf8303bb3..31d9527cc3 100644 --- a/jscomp/syntax/tests/printer/expr/expected/arraySet.res.txt +++ b/jscomp/syntax/tests/printer/expr/expected/arraySet.res.txt @@ -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 diff --git a/jscomp/syntax/tests/printer/expr/expected/braced.res.txt b/jscomp/syntax/tests/printer/expr/expected/braced.res.txt index 6cac4ca5bd..d60e067b4f 100644 --- a/jscomp/syntax/tests/printer/expr/expected/braced.res.txt +++ b/jscomp/syntax/tests/printer/expr/expected/braced.res.txt @@ -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"} diff --git a/jscomp/syntax/tests/printer/expr/expected/if.res.txt b/jscomp/syntax/tests/printer/expr/expected/if.res.txt index bbd54e8598..d7ed0b6a58 100644 --- a/jscomp/syntax/tests/printer/expr/expected/if.res.txt +++ b/jscomp/syntax/tests/printer/expr/expected/if.res.txt @@ -36,7 +36,7 @@ let x = sideEffect() } -if @res.syntaxSugar inclusions[index] = (uid, url) { +if inclusions[index] = (uid, url) { onChange(inclusions) } diff --git a/jscomp/syntax/tests/printer/expr/expected/unary.res.txt b/jscomp/syntax/tests/printer/expr/expected/unary.res.txt index 3bec06e67a..cfe9b42193 100644 --- a/jscomp/syntax/tests/printer/expr/expected/unary.res.txt +++ b/jscomp/syntax/tests/printer/expr/expected/unary.res.txt @@ -84,4 +84,4 @@ let () = { } let x = (!truths)[0] -(@res.syntaxSugar (!streets)[0] = "foo-street") +(!streets)[0] = "foo-street" diff --git a/jscomp/syntax/tests/printer/expr/expected/underscoreApply.res.txt b/jscomp/syntax/tests/printer/expr/expected/underscoreApply.res.txt index 3bdb79fd81..38d46244f6 100644 --- a/jscomp/syntax/tests/printer/expr/expected/underscoreApply.res.txt +++ b/jscomp/syntax/tests/printer/expr/expected/underscoreApply.res.txt @@ -49,7 +49,7 @@ f(a, b, _) ? g(x, y, _) : h(alpha, beta, _)
{f(a, b, _)}
f(a, b, _)[ix] -(@res.syntaxSugar f(a, b, _)[ix] = 2) +f(a, b, _)[ix] = 2 getDirector(a, b, _).name = "Steve"