Skip to content

Commit 2b02d84

Browse files
committed
fix(parser): allow for(using using stmts (#10985)
fixes #10981
1 parent 1aed99b commit 2b02d84

7 files changed

Lines changed: 31 additions & 12 deletions

File tree

crates/oxc_parser/src/js/statement.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,20 @@ impl<'a> ParserImpl<'a> {
345345
{
346346
return self.parse_variable_declaration_for_statement(span, r#await);
347347
}
348+
// [+Using, +Await] await [no LineTerminator here] using [no LineTerminator here]
349+
if self.cur_kind() == Kind::Await
350+
&& !self.peek_token().is_on_new_line()
351+
&& self.peek_kind() == Kind::Using
352+
&& !self.nth(2).is_on_new_line()
353+
{
354+
return self.parse_using_declaration_for_statement(span, r#await);
355+
}
348356

349-
if (self.cur_kind() == Kind::Await && self.peek_kind() == Kind::Using)
350-
|| (self.cur_kind() == Kind::Using && self.peek_kind() == Kind::Ident)
357+
// [+Using] using [no LineTerminator here] ForBinding[?Yield, ?Await, ~Pattern]
358+
if self.cur_kind() == Kind::Using
359+
&& !self.peek_token().is_on_new_line()
360+
&& self.peek_kind() != Kind::Of
361+
&& self.peek_kind().is_binding_identifier()
351362
{
352363
return self.parse_using_declaration_for_statement(span, r#await);
353364
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
using using = of;
3+
}
4+
{
5+
for (using using of of) {}
6+
}
7+
{
8+
for (using foo of of) {}
9+
}
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 : 35/35 (100.00%)
3-
Positive Passed: 35/35 (100.00%)
2+
AST Parsed : 36/36 (100.00%)
3+
Positive Passed: 36/36 (100.00%)

tasks/coverage/snapshots/parser_misc.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
parser_misc Summary:
2-
AST Parsed : 35/35 (100.00%)
3-
Positive Passed: 35/35 (100.00%)
2+
AST Parsed : 36/36 (100.00%)
3+
Positive Passed: 36/36 (100.00%)
44
Negative Passed: 33/33 (100.00%)
55

66
× Identifier `b` has already been declared

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 : 35/35 (100.00%)
3-
Positive Passed: 20/35 (57.14%)
2+
AST Parsed : 36/36 (100.00%)
3+
Positive Passed: 21/36 (58.33%)
44
semantic Error: tasks/coverage/misc/pass/oxc-1288.ts
55
Bindings mismatch:
66
after transform: ScopeId(0): ["from"]
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 : 35/35 (100.00%)
3-
Positive Passed: 35/35 (100.00%)
2+
AST Parsed : 36/36 (100.00%)
3+
Positive Passed: 36/36 (100.00%)

tasks/prettier_conformance/snapshots/prettier.js.snap.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
js compatibility: 236/699 (33.76%)
1+
js compatibility: 237/699 (33.91%)
22

33
# Failed
44

@@ -219,7 +219,6 @@ js compatibility: 236/699 (33.76%)
219219
| js/explicit-resource-management/using-declarations.js | 💥 | 80.00% |
220220
| js/explicit-resource-management/valid-await-using-comments.js | 💥 | 60.61% |
221221
| js/explicit-resource-management/valid-using-as-identifier-for-init.js | 💥 | 0.00% |
222-
| js/explicit-resource-management/valid-using-binding-using.js | 💥 | 0.00% |
223222
| js/export/blank-line-between-specifiers.js | 💥💥 | 95.00% |
224223
| js/export-default/function_in_template.js | 💥 | 0.00% |
225224
| js/export-default/iife.js | 💥 | 0.00% |

0 commit comments

Comments
 (0)