Skip to content

Commit

Permalink
Update break, continue printers to:
Browse files Browse the repository at this point in the history
- Un-wrap arbitrary number of parentheses
- Remove explicit breakout-level `1`
  • Loading branch information
nikulis committed Jan 20, 2018
1 parent ff2e44e commit da6aea4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
16 changes: 14 additions & 2 deletions src/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -965,12 +965,24 @@ function printNode(path, options, print) {
]);
case "break":
if (node.level) {
return concat(["break ", path.call(print, "level")]);
while (node.level.kind == "parenthesis") {
node.level = node.level.inner;
}
if (node.level.kind == "number" && node.level.value != 1) {
return concat(["break ", path.call(print, "level")]);
}
return "break";
}
return "break";
case "continue":
if (node.level) {
return concat(["continue ", path.call(print, "level")]);
while (node.level.kind == "parenthesis") {
node.level = node.level.inner;
}
if (node.level.kind == "number" && node.level.value != 1) {
return concat(["continue ", path.call(print, "level")]);
}
return "continue";
}
return "continue";
case "return":
Expand Down
8 changes: 5 additions & 3 deletions tests/break/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ while(true) {
break (1);
break 2;
break (2);
break(((3)));
}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<?php
for ($i = 0;$i < 10;$i++) {
Expand All @@ -33,9 +34,10 @@ for ($i = 0;$i < 10;$i++) {
while (true) {
break;
break 1;
break (1);
break;
break;
break 2;
break (2);
break 2;
break 3;
}
`;
1 change: 1 addition & 0 deletions tests/break/break.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
break (1);
break 2;
break (2);
break(((3)));
}
8 changes: 5 additions & 3 deletions tests/continue/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ while(true) {
continue (1);
continue 2;
continue (2);
continue(((3)));
}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<?php
for ($i = 0;$i < 10;$i++) {
Expand All @@ -33,9 +34,10 @@ for ($i = 0;$i < 10;$i++) {
while (true) {
continue;
continue 1;
continue (1);
continue;
continue;
continue 2;
continue (2);
continue 2;
continue 3;
}
`;
1 change: 1 addition & 0 deletions tests/continue/continue.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
continue (1);
continue 2;
continue (2);
continue(((3)));
}

0 comments on commit da6aea4

Please sign in to comment.