Skip to content

Commit c28807b

Browse files
committed
fix(parser): reject async await => {} in scripts (#15222)
`async await => {}` was rejected in modules but should be rejected in scripts as well.
1 parent 837ef21 commit c28807b

File tree

8 files changed

+28
-16
lines changed

8 files changed

+28
-16
lines changed

crates/oxc_parser/src/js/arrow.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ impl<'a> ParserImpl<'a> {
4141
let Expression::Identifier(ident) = &expr else {
4242
return self.unexpected();
4343
};
44+
// It is a Syntax Error if ArrowParameters Contains AwaitExpression is true.
45+
if ident.name == "await" {
46+
self.error(diagnostics::identifier_async("await", ident.span));
47+
}
4448
return Some(self.parse_simple_arrow_function_expression(
4549
span,
4650
ident,
File renamed without changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
codegen_misc Summary:
2-
AST Parsed : 49/49 (100.00%)
3-
Positive Passed: 49/49 (100.00%)
2+
AST Parsed : 48/48 (100.00%)
3+
Positive Passed: 48/48 (100.00%)
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
formatter_misc Summary:
2-
AST Parsed : 49/49 (100.00%)
3-
Positive Passed: 48/49 (97.96%)
4-
Expect to Parse: tasks/coverage/misc/pass/oxc-11487.cjs
5-
Cannot use `await` as an identifier in an async context
2+
AST Parsed : 48/48 (100.00%)
3+
Positive Passed: 48/48 (100.00%)

tasks/coverage/snapshots/parser_babel.snap

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ commit: 4cc3d888
33
parser_babel Summary:
44
AST Parsed : 2422/2440 (99.26%)
55
Positive Passed: 2395/2440 (98.16%)
6-
Negative Passed: 1675/1752 (95.61%)
7-
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2017/async-functions/async-await-as-arrow-binding-identifier/input.js
8-
6+
Negative Passed: 1676/1752 (95.66%)
97
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2018/object-rest-spread/comma-after-rest/input.js
108

119
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2018/object-rest-spread/comma-after-spread-for-in/input.js
@@ -5632,6 +5630,12 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
56325630
╰────
56335631
help: Either remove this `await` or add the `async` keyword to the enclosing function
56345632

5633+
× Cannot use `await` as an identifier in an async context
5634+
╭─[babel/packages/babel-parser/test/fixtures/es2017/async-functions/async-await-as-arrow-binding-identifier/input.js:1:7]
5635+
1 │ async await => {}
5636+
· ─────
5637+
╰────
5638+
56355639
× Expected a semicolon or an implicit semicolon after a statement, but found none
56365640
╭─[babel/packages/babel-parser/test/fixtures/es2017/async-functions/async-function-and-non-bmp-character/input.js:1:6]
56375641
1 │ async function𝐬 f() {}

tasks/coverage/snapshots/parser_misc.snap

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
parser_misc Summary:
2-
AST Parsed : 49/49 (100.00%)
3-
Positive Passed: 49/49 (100.00%)
4-
Negative Passed: 93/93 (100.00%)
2+
AST Parsed : 48/48 (100.00%)
3+
Positive Passed: 48/48 (100.00%)
4+
Negative Passed: 94/94 (100.00%)
55

66
× Cannot assign to 'arguments' in strict mode
77
╭─[misc/fail/arguments-eval.ts:1:10]
@@ -124,6 +124,12 @@ Negative Passed: 93/93 (100.00%)
124124
· ────
125125
╰────
126126

127+
× Cannot use `await` as an identifier in an async context
128+
╭─[misc/fail/oxc-11487.cjs:1:7]
129+
1async await => {}
130+
· ─────
131+
╰────
132+
127133
× Unexpected token
128134
╭─[misc/fail/oxc-11487.mjs:1:13]
129135
1async await => {}

tasks/coverage/snapshots/semantic_misc.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
semantic_misc Summary:
2-
AST Parsed : 49/49 (100.00%)
3-
Positive Passed: 31/49 (63.27%)
2+
AST Parsed : 48/48 (100.00%)
3+
Positive Passed: 30/48 (62.50%)
44
semantic Error: tasks/coverage/misc/pass/oxc-11593.ts
55
Scope children mismatch:
66
after transform: ScopeId(0): [ScopeId(1)]
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
transformer_misc Summary:
2-
AST Parsed : 49/49 (100.00%)
3-
Positive Passed: 49/49 (100.00%)
2+
AST Parsed : 48/48 (100.00%)
3+
Positive Passed: 48/48 (100.00%)

0 commit comments

Comments
 (0)