Repository: prettier/plugin-php
Pull request #782 (2018-10-11 14:46:24)

fix: parens for null coalescing operator
Bug

evilebottnawi: Appveyor broken on their side

Patch:
diff --git a/src/util.js b/src/util.js
index 056a85b..9c51c0e 100644
--- a/src/util.js
+++ b/src/util.js
@@ -38,6 +38,7 @@ const PRECEDENCE = {};
     "<<=",
     ">>="
   ],
+  ["??"],
   ["||"],
   ["&&"],
   ["|"],


Test patch:
diff --git a/tests/parens/__snapshots__/jsfmt.spec.js.snap b/tests/parens/__snapshots__/jsfmt.spec.js.snap
index fc76249..f17e8db 100644
--- a/tests/parens/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/parens/__snapshots__/jsfmt.spec.js.snap
@@ -614,6 +614,16 @@ $a ** -$b;
 ($a * $b) ** $c;
 $a ** ($b * $c);
 ($a % $b) ** $c;
+
+$var = $var + $var ?? '';
+$var = $var + ($var ?? '');
+$var = ($var + $var) ?? '';
+$var = $var ?? null + 1;
+$var = ($var ?? null) + 1;
+$var = $var && ($var ?? true);
+$var = ($var ?? true) && $var;
+$var = $var && ($var ?? null) === true;
+$var = ($var ?? null) === true && $var;
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 
@@ -942,6 +952,16 @@ $a ** -$b;
 $a ** ($b * $c);
 ($a % $b) ** $c;
 
+$var = $var + $var ?? '';
+$var = $var + ($var ?? '');
+$var = $var + $var ?? '';
+$var = $var ?? null + 1;
+$var = ($var ?? null) + 1;
+$var = $var && ($var ?? true);
+$var = ($var ?? true) && $var;
+$var = $var && ($var ?? null) === true;
+$var = ($var ?? null) === true && $var;
+
 `;
 
 exports[`block.php - php-verify: block.php 1`] = `
diff --git a/tests/parens/bin.php b/tests/parens/bin.php
index d936b05..af66005 100644
--- a/tests/parens/bin.php
+++ b/tests/parens/bin.php
@@ -307,3 +307,13 @@ $a ** -$b;
 ($a * $b) ** $c;
 $a ** ($b * $c);
 ($a % $b) ** $c;
+
+$var = $var + $var ?? '';
+$var = $var + ($var ?? '');
+$var = ($var + $var) ?? '';
+$var = $var ?? null + 1;
+$var = ($var ?? null) + 1;
+$var = $var && ($var ?? true);
+$var = ($var ?? true) && $var;
+$var = $var && ($var ?? null) === true;
+$var = ($var ?? null) === true && $var;
diff --git a/tests/return/__snapshots__/jsfmt.spec.js.snap b/tests/return/__snapshots__/jsfmt.spec.js.snap
index fb277e0..716c4de 100644
--- a/tests/return/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/return/__snapshots__/jsfmt.spec.js.snap
@@ -227,6 +227,14 @@ return is_string($this->recallerWithClass) && Str::contains($this->recaller, '|'
 return Str::contains($this->recaller, '|') && is_string($this->recallerWithClass);
 
 return in_array('odbc', $this->getAvailableDrivers()) && $config['odbc'] ?? null === true;
+return in_array('odbc', $this->getAvailableDrivers()) && $config['odbc'] ??
+    null === true;
+return in_array('odbc', $this->getAvailableDrivers()) && ($config['odbc'] ?? null) === true;
+return in_array('odbc', $this->getAvailableDrivers()) &&
+    ($config['odbc'] ?? null) === true;
+return ($map[$name] ?? $name).(! is_null($parameters) ? ':'.$parameters : '');
+return ($map[$name] ?? $name) .
+    (!is_null($parameters) ? ':' . $parameters : '');
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 
@@ -552,5 +560,15 @@ return Str::contains($this->recaller, '|') &&
 
 return in_array('odbc', $this->getAvailableDrivers()) && $config['odbc'] ??
     null === true;
+return in_array('odbc', $this->getAvailableDrivers()) && $config['odbc'] ??
+    null === true;
+return in_array('odbc', $this->getAvailableDrivers()) &&
+    ($config['odbc'] ?? null) === true;
+return in_array('odbc', $this->getAvailableDrivers()) &&
+    ($config['odbc'] ?? null) === true;
+return ($map[$name] ?? $name) .
+    (!is_null($parameters) ? ':' . $parameters : '');
+return ($map[$name] ?? $name) .
+    (!is_null($parameters) ? ':' . $parameters : '');
 
 `;
diff --git a/tests/return/return.php b/tests/return/return.php
index 3f4f650..1eb400f 100644
--- a/tests/return/return.php
+++ b/tests/return/return.php
@@ -224,3 +224,11 @@ return is_string($this->recallerWithClass) && Str::contains($this->recaller, '|'
 return Str::contains($this->recaller, '|') && is_string($this->recallerWithClass);
 
 return in_array('odbc', $this->getAvailableDrivers()) && $config['odbc'] ?? null === true;
+return in_array('odbc', $this->getAvailableDrivers()) && $config['odbc'] ??
+    null === true;
+return in_array('odbc', $this->getAvailableDrivers()) && ($config['odbc'] ?? null) === true;
+return in_array('odbc', $this->getAvailableDrivers()) &&
+    ($config['odbc'] ?? null) === true;
+return ($map[$name] ?? $name).(! is_null($parameters) ? ':'.$parameters : '');
+return ($map[$name] ?? $name) .
+    (!is_null($parameters) ? ':' . $parameters : '');