diff --git a/hoistpass.go b/hoistpass.go index c9c92e1..882c7b4 100644 --- a/hoistpass.go +++ b/hoistpass.go @@ -31,6 +31,9 @@ func (this *hoistPass) Enter(n_ *node.Node) error { // can't contain any hoistable statements return this.enterStmtList(&n.Stmts) + case *expr.Closure: + return this.enterStmtList(&n.Stmts) + case *node.Root: return this.enterStmtList(&n.Stmts) @@ -46,6 +49,30 @@ func (this *hoistPass) Enter(n_ *node.Node) error { case *binary.LogicalOr: return this.enterShortCircuitingBinOp(&n.Left, &n.Right) + // Don't try to hoist a ++i statement in the loop conditional + // Bypass by just walking the stmts in a new hoist context + // TODO handle hoisting within closures in conditional statements + case *stmt.For: + if sl, ok := n.Stmt.(*stmt.StmtList); ok { + return this.enterStmtList(&sl.Stmts) + } else { + // single statement, ignore + } + + case *stmt.Do: + if sl, ok := n.Stmt.(*stmt.StmtList); ok { + return this.enterStmtList(&sl.Stmts) + } else { + // single statement, ignore + } + + case *stmt.While: + if sl, ok := n.Stmt.(*stmt.StmtList); ok { + return this.enterStmtList(&sl.Stmts) + } else { + // single statement, ignore + } + case *expr.PreInc: // Hoist the whole increment expression up to statement context // We also have to convert it to a post-increment