@@ -2,7 +2,7 @@ use anyhow::Result;
2
2
use serde:: { Deserialize , Serialize } ;
3
3
use swc_core:: ecma:: {
4
4
ast:: {
5
- BlockStmt , CallExpr , Expr , Lit , MemberExpr , ModuleDecl , ModuleItem , Pass , Pat , Prop ,
5
+ BlockStmt , CallExpr , Expr , Lit , MemberExpr , ModuleDecl , ModuleItem , Pat , Program , Prop ,
6
6
SimpleAssignTarget , Stmt , Str , SwitchCase ,
7
7
} ,
8
8
visit:: AstParentKind ,
@@ -38,7 +38,6 @@ use crate::references::{
38
38
#[ derive( Default ) ]
39
39
pub struct CodeGeneration {
40
40
/// ast nodes matching the span will be visitor by the visitor
41
- pub root_visitors : Vec < Box < dyn PassFactory > > ,
42
41
pub visitors : Vec < ( Vec < AstParentKind > , Box < dyn AstModifier > ) > ,
43
42
pub hoisted_stmts : Vec < CodeGenerationHoistedStmt > ,
44
43
pub early_hoisted_stmts : Vec < CodeGenerationHoistedStmt > ,
@@ -52,34 +51,18 @@ impl CodeGeneration {
52
51
}
53
52
54
53
pub fn new (
55
- root_visitors : Vec < Box < dyn PassFactory > > ,
56
54
visitors : Vec < ( Vec < AstParentKind > , Box < dyn AstModifier > ) > ,
57
55
hoisted_stmts : Vec < CodeGenerationHoistedStmt > ,
58
56
early_hoisted_stmts : Vec < CodeGenerationHoistedStmt > ,
59
57
) -> Self {
60
58
CodeGeneration {
61
- root_visitors,
62
59
visitors,
63
60
hoisted_stmts,
64
61
early_hoisted_stmts,
65
62
}
66
63
}
67
64
68
- pub fn root_visitors ( root_visitors : Vec < Box < dyn PassFactory > > ) -> Self {
69
- CodeGeneration {
70
- root_visitors,
71
- ..Default :: default ( )
72
- }
73
- }
74
-
75
65
pub fn visitors ( visitors : Vec < ( Vec < AstParentKind > , Box < dyn AstModifier > ) > ) -> Self {
76
- #[ cfg( debug_assertions) ]
77
- for ( path, _) in visitors. iter ( ) {
78
- if path. is_empty ( ) {
79
- unreachable ! ( "if the path is empty, the visitor should be a root visitor" ) ;
80
- }
81
- }
82
-
83
66
CodeGeneration {
84
67
visitors,
85
68
..Default :: default ( )
@@ -113,10 +96,6 @@ impl CodeGenerationHoistedStmt {
113
96
}
114
97
}
115
98
116
- pub trait PassFactory : Send + Sync {
117
- fn create < ' a > ( & ' a self ) -> Box < dyn Pass + Send + Sync + ' a > ;
118
- }
119
-
120
99
macro_rules! method {
121
100
( $name: ident, $T: ty) => {
122
101
fn $name( & self , _node: & mut $T) { }
@@ -137,6 +116,7 @@ pub trait AstModifier: Send + Sync {
137
116
method ! ( visit_mut_str, Str ) ;
138
117
method ! ( visit_mut_block_stmt, BlockStmt ) ;
139
118
method ! ( visit_mut_switch_case, SwitchCase ) ;
119
+ method ! ( visit_mut_program, Program ) ;
140
120
}
141
121
142
122
pub trait ModifiableAst {
@@ -166,6 +146,7 @@ impl_modify!(visit_mut_lit, Lit);
166
146
impl_modify ! ( visit_mut_str, Str ) ;
167
147
impl_modify ! ( visit_mut_block_stmt, BlockStmt ) ;
168
148
impl_modify ! ( visit_mut_switch_case, SwitchCase ) ;
149
+ impl_modify ! ( visit_mut_program, Program ) ;
169
150
170
151
#[ derive( PartialEq , Eq , Serialize , Deserialize , TraceRawVcs , ValueDebugFormat , NonLocalValue ) ]
171
152
pub enum CodeGen {
0 commit comments