@@ -7,15 +7,17 @@ use oxc_span::{GetSpan, Span};
77
88use crate :: {
99 Context , ParserImpl , diagnostics,
10+ error_handler:: FatalError ,
1011 lexer:: { Kind , LexerCheckpoint , LexerContext , Token } ,
1112} ;
1213
13- #[ derive( Clone , Copy ) ]
14+ #[ derive( Clone ) ]
1415pub struct ParserCheckpoint < ' a > {
1516 lexer : LexerCheckpoint < ' a > ,
1617 cur_token : Token ,
1718 prev_span_end : u32 ,
1819 errors_pos : usize ,
20+ fatal_error : Option < FatalError > ,
1921}
2022
2123impl < ' a > ParserImpl < ' a > {
@@ -169,7 +171,8 @@ impl<'a> ParserImpl<'a> {
169171 pub ( crate ) fn asi ( & mut self ) -> Result < ( ) > {
170172 if !self . can_insert_semicolon ( ) {
171173 let span = Span :: new ( self . prev_token_end , self . prev_token_end ) ;
172- return Err ( diagnostics:: auto_semicolon_insertion ( span) ) ;
174+ let error = diagnostics:: auto_semicolon_insertion ( span) ;
175+ return Err ( self . set_fatal_error ( error) ) ;
173176 }
174177 if self . at ( Kind :: Semicolon ) {
175178 self . advance ( Kind :: Semicolon ) ;
@@ -186,10 +189,11 @@ impl<'a> ParserImpl<'a> {
186189 }
187190
188191 /// # Errors
189- pub ( crate ) fn expect_without_advance ( & self , kind : Kind ) -> Result < ( ) > {
192+ pub ( crate ) fn expect_without_advance ( & mut self , kind : Kind ) -> Result < ( ) > {
190193 if !self . at ( kind) {
191194 let range = self . cur_token ( ) . span ( ) ;
192- return Err ( diagnostics:: expect_token ( kind. to_str ( ) , self . cur_kind ( ) . to_str ( ) , range) ) ;
195+ let error = diagnostics:: expect_token ( kind. to_str ( ) , self . cur_kind ( ) . to_str ( ) , range) ;
196+ return Err ( self . set_fatal_error ( error) ) ;
193197 }
194198 Ok ( ( ) )
195199 }
@@ -271,22 +275,25 @@ impl<'a> ParserImpl<'a> {
271275 }
272276 }
273277
274- pub ( crate ) fn checkpoint ( & self ) -> ParserCheckpoint < ' a > {
278+ pub ( crate ) fn checkpoint ( & mut self ) -> ParserCheckpoint < ' a > {
275279 ParserCheckpoint {
276280 lexer : self . lexer . checkpoint ( ) ,
277281 cur_token : self . token ,
278282 prev_span_end : self . prev_token_end ,
279283 errors_pos : self . errors . len ( ) ,
284+ fatal_error : self . fatal_error . take ( ) ,
280285 }
281286 }
282287
283288 pub ( crate ) fn rewind ( & mut self , checkpoint : ParserCheckpoint < ' a > ) {
284- let ParserCheckpoint { lexer, cur_token, prev_span_end, errors_pos } = checkpoint;
289+ let ParserCheckpoint { lexer, cur_token, prev_span_end, errors_pos, fatal_error } =
290+ checkpoint;
285291
286292 self . lexer . rewind ( lexer) ;
287293 self . token = cur_token;
288294 self . prev_token_end = prev_span_end;
289295 self . errors . truncate ( errors_pos) ;
296+ self . fatal_error = fatal_error;
290297 }
291298
292299 /// # Errors
@@ -343,7 +350,7 @@ impl<'a> ParserImpl<'a> {
343350 let mut list = self . ast . vec ( ) ;
344351 loop {
345352 let kind = self . cur_kind ( ) ;
346- if kind == close || kind == Kind :: Eof {
353+ if kind == close || self . has_fatal_error ( ) {
347354 break ;
348355 }
349356 match f ( self ) ? {
@@ -373,7 +380,7 @@ impl<'a> ParserImpl<'a> {
373380 let mut first = true ;
374381 loop {
375382 let kind = self . cur_kind ( ) ;
376- if kind == close || kind == Kind :: Eof {
383+ if kind == close || self . has_fatal_error ( ) {
377384 break ;
378385 }
379386 if first {
@@ -408,7 +415,7 @@ impl<'a> ParserImpl<'a> {
408415 let mut first = true ;
409416 loop {
410417 let kind = self . cur_kind ( ) ;
411- if kind == close || kind == Kind :: Eof {
418+ if kind == close || self . has_fatal_error ( ) {
412419 break ;
413420 }
414421 if first {
0 commit comments