                 rv                        
                 
         visitFunction: (n) ->
-                ###
                 if n.ejs_env.closed.empty()
                         n.body.body.unshift
                                 type: syntax.VariableDeclaration,

                                kind: "var"
                        super
                else
                ###
                # okay, we know we need a fresh environment in this function
                
                env_name = "%env_#{n.ejs_env.id}"

                # insert environment creation (at the start of the function body)
                n.body.body.unshift
                        type: syntax.VariableDeclaration,
                        declarations: [{
                                type: syntax.VariableDeclarator
                                id:  create_identifier env_name
                                init:
                                        type: syntax.ObjectExpression
                                        properties: []
                        }],
                        kind: "var"

                if n.ejs_env.parent?
                        n.body.body.splice 1, 0, {
                                type: syntax.ExpressionStatement
                                expression:
                                        type: syntax.AssignmentExpression,
                                        operator: "="
                                        left:
                                                type: syntax.MemberExpression,
                                                computed: false,
                                                object: create_identifier env_name
                                                property: create_identifier "%env_#{n.ejs_env.parent.id}"
                                        right: create_identifier "%env_#{n.ejs_env.parent.id}"
                        }
                        

                # we need to push assignments of any closed over parameters into the environment at this point
                for param in n.params
                        if n.ejs_env.closed.member param.name
                                n.body.body.splice 1, 0, {
                                        type: syntax.ExpressionStatement
                                        expression:

                when syntax.ForStatement          then Set.union.apply null, (map free, [exp.init, exp.test, exp.update, exp.body])
                when syntax.ForInStatement        then Set.union.apply null, (map free, [exp.left, exp.right, exp.body])
                when syntax.WhileStatement        then Set.union.apply null, (map free, [exp.test, exp.body])
                when syntax.DoWhileStatement      then Set.union.apply null, (map free, [exp.test, exp.body])
                when syntax.SwitchStatement       then Set.union.apply null, [free exp.discriminant].concat (map free, exp.cases)
                when syntax.SwitchCase            then free_blocklike exp, exp.consequent
                when syntax.EmptyStatement        then new Set
