Repository: prettier/plugin-php
Pull request #553 (2018-08-31 10:25:20)

fix: closure by ref
bug :smile: 


Patch:
diff --git a/src/printer.js b/src/printer.js
index 1dd99b3..6d04bed 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -1675,6 +1675,7 @@ function printNode(path, options, print) {
 
       return concat([
         "function ",
+        node.byref ? "&" : "",
         printArgumentsList(path, options, print),
         node.uses && node.uses.length > 0
           ? group(


Test patch:
diff --git a/tests/closure/__snapshots__/jsfmt.spec.js.snap b/tests/closure/__snapshots__/jsfmt.spec.js.snap
index 5b00d47..0364257 100644
--- a/tests/closure/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/closure/__snapshots__/jsfmt.spec.js.snap
@@ -127,6 +127,11 @@ $rTDWLU = function(array $array) use ($longLongLongLongLongLongLongVar1, $longer
     return array_sum($array);
 };
 
+$var = function &() {
+    static $collection = array();
+
+    return $collection;
+};
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 
@@ -253,4 +258,10 @@ $rTDWLU = function (array $array) use (
     return array_sum($array);
 };
 
+$var = function &() {
+    static $collection = array();
+
+    return $collection;
+};
+
 `;
diff --git a/tests/closure/closure.php b/tests/closure/closure.php
index 0bb1c8c..ab14c9b 100644
--- a/tests/closure/closure.php
+++ b/tests/closure/closure.php
@@ -124,3 +124,8 @@ $rTDWLU = function(array $array) use ($longLongLongLongLongLongLongVar1, $longer
     return array_sum($array);
 };
 
+$var = function &() {
+    static $collection = array();
+
+    return $collection;
+};
diff --git a/tests/list/__snapshots__/jsfmt.spec.js.snap b/tests/list/__snapshots__/jsfmt.spec.js.snap
index 4bc28e4..e4c4cd5 100644
--- a/tests/list/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/list/__snapshots__/jsfmt.spec.js.snap
@@ -93,6 +93,20 @@ list(
 
     3 => $fourthVeryVeryVeryVeryLong
 ) = $arr;
+
+list("id" => $id1, "name" => $name1) = $data[0];
+["id" => $id1, "name" => $name1] = $data[0];
+
+foreach ($data as list("id" => $id, "name" => $name)) {
+    // logic here with $id and $name
+}
+
+foreach ($data as ["id" => $id, "name" => $name]) {
+    // logic here with $id and $name
+}
+
+function swap( &$a, &$b ): void
+{ [ $a, $b ] = [ $b, $a ]; }
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 
@@ -266,4 +280,20 @@ list(
     3 => $fourthVeryVeryVeryVeryLong
 ) = $arr;
 
+list("id" => $id1, "name" => $name1) = $data[0];
+["id" => $id1, "name" => $name1] = $data[0];
+
+foreach ($data as list("id" => $id, "name" => $name)) {
+    // logic here with $id and $name
+}
+
+foreach ($data as ["id" => $id, "name" => $name]) {
+    // logic here with $id and $name
+}
+
+function swap(&$a, &$b): void
+{
+    [$a, $b] = [$b, $a];
+}
+
 `;
diff --git a/tests/list/list.php b/tests/list/list.php
index 7075df7..a65bb79 100644
--- a/tests/list/list.php
+++ b/tests/list/list.php
@@ -90,3 +90,17 @@ list(
 
     3 => $fourthVeryVeryVeryVeryLong
 ) = $arr;
+
+list("id" => $id1, "name" => $name1) = $data[0];
+["id" => $id1, "name" => $name1] = $data[0];
+
+foreach ($data as list("id" => $id, "name" => $name)) {
+    // logic here with $id and $name
+}
+
+foreach ($data as ["id" => $id, "name" => $name]) {
+    // logic here with $id and $name
+}
+
+function swap( &$a, &$b ): void
+{ [ $a, $b ] = [ $b, $a ]; }