Skip to content

Commit 16f726c

Browse files
committed
Fix more edge cases
1 parent fc6a33a commit 16f726c

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed

src/ASTConverter/ASTConverter.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,16 @@ private static function _init_handle_map() : array {
452452
'PhpParser\Node\Expr\PropertyFetch' => function(PhpParser\Node\Expr\PropertyFetch $n, int $startLine) : ?\ast\Node {
453453
return self::_phpparser_propertyfetch_to_ast_prop($n, $startLine);
454454
},
455+
'PhpParser\Node\Expr\ShellExec' => function(PhpParser\Node\Expr\ShellExec $n, int $startLine) : \ast\Node {
456+
$parts = $n->parts;
457+
if (\count($parts) === 1 && $parts[0] instanceof PhpParser\Node\Scalar\EncapsedStringPart) {
458+
$value = $parts[0]->value;
459+
} else {
460+
$value_inner = array_map(function(PhpParser\Node $node) { return self::_phpparser_node_to_ast_node($node); }, $parts);
461+
$value = astnode(\ast\AST_ENCAPS_LIST, 0, $value_inner, $startLine);
462+
}
463+
return astnode(\ast\AST_SHELL_EXEC, 0, ['expr' => $value], $startLine);
464+
},
455465
'PhpParser\Node\Expr\StaticCall' => function(PhpParser\Node\Expr\StaticCall $n, int $startLine) : \ast\Node {
456466
return self::_ast_node_static_call(
457467
self::_phpparser_node_to_ast_node($n->class),
@@ -492,7 +502,7 @@ private static function _init_handle_map() : array {
492502
'PhpParser\Node\Expr\Variable' => function(PhpParser\Node\Expr\Variable $n, int $startLine) : ?\ast\Node {
493503
return self::_ast_node_variable($n->name, $startLine);
494504
},
495-
'PhpParser\Node\Expr\Yield_' => function(PhpParser\Node\Expr\Yield_ $n, int $startLine) : ?\ast\Node {
505+
'PhpParser\Node\Expr\Yield_' => function(PhpParser\Node\Expr\Yield_ $n, int $startLine) : \ast\Node {
496506
return astnode(
497507
\ast\AST_YIELD,
498508
0,
@@ -503,6 +513,14 @@ private static function _init_handle_map() : array {
503513
$startLine
504514
);
505515
},
516+
'PhpParser\Node\Expr\YieldFrom' => function(PhpParser\Node\Expr\YieldFrom $n, int $startLine) : \ast\Node {
517+
return astnode(
518+
\ast\AST_YIELD_FROM,
519+
0,
520+
['expr' => self::_phpparser_node_to_ast_node($n->expr)],
521+
$startLine
522+
);
523+
},
506524
'PhpParser\Node\Name' => function(PhpParser\Node\Name $n, int $startLine) : \ast\Node {
507525
return self::_ast_node_name(
508526
self::_phpparser_name_to_string($n),
@@ -838,6 +856,18 @@ private static function _init_handle_map() : array {
838856
'alias' => $n->newName,
839857
], $startLine);
840858
},
859+
'PhpParser\Node\Stmt\TraitUseAdaptation\Precedence' => function(PhpParser\Node\Stmt\TraitUseAdaptation\Precedence $n, int $startLine) : \ast\Node {
860+
$old_class = $n->trait !== null ? self::_phpparser_name_to_string($n->trait) : null;
861+
$flags = ($n->trait instanceof PhpParser\Node\Name\FullyQualified) ? \ast\flags\NAME_FQ : \ast\flags\NAME_NOT_FQ;
862+
// TODO: flags for visibility
863+
return astnode(\ast\AST_TRAIT_PRECEDENCE, 0, [
864+
'method' => astnode(\ast\AST_METHOD_REFERENCE, 0, [
865+
'class' => astnode(\ast\AST_NAME, $flags, ['name' => $old_class], $startLine),
866+
'method' => $n->method,
867+
], $startLine),
868+
'insteadof' => self::_phpparser_name_list_to_ast_name_list($n->insteadof, $startLine),
869+
], $startLine);
870+
},
841871
'PhpParser\Node\Stmt\TryCatch' => function(PhpParser\Node\Stmt\TryCatch $n, int $startLine) : \ast\Node {
842872
if (!is_array($n->catches)) {
843873
throw new \Error(sprintf("Unsupported type %s\n%s", get_class($n), var_export($n->catches, true)));

test_files/src/closure.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
(function ($value) { self::bar();})(4);

test_files/src/shell_exec.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
$x = 2;
3+
if (false) { `echo`; `echo '$x'`; }

test_files/src/use.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
22

33
class C {
4-
use T{
4+
use T, T2{
55
f1 as private f2;
6+
T2::f2 insteadof T;
67
}
78
}

test_files/src/yieldfrom.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
function foo() { yield from bar(); }

0 commit comments

Comments
 (0)