@@ -3,7 +3,7 @@ use oxc_allocator::Allocator;
33use oxc_codegen:: CodegenReturn ;
44use oxc_semantic:: SemanticBuilder ;
55use oxc_span:: SourceType ;
6- use oxc_transformer:: Transformer ;
6+ use oxc_transformer:: { ReplaceGlobalDefines , ReplaceGlobalDefinesConfig , Transformer } ;
77
88use crate :: { context:: TransformContext , isolated_declaration, SourceMap , TransformOptions } ;
99
@@ -105,9 +105,13 @@ fn transpile(ctx: &TransformContext<'_>, options: Option<TransformOptions>) -> C
105105 . build ( & ctx. program ( ) ) ;
106106 ctx. add_diagnostics ( semantic_ret. errors ) ;
107107
108+ let mut options = options;
109+ let define = options. as_mut ( ) . and_then ( |options| options. define . take ( ) ) ;
110+
108111 let options = options. map ( oxc_transformer:: TransformOptions :: from) . unwrap_or_default ( ) ;
109112
110- let ( symbols, scopes) = semantic_ret. semantic . into_symbol_table_and_scope_tree ( ) ;
113+ let ( mut symbols, mut scopes) = semantic_ret. semantic . into_symbol_table_and_scope_tree ( ) ;
114+
111115 let ret = Transformer :: new (
112116 ctx. allocator ,
113117 ctx. file_path ( ) ,
@@ -117,8 +121,27 @@ fn transpile(ctx: &TransformContext<'_>, options: Option<TransformOptions>) -> C
117121 options,
118122 )
119123 . build_with_symbols_and_scopes ( symbols, scopes, & mut ctx. program_mut ( ) ) ;
120-
121124 ctx. add_diagnostics ( ret. errors ) ;
125+ symbols = ret. symbols ;
126+ scopes = ret. scopes ;
127+
128+ if let Some ( define) = define {
129+ let define = define. into_iter ( ) . collect :: < Vec < _ > > ( ) ;
130+ match ReplaceGlobalDefinesConfig :: new ( & define) {
131+ Ok ( config) => {
132+ let _ret = ReplaceGlobalDefines :: new ( ctx. allocator , config) . build (
133+ symbols,
134+ scopes,
135+ & mut ctx. program_mut ( ) ,
136+ ) ;
137+ // symbols = ret.symbols;
138+ // scopes = ret.scopes;
139+ }
140+ Err ( errors) => {
141+ ctx. add_diagnostics ( errors) ;
142+ }
143+ }
144+ }
122145
123146 ctx. codegen ( ) . build ( & ctx. program ( ) )
124147}
0 commit comments