node: basic support for *expr.Closure
This commit is contained in:
parent
6b8d4d879a
commit
5105293ce6
9
fixtures/0013-closures.php
Normal file
9
fixtures/0013-closures.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
const FOO = 'X';
|
||||
|
||||
$x = function(string $param): string {
|
||||
return $param . FOO;
|
||||
};
|
||||
|
||||
echo $x("x");
|
18
node.go
18
node.go
@ -1036,6 +1036,24 @@ func (this *conversionState) convertNoFreeFloating(n_ node.Node) (string, error)
|
||||
|
||||
return className + constName, nil
|
||||
|
||||
case *expr.Closure:
|
||||
// Need to decide what to do with `this` binding
|
||||
// TODO figure out what it means to use `this` in all types of nested closures
|
||||
|
||||
if n.Static {
|
||||
return "", parseErr{n, fmt.Errorf("use of `static` in closure implies `this`-insensitive, but we can't make that true")}
|
||||
}
|
||||
|
||||
// TODO n.PhpDocComment
|
||||
// TODO n.ClosureUse
|
||||
|
||||
body, err := this.convertFunctionCommon(n.Params, n.ReturnType, n.ReturnsRef, n.Stmts)
|
||||
if err != nil {
|
||||
return "", parseErr{n, err}
|
||||
}
|
||||
|
||||
return "(func" + strings.TrimRight(body, " \n") + ")", nil
|
||||
|
||||
case *expr.Exit:
|
||||
// die(0) - set process exit code and exit
|
||||
// die("message") - print to stdout and exit 0
|
||||
|
Loading…
Reference in New Issue
Block a user