use super::ctx::Ctx;
use super::ctx::MinifyScope;
use parse_js::ast::NodeData;
use parse_js::ast::Syntax;
use parse_js::visit::Visitor;
pub struct Pass2<'a, 'b> {
pub ctx: Ctx<'a, 'b>,
}
impl<'a, 'b> Visitor<'a> for Pass2<'a, 'b> {
fn on_syntax_up(&mut self, n: &mut NodeData<'a>) -> () {
let scope = n.scope;
let named_fn_decl_name = match &n.stx {
Syntax::FunctionDecl {
export: false,
name: Some(name),
..
} => Some(name.loc),
_ => None,
};
if let Some(name) = named_fn_decl_name {
let decl_scope = scope
.find_self_or_ancestor(|t| t.is_closure_or_global())
.unwrap();
self
.ctx
.scopes
.entry(decl_scope)
.or_insert_with(|| MinifyScope::new(self.ctx.session))
.hoisted_functions
.insert(name, n.replace(self.ctx.session, Syntax::EmptyStmt {}));
return;
};
}
}