From 891092caf258fafd91dc5e117777d7db85ef85ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Tue, 28 Jul 2020 00:55:28 +0900 Subject: [PATCH] Fix typescript stripper (#905) swc_ecma_codegen: - Fix codegen of optional catch parameters (#904) swc_ecma_transforms: - Fix for nested catch clause --- ecmascript/codegen/Cargo.toml | 2 +- ecmascript/codegen/src/lib.rs | 8 +++++--- ecmascript/transforms/Cargo.toml | 2 +- .../src/compat/es2018/optional_catch_binding.rs | 6 ++++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ecmascript/codegen/Cargo.toml b/ecmascript/codegen/Cargo.toml index 43fadaa53d2..df22e6dd145 100644 --- a/ecmascript/codegen/Cargo.toml +++ b/ecmascript/codegen/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "swc_ecma_codegen" -version = "0.28.2" +version = "0.28.3" authors = ["강동윤 "] license = "Apache-2.0/MIT" repository = "https://github.com/swc-project/swc.git" diff --git a/ecmascript/codegen/src/lib.rs b/ecmascript/codegen/src/lib.rs index 35cb8070eca..83777c660ae 100644 --- a/ecmascript/codegen/src/lib.rs +++ b/ecmascript/codegen/src/lib.rs @@ -1986,9 +1986,11 @@ impl<'a> Emitter<'a> { keyword!("catch"); formatting_space!(); - punct!("("); - emit!(node.param); - punct!(")"); + if let Some(param) = &node.param { + punct!("("); + emit!(param); + punct!(")"); + } space!(); diff --git a/ecmascript/transforms/Cargo.toml b/ecmascript/transforms/Cargo.toml index e8ffe7a2234..23d9e91f844 100644 --- a/ecmascript/transforms/Cargo.toml +++ b/ecmascript/transforms/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "swc_ecma_transforms" -version = "0.15.1" +version = "0.15.2" authors = ["강동윤 "] license = "Apache-2.0/MIT" repository = "https://github.com/swc-project/swc.git" diff --git a/ecmascript/transforms/src/compat/es2018/optional_catch_binding.rs b/ecmascript/transforms/src/compat/es2018/optional_catch_binding.rs index 27e2719a94c..002a3b8a878 100644 --- a/ecmascript/transforms/src/compat/es2018/optional_catch_binding.rs +++ b/ecmascript/transforms/src/compat/es2018/optional_catch_binding.rs @@ -1,5 +1,5 @@ use swc_ecma_ast::*; -use swc_ecma_visit::Fold; +use swc_ecma_visit::{Fold, FoldWith}; struct OptionalCatchBinding; @@ -10,7 +10,9 @@ pub fn optional_catch_binding() -> impl Fold { } impl Fold for OptionalCatchBinding { - fn fold_catch_clause(&mut self, cc: CatchClause) -> CatchClause { + fn fold_catch_clause(&mut self, mut cc: CatchClause) -> CatchClause { + cc = cc.fold_children_with(self); + if cc.param.is_some() { return cc; }