node: support define()
This commit is contained in:
parent
142e26bbfe
commit
750bfd9bb2
22
node.go
22
node.go
@ -590,6 +590,28 @@ func (this *conversionState) convertNoFreeFloating(n_ node.Node) (string, error)
|
||||
ret += "this." + this.currentClassParentName + " = *super // copy by value\n"
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
if fnname, err := this.resolveName(fncall.Function); err == nil && fnname == "define" {
|
||||
// define() gets converted to const
|
||||
|
||||
if len(fncall.ArgumentList.Arguments) != 2 {
|
||||
return "", parseErr{fncall, fmt.Errorf("expected define() to have 2 arguments, found %d", len(fncall.ArgumentList.Arguments))}
|
||||
}
|
||||
|
||||
defineName := fncall.ArgumentList.Arguments[0].(*node.Argument).Expr // that much is always possible
|
||||
defineNameStr, ok := defineName.(*scalar.String)
|
||||
if !ok {
|
||||
return "", parseErr{fncall, fmt.Errorf("can't handle a complex expression in define() name")}
|
||||
}
|
||||
|
||||
rawDefineName, err := phpUnquote(defineNameStr.Value)
|
||||
if err != nil {
|
||||
return "", parseErr{fncall, err}
|
||||
}
|
||||
|
||||
// Convert to a final Const statement
|
||||
return this.convert(stmt.NewConstList([]node.Node{stmt.NewConstant(node.NewIdentifier(rawDefineName), fncall.ArgumentList.Arguments[1].(*node.Argument).Expr, "")}))
|
||||
}
|
||||
}
|
||||
|
||||
// Assignment expressions can take on better error-handling behaviour
|
||||
|
Loading…
Reference in New Issue
Block a user