Skip to content

Commit 7389651

Browse files
committed
fix(parser): report err on missing function body in expression
1 parent 5ab2a5b commit 7389651

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

crates/oxc_parser/src/js/function.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ impl<'a> ParserImpl<'a> {
121121
let type_parameters = self.parse_ts_type_parameters();
122122
let (this_param, params) = self.parse_formal_parameters(func_kind, param_kind);
123123
let return_type = if self.is_ts { self.parse_ts_return_type_annotation() } else { None };
124-
let body = if self.at(Kind::LCurly) { Some(self.parse_function_body()) } else { None };
124+
let body = if self.at(Kind::LCurly) || func_kind == FunctionKind::Expression {
125+
Some(self.parse_function_body())
126+
} else {
127+
None
128+
};
125129
self.ctx =
126130
self.ctx.and_in(ctx.has_in()).and_await(ctx.has_await()).and_yield(ctx.has_yield());
127131
if !self.is_ts && body.is_none() {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const x = function foo();

tasks/coverage/snapshots/parser_misc.snap

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
parser_misc Summary:
22
AST Parsed : 49/49 (100.00%)
33
Positive Passed: 49/49 (100.00%)
4-
Negative Passed: 92/92 (100.00%)
4+
Negative Passed: 93/93 (100.00%)
55

66
× Cannot assign to 'arguments' in strict mode
77
╭─[misc/fail/arguments-eval.ts:1:10]
@@ -2899,6 +2899,13 @@ Negative Passed: 92/92 (100.00%)
28992899
6 │ }
29002900
╰────
29012901
2902+
× Expected `{` but found `;`
2903+
╭─[misc/fail/oxc-14944.ts:1:25]
2904+
1 │ const x = function foo();
2905+
· ┬
2906+
· ╰── `{` expected
2907+
╰────
2908+
29022909
× Unexpected token
29032910
╭─[misc/fail/oxc-169.js:2:1]
29042911
11<(V=82<<t-j0<(V=$<LBI<(V=ut<I<(V=$<LBI<(V=uIV=82<<t-j0<(V=$<LBI<(V=ut<I<(V=$<LBI<(V<II>

0 commit comments

Comments
 (0)