@@ -552,9 +552,9 @@ func (c *funcContext) translateToplevelFunction(fun *ast.FuncDecl, info *analysi
552
552
},
553
553
}, stmts ... )
554
554
}
555
- params , body := translateFunction (fun .Type , stmts , c , sig , info , fun .Name .Name )
555
+ params , fun := translateFunction (fun .Type , stmts , c , sig , info , fun .Name .Name )
556
556
joinedParams = strings .Join (params , ", " )
557
- return []byte (fmt .Sprintf ("\t %s = function(%s) { \n %s \t } ;\n " , lhs , joinedParams , string ( body ) ))
557
+ return []byte (fmt .Sprintf ("\t %s = %s ;\n " , lhs , fun ))
558
558
}
559
559
560
560
if fun .Recv == nil {
@@ -603,7 +603,7 @@ func (c *funcContext) translateToplevelFunction(fun *ast.FuncDecl, info *analysi
603
603
return code .Bytes ()
604
604
}
605
605
606
- func translateFunction (typ * ast.FuncType , stmts []ast.Stmt , outerContext * funcContext , sig * types.Signature , info * analysis.FuncInfo , name string ) ([]string , [] byte ) {
606
+ func translateFunction (typ * ast.FuncType , stmts []ast.Stmt , outerContext * funcContext , sig * types.Signature , info * analysis.FuncInfo , name string ) ([]string , string ) {
607
607
c := & funcContext {
608
608
FuncInfo : info ,
609
609
p : outerContext .p ,
@@ -638,7 +638,7 @@ func translateFunction(typ *ast.FuncType, stmts []ast.Stmt, outerContext *funcCo
638
638
c .localVars = append (c .localVars , "$this = this" )
639
639
}
640
640
641
- body := c .CatchOutput (1 , func () {
641
+ body := string ( c .CatchOutput (1 , func () {
642
642
if c .sig != nil && c .sig .Results ().Len () != 0 && c .sig .Results ().At (0 ).Name () != "" {
643
643
c .resultNames = make ([]ast.Expr , c .sig .Results ().Len ())
644
644
for i := 0 ; i < c .sig .Results ().Len (); i ++ {
@@ -720,12 +720,12 @@ func translateFunction(typ *ast.FuncType, stmts []ast.Stmt, outerContext *funcCo
720
720
if suffix != "" {
721
721
c .Printf ("/* */%s" , suffix )
722
722
}
723
- })
723
+ }))
724
724
725
725
if len (c .localVars ) != 0 {
726
726
sort .Strings (c .localVars )
727
- body = append ([] byte ( fmt .Sprintf ("%svar %s;\n " , strings .Repeat ("\t " , c .p .indentation + 1 ), strings .Join (c .localVars , ", " ))), body ... )
727
+ body = fmt .Sprintf ("%svar %s;\n " , strings .Repeat ("\t " , c .p .indentation + 1 ), strings .Join (c .localVars , ", " )) + body
728
728
}
729
729
730
- return params , body
730
+ return params , fmt . Sprintf ( "function(%s) { \n %s%s}" , strings . Join ( params , ", " ), body , strings . Repeat ( " \t " , c . p . indentation ))
731
731
}
0 commit comments