 syntax = esprima.Syntax
 debug = require 'debug'
 path = require 'path'
-
-#debug.setLevel if __ejs? then 1 else 0
 
 { Set } = require 'set'
 { NodeVisitor } = require 'nodevisitor'


exports.compile = (tree, base_output_filename, source_filename) ->

        console.warn "compiling #{source_filename}"
        
        tree = insert_toplevel_func tree, base_output_filename



                # we don't need to recurse here since we won't have nested functions at this point
                n

sanitize_with_regexp = (filename) ->
        filename.replace /[.,-\/\\]/g, "_" # this is insanely inadequate

sanitize_with_replace = (filename) ->
        replace_all = (str, from, to) ->
                while (str.indexOf from) > -1
                        str = str.replace from, to
                str

        filename = replace_all filename, ".", "_"
        filename = replace_all filename, ",", "_"
        filename = replace_all filename, "-", "_"
        filename = replace_all filename, "/", "_"
        filename = replace_all filename, "\\", "_"
        
insert_toplevel_func = (tree, filename) ->
        sanitize = if __ejs? then sanitize_with_replace else sanitize_with_regexp
        toplevel =
                type: syntax.FunctionDeclaration,
                id:
