Skip to content

Commit

Permalink
fix(parser): parse async(...null) as call expression
Browse files Browse the repository at this point in the history
relates #255
  • Loading branch information
Boshen committed Apr 5, 2023
1 parent 6e35678 commit e30b992
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
10 changes: 8 additions & 2 deletions crates/oxc_parser/src/js/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,14 @@ impl<'a> Parser<'a> {
{
IsParenthesizedArrowFunction::True
}
// Rest parameter '(...a' is certainly not a parenthesized expression
Kind::Dot3 => IsParenthesizedArrowFunction::True,
// Rest parameter
// '(...ident' is not a parenthesized expression
// '(...null' is a parenthesized expression
Kind::Dot3 => match self.nth_kind(offset + 1) {
Kind::Ident => IsParenthesizedArrowFunction::True,
kind if kind.is_literal() => IsParenthesizedArrowFunction::False,
_ => IsParenthesizedArrowFunction::Maybe,
},
// '([ ...', '({ ... } can either be a parenthesized object or array expression or a destructing parameter
Kind::LBrack | Kind::LCurly => IsParenthesizedArrowFunction::Maybe,
_ if self.nth_kind(offset + 1).is_binding_identifier()
Expand Down
11 changes: 9 additions & 2 deletions crates/oxc_parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,20 @@ mod test {
let allocator = Allocator::default();
let source_type = SourceType::default();

let tests = [
let fail = [
"1<(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>",
];

for source in tests {
for source in fail {
let ret = Parser::new(&allocator, source, source_type).parse();
assert!(!ret.errors.is_empty());
}

let pass = ["async(...null)"];

for source in pass {
let ret = Parser::new(&allocator, source, source_type).parse();
assert!(ret.errors.is_empty());
}
}
}
7 changes: 3 additions & 4 deletions tasks/coverage/babel.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3925,7 +3925,7 @@ Expect to Parse: "typescript/types/const-type-parameters/input.ts"
× Unexpected token
╭─[es2015/uncategorised/286/input.js:1:1]
1 │ (...[ 5 ]) => {}
·
· ──
╰────
× Cannot assign to 'eval' in strict mode
Expand Down Expand Up @@ -6920,11 +6920,10 @@ Expect to Parse: "typescript/types/const-type-parameters/input.ts"
· ───
╰────
× Expected `=>` but found `+`
× Unexpected token
╭─[esprima/es2015-arrow-function/rest-without-arrow/input.js:1:1]
1 │ (...a) + 1
· ┬
· ╰── `=>` expected
· ───
╰────
× Cannot assign to 'eval' in strict mode
Expand Down

0 comments on commit e30b992

Please sign in to comment.