diff --git a/internal/checker/grammarchecks.go b/internal/checker/grammarchecks.go index 9ad9476d0a..75e0059718 100644 --- a/internal/checker/grammarchecks.go +++ b/internal/checker/grammarchecks.go @@ -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 { diff --git a/testdata/baselines/reference/submodule/conformance/awaitUsingDeclarations.16.errors.txt b/testdata/baselines/reference/submodule/conformance/awaitUsingDeclarations.16.errors.txt index db76601ffa..9cd24341b2 100644 --- a/testdata/baselines/reference/submodule/conformance/awaitUsingDeclarations.16.errors.txt +++ b/testdata/baselines/reference/submodule/conformance/awaitUsingDeclarations.16.errors.txt @@ -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 }; - ~~~~~ -!!! 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 }; - ~~~~~ -!!! 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. } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/awaitUsingDeclarations.16.errors.txt.diff b/testdata/baselines/reference/submodule/conformance/awaitUsingDeclarations.16.errors.txt.diff deleted file mode 100644 index 08b22b0be7..0000000000 --- a/testdata/baselines/reference/submodule/conformance/awaitUsingDeclarations.16.errors.txt.diff +++ /dev/null @@ -1,39 +0,0 @@ ---- old.awaitUsingDeclarations.16.errors.txt -+++ new.awaitUsingDeclarations.16.errors.txt -@@= skipped -0, +0 lines =@@ --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(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 (4 errors) ==== - declare namespace N { - await using x: { [Symbol.asyncDispose](): Promise }; -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --!!! error TS1546: 'await using' declarations are not allowed in ambient contexts. -+ ~~~~~ -+!!! error TS2852: 'await using' statements are only allowed within async functions and at the top levels of modules. - await using y: null; -- ~~~~~~~~~~~~~~~~~~~ --!!! error TS1546: 'await using' declarations are not allowed in ambient contexts. -+ ~~~~~ -+!!! error TS2852: 'await using' statements are only allowed within async functions and at the top levels of modules. - } - declare module 'M' { - await using x: { [Symbol.asyncDispose](): Promise }; -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --!!! error TS1546: 'await using' declarations are not allowed in ambient contexts. -+ ~~~~~ -+!!! error TS2852: 'await using' statements are only allowed within async functions and at the top levels of modules. - await using y: null; -- ~~~~~~~~~~~~~~~~~~~ --!!! error TS1546: 'await using' declarations are not allowed in ambient contexts. -+ ~~~~~ -+!!! error TS2852: 'await using' statements are only allowed within async functions and at the top levels of modules. - } - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/usingDeclarations.16.errors.txt b/testdata/baselines/reference/submodule/conformance/usingDeclarations.16.errors.txt new file mode 100644 index 0000000000..90514ada95 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/usingDeclarations.16.errors.txt @@ -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. + } + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/usingDeclarations.16.errors.txt.diff b/testdata/baselines/reference/submodule/conformance/usingDeclarations.16.errors.txt.diff deleted file mode 100644 index 71b566aa2b..0000000000 --- a/testdata/baselines/reference/submodule/conformance/usingDeclarations.16.errors.txt.diff +++ /dev/null @@ -1,28 +0,0 @@ ---- old.usingDeclarations.16.errors.txt -+++ new.usingDeclarations.16.errors.txt -@@= skipped -0, +0 lines =@@ --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. -- } -- -+ \ No newline at end of file