Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: 馃 remove unnecessary code #6575

Merged
merged 2 commits into from Dec 5, 2022

Conversation

IWANABETHATGUY
Copy link
Contributor

@IWANABETHATGUY IWANABETHATGUY commented Dec 4, 2022

Description:

  1. remove unnecessary code, this function is invoked but did nothing if it return true,
    also
    impl VisitMut for IdentCollector {
    noop_visit_mut_type!();
    fn visit_mut_catch_clause(&mut self, c: &mut CatchClause) {
    let old = self.is_pat_decl;
    self.is_pat_decl = true;
    c.param.visit_mut_children_with(self);
    self.is_pat_decl = old;
    self.is_pat_decl = false;
    c.body.visit_mut_with(self);
    self.is_pat_decl = old;
    }
    fn visit_mut_class_decl(&mut self, e: &mut ClassDecl) {
    if self.for_binding {
    e.ident.visit_mut_with(self);
    }
    e.class.visit_mut_with(self);
    }
    fn visit_mut_class_expr(&mut self, e: &mut ClassExpr) {
    e.class.visit_mut_with(self);
    }
    fn visit_mut_expr(&mut self, e: &mut Expr) {
    match e {
    Expr::Ident(..) if self.for_binding => {}
    _ => {
    e.visit_mut_children_with(self);
    }
    }
    }
    fn visit_mut_fn_decl(&mut self, e: &mut FnDecl) {
    if self.for_binding {
    e.ident.visit_mut_with(self);
    }
    e.function.visit_mut_with(self);
    }
    fn visit_mut_fn_expr(&mut self, e: &mut FnExpr) {
    if self.for_binding {
    e.ident.visit_mut_with(self);
    }
    e.function.visit_mut_with(self);
    }
    fn visit_mut_ident(&mut self, i: &mut Ident) {
    self.add(&*i);
    }
    fn visit_mut_labeled_stmt(&mut self, s: &mut LabeledStmt) {
    s.body.visit_mut_with(self);
    }
    fn visit_mut_param(&mut self, p: &mut Param) {
    let old = self.is_pat_decl;
    self.is_pat_decl = true;
    p.visit_mut_children_with(self);
    self.is_pat_decl = old;
    }
    fn visit_mut_pat(&mut self, p: &mut Pat) {
    match p {
    Pat::Ident(..) if self.for_binding && !self.is_pat_decl => {}
    _ => {
    p.visit_mut_children_with(self);
    }
    }
    }
    fn visit_mut_prop_name(&mut self, p: &mut PropName) {
    if let PropName::Computed(..) = p {
    p.visit_mut_children_with(self);
    }
    }
    fn visit_mut_var_declarator(&mut self, d: &mut VarDeclarator) {
    let old = self.is_pat_decl;
    self.is_pat_decl = true;
    d.name.visit_mut_with(self);
    self.is_pat_decl = false;
    d.init.visit_mut_with(self);
    self.is_pat_decl = old;
    }
    }
    , Although this visitor visit &mut Ast node, but we could see that it does't modified ast node, over all, remove
    those code is safe.
  2. This pr would improve a little performance.

BREAKING CHANGE:

Related issue (if exists):

@IWANABETHATGUY IWANABETHATGUY marked this pull request as draft December 4, 2022 12:31
@IWANABETHATGUY IWANABETHATGUY marked this pull request as ready for review December 4, 2022 13:10
@IWANABETHATGUY
Copy link
Contributor Author

@kdy1 , the benchmark CI is broken due to network issue, but I don't have permission to retry it, would you mind helping with rerunning it?

Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swc-bump:

  • swc_ecma_minifier

@kdy1 kdy1 enabled auto-merge (squash) December 5, 2022 00:14
@kdy1 kdy1 added this to the Planned milestone Dec 5, 2022
@kdy1 kdy1 self-assigned this Dec 5, 2022
@kdy1 kdy1 merged commit 586bfd5 into swc-project:main Dec 5, 2022
@IWANABETHATGUY IWANABETHATGUY deleted the chore/remove-unnecessary-code branch December 5, 2022 02:20
@kdy1 kdy1 modified the milestones: Planned, v1.3.22 Dec 9, 2022
@swc-project swc-project locked as resolved and limited conversation to collaborators Jan 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants