Skip to content

Feature implementation from commits b86ab7d..5a3271b #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: feature-base-branch-1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
81c9518
Fix getResolvePackageJsonImports utility (#61707)
andrewbranch May 16, 2025
b504a1e
Handle lock file 3 version when caching the typings ensuring we can r…
sheetalkamat May 21, 2025
44d4671
Update pr_owners.txt (#61798)
jakebailey Jun 3, 2025
3dd0a35
Initialize the map for dts to reference and source to reference when …
sheetalkamat Jun 4, 2025
2b88aeb
LEGO: Pull request from lego/hb_5378966c-b857-470a-8675-daebef4a6da1_…
csigs Jun 4, 2025
a591ca3
fix(61747): for (using of = is incorrectly parsed (#61764)
a-tarasyuk Jun 5, 2025
ac03ba4
fix(checker): report error when using bigint as enum key (#61777)
magic-akari Jun 5, 2025
cd34199
tsc --init update (#61813)
RyanCavanaugh Jun 6, 2025
a69c6d0
Add support for `import defer` proposal (#60757)
nicolo-ribaudo Jun 6, 2025
ffd98c1
feat: add Error.isError() to ESNext lib (#60788)
dirkluijk Jun 6, 2025
51dcd90
Cache mapper instantiations (#61505)
Andarist Jun 6, 2025
652ed7f
Add lib.esnext.sharedmemory (#61646)
Renegade334 Jun 6, 2025
1e24945
explicitly disallow `using` in ambient contexts (#61781)
Renegade334 Jun 6, 2025
fa2a0fc
Issue "'{0}' declarations can only be declared inside a block." for b…
Andarist Jun 6, 2025
7715955
Fix helpers emit for .cjs files in ESM module mode (#61814)
andrewbranch Jun 6, 2025
355b9e0
Avoid resolving source prop type when the target is `unknown`/`any` (…
Andarist Jun 6, 2025
97cfa26
optimization, reduce memory usage (#61822)
VincentBailly Jun 9, 2025
cb38d99
Add `--module node20` (#61805)
andrewbranch Jun 9, 2025
34d1ea6
Fix type variable leaks and cache inconsistencies (#61668)
ahejlsberg Jun 9, 2025
0dfd0c2
Restore `import defer =` parsing (#61837)
nicolo-ribaudo Jun 9, 2025
12e09f4
Port "Improve type discrimination algorithm" from tsgo (#61828)
jakebailey Jun 9, 2025
529ed09
fix link to "Help Wanted" issues (#61843)
AllenSH12 Jun 11, 2025
dd1e258
LEGO: Pull request from lego/hb_5378966c-b857-470a-8675-daebef4a6da1_…
csigs Jun 11, 2025
f1d2494
LEGO: Pull request from lego/hb_5378966c-b857-470a-8675-daebef4a6da1_…
csigs Jun 17, 2025
5a3271b
LEGO: Pull request from lego/hb_5378966c-b857-470a-8675-daebef4a6da1_…
csigs Jun 18, 2025
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
Prev Previous commit
Next Next commit
explicitly disallow using in ambient contexts (microsoft#61781)
  • Loading branch information
Renegade334 authored Jun 6, 2025
commit 1e2494566eb6d352844e00b34b15d67c025d307d
31 changes: 21 additions & 10 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52856,17 +52856,28 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}

const blockScopeFlags = declarationList.flags & NodeFlags.BlockScoped;
if ((blockScopeFlags === NodeFlags.Using || blockScopeFlags === NodeFlags.AwaitUsing) && isForInStatement(declarationList.parent)) {
return grammarErrorOnNode(
declarationList,
blockScopeFlags === NodeFlags.Using ?
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 === NodeFlags.Using || blockScopeFlags === NodeFlags.AwaitUsing) {
if (isForInStatement(declarationList.parent)) {
return grammarErrorOnNode(
declarationList,
blockScopeFlags === NodeFlags.Using ?
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 === NodeFlags.AwaitUsing) {
return checkAwaitGrammar(declarationList);
if (declarationList.flags & NodeFlags.Ambient) {
return grammarErrorOnNode(
declarationList,
blockScopeFlags === NodeFlags.Using ?
Diagnostics.using_declarations_are_not_allowed_in_ambient_contexts :
Diagnostics.await_using_declarations_are_not_allowed_in_ambient_contexts,
);
}

if (blockScopeFlags === NodeFlags.AwaitUsing) {
return checkAwaitGrammar(declarationList);
}
}

return false;
Expand Down
8 changes: 8 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1837,6 +1837,14 @@
"category": "Error",
"code": 1544
},
"'using' declarations are not allowed in ambient contexts.": {
"category": "Error",
"code": 1545
},
"'await using' declarations are not allowed in ambient contexts.": {
"category": "Error",
"code": 1546
},

"The types of '{0}' are incompatible between these types.": {
"category": "Error",
Expand Down
24 changes: 24 additions & 0 deletions tests/baselines/reference/awaitUsingDeclarations.16.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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 TS1546: 'await using' declarations are not allowed in ambient contexts.
await using y: null;
~~~~~~~~~~~~~~~~~~~
!!! error TS1546: 'await using' declarations are not allowed in ambient contexts.
}
declare module 'M' {
await using x: { [Symbol.asyncDispose](): Promise<void> };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1546: 'await using' declarations are not allowed in ambient contexts.
await using y: null;
~~~~~~~~~~~~~~~~~~~
!!! error TS1546: 'await using' declarations are not allowed in ambient contexts.
}

14 changes: 14 additions & 0 deletions tests/baselines/reference/awaitUsingDeclarations.16.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//// [tests/cases/conformance/statements/VariableStatements/usingDeclarations/awaitUsingDeclarations.16.ts] ////

//// [awaitUsingDeclarations.16.ts]
declare namespace N {
await using x: { [Symbol.asyncDispose](): Promise<void> };
await using y: null;
}
declare module 'M' {
await using x: { [Symbol.asyncDispose](): Promise<void> };
await using y: null;
}


//// [awaitUsingDeclarations.16.js]
24 changes: 24 additions & 0 deletions tests/baselines/reference/usingDeclarations.16.errors.txt
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.
}

14 changes: 14 additions & 0 deletions tests/baselines/reference/usingDeclarations.16.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//// [tests/cases/conformance/statements/VariableStatements/usingDeclarations/usingDeclarations.16.ts] ////

//// [usingDeclarations.16.ts]
declare namespace N {
using x: { [Symbol.dispose](): void };
using y: null;
}
declare module 'M' {
using x: { [Symbol.dispose](): void };
using y: null;
}


//// [usingDeclarations.16.js]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @target: esnext
// @module: esnext
// @lib: esnext
// @noTypesAndSymbols: true

declare namespace N {
await using x: { [Symbol.asyncDispose](): Promise<void> };
await using y: null;
}
declare module 'M' {
await using x: { [Symbol.asyncDispose](): Promise<void> };
await using y: null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @target: esnext
// @module: esnext
// @lib: esnext
// @noTypesAndSymbols: true

declare namespace N {
using x: { [Symbol.dispose](): void };
using y: null;
}
declare module 'M' {
using x: { [Symbol.dispose](): void };
using y: null;
}