Allow using Pass as a trait object

This commit is contained in:
강동윤 2019-01-14 17:54:42 +09:00
parent 2a49e1e896
commit 1710bb6e8a
19 changed files with 23 additions and 23 deletions

View File

@ -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" }

View File

@ -56,7 +56,7 @@ mod tests;
/// };
/// console.log(bob.printFriends());
/// ```
pub fn arrow() -> impl Pass {
pub fn arrow() -> impl Pass + Clone + Copy {
Arrow
}

View File

@ -1,4 +1,3 @@
use crate::pass::Pass;
use ast::*;
use swc_common::{Fold, FoldWith, DUMMY_SP};

View File

@ -1,4 +1,4 @@
use crate::{helpers::Helpers, pass::Pass, util::ExprFactory};
use crate::{helpers::Helpers, util::ExprFactory};
use ast::*;
use std::{
iter,

View File

@ -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<Helpers>) -> impl Pass {
pub fn computed_properties(helpers: Arc<Helpers>) -> impl Pass + Clone {
ComputedProps { helpers }
}

View File

@ -35,7 +35,7 @@ mod tests;
/// b = _arr2[1],
/// rest = _arr2.slice(2);
/// ```
pub fn destructuring(helpers: Arc<Helpers>) -> impl Pass {
pub fn destructuring(helpers: Arc<Helpers>) -> impl Pass + Clone {
Destructuring { helpers }
}

View File

@ -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
}

View File

@ -42,7 +42,7 @@ mod tests;
/// }
/// }
/// ```
pub fn for_of() -> impl Pass {
pub fn for_of() -> impl Pass + Clone + Copy {
ForOf
}

View File

@ -1,4 +1,3 @@
use crate::pass::Pass;
use ast::*;
use swc_common::{Fold, FoldWith};

View File

@ -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<Helpers>) -> impl Pass {
fn exprs(helpers: &Arc<Helpers>) -> impl Pass {
pub fn es2015(helpers: &Arc<Helpers>) -> impl Pass + Clone {
fn exprs(helpers: &Arc<Helpers>) -> impl Pass + Clone {
chain_at!(
Expr,
arrow(),
@ -51,7 +50,7 @@ pub fn es2015(helpers: &Arc<Helpers>) -> impl Pass {
)
}
fn stmts(helpers: &Arc<Helpers>) -> impl Pass {
fn stmts(helpers: &Arc<Helpers>) -> impl Pass + Clone {
chain_at!(
Stmt,
exprs(helpers),

View File

@ -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};

View File

@ -1,4 +1,4 @@
use crate::{helpers::Helpers, pass::Pass, util::ExprFactory};
use crate::{helpers::Helpers, util::ExprFactory};
use ast::*;
use std::{
iter,

View File

@ -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)]

View File

@ -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()
}

View File

@ -33,7 +33,7 @@ mod tests;
/// yield bar();
/// });
/// ```
pub fn async_to_generator(helpers: Arc<Helpers>) -> impl Pass {
pub fn async_to_generator(helpers: Arc<Helpers>) -> impl Pass + Clone {
AsyncToGenerator { helpers }
}

View File

@ -4,6 +4,6 @@ use std::sync::Arc;
mod async_to_generator;
pub fn es2017(helpers: &Arc<Helpers>) -> impl Pass {
pub fn es2017(helpers: &Arc<Helpers>) -> impl Pass + Clone {
async_to_generator(helpers.clone())
}

View File

@ -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<Helpers>) -> impl Fold<Module> {
pub fn object_rest_spread(helpers: Arc<Helpers>) -> impl Pass + Clone {
chain!(
ObjectRest {
helpers: helpers.clone(),
@ -24,6 +25,7 @@ pub fn object_rest_spread(helpers: Arc<Helpers>) -> impl Fold<Module> {
)
}
#[derive(Clone)]
struct ObjectRest {
helpers: Arc<Helpers>,
}
@ -899,6 +901,7 @@ fn simplify_pat(pat: Pat) -> Pat {
pat.fold_with(&mut PatSimplifier)
}
#[derive(Clone)]
struct ObjectSpread {
helpers: Arc<Helpers>,
}

View File

@ -31,6 +31,7 @@ extern crate test;
#[macro_use]
extern crate testing;
extern crate either;
extern crate objekt;
extern crate serde;
pub use self::{

View File

@ -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<P> Pass for P
where P: ?Sized + Clone + $( ::swc_common::Fold<$T> +)*{
where P: ?Sized + objekt::Clone + $( ::swc_common::Fold<$T> +)*{
}