Skip to content
Closed
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
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -8332,6 +8332,10 @@
"category": "Message",
"code": 95197
},
"A '{0}' declaration cannot be placed within a 'case' or 'default' clause.": {
"category": "Error",
"code": 95198
},

"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
"category": "Error",
Expand Down
8 changes: 8 additions & 0 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7678,12 +7678,20 @@ namespace Parser {
break;
case SyntaxKind.UsingKeyword:
flags |= NodeFlags.Using;
if ((parsingContext & (1 << ParsingContext.SwitchClauseStatements)) &&
!(parsingContext & (1 << ParsingContext.BlockStatements))) {
parseErrorAtCurrentToken(Diagnostics.A_0_declaration_cannot_be_placed_within_a_case_or_default_clause, "using");
}
break;
case SyntaxKind.AwaitKeyword:
if (!isAwaitUsingDeclaration()) {
break;
}
flags |= NodeFlags.AwaitUsing;
if ((parsingContext & (1 << ParsingContext.SwitchClauseStatements)) &&
!(parsingContext & (1 << ParsingContext.BlockStatements))) {
parseErrorAtCurrentToken(Diagnostics.A_0_declaration_cannot_be_placed_within_a_case_or_default_clause, "await using");
}
nextToken();
break;
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
awaitUsingDeclarations.1.ts(1,1): error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
awaitUsingDeclarations.1.ts(36,5): error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
awaitUsingDeclarations.1.ts(41,9): error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
awaitUsingDeclarations.1.ts(45,9): error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
awaitUsingDeclarations.1.ts(52,13): error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
awaitUsingDeclarations.1.ts(57,5): error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
awaitUsingDeclarations.1.ts(60,5): error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
awaitUsingDeclarations.1.ts(63,5): error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
awaitUsingDeclarations.1.ts(67,5): error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
awaitUsingDeclarations.1.ts(70,5): error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
awaitUsingDeclarations.1.ts(74,5): error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
awaitUsingDeclarations.1.ts(79,5): error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
awaitUsingDeclarations.1.ts(85,5): error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
awaitUsingDeclarations.1.ts(90,5): error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
awaitUsingDeclarations.1.ts(94,5): error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
awaitUsingDeclarations.1.ts(41,9): error TS95198: A 'await using' declaration cannot be placed within a 'case' or 'default' clause.
awaitUsingDeclarations.1.ts(45,9): error TS95198: A 'await using' declaration cannot be placed within a 'case' or 'default' clause.
awaitUsingDeclarations.1.ts(52,13): error TS95198: A 'await using' declaration cannot be placed within a 'case' or 'default' clause.


==== awaitUsingDeclarations.1.ts (15 errors) ====
==== awaitUsingDeclarations.1.ts (3 errors) ====
await using d1 = { async [Symbol.asyncDispose]() {} };
~~~~~
!!! error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.

async function af() {
await using d3 = { async [Symbol.asyncDispose]() {} };
Expand Down Expand Up @@ -54,21 +40,19 @@ awaitUsingDeclarations.1.ts(94,5): error TS2854: Top-level 'await using' stateme

{
await using d19 = { async [Symbol.asyncDispose]() {} };
~~~~~
!!! error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
}

switch (Math.random()) {
case 0:
await using d20 = { async [Symbol.asyncDispose]() {} };
~~~~~
!!! error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
!!! error TS95198: A 'await using' declaration cannot be placed within a 'case' or 'default' clause.
break;

case 1:
await using d21 = { async [Symbol.asyncDispose]() {} };
~~~~~
!!! error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
!!! error TS95198: A 'await using' declaration cannot be placed within a 'case' or 'default' clause.
break;
}

Expand All @@ -77,69 +61,49 @@ awaitUsingDeclarations.1.ts(94,5): error TS2854: Top-level 'await using' stateme
case 0:
await using d22 = { async [Symbol.asyncDispose]() {} };
~~~~~
!!! error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
!!! error TS95198: A 'await using' declaration cannot be placed within a 'case' or 'default' clause.
break;
}

try {
await using d23 = { async [Symbol.asyncDispose]() {} };
~~~~~
!!! error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
}
catch {
await using d24 = { async [Symbol.asyncDispose]() {} };
~~~~~
!!! error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
}
finally {
await using d25 = { async [Symbol.asyncDispose]() {} };
~~~~~
!!! error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
}

if (true) {
await using d26 = { async [Symbol.asyncDispose]() {} };
~~~~~
!!! error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
}
else {
await using d27 = { async [Symbol.asyncDispose]() {} };
~~~~~
!!! error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
}

while (true) {
await using d28 = { async [Symbol.asyncDispose]() {} };
~~~~~
!!! error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
break;
}

do {
await using d29 = { async [Symbol.asyncDispose]() {} };
~~~~~
!!! error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
break;
}
while (true);

for (;;) {
await using d30 = { async [Symbol.asyncDispose]() {} };
~~~~~
!!! error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
break;
}

for (const x in {}) {
await using d31 = { async [Symbol.asyncDispose]() {} };
~~~~~
!!! error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
}

for (const x of []) {
await using d32 = { async [Symbol.asyncDispose]() {} };
~~~~~
!!! error TS2854: Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
}

export {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
awaitUsingDeclarations.1.ts(41,9): error TS95198: A 'await using' declaration cannot be placed within a 'case' or 'default' clause.
awaitUsingDeclarations.1.ts(45,9): error TS95198: A 'await using' declaration cannot be placed within a 'case' or 'default' clause.
awaitUsingDeclarations.1.ts(52,13): error TS95198: A 'await using' declaration cannot be placed within a 'case' or 'default' clause.


==== awaitUsingDeclarations.1.ts (3 errors) ====
await using d1 = { async [Symbol.asyncDispose]() {} };

async function af() {
await using d3 = { async [Symbol.asyncDispose]() {} };
await null;
}

async function * ag() {
await using d5 = { async [Symbol.asyncDispose]() {} };
yield;
await null;
}

const a = async () => {
await using d6 = { async [Symbol.asyncDispose]() {} };
};

class C1 {
a = async () => {
await using d7 = { async [Symbol.asyncDispose]() {} };
};

async am() {
await using d13 = { async [Symbol.asyncDispose]() {} };
await null;
}

async * ag() {
await using d15 = { async [Symbol.asyncDispose]() {} };
yield;
await null;
}
}

{
await using d19 = { async [Symbol.asyncDispose]() {} };
}

switch (Math.random()) {
case 0:
await using d20 = { async [Symbol.asyncDispose]() {} };
~~~~~
!!! error TS95198: A 'await using' declaration cannot be placed within a 'case' or 'default' clause.
break;

case 1:
await using d21 = { async [Symbol.asyncDispose]() {} };
~~~~~
!!! error TS95198: A 'await using' declaration cannot be placed within a 'case' or 'default' clause.
break;
}

if (true)
switch (0) {
case 0:
await using d22 = { async [Symbol.asyncDispose]() {} };
~~~~~
!!! error TS95198: A 'await using' declaration cannot be placed within a 'case' or 'default' clause.
break;
}

try {
await using d23 = { async [Symbol.asyncDispose]() {} };
}
catch {
await using d24 = { async [Symbol.asyncDispose]() {} };
}
finally {
await using d25 = { async [Symbol.asyncDispose]() {} };
}

if (true) {
await using d26 = { async [Symbol.asyncDispose]() {} };
}
else {
await using d27 = { async [Symbol.asyncDispose]() {} };
}

while (true) {
await using d28 = { async [Symbol.asyncDispose]() {} };
break;
}

do {
await using d29 = { async [Symbol.asyncDispose]() {} };
break;
}
while (true);

for (;;) {
await using d30 = { async [Symbol.asyncDispose]() {} };
break;
}

for (const x in {}) {
await using d31 = { async [Symbol.asyncDispose]() {} };
}

for (const x of []) {
await using d32 = { async [Symbol.asyncDispose]() {} };
}

export {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
awaitUsingDeclarations.1.ts(41,9): error TS95198: A 'await using' declaration cannot be placed within a 'case' or 'default' clause.
awaitUsingDeclarations.1.ts(45,9): error TS95198: A 'await using' declaration cannot be placed within a 'case' or 'default' clause.
awaitUsingDeclarations.1.ts(52,13): error TS95198: A 'await using' declaration cannot be placed within a 'case' or 'default' clause.


==== awaitUsingDeclarations.1.ts (3 errors) ====
await using d1 = { async [Symbol.asyncDispose]() {} };

async function af() {
await using d3 = { async [Symbol.asyncDispose]() {} };
await null;
}

async function * ag() {
await using d5 = { async [Symbol.asyncDispose]() {} };
yield;
await null;
}

const a = async () => {
await using d6 = { async [Symbol.asyncDispose]() {} };
};

class C1 {
a = async () => {
await using d7 = { async [Symbol.asyncDispose]() {} };
};

async am() {
await using d13 = { async [Symbol.asyncDispose]() {} };
await null;
}

async * ag() {
await using d15 = { async [Symbol.asyncDispose]() {} };
yield;
await null;
}
}

{
await using d19 = { async [Symbol.asyncDispose]() {} };
}

switch (Math.random()) {
case 0:
await using d20 = { async [Symbol.asyncDispose]() {} };
~~~~~
!!! error TS95198: A 'await using' declaration cannot be placed within a 'case' or 'default' clause.
break;

case 1:
await using d21 = { async [Symbol.asyncDispose]() {} };
~~~~~
!!! error TS95198: A 'await using' declaration cannot be placed within a 'case' or 'default' clause.
break;
}

if (true)
switch (0) {
case 0:
await using d22 = { async [Symbol.asyncDispose]() {} };
~~~~~
!!! error TS95198: A 'await using' declaration cannot be placed within a 'case' or 'default' clause.
break;
}

try {
await using d23 = { async [Symbol.asyncDispose]() {} };
}
catch {
await using d24 = { async [Symbol.asyncDispose]() {} };
}
finally {
await using d25 = { async [Symbol.asyncDispose]() {} };
}

if (true) {
await using d26 = { async [Symbol.asyncDispose]() {} };
}
else {
await using d27 = { async [Symbol.asyncDispose]() {} };
}

while (true) {
await using d28 = { async [Symbol.asyncDispose]() {} };
break;
}

do {
await using d29 = { async [Symbol.asyncDispose]() {} };
break;
}
while (true);

for (;;) {
await using d30 = { async [Symbol.asyncDispose]() {} };
break;
}

for (const x in {}) {
await using d31 = { async [Symbol.asyncDispose]() {} };
}

for (const x of []) {
await using d32 = { async [Symbol.asyncDispose]() {} };
}

export {};
Loading
Loading