Skip to content
Merged
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
9 changes: 7 additions & 2 deletions internal/checker/grammarchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -1700,8 +1700,13 @@ func (c *Checker) checkGrammarVariableDeclarationList(declarationList *ast.Varia
}

blockScopeFlags := declarationList.Flags & ast.NodeFlagsBlockScoped
if (blockScopeFlags == ast.NodeFlagsUsing || blockScopeFlags == ast.NodeFlagsAwaitUsing) && ast.IsForInStatement(declarationList.Parent) {
return c.grammarErrorOnNode(declarationList.AsNode(), core.IfElse(blockScopeFlags == ast.NodeFlagsUsing, diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_using_declaration, diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_an_await_using_declaration))
if blockScopeFlags == ast.NodeFlagsUsing || blockScopeFlags == ast.NodeFlagsAwaitUsing {
if ast.IsForInStatement(declarationList.Parent) {
return c.grammarErrorOnNode(declarationList.AsNode(), core.IfElse(blockScopeFlags == ast.NodeFlagsUsing, diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_using_declaration, diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_an_await_using_declaration))
}
if declarationList.Flags&ast.NodeFlagsAmbient != 0 {
return c.grammarErrorOnNode(declarationList.AsNode(), core.IfElse(blockScopeFlags == ast.NodeFlagsUsing, diagnostics.X_using_declarations_are_not_allowed_in_ambient_contexts, diagnostics.X_await_using_declarations_are_not_allowed_in_ambient_contexts))
}
}

if blockScopeFlags == ast.NodeFlagsAwaitUsing {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
awaitUsingDeclarations.16.ts(2,5): error TS2852: 'await using' statements are only allowed within async functions and at the top levels of modules.
awaitUsingDeclarations.16.ts(3,5): error TS2852: 'await using' statements are only allowed within async functions and at the top levels of modules.
awaitUsingDeclarations.16.ts(6,5): error TS2852: 'await using' statements are only allowed within async functions and at the top levels of modules.
awaitUsingDeclarations.16.ts(7,5): error TS2852: 'await using' statements are only allowed within async functions and at the top levels of modules.
awaitUsingDeclarations.16.ts(2,5): error TS1546: 'await using' declarations are not allowed in ambient contexts.
awaitUsingDeclarations.16.ts(3,5): error TS1546: 'await using' declarations are not allowed in ambient contexts.
awaitUsingDeclarations.16.ts(6,5): error TS1546: 'await using' declarations are not allowed in ambient contexts.
awaitUsingDeclarations.16.ts(7,5): error TS1546: 'await using' declarations are not allowed in ambient contexts.


==== awaitUsingDeclarations.16.ts (4 errors) ====
declare namespace N {
await using x: { [Symbol.asyncDispose](): Promise<void> };
~~~~~
!!! error TS2852: 'await using' statements are only allowed within async functions and at the top levels of modules.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1546: 'await using' declarations are not allowed in ambient contexts.
await using y: null;
~~~~~
!!! error TS2852: 'await using' statements are only allowed within async functions and at the top levels of modules.
~~~~~~~~~~~~~~~~~~~
!!! error TS1546: 'await using' declarations are not allowed in ambient contexts.
}
declare module 'M' {
await using x: { [Symbol.asyncDispose](): Promise<void> };
~~~~~
!!! error TS2852: 'await using' statements are only allowed within async functions and at the top levels of modules.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1546: 'await using' declarations are not allowed in ambient contexts.
await using y: null;
~~~~~
!!! error TS2852: 'await using' statements are only allowed within async functions and at the top levels of modules.
~~~~~~~~~~~~~~~~~~~
!!! error TS1546: 'await using' declarations are not allowed in ambient contexts.
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
usingDeclarations.16.ts(2,5): error TS1545: 'using' declarations are not allowed in ambient contexts.
usingDeclarations.16.ts(3,5): error TS1545: 'using' declarations are not allowed in ambient contexts.
usingDeclarations.16.ts(6,5): error TS1545: 'using' declarations are not allowed in ambient contexts.
usingDeclarations.16.ts(7,5): error TS1545: 'using' declarations are not allowed in ambient contexts.


==== usingDeclarations.16.ts (4 errors) ====
declare namespace N {
using x: { [Symbol.dispose](): void };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1545: 'using' declarations are not allowed in ambient contexts.
using y: null;
~~~~~~~~~~~~~
!!! error TS1545: 'using' declarations are not allowed in ambient contexts.
}
declare module 'M' {
using x: { [Symbol.dispose](): void };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1545: 'using' declarations are not allowed in ambient contexts.
using y: null;
~~~~~~~~~~~~~
!!! error TS1545: 'using' declarations are not allowed in ambient contexts.
}

This file was deleted.