From 7d37df1f8201369aa5929dcf02144507af867836 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 5 Aug 2026 23:35:50 +0000
Subject: [PATCH 1/5] Initial plan
From a4834fa113fcbce35a1de77a30f289b0bc5c13b5 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 5 Aug 2026 23:55:57 +0000
Subject: [PATCH 2/5] Fix concurrent diagnostics for nested module declarations
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
---
internal/checker/checker.go | 12 +++
internal/execute/tsctests/tsc_test.go | 31 +++++++
.../concurrent.js | 87 +++++++++++++++++++
.../single-threaded.js | 87 +++++++++++++++++++
4 files changed, 217 insertions(+)
create mode 100644 testdata/baselines/reference/tsc/moduleDeclarationsInNonScopeBlock/concurrent.js
create mode 100644 testdata/baselines/reference/tsc/moduleDeclarationsInNonScopeBlock/single-threaded.js
diff --git a/internal/checker/checker.go b/internal/checker/checker.go
index 0a59c319876..c9cf3132d5c 100644
--- a/internal/checker/checker.go
+++ b/internal/checker/checker.go
@@ -5278,6 +5278,7 @@ func (c *Checker) checkImportDeclaration(node *ast.ImportDeclarationNode) {
}
if c.checkGrammarModuleElementContext(node, diagnostic) {
// If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
+ c.checkExternalModuleNameInGlobalScope(node)
return
}
if !c.checkGrammarModifiers(node) && node.Modifiers() != nil {
@@ -5468,6 +5469,7 @@ func (c *Checker) checkImportEqualsDeclaration(node *ast.Node) {
diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_module,
diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_namespace_or_module)
if c.checkGrammarModuleElementContext(node, diagnostic) {
+ c.checkExternalModuleNameInGlobalScope(node)
return // If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
}
c.checkGrammarModifiers(node)
@@ -5510,6 +5512,7 @@ func (c *Checker) checkExportDeclaration(node *ast.ExportDeclarationNode) {
diagnostics.An_export_declaration_can_only_be_used_at_the_top_level_of_a_module,
diagnostics.An_export_declaration_can_only_be_used_at_the_top_level_of_a_namespace_or_module)
if c.checkGrammarModuleElementContext(node, diagnostic) {
+ c.checkExternalModuleNameInGlobalScope(node)
return // If we hit an export in an illegal context, just bail out to avoid cascading errors.
}
exportDecl := node.AsExportDeclaration()
@@ -5553,6 +5556,15 @@ func (c *Checker) checkExportDeclaration(node *ast.ExportDeclarationNode) {
c.checkImportAttributes(node)
}
+func (c *Checker) checkExternalModuleNameInGlobalScope(node *ast.Node) {
+ if getEnclosingContainer(node).Kind != ast.KindSourceFile || ast.IsImportDeclarationOrJSImportDeclaration(node) && node.ImportClause() == nil {
+ return
+ }
+ if moduleName := ast.GetExternalModuleName(node); moduleName != nil {
+ c.resolveExternalModuleName(node, moduleName, false)
+ }
+}
+
func (c *Checker) checkExportSpecifier(node *ast.ExportSpecifierNode) {
c.checkAliasSymbol(node)
hasModuleSpecifier := node.Parent.Parent.ModuleSpecifier() != nil
diff --git a/internal/execute/tsctests/tsc_test.go b/internal/execute/tsctests/tsc_test.go
index 69d7b3bc207..54962653e19 100644
--- a/internal/execute/tsctests/tsc_test.go
+++ b/internal/execute/tsctests/tsc_test.go
@@ -3821,6 +3821,37 @@ func TestTscNoEmit(t *testing.T) {
}
}
+func TestTscModuleDeclarationsInNonScopeBlock(t *testing.T) {
+ t.Parallel()
+ files := FileMap{
+ "/home/src/projects/project/a.ts": stringtestutil.Dedent(`
+ {
+ export { a } from "exportNamed";
+ export * from "exportStar";
+ import { b } from "importNamed";
+ import c = require("importEquals");
+ import "sideEffect";
+ }
+ `),
+ }
+ for _, test := range []*tscInput{
+ {
+ subScenario: "concurrent",
+ files: files,
+ cwd: "/home/src/projects/project",
+ commandLineArgs: []string{"--noEmit", "a.ts"},
+ },
+ {
+ subScenario: "single threaded",
+ files: files,
+ cwd: "/home/src/projects/project",
+ commandLineArgs: []string{"--noEmit", "--singleThreaded", "a.ts"},
+ },
+ } {
+ test.run(t, "moduleDeclarationsInNonScopeBlock")
+ }
+}
+
func TestTscNoEmitOnError(t *testing.T) {
t.Parallel()
type tscNoEmitOnErrorScenario struct {
diff --git a/testdata/baselines/reference/tsc/moduleDeclarationsInNonScopeBlock/concurrent.js b/testdata/baselines/reference/tsc/moduleDeclarationsInNonScopeBlock/concurrent.js
new file mode 100644
index 00000000000..42f1c0fd315
--- /dev/null
+++ b/testdata/baselines/reference/tsc/moduleDeclarationsInNonScopeBlock/concurrent.js
@@ -0,0 +1,87 @@
+currentDirectory::/home/src/projects/project
+useCaseSensitiveFileNames::true
+Input::
+//// [/home/src/projects/project/a.ts] *new*
+{
+ export { a } from "exportNamed";
+ export * from "exportStar";
+ import { b } from "importNamed";
+ import c = require("importEquals");
+ import "sideEffect";
+}
+
+tsgo --noEmit a.ts
+ExitStatus:: DiagnosticsPresent_OutputsSkipped
+Output::
+[96ma.ts[0m:[93m2[0m:[93m5[0m - [91merror[0m[90m TS1233: [0mAn export declaration can only be used at the top level of a namespace or module.
+
+[7m2[0m export { a } from "exportNamed";
+[7m [0m [91m ~~~~~~[0m
+
+[96ma.ts[0m:[93m2[0m:[93m23[0m - [91merror[0m[90m TS2307: [0mCannot find module 'exportNamed' or its corresponding type declarations.
+
+[7m2[0m export { a } from "exportNamed";
+[7m [0m [91m ~~~~~~~~~~~~~[0m
+
+[96ma.ts[0m:[93m3[0m:[93m5[0m - [91merror[0m[90m TS1233: [0mAn export declaration can only be used at the top level of a namespace or module.
+
+[7m3[0m export * from "exportStar";
+[7m [0m [91m ~~~~~~[0m
+
+[96ma.ts[0m:[93m3[0m:[93m19[0m - [91merror[0m[90m TS2307: [0mCannot find module 'exportStar' or its corresponding type declarations.
+
+[7m3[0m export * from "exportStar";
+[7m [0m [91m ~~~~~~~~~~~~[0m
+
+[96ma.ts[0m:[93m4[0m:[93m5[0m - [91merror[0m[90m TS1232: [0mAn import declaration can only be used at the top level of a namespace or module.
+
+[7m4[0m import { b } from "importNamed";
+[7m [0m [91m ~~~~~~[0m
+
+[96ma.ts[0m:[93m4[0m:[93m23[0m - [91merror[0m[90m TS2307: [0mCannot find module 'importNamed' or its corresponding type declarations.
+
+[7m4[0m import { b } from "importNamed";
+[7m [0m [91m ~~~~~~~~~~~~~[0m
+
+[96ma.ts[0m:[93m5[0m:[93m5[0m - [91merror[0m[90m TS1232: [0mAn import declaration can only be used at the top level of a namespace or module.
+
+[7m5[0m import c = require("importEquals");
+[7m [0m [91m ~~~~~~[0m
+
+[96ma.ts[0m:[93m5[0m:[93m24[0m - [91merror[0m[90m TS2307: [0mCannot find module 'importEquals' or its corresponding type declarations.
+
+[7m5[0m import c = require("importEquals");
+[7m [0m [91m ~~~~~~~~~~~~~~[0m
+
+[96ma.ts[0m:[93m6[0m:[93m5[0m - [91merror[0m[90m TS1232: [0mAn import declaration can only be used at the top level of a namespace or module.
+
+[7m6[0m import "sideEffect";
+[7m [0m [91m ~~~~~~[0m
+
+
+Found 9 errors in the same file, starting at: a.ts[90m:2[0m
+
+//// [/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts] *Lib*
+///
+interface Boolean {}
+interface Function {}
+interface CallableFunction {}
+interface NewableFunction {}
+interface IArguments {}
+interface Number { toExponential: any; }
+interface Object {}
+interface RegExp {}
+interface String { charAt: any; }
+interface Array { length: number; [n: number]: T; }
+interface ReadonlyArray {}
+interface SymbolConstructor {
+ (desc?: string | number): symbol;
+ for(name: string): symbol;
+ readonly toStringTag: symbol;
+}
+declare var Symbol: SymbolConstructor;
+interface Symbol {
+ readonly [Symbol.toStringTag]: string;
+}
+declare const console: { log(msg: any): void; };
+
diff --git a/testdata/baselines/reference/tsc/moduleDeclarationsInNonScopeBlock/single-threaded.js b/testdata/baselines/reference/tsc/moduleDeclarationsInNonScopeBlock/single-threaded.js
new file mode 100644
index 00000000000..5dabf6ff62b
--- /dev/null
+++ b/testdata/baselines/reference/tsc/moduleDeclarationsInNonScopeBlock/single-threaded.js
@@ -0,0 +1,87 @@
+currentDirectory::/home/src/projects/project
+useCaseSensitiveFileNames::true
+Input::
+//// [/home/src/projects/project/a.ts] *new*
+{
+ export { a } from "exportNamed";
+ export * from "exportStar";
+ import { b } from "importNamed";
+ import c = require("importEquals");
+ import "sideEffect";
+}
+
+tsgo --noEmit --singleThreaded a.ts
+ExitStatus:: DiagnosticsPresent_OutputsSkipped
+Output::
+[96ma.ts[0m:[93m2[0m:[93m5[0m - [91merror[0m[90m TS1233: [0mAn export declaration can only be used at the top level of a namespace or module.
+
+[7m2[0m export { a } from "exportNamed";
+[7m [0m [91m ~~~~~~[0m
+
+[96ma.ts[0m:[93m2[0m:[93m23[0m - [91merror[0m[90m TS2307: [0mCannot find module 'exportNamed' or its corresponding type declarations.
+
+[7m2[0m export { a } from "exportNamed";
+[7m [0m [91m ~~~~~~~~~~~~~[0m
+
+[96ma.ts[0m:[93m3[0m:[93m5[0m - [91merror[0m[90m TS1233: [0mAn export declaration can only be used at the top level of a namespace or module.
+
+[7m3[0m export * from "exportStar";
+[7m [0m [91m ~~~~~~[0m
+
+[96ma.ts[0m:[93m3[0m:[93m19[0m - [91merror[0m[90m TS2307: [0mCannot find module 'exportStar' or its corresponding type declarations.
+
+[7m3[0m export * from "exportStar";
+[7m [0m [91m ~~~~~~~~~~~~[0m
+
+[96ma.ts[0m:[93m4[0m:[93m5[0m - [91merror[0m[90m TS1232: [0mAn import declaration can only be used at the top level of a namespace or module.
+
+[7m4[0m import { b } from "importNamed";
+[7m [0m [91m ~~~~~~[0m
+
+[96ma.ts[0m:[93m4[0m:[93m23[0m - [91merror[0m[90m TS2307: [0mCannot find module 'importNamed' or its corresponding type declarations.
+
+[7m4[0m import { b } from "importNamed";
+[7m [0m [91m ~~~~~~~~~~~~~[0m
+
+[96ma.ts[0m:[93m5[0m:[93m5[0m - [91merror[0m[90m TS1232: [0mAn import declaration can only be used at the top level of a namespace or module.
+
+[7m5[0m import c = require("importEquals");
+[7m [0m [91m ~~~~~~[0m
+
+[96ma.ts[0m:[93m5[0m:[93m24[0m - [91merror[0m[90m TS2307: [0mCannot find module 'importEquals' or its corresponding type declarations.
+
+[7m5[0m import c = require("importEquals");
+[7m [0m [91m ~~~~~~~~~~~~~~[0m
+
+[96ma.ts[0m:[93m6[0m:[93m5[0m - [91merror[0m[90m TS1232: [0mAn import declaration can only be used at the top level of a namespace or module.
+
+[7m6[0m import "sideEffect";
+[7m [0m [91m ~~~~~~[0m
+
+
+Found 9 errors in the same file, starting at: a.ts[90m:2[0m
+
+//// [/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts] *Lib*
+///
+interface Boolean {}
+interface Function {}
+interface CallableFunction {}
+interface NewableFunction {}
+interface IArguments {}
+interface Number { toExponential: any; }
+interface Object {}
+interface RegExp {}
+interface String { charAt: any; }
+interface Array { length: number; [n: number]: T; }
+interface ReadonlyArray {}
+interface SymbolConstructor {
+ (desc?: string | number): symbol;
+ for(name: string): symbol;
+ readonly toStringTag: symbol;
+}
+declare var Symbol: SymbolConstructor;
+interface Symbol {
+ readonly [Symbol.toStringTag]: string;
+}
+declare const console: { log(msg: any): void; };
+
From eb2f6bf645ced14f80fda53f0bde7cb22a8d3c2a Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 6 Aug 2026 00:07:18 +0000
Subject: [PATCH 3/5] Accept nested module diagnostic baseline
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
---
.../moduleElementsInWrongContext.errors.txt | 5 +++-
...duleElementsInWrongContext.errors.txt.diff | 27 +++++++++++++++++++
2 files changed, 31 insertions(+), 1 deletion(-)
create mode 100644 testdata/baselines/reference/submodule/compiler/moduleElementsInWrongContext.errors.txt.diff
diff --git a/testdata/baselines/reference/submodule/compiler/moduleElementsInWrongContext.errors.txt b/testdata/baselines/reference/submodule/compiler/moduleElementsInWrongContext.errors.txt
index af0204ba8e2..9ebc0a62740 100644
--- a/testdata/baselines/reference/submodule/compiler/moduleElementsInWrongContext.errors.txt
+++ b/testdata/baselines/reference/submodule/compiler/moduleElementsInWrongContext.errors.txt
@@ -11,13 +11,14 @@ moduleElementsInWrongContext.ts(21,5): error TS1184: Modifiers cannot appear her
moduleElementsInWrongContext.ts(22,5): error TS1184: Modifiers cannot appear here.
moduleElementsInWrongContext.ts(23,5): error TS1232: An import declaration can only be used at the top level of a namespace or module.
moduleElementsInWrongContext.ts(24,5): error TS1232: An import declaration can only be used at the top level of a namespace or module.
+moduleElementsInWrongContext.ts(24,25): error TS2307: Cannot find module 'foo' or its corresponding type declarations.
moduleElementsInWrongContext.ts(25,5): error TS1232: An import declaration can only be used at the top level of a namespace or module.
moduleElementsInWrongContext.ts(26,5): error TS1232: An import declaration can only be used at the top level of a namespace or module.
moduleElementsInWrongContext.ts(27,5): error TS1232: An import declaration can only be used at the top level of a namespace or module.
moduleElementsInWrongContext.ts(28,5): error TS1232: An import declaration can only be used at the top level of a namespace or module.
-==== moduleElementsInWrongContext.ts (17 errors) ====
+==== moduleElementsInWrongContext.ts (18 errors) ====
{
namespace M { }
~~~~~~~~~
@@ -68,6 +69,8 @@ moduleElementsInWrongContext.ts(28,5): error TS1232: An import declaration can o
import I2 = require("foo");
~~~~~~
!!! error TS1232: An import declaration can only be used at the top level of a namespace or module.
+ ~~~~~
+!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations.
import * as Foo from "ambient";
~~~~~~
!!! error TS1232: An import declaration can only be used at the top level of a namespace or module.
diff --git a/testdata/baselines/reference/submodule/compiler/moduleElementsInWrongContext.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/moduleElementsInWrongContext.errors.txt.diff
new file mode 100644
index 00000000000..af75aef53ba
--- /dev/null
+++ b/testdata/baselines/reference/submodule/compiler/moduleElementsInWrongContext.errors.txt.diff
@@ -0,0 +1,27 @@
+--- old.moduleElementsInWrongContext.errors.txt
++++ new.moduleElementsInWrongContext.errors.txt
+@@= skipped -10, +10 lines =@@
+ moduleElementsInWrongContext.ts(22,5): error TS1184: Modifiers cannot appear here.
+ moduleElementsInWrongContext.ts(23,5): error TS1232: An import declaration can only be used at the top level of a namespace or module.
+ moduleElementsInWrongContext.ts(24,5): error TS1232: An import declaration can only be used at the top level of a namespace or module.
++moduleElementsInWrongContext.ts(24,25): error TS2307: Cannot find module 'foo' or its corresponding type declarations.
+ moduleElementsInWrongContext.ts(25,5): error TS1232: An import declaration can only be used at the top level of a namespace or module.
+ moduleElementsInWrongContext.ts(26,5): error TS1232: An import declaration can only be used at the top level of a namespace or module.
+ moduleElementsInWrongContext.ts(27,5): error TS1232: An import declaration can only be used at the top level of a namespace or module.
+ moduleElementsInWrongContext.ts(28,5): error TS1232: An import declaration can only be used at the top level of a namespace or module.
+
+
+-==== moduleElementsInWrongContext.ts (17 errors) ====
++==== moduleElementsInWrongContext.ts (18 errors) ====
+ {
+ namespace M { }
+ ~~~~~~~~~
+@@= skipped -57, +58 lines =@@
+ import I2 = require("foo");
+ ~~~~~~
+ !!! error TS1232: An import declaration can only be used at the top level of a namespace or module.
++ ~~~~~
++!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations.
+ import * as Foo from "ambient";
+ ~~~~~~
+ !!! error TS1232: An import declaration can only be used at the top level of a namespace or module.
\ No newline at end of file
From bb270c5197081d0e1eaf4dd10d9a5bc908c31c39 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 6 Aug 2026 00:13:37 +0000
Subject: [PATCH 4/5] Clarify nested import condition
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
---
internal/checker/checker.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/internal/checker/checker.go b/internal/checker/checker.go
index c9cf3132d5c..7301ed7b7e1 100644
--- a/internal/checker/checker.go
+++ b/internal/checker/checker.go
@@ -5557,7 +5557,7 @@ func (c *Checker) checkExportDeclaration(node *ast.ExportDeclarationNode) {
}
func (c *Checker) checkExternalModuleNameInGlobalScope(node *ast.Node) {
- if getEnclosingContainer(node).Kind != ast.KindSourceFile || ast.IsImportDeclarationOrJSImportDeclaration(node) && node.ImportClause() == nil {
+ if getEnclosingContainer(node).Kind != ast.KindSourceFile || (ast.IsImportDeclarationOrJSImportDeclaration(node) && node.ImportClause() == nil) {
return
}
if moduleName := ast.GetExternalModuleName(node); moduleName != nil {
From 0c45b2997f8913f02df6442a88f945d32236ee97 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 6 Aug 2026 00:34:22 +0000
Subject: [PATCH 5/5] Use compiler baseline for nested module diagnostics
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
---
internal/execute/tsctests/tsc_test.go | 31 -------
...duleDeclarationsInNonScopeBlock.errors.txt | 38 ++++++++
.../moduleDeclarationsInNonScopeBlock.js | 21 +++++
.../moduleDeclarationsInNonScopeBlock.symbols | 17 ++++
.../moduleDeclarationsInNonScopeBlock.types | 17 ++++
.../concurrent.js | 87 -------------------
.../single-threaded.js | 87 -------------------
.../moduleDeclarationsInNonScopeBlock.ts | 7 ++
8 files changed, 100 insertions(+), 205 deletions(-)
create mode 100644 testdata/baselines/reference/compiler/moduleDeclarationsInNonScopeBlock.errors.txt
create mode 100644 testdata/baselines/reference/compiler/moduleDeclarationsInNonScopeBlock.js
create mode 100644 testdata/baselines/reference/compiler/moduleDeclarationsInNonScopeBlock.symbols
create mode 100644 testdata/baselines/reference/compiler/moduleDeclarationsInNonScopeBlock.types
delete mode 100644 testdata/baselines/reference/tsc/moduleDeclarationsInNonScopeBlock/concurrent.js
delete mode 100644 testdata/baselines/reference/tsc/moduleDeclarationsInNonScopeBlock/single-threaded.js
create mode 100644 testdata/tests/cases/compiler/moduleDeclarationsInNonScopeBlock.ts
diff --git a/internal/execute/tsctests/tsc_test.go b/internal/execute/tsctests/tsc_test.go
index 54962653e19..69d7b3bc207 100644
--- a/internal/execute/tsctests/tsc_test.go
+++ b/internal/execute/tsctests/tsc_test.go
@@ -3821,37 +3821,6 @@ func TestTscNoEmit(t *testing.T) {
}
}
-func TestTscModuleDeclarationsInNonScopeBlock(t *testing.T) {
- t.Parallel()
- files := FileMap{
- "/home/src/projects/project/a.ts": stringtestutil.Dedent(`
- {
- export { a } from "exportNamed";
- export * from "exportStar";
- import { b } from "importNamed";
- import c = require("importEquals");
- import "sideEffect";
- }
- `),
- }
- for _, test := range []*tscInput{
- {
- subScenario: "concurrent",
- files: files,
- cwd: "/home/src/projects/project",
- commandLineArgs: []string{"--noEmit", "a.ts"},
- },
- {
- subScenario: "single threaded",
- files: files,
- cwd: "/home/src/projects/project",
- commandLineArgs: []string{"--noEmit", "--singleThreaded", "a.ts"},
- },
- } {
- test.run(t, "moduleDeclarationsInNonScopeBlock")
- }
-}
-
func TestTscNoEmitOnError(t *testing.T) {
t.Parallel()
type tscNoEmitOnErrorScenario struct {
diff --git a/testdata/baselines/reference/compiler/moduleDeclarationsInNonScopeBlock.errors.txt b/testdata/baselines/reference/compiler/moduleDeclarationsInNonScopeBlock.errors.txt
new file mode 100644
index 00000000000..b89d3156232
--- /dev/null
+++ b/testdata/baselines/reference/compiler/moduleDeclarationsInNonScopeBlock.errors.txt
@@ -0,0 +1,38 @@
+moduleDeclarationsInNonScopeBlock.ts(2,5): error TS1233: An export declaration can only be used at the top level of a namespace or module.
+moduleDeclarationsInNonScopeBlock.ts(2,23): error TS2307: Cannot find module 'exportNamed' or its corresponding type declarations.
+moduleDeclarationsInNonScopeBlock.ts(3,5): error TS1233: An export declaration can only be used at the top level of a namespace or module.
+moduleDeclarationsInNonScopeBlock.ts(3,19): error TS2307: Cannot find module 'exportStar' or its corresponding type declarations.
+moduleDeclarationsInNonScopeBlock.ts(4,5): error TS1232: An import declaration can only be used at the top level of a namespace or module.
+moduleDeclarationsInNonScopeBlock.ts(4,23): error TS2307: Cannot find module 'importNamed' or its corresponding type declarations.
+moduleDeclarationsInNonScopeBlock.ts(5,5): error TS1232: An import declaration can only be used at the top level of a namespace or module.
+moduleDeclarationsInNonScopeBlock.ts(5,24): error TS2307: Cannot find module 'importEquals' or its corresponding type declarations.
+moduleDeclarationsInNonScopeBlock.ts(6,5): error TS1232: An import declaration can only be used at the top level of a namespace or module.
+
+
+==== moduleDeclarationsInNonScopeBlock.ts (9 errors) ====
+ {
+ export { a } from "exportNamed";
+ ~~~~~~
+!!! error TS1233: An export declaration can only be used at the top level of a namespace or module.
+ ~~~~~~~~~~~~~
+!!! error TS2307: Cannot find module 'exportNamed' or its corresponding type declarations.
+ export * from "exportStar";
+ ~~~~~~
+!!! error TS1233: An export declaration can only be used at the top level of a namespace or module.
+ ~~~~~~~~~~~~
+!!! error TS2307: Cannot find module 'exportStar' or its corresponding type declarations.
+ import { b } from "importNamed";
+ ~~~~~~
+!!! error TS1232: An import declaration can only be used at the top level of a namespace or module.
+ ~~~~~~~~~~~~~
+!!! error TS2307: Cannot find module 'importNamed' or its corresponding type declarations.
+ import c = require("importEquals");
+ ~~~~~~
+!!! error TS1232: An import declaration can only be used at the top level of a namespace or module.
+ ~~~~~~~~~~~~~~
+!!! error TS2307: Cannot find module 'importEquals' or its corresponding type declarations.
+ import "sideEffect";
+ ~~~~~~
+!!! error TS1232: An import declaration can only be used at the top level of a namespace or module.
+ }
+
\ No newline at end of file
diff --git a/testdata/baselines/reference/compiler/moduleDeclarationsInNonScopeBlock.js b/testdata/baselines/reference/compiler/moduleDeclarationsInNonScopeBlock.js
new file mode 100644
index 00000000000..c5072e7e789
--- /dev/null
+++ b/testdata/baselines/reference/compiler/moduleDeclarationsInNonScopeBlock.js
@@ -0,0 +1,21 @@
+//// [tests/cases/compiler/moduleDeclarationsInNonScopeBlock.ts] ////
+
+//// [moduleDeclarationsInNonScopeBlock.ts]
+{
+ export { a } from "exportNamed";
+ export * from "exportStar";
+ import { b } from "importNamed";
+ import c = require("importEquals");
+ import "sideEffect";
+}
+
+
+//// [moduleDeclarationsInNonScopeBlock.js]
+"use strict";
+{
+ export { a } from "exportNamed";
+ export * from "exportStar";
+ import { b } from "importNamed";
+ import c = require("importEquals");
+ import "sideEffect";
+}
diff --git a/testdata/baselines/reference/compiler/moduleDeclarationsInNonScopeBlock.symbols b/testdata/baselines/reference/compiler/moduleDeclarationsInNonScopeBlock.symbols
new file mode 100644
index 00000000000..240e3397d6c
--- /dev/null
+++ b/testdata/baselines/reference/compiler/moduleDeclarationsInNonScopeBlock.symbols
@@ -0,0 +1,17 @@
+//// [tests/cases/compiler/moduleDeclarationsInNonScopeBlock.ts] ////
+
+=== moduleDeclarationsInNonScopeBlock.ts ===
+{
+ export { a } from "exportNamed";
+>a : Symbol(a, Decl(moduleDeclarationsInNonScopeBlock.ts, 1, 12))
+
+ export * from "exportStar";
+ import { b } from "importNamed";
+>b : Symbol(b, Decl(moduleDeclarationsInNonScopeBlock.ts, 3, 12))
+
+ import c = require("importEquals");
+>c : Symbol(c, Decl(moduleDeclarationsInNonScopeBlock.ts, 3, 36))
+
+ import "sideEffect";
+}
+
diff --git a/testdata/baselines/reference/compiler/moduleDeclarationsInNonScopeBlock.types b/testdata/baselines/reference/compiler/moduleDeclarationsInNonScopeBlock.types
new file mode 100644
index 00000000000..9e865e58cf2
--- /dev/null
+++ b/testdata/baselines/reference/compiler/moduleDeclarationsInNonScopeBlock.types
@@ -0,0 +1,17 @@
+//// [tests/cases/compiler/moduleDeclarationsInNonScopeBlock.ts] ////
+
+=== moduleDeclarationsInNonScopeBlock.ts ===
+{
+ export { a } from "exportNamed";
+>a : any
+
+ export * from "exportStar";
+ import { b } from "importNamed";
+>b : any
+
+ import c = require("importEquals");
+>c : any
+
+ import "sideEffect";
+}
+
diff --git a/testdata/baselines/reference/tsc/moduleDeclarationsInNonScopeBlock/concurrent.js b/testdata/baselines/reference/tsc/moduleDeclarationsInNonScopeBlock/concurrent.js
deleted file mode 100644
index 42f1c0fd315..00000000000
--- a/testdata/baselines/reference/tsc/moduleDeclarationsInNonScopeBlock/concurrent.js
+++ /dev/null
@@ -1,87 +0,0 @@
-currentDirectory::/home/src/projects/project
-useCaseSensitiveFileNames::true
-Input::
-//// [/home/src/projects/project/a.ts] *new*
-{
- export { a } from "exportNamed";
- export * from "exportStar";
- import { b } from "importNamed";
- import c = require("importEquals");
- import "sideEffect";
-}
-
-tsgo --noEmit a.ts
-ExitStatus:: DiagnosticsPresent_OutputsSkipped
-Output::
-[96ma.ts[0m:[93m2[0m:[93m5[0m - [91merror[0m[90m TS1233: [0mAn export declaration can only be used at the top level of a namespace or module.
-
-[7m2[0m export { a } from "exportNamed";
-[7m [0m [91m ~~~~~~[0m
-
-[96ma.ts[0m:[93m2[0m:[93m23[0m - [91merror[0m[90m TS2307: [0mCannot find module 'exportNamed' or its corresponding type declarations.
-
-[7m2[0m export { a } from "exportNamed";
-[7m [0m [91m ~~~~~~~~~~~~~[0m
-
-[96ma.ts[0m:[93m3[0m:[93m5[0m - [91merror[0m[90m TS1233: [0mAn export declaration can only be used at the top level of a namespace or module.
-
-[7m3[0m export * from "exportStar";
-[7m [0m [91m ~~~~~~[0m
-
-[96ma.ts[0m:[93m3[0m:[93m19[0m - [91merror[0m[90m TS2307: [0mCannot find module 'exportStar' or its corresponding type declarations.
-
-[7m3[0m export * from "exportStar";
-[7m [0m [91m ~~~~~~~~~~~~[0m
-
-[96ma.ts[0m:[93m4[0m:[93m5[0m - [91merror[0m[90m TS1232: [0mAn import declaration can only be used at the top level of a namespace or module.
-
-[7m4[0m import { b } from "importNamed";
-[7m [0m [91m ~~~~~~[0m
-
-[96ma.ts[0m:[93m4[0m:[93m23[0m - [91merror[0m[90m TS2307: [0mCannot find module 'importNamed' or its corresponding type declarations.
-
-[7m4[0m import { b } from "importNamed";
-[7m [0m [91m ~~~~~~~~~~~~~[0m
-
-[96ma.ts[0m:[93m5[0m:[93m5[0m - [91merror[0m[90m TS1232: [0mAn import declaration can only be used at the top level of a namespace or module.
-
-[7m5[0m import c = require("importEquals");
-[7m [0m [91m ~~~~~~[0m
-
-[96ma.ts[0m:[93m5[0m:[93m24[0m - [91merror[0m[90m TS2307: [0mCannot find module 'importEquals' or its corresponding type declarations.
-
-[7m5[0m import c = require("importEquals");
-[7m [0m [91m ~~~~~~~~~~~~~~[0m
-
-[96ma.ts[0m:[93m6[0m:[93m5[0m - [91merror[0m[90m TS1232: [0mAn import declaration can only be used at the top level of a namespace or module.
-
-[7m6[0m import "sideEffect";
-[7m [0m [91m ~~~~~~[0m
-
-
-Found 9 errors in the same file, starting at: a.ts[90m:2[0m
-
-//// [/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts] *Lib*
-///
-interface Boolean {}
-interface Function {}
-interface CallableFunction {}
-interface NewableFunction {}
-interface IArguments {}
-interface Number { toExponential: any; }
-interface Object {}
-interface RegExp {}
-interface String { charAt: any; }
-interface Array { length: number; [n: number]: T; }
-interface ReadonlyArray {}
-interface SymbolConstructor {
- (desc?: string | number): symbol;
- for(name: string): symbol;
- readonly toStringTag: symbol;
-}
-declare var Symbol: SymbolConstructor;
-interface Symbol {
- readonly [Symbol.toStringTag]: string;
-}
-declare const console: { log(msg: any): void; };
-
diff --git a/testdata/baselines/reference/tsc/moduleDeclarationsInNonScopeBlock/single-threaded.js b/testdata/baselines/reference/tsc/moduleDeclarationsInNonScopeBlock/single-threaded.js
deleted file mode 100644
index 5dabf6ff62b..00000000000
--- a/testdata/baselines/reference/tsc/moduleDeclarationsInNonScopeBlock/single-threaded.js
+++ /dev/null
@@ -1,87 +0,0 @@
-currentDirectory::/home/src/projects/project
-useCaseSensitiveFileNames::true
-Input::
-//// [/home/src/projects/project/a.ts] *new*
-{
- export { a } from "exportNamed";
- export * from "exportStar";
- import { b } from "importNamed";
- import c = require("importEquals");
- import "sideEffect";
-}
-
-tsgo --noEmit --singleThreaded a.ts
-ExitStatus:: DiagnosticsPresent_OutputsSkipped
-Output::
-[96ma.ts[0m:[93m2[0m:[93m5[0m - [91merror[0m[90m TS1233: [0mAn export declaration can only be used at the top level of a namespace or module.
-
-[7m2[0m export { a } from "exportNamed";
-[7m [0m [91m ~~~~~~[0m
-
-[96ma.ts[0m:[93m2[0m:[93m23[0m - [91merror[0m[90m TS2307: [0mCannot find module 'exportNamed' or its corresponding type declarations.
-
-[7m2[0m export { a } from "exportNamed";
-[7m [0m [91m ~~~~~~~~~~~~~[0m
-
-[96ma.ts[0m:[93m3[0m:[93m5[0m - [91merror[0m[90m TS1233: [0mAn export declaration can only be used at the top level of a namespace or module.
-
-[7m3[0m export * from "exportStar";
-[7m [0m [91m ~~~~~~[0m
-
-[96ma.ts[0m:[93m3[0m:[93m19[0m - [91merror[0m[90m TS2307: [0mCannot find module 'exportStar' or its corresponding type declarations.
-
-[7m3[0m export * from "exportStar";
-[7m [0m [91m ~~~~~~~~~~~~[0m
-
-[96ma.ts[0m:[93m4[0m:[93m5[0m - [91merror[0m[90m TS1232: [0mAn import declaration can only be used at the top level of a namespace or module.
-
-[7m4[0m import { b } from "importNamed";
-[7m [0m [91m ~~~~~~[0m
-
-[96ma.ts[0m:[93m4[0m:[93m23[0m - [91merror[0m[90m TS2307: [0mCannot find module 'importNamed' or its corresponding type declarations.
-
-[7m4[0m import { b } from "importNamed";
-[7m [0m [91m ~~~~~~~~~~~~~[0m
-
-[96ma.ts[0m:[93m5[0m:[93m5[0m - [91merror[0m[90m TS1232: [0mAn import declaration can only be used at the top level of a namespace or module.
-
-[7m5[0m import c = require("importEquals");
-[7m [0m [91m ~~~~~~[0m
-
-[96ma.ts[0m:[93m5[0m:[93m24[0m - [91merror[0m[90m TS2307: [0mCannot find module 'importEquals' or its corresponding type declarations.
-
-[7m5[0m import c = require("importEquals");
-[7m [0m [91m ~~~~~~~~~~~~~~[0m
-
-[96ma.ts[0m:[93m6[0m:[93m5[0m - [91merror[0m[90m TS1232: [0mAn import declaration can only be used at the top level of a namespace or module.
-
-[7m6[0m import "sideEffect";
-[7m [0m [91m ~~~~~~[0m
-
-
-Found 9 errors in the same file, starting at: a.ts[90m:2[0m
-
-//// [/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts] *Lib*
-///
-interface Boolean {}
-interface Function {}
-interface CallableFunction {}
-interface NewableFunction {}
-interface IArguments {}
-interface Number { toExponential: any; }
-interface Object {}
-interface RegExp {}
-interface String { charAt: any; }
-interface Array { length: number; [n: number]: T; }
-interface ReadonlyArray {}
-interface SymbolConstructor {
- (desc?: string | number): symbol;
- for(name: string): symbol;
- readonly toStringTag: symbol;
-}
-declare var Symbol: SymbolConstructor;
-interface Symbol {
- readonly [Symbol.toStringTag]: string;
-}
-declare const console: { log(msg: any): void; };
-
diff --git a/testdata/tests/cases/compiler/moduleDeclarationsInNonScopeBlock.ts b/testdata/tests/cases/compiler/moduleDeclarationsInNonScopeBlock.ts
new file mode 100644
index 00000000000..345e899fe27
--- /dev/null
+++ b/testdata/tests/cases/compiler/moduleDeclarationsInNonScopeBlock.ts
@@ -0,0 +1,7 @@
+{
+ export { a } from "exportNamed";
+ export * from "exportStar";
+ import { b } from "importNamed";
+ import c = require("importEquals");
+ import "sideEffect";
+}