Repository navigation
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: ParserThe parser didn't handle the syntax correctlyThe parser didn't handle the syntax correctly
Milestone
Description
π Search Terms
explicit resource management, using, await using, switch, case clause, default clause
π Version & Regression Information
- This changed between versions ______ and _______
- This changed in commit or PR _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______
β― Playground Link
π» Code
switch (Math.random()) {
case 0:
using d20 = { [Symbol.dispose]() {} };
break;
case 1:
await using d21 = { [Symbol.dispose]() {} };
break;
}
export {}π Actual behavior
No error happens.
π Expected behavior
The error is reported that using / await using cannot be used here.
Additional information about the issue
The spec was updated to disallow this (rbuckton/ecma262#14).
Related PRs in other projects:
- Disallow using in bare case statementΒ babel/babel#17323
- fix: raises syntax errors on invalid
usingdeclarationsΒ acornjs/acorn#1374
Some tests needs to be updated. For example:
Lines 98 to 113 in 1654ebf
| switch (Math.random()) { | |
| case 0: | |
| using d20 = { [Symbol.dispose]() {} }; | |
| break; | |
| case 1: | |
| using d21 = { [Symbol.dispose]() {} }; | |
| break; | |
| } | |
| if (true) | |
| switch (0) { | |
| case 0: | |
| using d22 = { [Symbol.dispose]() {} }; | |
| break; | |
| } |
Reacted by RenΓ© and Connor Shea
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: ParserThe parser didn't handle the syntax correctlyThe parser didn't handle the syntax correctly
Activity
RyanCavanaugh commentedon Nov 5, 2025
Reject using and await using declarations in switch case/default clauses
fix(parser): reject using/await using in switch case/default clauses
fix(parser): reject `using` / `await using` in a switch `case` / `defβ¦
fix(parser): reject `using` / `await using` in a switch `case` / `defβ¦