Skip to content

Commit

Permalink
fix(webpack/ast): Reduce if statements (swc-project#2969)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 authored and nicholasxjy committed Dec 18, 2021
1 parent 4211786 commit 50cc642
Show file tree
Hide file tree
Showing 6 changed files with 515 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/swc_webpack_ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2018"
license = "Apache-2.0"
name = "swc_webpack_ast"
repository = "https://github.com/swc-project/swc.git"
version = "0.5.0"
version = "0.5.1"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
9 changes: 9 additions & 0 deletions crates/swc_webpack_ast/src/reducer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,15 @@ impl VisitMut for ReduceAst {
return;
}
}

if is.cons.is_empty() && is.alt.is_empty() {
self.changed = true;
*stmt = Stmt::Expr(ExprStmt {
span: DUMMY_SP,
expr: is.test.take(),
});
return;
}
}

Stmt::While(s) => {
Expand Down
7 changes: 6 additions & 1 deletion crates/swc_webpack_ast/tests/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ impl VisitMut for AssertValid {
panic!("found an identifier with dummy span: {:?}", i)
}
}

fn visit_mut_module(&mut self, m: &mut Module) {
dbg!(&*m);

m.visit_mut_children_with(self);
}
}

#[testing::fixture("../swc_ecma_parser/tests/typescript/tsc/**/input.ts")]
Expand Down Expand Up @@ -84,7 +90,6 @@ fn assert_no_invalid(input: PathBuf) {
};

module.visit_mut_with(&mut pass);
dbg!(&module);
module.visit_mut_with(&mut AssertValid);

Ok(())
Expand Down
Loading

0 comments on commit 50cc642

Please sign in to comment.