File tree 9 files changed +18
-20
lines changed
9 files changed +18
-20
lines changed Original file line number Diff line number Diff line change @@ -101,11 +101,7 @@ pub trait CompilerInterface {
101
101
ControlFlow :: Continue ( ( ) )
102
102
}
103
103
104
- fn after_semantic (
105
- & mut self ,
106
- _program : & mut Program < ' _ > ,
107
- _semantic_return : & mut SemanticBuilderReturn ,
108
- ) -> ControlFlow < ( ) > {
104
+ fn after_semantic ( & mut self , _semantic_return : & mut SemanticBuilderReturn ) -> ControlFlow < ( ) > {
109
105
ControlFlow :: Continue ( ( ) )
110
106
}
111
107
@@ -148,7 +144,7 @@ pub trait CompilerInterface {
148
144
self . handle_errors ( semantic_return. errors ) ;
149
145
return ;
150
146
}
151
- if self . after_semantic ( & mut program , & mut semantic_return) . is_break ( ) {
147
+ if self . after_semantic ( & mut semantic_return) . is_break ( ) {
152
148
return ;
153
149
}
154
150
@@ -235,7 +231,7 @@ pub trait CompilerInterface {
235
231
Parser :: new ( allocator, source_text, source_type) . with_options ( self . parse_options ( ) ) . parse ( )
236
232
}
237
233
238
- fn semantic < ' a > ( & self , program : & Program < ' a > ) -> SemanticBuilderReturn < ' a > {
234
+ fn semantic < ' a > ( & self , program : & ' a Program < ' a > ) -> SemanticBuilderReturn < ' a > {
239
235
let mut builder = SemanticBuilder :: new ( ) ;
240
236
241
237
if self . transform_options ( ) . is_some ( ) {
Original file line number Diff line number Diff line change @@ -223,7 +223,7 @@ impl Runtime {
223
223
. with_scope_tree_child_ids ( true )
224
224
. with_build_jsdoc ( true )
225
225
. with_check_syntax_error ( check_syntax_errors)
226
- . build ( & ret. program ) ;
226
+ . build ( allocator . alloc ( ret. program ) ) ;
227
227
228
228
if !semantic_ret. errors . is_empty ( ) {
229
229
return semantic_ret. errors . into_iter ( ) . map ( |err| Message :: new ( err, None ) ) . collect ( ) ;
Original file line number Diff line number Diff line change @@ -223,7 +223,7 @@ impl<'a> SemanticBuilder<'a> {
223
223
/// Finalize the builder.
224
224
///
225
225
/// # Panics
226
- pub fn build ( mut self , program : & Program < ' a > ) -> SemanticBuilderReturn < ' a > {
226
+ pub fn build ( mut self , program : & ' a Program < ' a > ) -> SemanticBuilderReturn < ' a > {
227
227
self . source_text = program. source_text ;
228
228
self . source_type = program. source_type ;
229
229
if self . build_jsdoc {
Original file line number Diff line number Diff line change @@ -207,7 +207,7 @@ mod test {
207
207
) -> Semantic < ' a > {
208
208
let source_type = source_type. unwrap_or_default ( ) ;
209
209
let ret = Parser :: new ( allocator, source_text, source_type) . parse ( ) ;
210
- SemanticBuilder :: new ( ) . with_build_jsdoc ( true ) . build ( & ret. program ) . semantic
210
+ SemanticBuilder :: new ( ) . with_build_jsdoc ( true ) . build ( allocator . alloc ( ret. program ) ) . semantic
211
211
}
212
212
213
213
fn get_jsdocs < ' a > (
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ mod test {
45
45
fn build_semantic < ' a > ( allocator : & ' a Allocator , source_text : & ' a str ) -> Semantic < ' a > {
46
46
let source_type = SourceType :: default ( ) ;
47
47
let ret = Parser :: new ( allocator, source_text, source_type) . parse ( ) ;
48
- SemanticBuilder :: new ( ) . with_build_jsdoc ( true ) . build ( & ret. program ) . semantic
48
+ SemanticBuilder :: new ( ) . with_build_jsdoc ( true ) . build ( allocator . alloc ( ret. program ) ) . semantic
49
49
}
50
50
51
51
#[ test]
Original file line number Diff line number Diff line change @@ -194,7 +194,7 @@ mod test {
194
194
fn build_semantic < ' a > ( allocator : & ' a Allocator , source_text : & ' a str ) -> Semantic < ' a > {
195
195
let source_type = SourceType :: default ( ) ;
196
196
let ret = Parser :: new ( allocator, source_text, source_type) . parse ( ) ;
197
- SemanticBuilder :: new ( ) . with_build_jsdoc ( true ) . build ( & ret. program ) . semantic
197
+ SemanticBuilder :: new ( ) . with_build_jsdoc ( true ) . build ( allocator . alloc ( ret. program ) ) . semantic
198
198
}
199
199
200
200
#[ test]
Original file line number Diff line number Diff line change @@ -247,7 +247,7 @@ mod tests {
247
247
) -> Semantic < ' s > {
248
248
let parse = oxc_parser:: Parser :: new ( allocator, source, source_type) . parse ( ) ;
249
249
assert ! ( parse. errors. is_empty( ) ) ;
250
- let semantic = SemanticBuilder :: new ( ) . build ( & parse. program ) ;
250
+ let semantic = SemanticBuilder :: new ( ) . build ( allocator . alloc ( parse. program ) ) ;
251
251
assert ! ( semantic. errors. is_empty( ) , "Parse error: {}" , semantic. errors[ 0 ] ) ;
252
252
semantic. semantic
253
253
}
Original file line number Diff line number Diff line change @@ -171,7 +171,7 @@ impl<'a> SemanticTester<'a> {
171
171
. with_check_syntax_error ( true )
172
172
. with_cfg ( self . cfg )
173
173
. with_scope_tree_child_ids ( self . scope_tree_child_ids )
174
- . build ( & parse. program )
174
+ . build ( self . allocator . alloc ( parse. program ) )
175
175
}
176
176
177
177
pub fn basic_blocks_count ( & self ) -> usize {
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ use rustc_hash::FxHashSet;
4
4
5
5
use oxc:: {
6
6
allocator:: Allocator ,
7
- ast:: { ast:: Program , Comment } ,
7
+ ast:: { ast:: Program , AstKind , Comment } ,
8
8
codegen:: { CodegenOptions , CodegenReturn } ,
9
9
diagnostics:: OxcDiagnostic ,
10
10
minifier:: CompressOptions ,
@@ -80,12 +80,14 @@ impl CompilerInterface for Driver {
80
80
ControlFlow :: Continue ( ( ) )
81
81
}
82
82
83
- fn after_semantic (
84
- & mut self ,
85
- program : & mut Program < ' _ > ,
86
- ret : & mut SemanticBuilderReturn ,
87
- ) -> ControlFlow < ( ) > {
83
+ fn after_semantic ( & mut self , ret : & mut SemanticBuilderReturn ) -> ControlFlow < ( ) > {
88
84
if self . check_semantic {
85
+ let Some ( root_node) = ret. semantic . nodes ( ) . root_node ( ) else {
86
+ return ControlFlow :: Break ( ( ) ) ;
87
+ } ;
88
+ let AstKind :: Program ( program) = root_node. kind ( ) else {
89
+ return ControlFlow :: Break ( ( ) ) ;
90
+ } ;
89
91
if let Some ( errors) = check_semantic_ids ( program) {
90
92
self . errors . extend ( errors) ;
91
93
return ControlFlow :: Break ( ( ) ) ;
You can’t perform that action at this time.
0 commit comments