豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 420d7d6

Browse files
committed
fix: handle assignref in needsParens like assign
assignref was missing from the needsParens switch, falling through to return false. This caused parens to be dropped in contexts where they change semantics, e.g. $a = ($b =& $var) + 5 became $a = $b = &$var + 5.
1 parent cf80f5e commit 420d7d6

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

tests/assignref/__snapshots__/jsfmt.spec.mjs.snap

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`assignref.php 1`] = `
44
====================================options=====================================
@@ -42,6 +42,7 @@ $cached_var = &drupal_static(__FUNCTION__);
4242
4343
$test = ['key' => &$value];
4444
$test = ['key' => &$value['something']];
45+
$x = $y =& $z;
4546
4647
=====================================output=====================================
4748
<?php
@@ -56,7 +57,7 @@ class Foo
5657
}
5758
}
5859
59-
$a = &$b / 100;
60+
($a = &$b) / 100;
6061
6162
$var =
6263
$arr[
@@ -96,6 +97,7 @@ $cached_var = &drupal_static(__FUNCTION__);
9697
9798
$test = ["key" => &$value];
9899
$test = ["key" => &$value["something"]];
100+
$x = $y = &$z;
99101
100102
================================================================================
101103
`;

tests/assignref/assignref.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ public function test() {
3434

3535
$test = ['key' => &$value];
3636
$test = ['key' => &$value['something']];
37+
$x = $y =& $z;

tests/parens/__snapshots__/jsfmt.spec.mjs.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -672,14 +672,14 @@ $test = $var = &$test;
672672
$test = $var = &$test;
673673
674674
$a = ($b = $var) + 5;
675-
$a = $b = &$var + 5;
675+
$a = ($b = &$var) + 5;
676676
677677
$a = ($b = $var) || 5;
678-
$a = $b = &$var || 5;
678+
$a = ($b = &$var) || 5;
679679
680-
if ($foo = &$bar && count($foo) > 0) {
680+
if (($foo = &$bar) && count($foo) > 0) {
681681
}
682-
if ($foo = &test1() && test2($foo) > 0) {
682+
if (($foo = &test1()) && test2($foo) > 0) {
683683
}
684684
685685
call($a = &$b);
@@ -720,14 +720,14 @@ $test = $var = &$test;
720720
$test = $var = &$test;
721721
722722
$a = ($b = $var) + 5;
723-
$a = $b = &$var + 5;
723+
$a = ($b = &$var) + 5;
724724
725725
$a = ($b = $var) || 5;
726-
$a = $b = &$var || 5;
726+
$a = ($b = &$var) || 5;
727727
728-
if ($foo = &$bar && count($foo) > 0) {
728+
if (($foo = &$bar) && count($foo) > 0) {
729729
}
730-
if ($foo = &test1() && test2($foo) > 0) {
730+
if (($foo = &test1()) && test2($foo) > 0) {
731731
}
732732
733733
call($a = &$b);

0 commit comments

Comments
 (0)