Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fuzz async #257

Merged
merged 2 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions crates/oxc_parser/src/js/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,24 @@ impl<'a> Parser<'a> {
Kind::LParen => match self.nth_kind(offset + 1) {
// '()' is an arrow expression if followed by an '=>', a type annotation or body.
// Otherwise, a parenthesized expression with a missing inner expression
Kind::RParen
if matches!(
self.nth_kind(offset + 2),
Kind::Arrow | Kind::Colon | Kind::LCurly
) =>
{
IsParenthesizedArrowFunction::True
Kind::RParen => {
let kind = self.nth_kind(offset + 2);
if self.ts_enabled() && kind == Kind::Colon {
IsParenthesizedArrowFunction::Maybe
} else if matches!(kind, Kind::Arrow | Kind::LCurly) {
IsParenthesizedArrowFunction::True
} else {
IsParenthesizedArrowFunction::False
}
}
// 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)", "null?async():null", "switch(null){case async():}"];

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
14 changes: 11 additions & 3 deletions tasks/coverage/typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9214,15 +9214,23 @@ Expect to Parse: "salsa/privateIdentifierExpando.ts"
5 │
╰────

× Expected `=>` but found `{`
× Empty parenthesized expression
╭─[parser/ecmascript5/RegressionTests/parser509669.ts:1:1]
1 │ function foo():any {
2 │ return ():void {};
· ┬
· ╰── `=>` expected
· ▲
3 │ }
╰────

× Expected a semicolon or an implicit semicolon after a statement, but found none
╭─[parser/ecmascript5/RegressionTests/parser509669.ts:1:1]
1 │ function foo():any {
2 │ return ():void {};
· ▲
3 │ }
╰────
help: Try insert a semicolon here

× Expected `}` but found `EOF`
╭─[parser/ecmascript5/RegressionTests/parser512084.ts:1:1]
1 │ class foo {
Expand Down