@@ -87,6 +87,10 @@ impl<'a> ParserImpl<'a> {
8787 self . eat_decorators ( ) ?;
8888 }
8989
90+ // For performance reasons, match orders are:
91+ // 1. plain if check
92+ // 2. check current token
93+ // 3. peek token
9094 match self . cur_kind ( ) {
9195 Kind :: LCurly => self . parse_block_statement ( ) ,
9296 Kind :: Semicolon => Ok ( self . parse_empty_statement ( ) ) ,
@@ -101,24 +105,28 @@ impl<'a> ParserImpl<'a> {
101105 Kind :: Try => self . parse_try_statement ( ) ,
102106 Kind :: Debugger => self . parse_debugger_statement ( ) ,
103107 Kind :: Class => self . parse_class_statement ( stmt_ctx, start_span) ,
104- Kind :: Import if !matches ! ( self . peek_kind( ) , Kind :: Dot | Kind :: LParen ) => {
105- self . parse_import_declaration ( )
106- }
107108 Kind :: Export => self . parse_export_declaration ( ) ,
108109 // [+Return] ReturnStatement[?Yield, ?Await]
109110 Kind :: Return => self . parse_return_statement ( ) ,
110111 Kind :: Var => self . parse_variable_statement ( stmt_ctx) ,
112+ // Fast path
113+ Kind :: Function => self . parse_function_declaration ( stmt_ctx) ,
114+ Kind :: Let if !self . cur_token ( ) . escaped ( ) => self . parse_let ( stmt_ctx) ,
115+ Kind :: Import if !matches ! ( self . peek_kind( ) , Kind :: Dot | Kind :: LParen ) => {
116+ self . parse_import_declaration ( )
117+ }
111118 Kind :: Const if !( self . is_ts && self . is_at_enum_declaration ( ) ) => {
112119 self . parse_variable_statement ( stmt_ctx)
113120 }
114- Kind :: Let if !self . cur_token ( ) . escaped ( ) => self . parse_let ( stmt_ctx) ,
115121 Kind :: Await
116122 if self . peek_kind ( ) == Kind :: Using && self . nth_kind ( 2 ) . is_binding_identifier ( ) =>
117123 {
118124 self . parse_using ( )
119125 }
120126 Kind :: Using if self . peek_kind ( ) . is_binding_identifier ( ) => self . parse_using ( ) ,
121- _ if self . at_function_with_async ( ) => self . parse_function_declaration ( stmt_ctx) ,
127+ Kind :: Async if self . peek_at ( Kind :: Function ) && !self . peek_token ( ) . is_on_new_line => {
128+ self . parse_function_declaration ( stmt_ctx)
129+ }
122130 _ if self . is_ts && self . at_start_of_ts_declaration ( ) => {
123131 self . parse_ts_declaration_statement ( start_span)
124132 }
0 commit comments