Skip to content

Commit

Permalink
fix(parser): check for @flow with recoverable errors as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Aug 28, 2024
1 parent 5e27798 commit e1d8b92
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions crates/oxc_parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,7 @@ impl<'a> ParserImpl<'a> {
let (program, panicked) = match self.parse_program() {
Ok(program) => (program, false),
Err(error) => {
let error =
self.flow_error().unwrap_or_else(|| self.overlong_error().unwrap_or(error));
self.error(error);
self.error(self.overlong_error().unwrap_or(error));
let program = self.ast.program(
Span::default(),
self.source_type,
Expand All @@ -316,7 +314,18 @@ impl<'a> ParserImpl<'a> {
(program, true)
}
};
let errors = self.lexer.errors.into_iter().chain(self.errors).collect();
let mut errors = vec![];
// only check for `@flow` if the file failed to parse.
if !self.lexer.errors.is_empty() || !self.errors.is_empty() {
if let Some(error) = self.flow_error() {
errors.push(error);
}
}
if errors.len() != 1 {
errors.reserve(self.lexer.errors.len() + self.errors.len());
errors.extend(self.lexer.errors);
errors.extend(self.errors);
}
let trivias = self.lexer.trivia_builder.build();
ParserReturn { program, errors, trivias, panicked }
}
Expand Down Expand Up @@ -448,6 +457,7 @@ mod test {
*/
asdf asdf
",
"/* @flow */ let a; let a;",
];
for source in sources {
let ret = Parser::new(&allocator, source, source_type).parse();
Expand Down

0 comments on commit e1d8b92

Please sign in to comment.