@@ -22,8 +22,15 @@ test(function () {
22
22
Assert::same ('($a ?? null) ' , optionalChaining ('$a? ' ));
23
23
Assert::same ('(($a ?? null)) ' , optionalChaining ('($a?) ' ));
24
24
Assert::same ('a? ' , optionalChaining ('a? ' ));
25
+ Assert::same ('(($_tmp = $foo ?? null) === null ? null : $_tmp[1]) ' , optionalChaining ('$foo?[1] ' ));
25
26
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 ' ));
26
29
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]? ]? ' ));
27
34
28
35
Assert::same ('(($_tmp = $foo ?? null) === null ? null : $_tmp->prop) ' , optionalChaining ('$foo?->prop ' ));
29
36
Assert::same ('($foo->prop ?? null) ' , optionalChaining ('$foo->prop? ' ));
@@ -50,17 +57,20 @@ test(function () {
50
57
Assert::same ('$var->prop->elem[1]->call(2)->item ' , optionalChaining ('$var->prop->elem[1]->call(2)->item ' ));
51
58
Assert::same ('(($_tmp = $var ?? null) === null ? null : $_tmp->prop->elem[1]->call(2)->item) ' , optionalChaining ('$var?->prop->elem[1]->call(2)->item ' ));
52
59
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 ' ));
53
61
Assert::same ('(($_tmp = $var->prop->elem[1] ?? null) === null ? null : $_tmp->call(2)->item) ' , optionalChaining ('$var->prop->elem[1]?->call(2)->item ' ));
54
62
Assert::same ('(($_tmp = $var->prop->elem[1]->call(2) ?? null) === null ? null : $_tmp->item) ' , optionalChaining ('$var->prop->elem[1]->call(2)?->item ' ));
55
63
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
+ );
56
68
});
57
69
58
70
59
71
test (function () { // not allowed
60
72
Assert::same ('$foo ?(hello) ' , optionalChaining ('$foo?(hello) ' ));
61
73
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
64
74
});
65
75
66
76
0 commit comments