mirror of
https://github.com/swc-project/swc.git
synced 2024-11-23 17:54:15 +03:00
Allow using Pass
as a trait object
This commit is contained in:
parent
2a49e1e896
commit
1710bb6e8a
@ -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" }
|
||||
|
@ -56,7 +56,7 @@ mod tests;
|
||||
/// };
|
||||
/// console.log(bob.printFriends());
|
||||
/// ```
|
||||
pub fn arrow() -> impl Pass {
|
||||
pub fn arrow() -> impl Pass + Clone + Copy {
|
||||
Arrow
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
use crate::pass::Pass;
|
||||
use ast::*;
|
||||
use swc_common::{Fold, FoldWith, DUMMY_SP};
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{helpers::Helpers, pass::Pass, util::ExprFactory};
|
||||
use crate::{helpers::Helpers, util::ExprFactory};
|
||||
use ast::*;
|
||||
use std::{
|
||||
iter,
|
||||
|
@ -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 }
|
||||
}
|
||||
|
||||
|
@ -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 }
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ mod tests;
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
pub fn for_of() -> impl Pass {
|
||||
pub fn for_of() -> impl Pass + Clone + Copy {
|
||||
ForOf
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
use crate::pass::Pass;
|
||||
use ast::*;
|
||||
use swc_common::{Fold, FoldWith};
|
||||
|
||||
|
@ -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),
|
||||
|
@ -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};
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{helpers::Helpers, pass::Pass, util::ExprFactory};
|
||||
use crate::{helpers::Helpers, util::ExprFactory};
|
||||
use ast::*;
|
||||
use std::{
|
||||
iter,
|
||||
|
@ -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)]
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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 }
|
||||
}
|
||||
|
||||
|
@ -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())
|
||||
}
|
||||
|
@ -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>,
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ extern crate test;
|
||||
#[macro_use]
|
||||
extern crate testing;
|
||||
extern crate either;
|
||||
extern crate objekt;
|
||||
extern crate serde;
|
||||
|
||||
pub use self::{
|
||||
|
@ -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> +)*{
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user