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 correctlyHelp WantedYou can do thisYou can do this
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 correctlyHelp WantedYou can do thisYou can do this
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…