Skip to content

Commit

Permalink
fix(parser): fix panic on multi-byte char in private identifer
Browse files Browse the repository at this point in the history
relates #232
  • Loading branch information
Boshen committed Apr 1, 2023
1 parent 2d7677d commit 007b773
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 52 deletions.
8 changes: 6 additions & 2 deletions crates/oxc_parser/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,11 +726,15 @@ impl<'a> Lexer<'a> {
self.identifier_unicode_escape_sequence(&mut builder, true);
}
Some(c) => {
self.error(diagnostics::InvalidCharacter(c, Span::new(start, self.offset() - 1)));
#[allow(clippy::cast_possible_truncation)]
self.error(diagnostics::InvalidCharacter(
c,
Span::new(start, start + c.len_utf8() as u32),
));
return Kind::Undetermined;
}
None => {
self.error(diagnostics::UnexpectedEnd(Span::new(start, self.offset() - 1)));
self.error(diagnostics::UnexpectedEnd(Span::new(start, start)));
return Kind::Undetermined;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tasks/coverage/babel.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8245,7 +8245,7 @@ Expect to Parse: "typescript/types/const-type-parameters/input.ts"
× Invalid Character `=`
╭─[esprima/invalid-syntax/migrated_0065/input.js:1:1]
1i #= 42
·
·
╰────
× Expected a semicolon or an implicit semicolon after a statement, but found none
Expand Down
Loading

0 comments on commit 007b773

Please sign in to comment.