@@ -11,7 +11,7 @@ use super::{list::FormalParameterList, FunctionKind};
1111
1212impl FunctionKind {
1313 pub ( crate ) fn is_id_required ( self ) -> bool {
14- matches ! ( self , Self :: Declaration { single_statement : true } )
14+ matches ! ( self , Self :: Declaration )
1515 }
1616
1717 pub ( crate ) fn is_expression ( self ) -> bool {
@@ -80,7 +80,7 @@ impl<'a> ParserImpl<'a> {
8080 }
8181
8282 let function_type = match func_kind {
83- FunctionKind :: Declaration { .. } | FunctionKind :: DefaultExport => {
83+ FunctionKind :: Declaration | FunctionKind :: DefaultExport => {
8484 if body. is_none ( ) {
8585 FunctionType :: TSDeclareFunction
8686 } else {
@@ -123,8 +123,7 @@ impl<'a> ParserImpl<'a> {
123123 & mut self ,
124124 stmt_ctx : StatementContext ,
125125 ) -> Result < Statement < ' a > > {
126- let func_kind =
127- FunctionKind :: Declaration { single_statement : stmt_ctx. is_single_statement ( ) } ;
126+ let func_kind = FunctionKind :: Declaration ;
128127 let decl = self . parse_function_impl ( func_kind) ?;
129128 if stmt_ctx. is_single_statement ( ) {
130129 if decl. r#async {
@@ -153,7 +152,7 @@ impl<'a> ParserImpl<'a> {
153152 let r#async = self . eat ( Kind :: Async ) ;
154153 self . expect ( Kind :: Function ) ?;
155154 let generator = self . eat ( Kind :: Star ) ;
156- let id = self . parse_function_id ( func_kind, r#async, generator) ;
155+ let id = self . parse_function_id ( func_kind, r#async, generator) ? ;
157156 self . parse_function ( span, id, r#async, generator, func_kind, Modifiers :: empty ( ) )
158157 }
159158
@@ -168,7 +167,7 @@ impl<'a> ParserImpl<'a> {
168167 let r#async = modifiers. contains ( ModifierKind :: Async ) ;
169168 self . expect ( Kind :: Function ) ?;
170169 let generator = self . eat ( Kind :: Star ) ;
171- let id = self . parse_function_id ( func_kind, r#async, generator) ;
170+ let id = self . parse_function_id ( func_kind, r#async, generator) ? ;
172171 self . parse_function ( start_span, id, r#async, generator, func_kind, modifiers)
173172 }
174173
@@ -182,7 +181,7 @@ impl<'a> ParserImpl<'a> {
182181 self . expect ( Kind :: Function ) ?;
183182
184183 let generator = self . eat ( Kind :: Star ) ;
185- let id = self . parse_function_id ( func_kind, r#async, generator) ;
184+ let id = self . parse_function_id ( func_kind, r#async, generator) ? ;
186185 let function =
187186 self . parse_function ( span, id, r#async, generator, func_kind, Modifiers :: empty ( ) ) ?;
188187
@@ -257,7 +256,7 @@ impl<'a> ParserImpl<'a> {
257256 kind : FunctionKind ,
258257 r#async : bool ,
259258 generator : bool ,
260- ) -> Option < BindingIdentifier < ' a > > {
259+ ) -> Result < Option < BindingIdentifier < ' a > > > {
261260 let ctx = self . ctx ;
262261 if kind. is_expression ( ) {
263262 self . ctx = self . ctx . and_await ( r#async) . and_yield ( generator) ;
@@ -270,9 +269,15 @@ impl<'a> ParserImpl<'a> {
270269 self . ctx = ctx;
271270
272271 if kind. is_id_required ( ) && id. is_none ( ) {
273- self . error ( diagnostics:: expect_function_name ( self . cur_token ( ) . span ( ) ) ) ;
272+ match self . cur_kind ( ) {
273+ Kind :: LParen => {
274+ self . error ( diagnostics:: expect_function_name ( self . cur_token ( ) . span ( ) ) ) ;
275+ }
276+ kind if kind. is_reserved_keyword ( ) => self . expect_without_advance ( Kind :: Ident ) ?,
277+ _ => { }
278+ }
274279 }
275280
276- id
281+ Ok ( id )
277282 }
278283}
0 commit comments