Is this just finding variable/function identifiers? If so, you can accomplish it a lot easier using figure_out_scope. http://lisperator.net/uglifyjs/scope