diff --git a/ecmascript/transforms/Cargo.toml b/ecmascript/transforms/Cargo.toml index 702eeddc198..e76607aec33 100644 --- a/ecmascript/transforms/Cargo.toml +++ b/ecmascript/transforms/Cargo.toml @@ -16,6 +16,7 @@ swc_ecma_parser = { path ="../parser" } either = "1.5" fnv = "1" serde = { version = "1", features = ["derive"] } +objekt = "0.1" [dev-dependencies] testing = { path ="../../testing" } diff --git a/ecmascript/transforms/src/compat/es2015/arrow/mod.rs b/ecmascript/transforms/src/compat/es2015/arrow/mod.rs index 703af6810a2..81a0b37708d 100644 --- a/ecmascript/transforms/src/compat/es2015/arrow/mod.rs +++ b/ecmascript/transforms/src/compat/es2015/arrow/mod.rs @@ -56,7 +56,7 @@ mod tests; /// }; /// console.log(bob.printFriends()); /// ``` -pub fn arrow() -> impl Pass { +pub fn arrow() -> impl Pass + Clone + Copy { Arrow } diff --git a/ecmascript/transforms/src/compat/es2015/block_scoped_fn.rs b/ecmascript/transforms/src/compat/es2015/block_scoped_fn.rs index 46ecf1590b7..754beaf345e 100644 --- a/ecmascript/transforms/src/compat/es2015/block_scoped_fn.rs +++ b/ecmascript/transforms/src/compat/es2015/block_scoped_fn.rs @@ -1,4 +1,3 @@ -use crate::pass::Pass; use ast::*; use swc_common::{Fold, FoldWith, DUMMY_SP}; diff --git a/ecmascript/transforms/src/compat/es2015/classes/mod.rs b/ecmascript/transforms/src/compat/es2015/classes/mod.rs index 27b6afc49e0..66ee2c30783 100644 --- a/ecmascript/transforms/src/compat/es2015/classes/mod.rs +++ b/ecmascript/transforms/src/compat/es2015/classes/mod.rs @@ -1,4 +1,4 @@ -use crate::{helpers::Helpers, pass::Pass, util::ExprFactory}; +use crate::{helpers::Helpers, util::ExprFactory}; use ast::*; use std::{ iter, diff --git a/ecmascript/transforms/src/compat/es2015/computed_props/mod.rs b/ecmascript/transforms/src/compat/es2015/computed_props/mod.rs index 56bc43248c0..abfbb0286fe 100644 --- a/ecmascript/transforms/src/compat/es2015/computed_props/mod.rs +++ b/ecmascript/transforms/src/compat/es2015/computed_props/mod.rs @@ -41,7 +41,7 @@ mod tests; /// /// TODO(kdy1): cache reference like (_f = f, mutatorMap[_f].get = function(){}) /// instead of (mutatorMap[f].get = function(){} -pub fn computed_properties(helpers: Arc) -> impl Pass { +pub fn computed_properties(helpers: Arc) -> impl Pass + Clone { ComputedProps { helpers } } diff --git a/ecmascript/transforms/src/compat/es2015/destructuring/mod.rs b/ecmascript/transforms/src/compat/es2015/destructuring/mod.rs index bfc3a366c57..1b02ef915c5 100644 --- a/ecmascript/transforms/src/compat/es2015/destructuring/mod.rs +++ b/ecmascript/transforms/src/compat/es2015/destructuring/mod.rs @@ -35,7 +35,7 @@ mod tests; /// b = _arr2[1], /// rest = _arr2.slice(2); /// ``` -pub fn destructuring(helpers: Arc) -> impl Pass { +pub fn destructuring(helpers: Arc) -> impl Pass + Clone { Destructuring { helpers } } diff --git a/ecmascript/transforms/src/compat/es2015/duplicate_keys/mod.rs b/ecmascript/transforms/src/compat/es2015/duplicate_keys/mod.rs index f2d83a5918d..8a97a2ffea4 100644 --- a/ecmascript/transforms/src/compat/es2015/duplicate_keys/mod.rs +++ b/ecmascript/transforms/src/compat/es2015/duplicate_keys/mod.rs @@ -7,7 +7,7 @@ use swc_common::{Fold, FoldWith, Spanned}; #[cfg(test)] mod tests; -pub fn duplicate_keys() -> impl Pass { +pub fn duplicate_keys() -> impl Pass + Clone + Copy { DuplicateKeys } diff --git a/ecmascript/transforms/src/compat/es2015/for_of/mod.rs b/ecmascript/transforms/src/compat/es2015/for_of/mod.rs index 2cc31ef4822..cba55573bf4 100644 --- a/ecmascript/transforms/src/compat/es2015/for_of/mod.rs +++ b/ecmascript/transforms/src/compat/es2015/for_of/mod.rs @@ -42,7 +42,7 @@ mod tests; /// } /// } /// ``` -pub fn for_of() -> impl Pass { +pub fn for_of() -> impl Pass + Clone + Copy { ForOf } diff --git a/ecmascript/transforms/src/compat/es2015/function_name/mod.rs b/ecmascript/transforms/src/compat/es2015/function_name/mod.rs index 1649d6d5927..754038ffdef 100644 --- a/ecmascript/transforms/src/compat/es2015/function_name/mod.rs +++ b/ecmascript/transforms/src/compat/es2015/function_name/mod.rs @@ -1,4 +1,3 @@ -use crate::pass::Pass; use ast::*; use swc_common::{Fold, FoldWith}; diff --git a/ecmascript/transforms/src/compat/es2015/mod.rs b/ecmascript/transforms/src/compat/es2015/mod.rs index bab7e6c62d7..557c2f44fd2 100644 --- a/ecmascript/transforms/src/compat/es2015/mod.rs +++ b/ecmascript/transforms/src/compat/es2015/mod.rs @@ -8,7 +8,6 @@ pub use self::{ use crate::{helpers::Helpers, pass::Pass}; use ast::{Expr, Module, Stmt}; use std::sync::Arc; -use swc_common::Fold; mod arrow; mod block_scoped_fn; @@ -28,8 +27,8 @@ mod template_literal; mod typeof_symbol; /// Compiles es2015 to es5. -pub fn es2015(helpers: &Arc) -> impl Pass { - fn exprs(helpers: &Arc) -> impl Pass { +pub fn es2015(helpers: &Arc) -> impl Pass + Clone { + fn exprs(helpers: &Arc) -> impl Pass + Clone { chain_at!( Expr, arrow(), @@ -51,7 +50,7 @@ pub fn es2015(helpers: &Arc) -> impl Pass { ) } - fn stmts(helpers: &Arc) -> impl Pass { + fn stmts(helpers: &Arc) -> impl Pass + Clone { chain_at!( Stmt, exprs(helpers), diff --git a/ecmascript/transforms/src/compat/es2015/parameters/mod.rs b/ecmascript/transforms/src/compat/es2015/parameters/mod.rs index 7e9b3362d6d..1cace77e495 100644 --- a/ecmascript/transforms/src/compat/es2015/parameters/mod.rs +++ b/ecmascript/transforms/src/compat/es2015/parameters/mod.rs @@ -1,4 +1,4 @@ -use crate::{pass::Pass, util::ExprFactory}; +use crate::util::ExprFactory; use ast::*; use swc_common::{Fold, FoldWith, Mark, Spanned, DUMMY_SP}; diff --git a/ecmascript/transforms/src/compat/es2015/template_literal/mod.rs b/ecmascript/transforms/src/compat/es2015/template_literal/mod.rs index 8f8d5cdad02..a62185b455d 100644 --- a/ecmascript/transforms/src/compat/es2015/template_literal/mod.rs +++ b/ecmascript/transforms/src/compat/es2015/template_literal/mod.rs @@ -1,4 +1,4 @@ -use crate::{helpers::Helpers, pass::Pass, util::ExprFactory}; +use crate::{helpers::Helpers, util::ExprFactory}; use ast::*; use std::{ iter, diff --git a/ecmascript/transforms/src/compat/es2016/exponentation.rs b/ecmascript/transforms/src/compat/es2016/exponentation.rs index ee5e25ad4fe..11334e3cb13 100644 --- a/ecmascript/transforms/src/compat/es2016/exponentation.rs +++ b/ecmascript/transforms/src/compat/es2016/exponentation.rs @@ -24,7 +24,7 @@ use swc_common::{Fold, FoldWith, Mark, Span, Spanned, Visit, VisitWith, DUMMY_SP /// /// x = Math.pow(x, 3); /// ``` -pub fn exponentation() -> impl Pass { +pub fn exponentation() -> impl Pass + Clone { Exponentation } #[derive(Clone, Copy)] diff --git a/ecmascript/transforms/src/compat/es2016/mod.rs b/ecmascript/transforms/src/compat/es2016/mod.rs index 3ace800028d..78c5f3f857f 100644 --- a/ecmascript/transforms/src/compat/es2016/mod.rs +++ b/ecmascript/transforms/src/compat/es2016/mod.rs @@ -1,10 +1,8 @@ pub use self::exponentation::exponentation; use crate::pass::Pass; -use ast::Module; -use swc_common::Fold; mod exponentation; -pub fn es2016() -> impl Pass { +pub fn es2016() -> impl Pass + Clone { exponentation() } diff --git a/ecmascript/transforms/src/compat/es2017/async_to_generator/mod.rs b/ecmascript/transforms/src/compat/es2017/async_to_generator/mod.rs index 7facc8a8527..800915247b3 100644 --- a/ecmascript/transforms/src/compat/es2017/async_to_generator/mod.rs +++ b/ecmascript/transforms/src/compat/es2017/async_to_generator/mod.rs @@ -33,7 +33,7 @@ mod tests; /// yield bar(); /// }); /// ``` -pub fn async_to_generator(helpers: Arc) -> impl Pass { +pub fn async_to_generator(helpers: Arc) -> impl Pass + Clone { AsyncToGenerator { helpers } } diff --git a/ecmascript/transforms/src/compat/es2017/mod.rs b/ecmascript/transforms/src/compat/es2017/mod.rs index 70d62b6946d..cc2cd06b8e6 100644 --- a/ecmascript/transforms/src/compat/es2017/mod.rs +++ b/ecmascript/transforms/src/compat/es2017/mod.rs @@ -4,6 +4,6 @@ use std::sync::Arc; mod async_to_generator; -pub fn es2017(helpers: &Arc) -> impl Pass { +pub fn es2017(helpers: &Arc) -> impl Pass + Clone { async_to_generator(helpers.clone()) } diff --git a/ecmascript/transforms/src/compat/es2018/object_rest_spread/mod.rs b/ecmascript/transforms/src/compat/es2018/object_rest_spread/mod.rs index bacca5ba6d5..4d31bf39250 100644 --- a/ecmascript/transforms/src/compat/es2018/object_rest_spread/mod.rs +++ b/ecmascript/transforms/src/compat/es2018/object_rest_spread/mod.rs @@ -1,5 +1,6 @@ use crate::{ helpers::Helpers, + pass::Pass, util::{ExprFactory, StmtLike}, }; use ast::*; @@ -15,7 +16,7 @@ use swc_common::{ mod tests; /// `@babel/plugin-proposal-object-rest-spread` -pub fn object_rest_spread(helpers: Arc) -> impl Fold { +pub fn object_rest_spread(helpers: Arc) -> impl Pass + Clone { chain!( ObjectRest { helpers: helpers.clone(), @@ -24,6 +25,7 @@ pub fn object_rest_spread(helpers: Arc) -> impl Fold { ) } +#[derive(Clone)] struct ObjectRest { helpers: Arc, } @@ -899,6 +901,7 @@ fn simplify_pat(pat: Pat) -> Pat { pat.fold_with(&mut PatSimplifier) } +#[derive(Clone)] struct ObjectSpread { helpers: Arc, } diff --git a/ecmascript/transforms/src/lib.rs b/ecmascript/transforms/src/lib.rs index a96c259994c..c80506e106f 100644 --- a/ecmascript/transforms/src/lib.rs +++ b/ecmascript/transforms/src/lib.rs @@ -31,6 +31,7 @@ extern crate test; #[macro_use] extern crate testing; extern crate either; +extern crate objekt; extern crate serde; pub use self::{ diff --git a/ecmascript/transforms/src/pass.rs b/ecmascript/transforms/src/pass.rs index 23ceee1afeb..23a93f7d94c 100644 --- a/ecmascript/transforms/src/pass.rs +++ b/ecmascript/transforms/src/pass.rs @@ -15,9 +15,9 @@ macro_rules! mk_impl { macro_rules! mk_trait { ($($T:ty,)*) => { /// Crazy trait to make traversal fast again. - pub trait Pass: Clone + $( ::swc_common::Fold<$T> + )* {} + pub trait Pass: objekt::Clone + $( ::swc_common::Fold<$T> + )* {} impl

Pass for P - where P: ?Sized + Clone + $( ::swc_common::Fold<$T> +)*{ + where P: ?Sized + objekt::Clone + $( ::swc_common::Fold<$T> +)*{ }