Repository: prettier/plugin-php
Pull request #577 (2018-09-06 14:34:01)

feat: better print parameter node
:star: 


Patch:
diff --git a/src/needs-parens.js b/src/needs-parens.js
index 9ca2485..708e517 100644
--- a/src/needs-parens.js
+++ b/src/needs-parens.js
@@ -1,5 +1,7 @@
 "use strict";
 
+const { isLookupNode } = require("./util");
+
 function needsParens(path) {
   const parent = path.getParentNode();
 
@@ -7,13 +9,47 @@ function needsParens(path) {
     return false;
   }
 
+  const name = path.getName();
   const node = path.getNode();
 
-  if (["include", "print", "return", "echo"].includes(parent.kind)) {
+  if (
+    [
+      //  No need parens for top level children of this nodes
+      "program",
+      "namespace",
+      "declare",
+      "block",
+
+      // No need parens
+      "include",
+      "print",
+      "return",
+      "echo"
+    ].includes(parent.kind)
+  ) {
     return false;
   }
 
   switch (node.kind) {
+    case "unary":
+      switch (parent.kind) {
+        case "unary":
+          return (
+            node.type === parent.type &&
+            (node.type === "+" || node.type === "-")
+          );
+        case "bin":
+          return parent.type === "**" && name === "left";
+        default:
+          return false;
+      }
+    case "new": {
+      if (isLookupNode(parent)) {
+        return true;
+      }
+
+      return false;
+    }
     case "boolean":
     case "string":
     case "number":
diff --git a/src/printer.js b/src/printer.js
index 6a2586a..7544143 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -1438,10 +1438,6 @@ function printNode(path, options, print) {
       ]);
 
       if (node.value) {
-        const isHeredocOrNowdocNode =
-          (node.value.kind === "encapsed" && node.value.type === "heredoc") ||
-          node.value.kind === "nowdoc";
-
         return group(
           concat([
             name,
@@ -1450,14 +1446,15 @@ function printNode(path, options, print) {
             // and value, we store them as dangling comments
             hasDanglingComments(node) ? " " : "",
             comments.printDanglingComments(path, options, true),
-            indent(
-              concat([
-                isHeredocOrNowdocNode ? " " : line,
-                "= ",
-                path.call(print, "value")
-              ])
-            ),
-            isHeredocOrNowdocNode ? hardline : ""
+            concat([
+              " =",
+              printAssignmentRight(
+                node.name,
+                node.value,
+                path.call(print, "value"),
+                options
+              )
+            ])
           ])
         );
       }
@@ -2062,18 +2059,7 @@ function printNode(path, options, print) {
     case "unset":
     case "empty":
       return group(
-        concat([
-          node.kind,
-          "(",
-          indent(
-            concat([
-              softline,
-              join(concat([",", line]), path.map(print, "arguments"))
-            ])
-          ),
-          softline,
-          ")"
-        ])
+        concat([node.kind, printArgumentsList(path, options, print)])
       );
     case "variable":
       return concat([
diff --git a/src/util.js b/src/util.js
index a8916a7..3cde804 100644
--- a/src/util.js
+++ b/src/util.js
@@ -231,7 +231,7 @@ function isFirstChildrenInlineNode(path) {
  * appear as function arguments or array elements
  */
 function docShouldHaveTrailingNewline(path) {
-  return ["array"].includes(path.getParentNode().kind);
+  return ["array", "parameter"].includes(path.getParentNode().kind);
 }
 
 function lineShouldEndWithSemicolon(path) {


Test patch:
diff --git a/tests/comments/__snapshots__/jsfmt.spec.js.snap b/tests/comments/__snapshots__/jsfmt.spec.js.snap
index de60a9f..afbf75f 100644
--- a/tests/comments/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/comments/__snapshots__/jsfmt.spec.js.snap
@@ -1638,8 +1638,7 @@ function bar(/* Comment */ &$a /* Comment */) {}
 
 function foo(
     /* Comment */ $a,
-    /* Comment */ array /* Comment */ $b /* Comment */
-        = /* Comment */ [] /* Comment */
+    /* Comment */ array /* Comment */ $b /* Comment */ = /* Comment */ [] /* Comment */
 ) {
 }
 
diff --git a/tests/member_chain/__snapshots__/jsfmt.spec.js.snap b/tests/member_chain/__snapshots__/jsfmt.spec.js.snap
index 6b0e0c0..8f68f2b 100644
--- a/tests/member_chain/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/member_chain/__snapshots__/jsfmt.spec.js.snap
@@ -400,7 +400,7 @@ method()
         return $x;
     });
 
-($a->a()->b());
+$a->a()->b();
 $a->a()->b();
 $a->a()->b;
 $a->b->a();
diff --git a/tests/parameter/__snapshots__/jsfmt.spec.js.snap b/tests/parameter/__snapshots__/jsfmt.spec.js.snap
new file mode 100644
index 0000000..8f0a81a
--- /dev/null
+++ b/tests/parameter/__snapshots__/jsfmt.spec.js.snap
@@ -0,0 +1,228 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`parameter.php 1`] = `
+<?php
+
+function foo($arg)
+{
+    return $arg;
+}
+
+function foo1(&$arg)
+{
+    return $arg;
+}
+
+function makecoffee($type = "cappuccino")
+{
+    return "Making a cup of $type.\\n";
+}
+
+function makecoffee1($types = array("cappuccino"), $coffeeMaker = NULL)
+{
+    $device = is_null($coffeeMaker) ? "hands" : $coffeeMaker;
+    return "Making a cup of ".join(", ", $types)." with $device.\\n";
+}
+
+function f(C $c) {
+    echo get_class($c)."\\n";
+}
+
+function f1(C $c = null) {
+    var_dump($c);
+}
+
+function sum(int $a, int $b) {
+    return $a + $b;
+}
+
+function sum1(...$numbers) {
+    $acc = 0;
+    foreach ($numbers as $n) {
+        $acc += $n;
+    }
+    return $acc;
+}
+
+function total_intervals($unit, DateInterval ...$intervals) {
+    $time = 0;
+    foreach ($intervals as $interval) {
+        $time += $interval->$unit;
+    }
+    return $time;
+}
+
+function testReturn(?string $name): ?string
+{
+    return $name;
+}
+
+function intArg(int $c = 111111111111111111111111111111111111111111111111111111111111111111111111) {
+    var_dump($c);
+}
+
+function bar($arg = array("veryVeryVeryVeryVeryVeryVeryVeryVeryLongString", "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString", "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString"))
+{
+    return $arg;
+}
+
+function bar1(
+    $arg = array(
+        "key1" => "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString",
+
+        "key2" => "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString",
+
+        "key3" => "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString"
+    )
+) {
+    return $arg;
+}
+
+function bar2($arg = "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString" . "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString" . "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString")
+{
+    return $arg;
+}
+
+function bar3($arg = "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString" ? "1" : "2")
+{
+    return $arg;
+}
+
+function bar4(string $arg = "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString" ? "1" : "2")
+{
+    return $arg;
+}
+
+function bar5($arg = "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString" === "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString" ? "1" : "2")
+{
+    return $arg;
+}
+
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+<?php
+
+function foo($arg)
+{
+    return $arg;
+}
+
+function foo1(&$arg)
+{
+    return $arg;
+}
+
+function makecoffee($type = "cappuccino")
+{
+    return "Making a cup of $type.\\n";
+}
+
+function makecoffee1($types = array("cappuccino"), $coffeeMaker = null)
+{
+    $device = is_null($coffeeMaker) ? "hands" : $coffeeMaker;
+    return "Making a cup of " . join(", ", $types) . " with $device.\\n";
+}
+
+function f(C $c)
+{
+    echo get_class($c) . "\\n";
+}
+
+function f1(C $c = null)
+{
+    var_dump($c);
+}
+
+function sum(int $a, int $b)
+{
+    return $a + $b;
+}
+
+function sum1(...$numbers)
+{
+    $acc = 0;
+    foreach ($numbers as $n) {
+        $acc += $n;
+    }
+    return $acc;
+}
+
+function total_intervals($unit, DateInterval ...$intervals)
+{
+    $time = 0;
+    foreach ($intervals as $interval) {
+        $time += $interval->$unit;
+    }
+    return $time;
+}
+
+function testReturn(?string $name): ?string
+{
+    return $name;
+}
+
+function intArg(
+    int $c = 111111111111111111111111111111111111111111111111111111111111111111111111
+) {
+    var_dump($c);
+}
+
+function bar(
+    $arg = array(
+        "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString",
+        "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString",
+        "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString"
+    )
+) {
+    return $arg;
+}
+
+function bar1(
+    $arg = array(
+        "key1" => "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString",
+
+        "key2" => "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString",
+
+        "key3" => "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString"
+    )
+)
+{
+    return $arg;
+}
+
+function bar2(
+    $arg =
+        "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString" .
+            "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString" .
+            "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString"
+) {
+    return $arg;
+}
+
+function bar3(
+    $arg = "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString"
+        ? "1"
+        : "2"
+) {
+    return $arg;
+}
+
+function bar4(
+    string $arg = "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString"
+        ? "1"
+        : "2"
+) {
+    return $arg;
+}
+
+function bar5(
+    $arg =
+        "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString" ===
+        "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString"
+            ? "1"
+            : "2"
+) {
+    return $arg;
+}
+
+`;
diff --git a/tests/parameter/jsfmt.spec.js b/tests/parameter/jsfmt.spec.js
new file mode 100644
index 0000000..e395434
--- /dev/null
+++ b/tests/parameter/jsfmt.spec.js
@@ -0,0 +1,1 @@
+run_spec(__dirname, ["php"]);
diff --git a/tests/parameter/parameter.php b/tests/parameter/parameter.php
new file mode 100644
index 0000000..2494cca
--- /dev/null
+++ b/tests/parameter/parameter.php
@@ -0,0 +1,98 @@
+<?php
+
+function foo($arg)
+{
+    return $arg;
+}
+
+function foo1(&$arg)
+{
+    return $arg;
+}
+
+function makecoffee($type = "cappuccino")
+{
+    return "Making a cup of $type.\n";
+}
+
+function makecoffee1($types = array("cappuccino"), $coffeeMaker = NULL)
+{
+    $device = is_null($coffeeMaker) ? "hands" : $coffeeMaker;
+    return "Making a cup of ".join(", ", $types)." with $device.\n";
+}
+
+function f(C $c) {
+    echo get_class($c)."\n";
+}
+
+function f1(C $c = null) {
+    var_dump($c);
+}
+
+function sum(int $a, int $b) {
+    return $a + $b;
+}
+
+function sum1(...$numbers) {
+    $acc = 0;
+    foreach ($numbers as $n) {
+        $acc += $n;
+    }
+    return $acc;
+}
+
+function total_intervals($unit, DateInterval ...$intervals) {
+    $time = 0;
+    foreach ($intervals as $interval) {
+        $time += $interval->$unit;
+    }
+    return $time;
+}
+
+function testReturn(?string $name): ?string
+{
+    return $name;
+}
+
+function intArg(int $c = 111111111111111111111111111111111111111111111111111111111111111111111111) {
+    var_dump($c);
+}
+
+function bar($arg = array("veryVeryVeryVeryVeryVeryVeryVeryVeryLongString", "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString", "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString"))
+{
+    return $arg;
+}
+
+function bar1(
+    $arg = array(
+        "key1" => "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString",
+
+        "key2" => "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString",
+
+        "key3" => "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString"
+    )
+) {
+    return $arg;
+}
+
+function bar2($arg = "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString" . "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString" . "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString")
+{
+    return $arg;
+}
+
+function bar3($arg = "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString" ? "1" : "2")
+{
+    return $arg;
+}
+
+function bar4(string $arg = "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString" ? "1" : "2")
+{
+    return $arg;
+}
+
+function bar5($arg = "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString" === "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString" ? "1" : "2")
+{
+    return $arg;
+}
+
+
diff --git a/tests/parens/__snapshots__/jsfmt.spec.js.snap b/tests/parens/__snapshots__/jsfmt.spec.js.snap
index 273626d..9fc961d 100644
--- a/tests/parens/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/parens/__snapshots__/jsfmt.spec.js.snap
@@ -96,16 +96,16 @@ $var = (true and false);
 <?php
 
 $var = 1;
-($var = 1);
+$var = 1;
+$var = $var = 1;
+$var = ($var = 1);
 $var = $var = 1;
 $var = ($var = 1);
-($var = $var = 1);
-($var = ($var = 1));
 $var = $var = $var = $var;
 $var = $var = ($var = $var);
 $var = ($var = $var = $var);
 $var = ($var = ($var = $var));
-($var = ($var = ($var = $var)));
+$var = ($var = ($var = $var));
 
 $var = $var++;
 $var = ($var++);
@@ -118,10 +118,10 @@ $var = --$var;
 $var = (--$var);
 
 $var = ~$var;
-$var = (~$var);
+$var = ~$var;
 
 $var = !$var;
-$var = (!$var);
+$var = !$var;
 
 $var = $var += 10;
 $var = ($var += 10);
@@ -187,6 +187,22 @@ $var = (true and false);
 
 `;
 
+exports[`block.php 1`] = `
+<?php
+
+function foo() {
+    ($a->c());
+}
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+<?php
+
+function foo()
+{
+    $a->c();
+}
+
+`;
+
 exports[`control-structures.php 1`] = `
 <?php
 
@@ -328,6 +344,36 @@ while ($i++ < 5) {
 
 `;
 
+exports[`declare.php 1`] = `
+<?php
+
+declare(strict_types=1);
+
+($a->c());
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+<?php
+
+declare(strict_types=1);
+
+$a->c();
+
+`;
+
+exports[`namespace.php 1`] = `
+<?php
+
+namespace Foo;
+
+($a->c());
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+<?php
+
+namespace Foo;
+
+$a->c();
+
+`;
+
 exports[`new.php 1`] = `
 <?php
 (new Translator(
@@ -356,26 +402,47 @@ exports[`new.php 1`] = `
     ['foo' => 'bar']
 ))
 ?>
+<?php
+
+$var = new Foo();
+$var = (new Foo());
+$var = (new Foo())->c();
+$var = (new class {
+    public function log($msg)
+    {
+        echo $msg;
+    }
+});
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
-(new Translator(
+new Translator(
     $container,
     new MessageFormatter(),
     'en',
     array(),
     array('foo' => 'bar')
-)); ?>
-<?php (new Translator(
+); ?>
+<?php new Translator(
     $container,
     new MessageFormatter(),
     'en',
     $someOtherVar,
     array('foo' => 'bar')
-)); ?>
-<?php (new Translator($container, new MessageFormatter(), 'en', $someOtherVar, [
+); ?>
+<?php new Translator($container, new MessageFormatter(), 'en', $someOtherVar, [
     'foo' => 'bar'
-]));
-?>
+]); ?>
+<?php
+$var = new Foo();
+$var = new Foo();
+$var = (new Foo())->c();
+$var = new class {
+    public function log($msg)
+    {
+        echo $msg;
+    }
+};
+
 
 `;
 
@@ -390,6 +457,160 @@ include $test ? 'foo' : 'bar';
 
 `;
 
+exports[`program.php 1`] = `
+<?php
+
+($a->c());
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+<?php
+
+$a->c();
+
+`;
+
+exports[`return.php 1`] = `
+<?php
+
+return;
+return 1;
+return (1);
+return (1 + 2);
+return ('veryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString' . 'veryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString');
+return ($var1 + $var2);
+return $var ? ($var1 ? 1 : 2) : ($var2 ? 3 : 4);
+return ('veryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString' ? 'veryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString' : 'veryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString');
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+<?php
+
+return;
+return 1;
+return 1;
+return 1 + 2;
+return (
+    'veryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString' .
+    'veryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString'
+);
+return $var1 + $var2;
+return $var ? ($var1 ? 1 : 2) : ($var2 ? 3 : 4);
+return 'veryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString'
+    ? 'veryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString'
+    : 'veryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString';
+
+`;
+
+exports[`unary.php 1`] = `
+<?php
+
++$var;
++($var);
+(+$var);
+
+-$var;
+-($var);
+(-$var);
+
+~$var;
+~($var);
+(~$var);
+
+!$var;
+!($var);
+(!$var);
+
+!!$var;
+!(!$var);
+(!(!$var));
+(!!$var);
+
+$var = (+$var);
+$var = +(+$var);
+
+$var = (-$var);
+$var = -(-$var);
+
+$var = (~$var);
+$var = ~(~$var);
+
+$var = (!$var);
+$var = !(!$var);
+
+$a = +$a ** 1;
+$a = (+$a) ** 1;
+$a = 1 ** (+$a);
+
+$var = call(+$a);
+$var = call((+$a));
+
+$var = +($foo->bar);
+
+$var = +$var || +$var;
+$var = (+$var) || (+$var);
+$var = ((+$var) || (+$var));
+
+$var = -(+($var));
+
+$var = ~(+$var);
+
+$var = ~$var += 1;
+$var = ~($var += 1);
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+<?php
+
++$var;
++$var;
++$var;
+
+-$var;
+-$var;
+-$var;
+
+~$var;
+~$var;
+~$var;
+
+!$var;
+!$var;
+!$var;
+
+!!$var;
+!!$var;
+!!$var;
+!!$var;
+
+$var = +$var;
+$var = +(+$var);
+
+$var = -$var;
+$var = -(-$var);
+
+$var = ~$var;
+$var = ~~$var;
+
+$var = !$var;
+$var = !!$var;
+
+$a = (+$a) ** 1;
+$a = (+$a) ** 1;
+$a = 1 ** +$a;
+
+$var = call(+$a);
+$var = call(+$a);
+
+$var = +($foo->bar);
+
+$var = +$var || +$var;
+$var = +$var || +$var;
+$var = (+$var || +$var);
+
+$var = -+$var;
+
+$var = ~+$var;
+
+$var = ~$var += 1;
+$var = ~($var += 1);
+
+`;
+
 exports[`unnecessary.php 1`] = `
 <?php
 $test = 1;
diff --git a/tests/parens/block.php b/tests/parens/block.php
new file mode 100644
index 0000000..36a06b8
--- /dev/null
+++ b/tests/parens/block.php
@@ -0,0 +1,5 @@
+<?php
+
+function foo() {
+    ($a->c());
+}
diff --git a/tests/parens/declare.php b/tests/parens/declare.php
new file mode 100644
index 0000000..18675ed
--- /dev/null
+++ b/tests/parens/declare.php
@@ -0,0 +1,5 @@
+<?php
+
+declare(strict_types=1);
+
+($a->c());
diff --git a/tests/parens/namespace.php b/tests/parens/namespace.php
new file mode 100644
index 0000000..712d045
--- /dev/null
+++ b/tests/parens/namespace.php
@@ -0,0 +1,5 @@
+<?php
+
+namespace Foo;
+
+($a->c());
diff --git a/tests/parens/new.php b/tests/parens/new.php
index 37bb40e..cd49f94 100644
--- a/tests/parens/new.php
+++ b/tests/parens/new.php
@@ -25,3 +25,14 @@
     ['foo' => 'bar']
 ))
 ?>
+<?php
+
+$var = new Foo();
+$var = (new Foo());
+$var = (new Foo())->c();
+$var = (new class {
+    public function log($msg)
+    {
+        echo $msg;
+    }
+});
diff --git a/tests/parens/program.php b/tests/parens/program.php
new file mode 100644
index 0000000..d8de364
--- /dev/null
+++ b/tests/parens/program.php
@@ -0,0 +1,3 @@
+<?php
+
+($a->c());
diff --git a/tests/parens/return.php b/tests/parens/return.php
new file mode 100644
index 0000000..e5b300d
--- /dev/null
+++ b/tests/parens/return.php
@@ -0,0 +1,10 @@
+<?php
+
+return;
+return 1;
+return (1);
+return (1 + 2);
+return ('veryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString' . 'veryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString');
+return ($var1 + $var2);
+return $var ? ($var1 ? 1 : 2) : ($var2 ? 3 : 4);
+return ('veryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString' ? 'veryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString' : 'veryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString');
diff --git a/tests/parens/unary.php b/tests/parens/unary.php
new file mode 100644
index 0000000..1ed04a5
--- /dev/null
+++ b/tests/parens/unary.php
@@ -0,0 +1,54 @@
+<?php
+
++$var;
++($var);
+(+$var);
+
+-$var;
+-($var);
+(-$var);
+
+~$var;
+~($var);
+(~$var);
+
+!$var;
+!($var);
+(!$var);
+
+!!$var;
+!(!$var);
+(!(!$var));
+(!!$var);
+
+$var = (+$var);
+$var = +(+$var);
+
+$var = (-$var);
+$var = -(-$var);
+
+$var = (~$var);
+$var = ~(~$var);
+
+$var = (!$var);
+$var = !(!$var);
+
+$a = +$a ** 1;
+$a = (+$a) ** 1;
+$a = 1 ** (+$a);
+
+$var = call(+$a);
+$var = call((+$a));
+
+$var = +($foo->bar);
+
+$var = +$var || +$var;
+$var = (+$var) || (+$var);
+$var = ((+$var) || (+$var));
+
+$var = -(+($var));
+
+$var = ~(+$var);
+
+$var = ~$var += 1;
+$var = ~($var += 1);
diff --git a/tests/sys/__snapshots__/jsfmt.spec.js.snap b/tests/sys/__snapshots__/jsfmt.spec.js.snap
index 56b0178..4f1be7d 100644
--- a/tests/sys/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/sys/__snapshots__/jsfmt.spec.js.snap
@@ -17,6 +17,17 @@ isset($test);
 unset($test);
 
 empty($test);
+
+isset($test, $test, $test,$test, $test, $test, $test, $test, $test, $test, $test, $test);
+
+isset($test['foo']);
+isset($a['cake']['a']['b']);
+isset($expected_array_got_string['some_key']);
+isset($expected_array_got_string[0]);
+isset($expected_array_got_string['0']);
+isset($expected_array_got_string[0.5]);
+isset($expected_array_got_string['0.5']);
+isset($expected_array_got_string['0 Mostel']);
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 echo "test echo";
@@ -39,4 +50,28 @@ unset($test);
 
 empty($test);
 
+isset(
+    $test,
+    $test,
+    $test,
+    $test,
+    $test,
+    $test,
+    $test,
+    $test,
+    $test,
+    $test,
+    $test,
+    $test
+);
+
+isset($test['foo']);
+isset($a['cake']['a']['b']);
+isset($expected_array_got_string['some_key']);
+isset($expected_array_got_string[0]);
+isset($expected_array_got_string['0']);
+isset($expected_array_got_string[0.5]);
+isset($expected_array_got_string['0.5']);
+isset($expected_array_got_string['0 Mostel']);
+
 `;
diff --git a/tests/sys/sys.php b/tests/sys/sys.php
index abec7de..03e6fef 100644
--- a/tests/sys/sys.php
+++ b/tests/sys/sys.php
@@ -14,3 +14,14 @@ isset($test);
 unset($test);
 
 empty($test);
+
+isset($test, $test, $test,$test, $test, $test, $test, $test, $test, $test, $test, $test);
+
+isset($test['foo']);
+isset($a['cake']['a']['b']);
+isset($expected_array_got_string['some_key']);
+isset($expected_array_got_string[0]);
+isset($expected_array_got_string['0']);
+isset($expected_array_got_string[0.5]);
+isset($expected_array_got_string['0.5']);
+isset($expected_array_got_string['0 Mostel']);