@@ -22,8 +22,15 @@ test(function () {
2222 Assert::same ('($a ?? null) ' , optionalChaining ('$a? ' ));
2323 Assert::same ('(($a ?? null)) ' , optionalChaining ('($a?) ' ));
2424 Assert::same ('a? ' , optionalChaining ('a? ' ));
25+ Assert::same ('(($_tmp = $foo ?? null) === null ? null : $_tmp[1]) ' , optionalChaining ('$foo?[1] ' ));
2526 Assert::same ('($foo[1] ?? null) ' , optionalChaining ('$foo[1]? ' ));
27+ Assert::same ('(($_tmp = $foo ?? null) === null ? null : ($_tmp[1] ?? null)) ' , optionalChaining ('$foo?[1]? ' ));
28+ Assert::same ('(($_tmp = $foo ?? null) === null ? null : ($_tmp[1] ?? null)) + 10 ' , optionalChaining ('$foo?[1]? + 10 ' ));
2629 Assert::same ('(($foo[1] ?? null)) ' , optionalChaining ('($foo[1]?) ' ));
30+ Assert::same ('((($_tmp = $foo ?? null) === null ? null : $_tmp[1])) ' , optionalChaining ('($foo?[1]) ' ));
31+ Assert::same ('[(($_tmp = $foo ?? null) === null ? null : ($_tmp[1] ?? null))] ' , optionalChaining ('[$foo?[1]?] ' ));
32+ Assert::same ('(($_tmp = $foo ?? null) === null ? null : ($_tmp[ ($a ?? null) ] ?? null)) ' , optionalChaining ('$foo?[ $a? ]? ' ));
33+ Assert::same ('(($_tmp = $foo ?? null) === null ? null : ($_tmp[ (($_tmp = $a ?? null) === null ? null : ($_tmp[2] ?? null)) ] ?? null)) ' , optionalChaining ('$foo?[ $a?[2]? ]? ' ));
2734
2835 Assert::same ('(($_tmp = $foo ?? null) === null ? null : $_tmp->prop) ' , optionalChaining ('$foo?->prop ' ));
2936 Assert::same ('($foo->prop ?? null) ' , optionalChaining ('$foo->prop? ' ));
@@ -50,17 +57,20 @@ test(function () {
5057 Assert::same ('$var->prop->elem[1]->call(2)->item ' , optionalChaining ('$var->prop->elem[1]->call(2)->item ' ));
5158 Assert::same ('(($_tmp = $var ?? null) === null ? null : $_tmp->prop->elem[1]->call(2)->item) ' , optionalChaining ('$var?->prop->elem[1]->call(2)->item ' ));
5259 Assert::same ('(($_tmp = $var->prop ?? null) === null ? null : $_tmp->elem[1]->call(2)->item) ' , optionalChaining ('$var->prop?->elem[1]->call(2)->item ' ));
60+ Assert::same ('(($_tmp = $var->prop->elem ?? null) === null ? null : $_tmp[1]->call(2)->item) ' , optionalChaining ('$var->prop->elem?[1]->call(2)->item ' ));
5361 Assert::same ('(($_tmp = $var->prop->elem[1] ?? null) === null ? null : $_tmp->call(2)->item) ' , optionalChaining ('$var->prop->elem[1]?->call(2)->item ' ));
5462 Assert::same ('(($_tmp = $var->prop->elem[1]->call(2) ?? null) === null ? null : $_tmp->item) ' , optionalChaining ('$var->prop->elem[1]->call(2)?->item ' ));
5563 Assert::same ('($var->prop->elem[1]->call(2)->item ?? null) ' , optionalChaining ('$var->prop->elem[1]->call(2)->item? ' ));
64+ Assert::same (
65+ '(($_tmp = $var ?? null) === null ? null : (($_tmp = $_tmp->prop ?? null) === null ? null : (($_tmp = $_tmp->elem ?? null) === null ? null : (($_tmp = $_tmp[1] ?? null) === null ? null : (($_tmp = $_tmp->call(2) ?? null) === null ? null : ($_tmp->item ?? null)))))) ' ,
66+ optionalChaining ('$var?->prop?->elem?[1]?->call(2)?->item? ' )
67+ );
5668});
5769
5870
5971test (function () { // not allowed
6072 Assert::same ('$foo ?(hello) ' , optionalChaining ('$foo?(hello) ' ));
6173 Assert::same ('$foo->foo ?(hello) ' , optionalChaining ('$foo->foo?(hello) ' ));
62-
63- Assert::same ('$foo ?[1] ' , optionalChaining ('$foo?[1] ' )); // not allowed due to collision with short ternary
6474});
6575
6676
0 commit comments