Skip to content

Commit

Permalink
parser/pprint_ast: force parentheses around switch (...)/try (...)
Browse files Browse the repository at this point in the history
  • Loading branch information
let-def authored and jordwalke committed Jan 6, 2018
1 parent acd5a06 commit 03e2564
Show file tree
Hide file tree
Showing 23 changed files with 118 additions and 123 deletions.
4 changes: 2 additions & 2 deletions formatTest/typeCheckedTests/expected_output/attributes.re
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ external debounce :
let x = "hi";

let res =
switch x {
switch (x) {
| _ =>
[@attr]
{
Expand All @@ -530,7 +530,7 @@ let res =
};

let res =
switch x {
switch (x) {
| _ => [@attr] String.(Array.(concat))
};

Expand Down
2 changes: 1 addition & 1 deletion formatTest/typeCheckedTests/expected_output/comments.re
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ let result =
};

let result =
switch None {
switch (None) {
| Some({fieldOne: 20}) =>
/* Where does this comment go? */
let tmp = 0;
Expand Down
6 changes: 3 additions & 3 deletions formatTest/typeCheckedTests/expected_output/jsx.re
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ module Namespace = {

module Optional1 = {
let createElement = (~required, ~children, ()) =>
switch required {
switch (required) {
| Some(a) => {displayName: a}
| None => {displayName: "nope"}
};
Expand All @@ -110,7 +110,7 @@ module Optional1 = {
module Optional2 = {
let createElement =
(~optional=?, ~children, ()) =>
switch optional {
switch (optional) {
| Some(a) => {displayName: a}
| None => {displayName: "nope"}
};
Expand All @@ -119,7 +119,7 @@ module Optional2 = {
module DefaultArg = {
let createElement =
(~default=Some("foo"), ~children, ()) =>
switch default {
switch (default) {
| Some(a) => {displayName: a}
| None => {displayName: "nope"}
};
Expand Down
2 changes: 1 addition & 1 deletion formatTest/typeCheckedTests/expected_output/mlSyntax.re
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type a =
| A(bcd);

let result =
switch B {
switch (B) {
| B
| C
| D
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type a =
| A(bcd);

let result =
switch B {
switch (B) {
| B
| C
| D
Expand Down
2 changes: 1 addition & 1 deletion formatTest/typeCheckedTests/expected_output/mutation.re
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ holdsABool.contents = holdsAnInt.contents == 100;

let numberToSwitchOn = 100;

switch numberToSwitchOn {
switch (numberToSwitchOn) {
| (-3)
| (-2)
| (-1) => ()
Expand Down
4 changes: 2 additions & 2 deletions formatTest/typeCheckedTests/expected_output/oo.re
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class virtual stack ('a) (init) = {
val mutable v: list('a) = init;
pub virtual implementMe: int => int;
pub pop =
switch v {
switch (v) {
| [hd, ...tl] =>
v = tl;
Some(hd);
Expand Down Expand Up @@ -43,7 +43,7 @@ class virtual stackWithAttributes ('a) (init) = {
val mutable v: list('a) = init;
pub virtual implementMe: int => int;
pub pop =
switch v {
switch (v) {
| [hd, ...tl] =>
v = tl;
Some(hd);
Expand Down
18 changes: 9 additions & 9 deletions formatTest/typeCheckedTests/expected_output/patternMatching.re
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ switch (Some(1)) {
};

/* with parens around direct list pattern in constructor pattern */
switch None {
switch (None) {
| Some([]) => ()
| Some([_]) when true => ()
| Some([x]) => ()
Expand All @@ -199,7 +199,7 @@ switch None {
};

/* no parens around direct list pattern in constructor pattern (sugar) */
switch None {
switch (None) {
| Some([]) => ()
| Some([_]) when true => ()
| Some([x]) => ()
Expand All @@ -209,7 +209,7 @@ switch None {
};

/* with parens around direct array pattern in constructor pattern */
switch None {
switch (None) {
| Some([||]) => "empty"
| Some([|_|]) when true => "one any"
| Some([|a|]) => "one"
Expand All @@ -218,7 +218,7 @@ switch None {
};

/* no parens around direct array pattern in constructor pattern (sugar) */
switch None {
switch (None) {
| Some([||]) => "empty"
| Some([|_|]) when true => "one any"
| Some([|a|]) => "one"
Expand All @@ -227,20 +227,20 @@ switch None {
};

/* parens around direct record pattern in constructor pattern */
switch None {
switch (None) {
| Some({x}) when true => ()
| Some({x, y}) => ()
| _ => ()
};

/* no parens around direct record pattern in constructor pattern (sugar) */
switch None {
switch (None) {
| Some({x}) when true => ()
| Some({x, y}) => ()
| _ => ()
};

switch None {
switch (None) {
| Some([|
someSuperLongString,
thisShouldBreakTheLine
Expand All @@ -249,7 +249,7 @@ switch None {
| _ => ()
};

switch None {
switch (None) {
| Some((
someSuperLongString,
thisShouldBreakTheLine
Expand All @@ -258,7 +258,7 @@ switch None {
| _ => ()
};

switch None {
switch (None) {
| Some([
someSuperLongString,
thisShouldBreakTheLine
Expand Down
4 changes: 2 additions & 2 deletions formatTest/typeCheckedTests/expected_output/reasonComments.re
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ and y2 = {
};

let result =
switch None {
switch (None) {
| Some({fieldOne: 20, fieldA: a}) =>
/* Where does this comment go? */
let tmp = 0;
Expand All @@ -242,7 +242,7 @@ let res =
* Now these end of line comments *should* be retained.
*/
let result =
switch None {
switch (None) {
| Some({
fieldOne: 20, /* end of line */
fieldA:
Expand Down
4 changes: 2 additions & 2 deletions formatTest/typeCheckedTests/input/attributes.re
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ external debounce : int => ([@bs.meth] (unit => unit)) => ([@bs.meth] (unit => [

let x = "hi";

let res = switch x {
let res = switch (x) {
| _ =>
[@attr]
{
Expand All @@ -384,7 +384,7 @@ let res = switch x {
}
};

let res = switch x {
let res = switch (x) {
| _ =>
[@attr]
{
Expand Down
18 changes: 9 additions & 9 deletions formatTest/typeCheckedTests/input/patternMatching.re
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ switch (Some(1)) {
};

/* with parens around direct list pattern in constructor pattern */
switch None {
switch (None) {
| Some([]) => ()
| Some([_]) when true => ()
| Some([x]) => ()
Expand All @@ -165,7 +165,7 @@ switch None {
};

/* no parens around direct list pattern in constructor pattern (sugar) */
switch None {
switch (None) {
| Some [] => ()
| Some [_] when true => ()
| Some [x] => ()
Expand All @@ -175,7 +175,7 @@ switch None {
};

/* with parens around direct array pattern in constructor pattern */
switch None {
switch (None) {
| Some([| |]) => "empty"
| Some([| _ |]) when true => "one any"
| Some([| a |]) => "one"
Expand All @@ -184,7 +184,7 @@ switch None {
};

/* no parens around direct array pattern in constructor pattern (sugar) */
switch None {
switch (None) {
| Some [||] => "empty"
| Some [|_|] when true => "one any"
| Some [|a|] => "one"
Expand All @@ -193,30 +193,30 @@ switch None {
};

/* parens around direct record pattern in constructor pattern */
switch None {
switch (None) {
| Some({x}) when true => ()
| Some({x, y}) => ()
| _ => ()
};

/* no parens around direct record pattern in constructor pattern (sugar) */
switch None {
switch (None) {
| Some {x} when true => ()
| Some {x, y} => ()
| _ => ()
};

switch None {
switch (None) {
| Some([|someSuperLongString, thisShouldBreakTheLine|]) => ()
| _ => ()
};

switch None {
switch (None) {
| Some((someSuperLongString, thisShouldBreakTheLine)) => ()
| _ => ()
};

switch None {
switch (None) {
| Some([someSuperLongString, thisShouldBreakTheLine]) => ()
| Some([someSuperLongString, ...es6ListSugarLikeSyntaxWhichIsSuperLong]) when true === true => ()
| Some([someSuperLongString, ...es6ListSugarLikeSyntaxWhichIsSuperLong]) => ()
Expand Down
12 changes: 6 additions & 6 deletions formatTest/unit_tests/expected_output/basicStructures.re
Original file line number Diff line number Diff line change
Expand Up @@ -409,27 +409,27 @@ let rec size =

/* Optimize for tail recursion */
let rec size = (soFar, lst) =>
switch lst {
switch (lst) {
| [] => 0
| [hd, ...tl] => size(soFar + 1, tl)
};

let nestedMatch = lstLst =>
switch lstLst {
switch (lstLst) {
| [hd, ...tl] when false => 10
| [hd, ...tl] =>
switch tl {
switch (tl) {
| [] => 0 + 0
| [tlHd, ...tlTl] => 0 + 1
}
| [] => 0
};

let nestedMatchWithWhen = lstLst =>
switch lstLst {
switch (lstLst) {
| [hd, ...tl] when false => 10
| [hd, ...tl] when true =>
switch tl {
switch (tl) {
| [] when false => 0 + 0
| [] when true => 0 + 0
| [tlHd, ...tlTl] => 0 + 1
Expand Down Expand Up @@ -764,7 +764,7 @@ let bar = {Foo.foo, Bar.bar};

({M.x, y}) => 1;

switch foo {
switch (foo) {
| {y: 1, M.x} => 2
};

Expand Down
4 changes: 2 additions & 2 deletions formatTest/unit_tests/expected_output/extensions.re
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let x = {

let x = {
if%extend (true) {1} else {2};
switch%extend None {
switch%extend (None) {
| Some(x) => assert false
| None => ()
};
Expand All @@ -35,7 +35,7 @@ let x = {
let x = if%extend (true) {1} else {2};

let x =
switch%extend None {
switch%extend (None) {
| Some(x) => assert false
| None => ()
};
Expand Down
2 changes: 1 addition & 1 deletion formatTest/unit_tests/expected_output/features403.re
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type expr('a) =

let rec eval: type a. expr(a) => a =
e =>
switch e {
switch (e) {
| Is0({test}) => eval(test) == 0
| Val({value}) => value
| Add({left, right}) =>
Expand Down
2 changes: 1 addition & 1 deletion formatTest/unit_tests/expected_output/if.re
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ let result =
* Try shouldn't be aliased as ternary!
*/
let res =
try something {
try (something) {
| true => "hi"
| false => "bye"
};
Expand Down
2 changes: 1 addition & 1 deletion formatTest/unit_tests/expected_output/infix.re
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ let includesACommentCloseInIdentifier = ( **\/ );
let shouldSimplifyAnythingExceptApplicationAndConstruction =
call("hi")
++ (
switch x {
switch (x) {
| _ => "hi"
}
)
Expand Down
2 changes: 1 addition & 1 deletion formatTest/unit_tests/expected_output/jsx.re
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ let tuples =
let icon =
<Icon
name=(
switch state.volume {
switch (state.volume) {
| v when v < 0.1 => "sound-off"
| v when v < 0.11 => "sound-min"
| v when v < 0.51 => "sound-med"
Expand Down
Loading

0 comments on commit 03e2564

Please sign in to comment.