@@ -11,7 +11,7 @@ use super::{list::FormalParameterList, FunctionKind};
11
11
12
12
impl FunctionKind {
13
13
pub ( crate ) fn is_id_required ( self ) -> bool {
14
- matches ! ( self , Self :: Declaration { single_statement : true } )
14
+ matches ! ( self , Self :: Declaration )
15
15
}
16
16
17
17
pub ( crate ) fn is_expression ( self ) -> bool {
@@ -80,7 +80,7 @@ impl<'a> ParserImpl<'a> {
80
80
}
81
81
82
82
let function_type = match func_kind {
83
- FunctionKind :: Declaration { .. } | FunctionKind :: DefaultExport => {
83
+ FunctionKind :: Declaration | FunctionKind :: DefaultExport => {
84
84
if body. is_none ( ) {
85
85
FunctionType :: TSDeclareFunction
86
86
} else {
@@ -123,8 +123,7 @@ impl<'a> ParserImpl<'a> {
123
123
& mut self ,
124
124
stmt_ctx : StatementContext ,
125
125
) -> Result < Statement < ' a > > {
126
- let func_kind =
127
- FunctionKind :: Declaration { single_statement : stmt_ctx. is_single_statement ( ) } ;
126
+ let func_kind = FunctionKind :: Declaration ;
128
127
let decl = self . parse_function_impl ( func_kind) ?;
129
128
if stmt_ctx. is_single_statement ( ) {
130
129
if decl. r#async {
@@ -153,7 +152,7 @@ impl<'a> ParserImpl<'a> {
153
152
let r#async = self . eat ( Kind :: Async ) ;
154
153
self . expect ( Kind :: Function ) ?;
155
154
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) ? ;
157
156
self . parse_function ( span, id, r#async, generator, func_kind, Modifiers :: empty ( ) )
158
157
}
159
158
@@ -168,7 +167,7 @@ impl<'a> ParserImpl<'a> {
168
167
let r#async = modifiers. contains ( ModifierKind :: Async ) ;
169
168
self . expect ( Kind :: Function ) ?;
170
169
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) ? ;
172
171
self . parse_function ( start_span, id, r#async, generator, func_kind, modifiers)
173
172
}
174
173
@@ -182,7 +181,7 @@ impl<'a> ParserImpl<'a> {
182
181
self . expect ( Kind :: Function ) ?;
183
182
184
183
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) ? ;
186
185
let function =
187
186
self . parse_function ( span, id, r#async, generator, func_kind, Modifiers :: empty ( ) ) ?;
188
187
@@ -257,7 +256,7 @@ impl<'a> ParserImpl<'a> {
257
256
kind : FunctionKind ,
258
257
r#async : bool ,
259
258
generator : bool ,
260
- ) -> Option < BindingIdentifier < ' a > > {
259
+ ) -> Result < Option < BindingIdentifier < ' a > > > {
261
260
let ctx = self . ctx ;
262
261
if kind. is_expression ( ) {
263
262
self . ctx = self . ctx . and_await ( r#async) . and_yield ( generator) ;
@@ -270,9 +269,15 @@ impl<'a> ParserImpl<'a> {
270
269
self . ctx = ctx;
271
270
272
271
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
+ }
274
279
}
275
280
276
- id
281
+ Ok ( id )
277
282
}
278
283
}
0 commit comments