Skip to content

Commit

Permalink
rebase on master after reasonml#2050, parse #= with higher preceden…
Browse files Browse the repository at this point in the history
…ce, parens

unnecessary on the right side
  • Loading branch information
anmonteiro committed Oct 2, 2018
1 parent e6b959e commit b32aa5f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 19 deletions.
28 changes: 14 additions & 14 deletions formatTest/unit_tests/expected_output/bucklescript.re
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ bla #= Some(10);

bla #= someFunc(Some(10));

test##var #= Some(-10);
test["var"] = Some(-10);

obj##.prop;

obj##.prod := exp;

preview##style##border
#= Js.string("1px black dashed");
preview["style"]["border"] =
Js.string("1px black dashed");

(preview##(style##border) #= args)(somenum);
(preview##(style["border"]) #= args)(somenum);

x##y##z #= xxxx##yyyy##zzzz;
x["y"]["z"] = xxxx["yyyy"]["zzzz"];

let result =
js_method_run1((!react)#createElement, foo);
Expand All @@ -36,12 +36,12 @@ let res = z##(q["a"]); /* AST */
let res = z##(q["a"]); /* Min parens */

/* These should print the same */
let res = !x##y; /* AST */
let res = !x##y; /* Minimum parens */
let res = !x["y"]; /* AST */
let res = !x["y"]; /* Minimum parens */

/* These should print the same */
let res = !z##q##a; /* AST */
let res = !z##q##a; /* Min parens */
let res = !z["q"]["a"]; /* AST */
let res = !z["q"]["a"]; /* Min parens */

/* These should print the same */
let res = ?!!x["y"]; /* AST */
Expand All @@ -51,12 +51,12 @@ let res = ?!!x["y"]; /* Minimum parens */
let res = ?!!z##(q["a"]); /* AST */
let res = ?!!z##(q["a"]); /* Min parens */

res #= ?!!z##q;
res #= ?!!z##(q##a);
res #= ?!!z["q"];
res #= ?!!z##(q["a"]);

let result = myFunction(x(y)##z, a(b) #= c);
let result = myFunction(x(y)["z"], a(b) #= c);

(!x)##y##(b##c);
(!x)["y"]##(b["c"]);

type a = {. "foo": bar};

Expand All @@ -75,7 +75,7 @@ let b = {
let c = {
"a": a,
"b": b,
"func": a => a##c #= func(10),
"func": a => a["c"] = func(10),
};

let d = {
Expand Down
14 changes: 9 additions & 5 deletions formatTest/unit_tests/expected_output/sharpop.re
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
foo #= bar[0];

foo##bar[0] = 3;
foo["bar"][0] = 3;

foo##bar[0]##baz[1] = 3;
foo["bar"][0]["baz"][1] = 3;

foo##bar[0]##baz[1];
foo["bar"][0]["baz"][1];

foo##bar #= bar[0];
foo["bar"] = bar[0];

foo##bar##baz #= bar##baz[0];
foo["bar"]["baz"] = bar["baz"][0];

foo[bar + 1];

Expand All @@ -21,3 +21,7 @@ foo.[bar + 1] = 1;
foo.{bar + 1} = 1;

foo[bar + 1] = 1;

bla #= Constr(x);

bla #= M.(someFunc(Some(10)));
4 changes: 4 additions & 0 deletions formatTest/unit_tests/input/sharpop.re
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ foo.[bar + 1] = 1;
foo.{bar + 1} = 1;

foo[bar + 1] = 1;

bla #= (Constr(x));

bla #= M.(someFunc(Some(10)));
10 changes: 10 additions & 0 deletions src/reason-parser/reason_pprint_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7438,6 +7438,16 @@ let printer = object(self:'self)
(* If there was a JSX attribute BUT JSX component wasn't detected,
that JSX attribute needs to be pretty printed so it doesn't get
lost *)
let isLeftSharpEqual = match funExpr.pexp_desc with
| Pexp_apply ({pexp_desc = Pexp_ident {txt = Lident "#="}}, _) -> true
| _ -> false
in
let formattedFunExpr =
if isLeftSharpEqual then
formatPrecedence ~loc:funExpr.pexp_loc (self#simplifyUnparseExpr funExpr)
else
self#simplifyUnparseExpr funExpr
in
let maybeJSXAttr = List.map self#attribute jsxAttrs in
let categorizeFunApplArgs args =
let reverseArgs = List.rev args in
Expand Down

0 comments on commit b32aa5f

Please sign in to comment.