Skip to content

Commit

Permalink
More fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Jul 11, 2024
1 parent 395d17a commit 71d8260
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 26 deletions.
6 changes: 5 additions & 1 deletion crates/swc_ecma_minifier/src/compress/optimize/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,11 @@ impl Optimizer<'_> {
// TODO: Optimize
}

Decl::TsInterface(_) | Decl::TsTypeAlias(_) | Decl::TsEnum(_) | Decl::TsModule(_) => {
Decl::TsInterface(_)
| Decl::TsTypeAlias(_)
| Decl::TsEnum(_)
| Decl::TsModule(_)
| Decl::Invalid(..) => {
// Nothing to do. We might change this to unreachable!()
}
}
Expand Down
19 changes: 8 additions & 11 deletions crates/swc_ecma_minifier/src/compress/pure/dead_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl Pure<'_> {
|(mut decls, mut hoisted_fns, mut new_stmts), stmt| {
match stmt.take().try_into_stmt() {
Ok(Stmt::Decl(Decl::Fn(f))) => {
hoisted_fns.push(f.into());
hoisted_fns.push(T::from(Stmt::from(f)));
}
Ok(t) => {
let ids = extract_var_ids(&t).into_iter().map(|i| VarDeclarator {
Expand All @@ -264,16 +264,13 @@ impl Pure<'_> {
);

if !decls.is_empty() {
new_stmts.push(
VarDecl {
span: DUMMY_SP,
kind: VarDeclKind::Var,
decls,
declare: false,
..Default::default()
}
.into(),
);
new_stmts.push(T::from(Stmt::from(VarDecl {
span: DUMMY_SP,
kind: VarDeclKind::Var,
decls,
declare: false,
..Default::default()
})));
}

new_stmts.extend(stmts.drain(..=idx));
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_estree_compat/src/babelify/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Babelify for Stmt {
Decl::TsTypeAlias(d) => Statement::TSTypeAliasDecl(d.babelify(ctx)),
Decl::TsEnum(d) => Statement::TSEnumDecl(d.babelify(ctx)),
Decl::TsModule(d) => Statement::TSModuleDecl(d.babelify(ctx)),
Decl::Invalid(d) => unreachable!(),
Decl::Invalid(..) => unreachable!(),
},
Stmt::Expr(s) => Statement::Expr(s.babelify(ctx)),
}
Expand Down
20 changes: 7 additions & 13 deletions crates/swc_estree_compat/src/swcify/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,20 @@ impl Swcify for Statement {
Statement::While(v) => v.swcify(ctx).into(),
Statement::With(v) => v.swcify(ctx).into(),
Statement::ClassDecl(v) => v.swcify(ctx).into(),
Statement::ExportAllDecl(v) => return ModuleItem::ModuleDecl(v.swcify(ctx).into()),
Statement::ExportDefaultDecl(v) => return ModuleItem::ModuleDecl(v.swcify(ctx)),
Statement::ExportNamedDecl(v) => return ModuleItem::ModuleDecl(v.swcify(ctx).into()),
Statement::ExportAllDecl(v) => ModuleItem::ModuleDecl(v.swcify(ctx).into()),
Statement::ExportDefaultDecl(v) => ModuleItem::ModuleDecl(v.swcify(ctx)),
Statement::ExportNamedDecl(v) => ModuleItem::ModuleDecl(v.swcify(ctx).into()),
Statement::ForOf(v) => v.swcify(ctx).into(),
Statement::ImportDecl(v) => return ModuleItem::ModuleDecl(v.swcify(ctx).into()),
Statement::ImportDecl(v) => ModuleItem::ModuleDecl(v.swcify(ctx).into()),
Statement::DeclClass(v) => v.swcify(ctx).into(),
Statement::DeclFunc(v) => v.swcify(ctx).into(),
Statement::DeclInterface(v) => v.swcify(ctx).into(),
Statement::DeclModule(v) => v.swcify(ctx).into(),
Statement::DeclareModuleExports(v) => {
return ModuleItem::ModuleDecl(v.swcify(ctx).into())
}
Statement::DeclareModuleExports(v) => ModuleItem::ModuleDecl(v.swcify(ctx).into()),
Statement::DeclTypeAlias(v) => v.swcify(ctx).into(),
Statement::DeclVar(v) => v.swcify(ctx).into(),
Statement::DeclExportDeclaration(v) => {
return ModuleItem::ModuleDecl(v.swcify(ctx).into())
}
Statement::DeclExportAllDeclaration(v) => {
return ModuleItem::ModuleDecl(v.swcify(ctx).into())
}
Statement::DeclExportDeclaration(v) => ModuleItem::ModuleDecl(v.swcify(ctx).into()),
Statement::DeclExportAllDeclaration(v) => ModuleItem::ModuleDecl(v.swcify(ctx).into()),
_ => {
todo!("swcify: {:?}", self)
}
Expand Down

0 comments on commit 71d8260

Please sign in to comment.