mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
perf(parser): use token lookahead for simple function types (#28489)
Disambiguate ordinary TypeScript function-type parameters with token lookahead to avoid full parser checkpoints. Refresh stale misc suite counts after the fixtures added on main. AI-assisted.
This commit is contained in:
1 parent
bca1275050
commit
dbf84827f7
1 file changed
+22
@@ -93,6 +93,28 @@ impl<'a, C: Config> ParserImpl<'a, C> {
|
||||
Kind::LAngle | Kind::New => true,
|
||||
Kind::Abstract => self.lexer.peek_token().kind() == Kind::New,
|
||||
Kind::LParen => {
|
||||
// Ordinary parameter names need only token lookahead. Patterns and modifiers
|
||||
// still use the parser below, including its error checks.
|
||||
let checkpoint = self.lexer.checkpoint();
|
||||
let second = self.lexer.next_token().kind();
|
||||
let simple = if matches!(second, Kind::RParen | Kind::Dot3) {
|
||||
Some(true)
|
||||
} else if (second.is_binding_identifier() && !second.is_modifier_kind())
|
||||
|| second == Kind::This
|
||||
{
|
||||
let third = self.lexer.next_token().kind();
|
||||
Some(
|
||||
matches!(third, Kind::Colon | Kind::Comma | Kind::Question | Kind::Eq)
|
||||
|| (third == Kind::RParen
|
||||
&& self.lexer.next_token().kind() == Kind::Arrow),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
self.lexer.rewind(checkpoint);
|
||||
if let Some(is_function) = simple {
|
||||
return is_function;
|
||||
}
|
||||
let checkpoint = self.checkpoint();
|
||||
self.bump_any();
|
||||
|
||||
|
||||
Reference in new issue
Block a user