diff --git a/crates/oxc_parser/src/js/function.rs b/crates/oxc_parser/src/js/function.rs index cc5f791ed1d05..7e4bf22e25cb4 100644 --- a/crates/oxc_parser/src/js/function.rs +++ b/crates/oxc_parser/src/js/function.rs @@ -121,7 +121,11 @@ impl<'a> ParserImpl<'a> { let type_parameters = self.parse_ts_type_parameters(); let (this_param, params) = self.parse_formal_parameters(func_kind, param_kind); let return_type = if self.is_ts { self.parse_ts_return_type_annotation() } else { None }; - let body = if self.at(Kind::LCurly) { Some(self.parse_function_body()) } else { None }; + let body = if self.at(Kind::LCurly) || func_kind == FunctionKind::Expression { + Some(self.parse_function_body()) + } else { + None + }; self.ctx = self.ctx.and_in(ctx.has_in()).and_await(ctx.has_await()).and_yield(ctx.has_yield()); if !self.is_ts && body.is_none() { diff --git a/tasks/coverage/misc/fail/oxc-14944.ts b/tasks/coverage/misc/fail/oxc-14944.ts new file mode 100644 index 0000000000000..58f0521d1dc7a --- /dev/null +++ b/tasks/coverage/misc/fail/oxc-14944.ts @@ -0,0 +1 @@ +const x = function foo(); diff --git a/tasks/coverage/snapshots/parser_misc.snap b/tasks/coverage/snapshots/parser_misc.snap index ea25b63ef693b..1e2b78234c5c0 100644 --- a/tasks/coverage/snapshots/parser_misc.snap +++ b/tasks/coverage/snapshots/parser_misc.snap @@ -1,7 +1,7 @@ parser_misc Summary: AST Parsed : 49/49 (100.00%) Positive Passed: 49/49 (100.00%) -Negative Passed: 92/92 (100.00%) +Negative Passed: 93/93 (100.00%) × Cannot assign to 'arguments' in strict mode ╭─[misc/fail/arguments-eval.ts:1:10] @@ -2899,6 +2899,13 @@ Negative Passed: 92/92 (100.00%) 6 │ } ╰──── + × Expected `{` but found `;` + ╭─[misc/fail/oxc-14944.ts:1:25] + 1 │ const x = function foo(); + · ┬ + · ╰── `{` expected + ╰──── + × Unexpected token ╭─[misc/fail/oxc-169.js:2:1] 1 │ 1<(V=82<