diff --git a/crates/swc/tests/fixture/issues-2xxx/2964/case-2/output/index.ts b/crates/swc/tests/fixture/issues-2xxx/2964/case-2/output/index.ts index 6364938c026..9e760eeaba3 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2964/case-2/output/index.ts +++ b/crates/swc/tests/fixture/issues-2xxx/2964/case-2/output/index.ts @@ -9,14 +9,14 @@ function _export(target, all) { }); } _export(exports, { - badIstanbul: ()=>badIstanbul, noop: ()=>noop, + badIstanbul: ()=>badIstanbul, downloadDocument: ()=>downloadDocument }); const _objectWithoutProperties = require("@swc/helpers/lib/_object_without_properties.js").default; //top comment const noop = ()=>{}; -var /* istanbul ignore next */ badIstanbul = (test)=>{ +/* istanbul ignore next */ const badIstanbul = (test)=>{ const { value } = test, pixelParams = _objectWithoutProperties(test, [ "value" ]); diff --git a/crates/swc/tests/fixture/issues-2xxx/2964/case-5/output/index.ts b/crates/swc/tests/fixture/issues-2xxx/2964/case-5/output/index.ts index 256daa74932..9b3f59bc79b 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2964/case-5/output/index.ts +++ b/crates/swc/tests/fixture/issues-2xxx/2964/case-5/output/index.ts @@ -9,9 +9,9 @@ function _export(target, all) { }); } _export(exports, { - foo: ()=>foo, a: ()=>a, - b: ()=>b + b: ()=>b, + foo: ()=>foo }); const _extends = require("@swc/helpers/lib/_extends.js").default; const a = 1; diff --git a/crates/swc_ecma_transforms_compat/src/es2015/block_scoping/mod.rs b/crates/swc_ecma_transforms_compat/src/es2015/block_scoping/mod.rs index 55d9be66c0b..fbbbcdef98b 100644 --- a/crates/swc_ecma_transforms_compat/src/es2015/block_scoping/mod.rs +++ b/crates/swc_ecma_transforms_compat/src/es2015/block_scoping/mod.rs @@ -581,7 +581,7 @@ impl BlockScoping { fn find_vars(node: &T) -> Vec where - T: for<'any> VisitWith>, + T: for<'any> VisitWith>, { let mut vars = vec![]; let mut v = VarCollector { to: &mut vars }; diff --git a/crates/swc_ecma_transforms_compat/src/es2018/object_rest_spread.rs b/crates/swc_ecma_transforms_compat/src/es2018/object_rest_spread.rs index 185ecd9e7a5..fa34fac1ea4 100644 --- a/crates/swc_ecma_transforms_compat/src/es2018/object_rest_spread.rs +++ b/crates/swc_ecma_transforms_compat/src/es2018/object_rest_spread.rs @@ -288,19 +288,16 @@ impl VisitMut for ObjectRest { span, decl: Decl::Var(var_decl), .. - }) => { + }) if var_decl.decls.iter().any(|v| v.name.is_object()) => { let specifiers = { - let mut found = vec![]; + let mut found: Vec = vec![]; let mut finder = VarCollector { to: &mut found }; var_decl.visit_with(&mut finder); found .into_iter() - .map(|(sym, ctxt)| ExportNamedSpecifier { + .map(|ident| ExportNamedSpecifier { span: DUMMY_SP, - orig: ModuleExportName::Ident(Ident::new( - sym, - DUMMY_SP.with_ctxt(ctxt), - )), + orig: ident.into(), exported: None, is_type_only: false, }) diff --git a/crates/swc_ecma_transforms_module/src/system_js.rs b/crates/swc_ecma_transforms_module/src/system_js.rs index a4b4b8bf169..830fd4b6e16 100644 --- a/crates/swc_ecma_transforms_module/src/system_js.rs +++ b/crates/swc_ecma_transforms_module/src/system_js.rs @@ -128,7 +128,7 @@ impl SystemJs { _ => Expr::Assign(assign_expr), }, PatOrExpr::Pat(pat) => { - let mut to = vec![]; + let mut to: Vec = vec![]; pat.visit_with(&mut VarCollector { to: &mut to }); match &**pat { @@ -392,7 +392,7 @@ impl SystemJs { fn hoist_var_decl(&mut self, var_decl: VarDecl) -> Option { let mut exprs = vec![]; for var_declarator in var_decl.decls { - let mut tos = vec![]; + let mut tos: Vec = vec![]; var_declarator.visit_with(&mut VarCollector { to: &mut tos }); for (sym, ctxt) in tos { @@ -433,7 +433,7 @@ impl SystemJs { if let VarDeclOrPat::VarDecl(mut var_decl) = var_decl_or_pat { if var_decl.kind == VarDeclKind::Var { let var_declarator = var_decl.decls.remove(0); - let mut tos = vec![]; + let mut tos: Vec = vec![]; var_declarator.visit_with(&mut VarCollector { to: &mut tos }); for to in tos { @@ -834,7 +834,7 @@ impl Fold for SystemJs { ..var_decl }; for var_declarator in var_decl.decls { - let mut tos = vec![]; + let mut tos: Vec = vec![]; var_declarator.visit_with(&mut VarCollector { to: &mut tos }); for to in tos { let ident = diff --git a/crates/swc_ecma_transforms_typescript/src/strip.rs b/crates/swc_ecma_transforms_typescript/src/strip.rs index 1112c6819a1..afaf5b5555f 100644 --- a/crates/swc_ecma_transforms_typescript/src/strip.rs +++ b/crates/swc_ecma_transforms_typescript/src/strip.rs @@ -386,7 +386,7 @@ where } Decl::Var(ref var) => { - let mut names = vec![]; + let mut names: Vec = vec![]; var.decls.visit_with(&mut VarCollector { to: &mut names }); for name in names { diff --git a/crates/swc_ecma_utils/src/var.rs b/crates/swc_ecma_utils/src/var.rs index 480a1da15b6..6e1dce2d81f 100644 --- a/crates/swc_ecma_utils/src/var.rs +++ b/crates/swc_ecma_utils/src/var.rs @@ -1,15 +1,15 @@ use swc_ecma_ast::*; use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; -use crate::Id; +use crate::ident::IdentLike; /// This collects variables bindings while ignoring if it's nested in /// expression. -pub struct VarCollector<'a> { - pub to: &'a mut Vec, +pub struct VarCollector<'a, I: IdentLike> { + pub to: &'a mut Vec, } -impl Visit for VarCollector<'_> { +impl<'a, I: IdentLike> Visit for VarCollector<'a, I> { noop_visit_type!(); fn visit_arrow_expr(&mut self, _: &ArrowExpr) {} @@ -25,7 +25,7 @@ impl Visit for VarCollector<'_> { } fn visit_ident(&mut self, i: &Ident) { - self.to.push((i.sym.clone(), i.span.ctxt())) + self.to.push(I::from_ident(i)) } fn visit_var_declarator(&mut self, node: &VarDeclarator) {