From e64f5908c4ca905fc7bba708ad0656c1cbb71365 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 06:34:38 +0000 Subject: [PATCH 1/5] Initial plan From 0b9e48431192fb3da53f29768ea1425c3324f42c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 06:56:15 +0000 Subject: [PATCH 2/5] Remove parser's ability to parse module declarations as namespaces Instead of issuing an error for `module X {}`, the parser now always treats it as `namespace X {}`. Only `declare module "foo"` and `namespace` syntax are distinguished. Changes: - Parser: Always use KindNamespaceKeyword for identifier-named module declarations - Checker: Remove suggestion diagnostic for module keyword usage - Checker: Remove unused getNonModifierTokenRangeOfNode utility - Printer tests: Update expected output for module->namespace conversion Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com> --- internal/checker/checker.go | 4 ---- internal/checker/utilities.go | 8 -------- internal/parser/parser.go | 6 +++--- internal/printer/printer_test.go | 4 ++-- 4 files changed, 5 insertions(+), 17 deletions(-) diff --git a/internal/checker/checker.go b/internal/checker/checker.go index 9dac7a0507b..d9649530335 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -5018,10 +5018,6 @@ func (c *Checker) checkModuleDeclaration(node *ast.Node) { } if ast.IsIdentifier(node.Name()) { c.checkCollisionsForDeclarationName(node, node.Name()) - if node.AsModuleDeclaration().Keyword == ast.KindModuleKeyword { - tokenRange := getNonModifierTokenRangeOfNode(node) - c.suggestionDiagnostics.Add(ast.NewDiagnostic(ast.GetSourceFileOfNode(node), tokenRange, diagnostics.A_namespace_declaration_should_not_be_declared_using_the_module_keyword_Please_use_the_namespace_keyword_instead)) - } } c.checkExportsOnMergedDeclarations(node) symbol := c.getSymbolOfDeclaration(node) diff --git a/internal/checker/utilities.go b/internal/checker/utilities.go index 41c4901e661..767952706f9 100644 --- a/internal/checker/utilities.go +++ b/internal/checker/utilities.go @@ -1259,14 +1259,6 @@ func minAndMax[T any](slice []T, getValue func(value T) int) (int, int) { return minValue, maxValue } -func getNonModifierTokenRangeOfNode(node *ast.Node) core.TextRange { - pos := node.Pos() - if last := ast.FindLastVisibleNode(node.ModifierNodes()); last != nil { - pos = last.Pos() - } - return scanner.GetRangeOfTokenAtPosition(ast.GetSourceFileOfNode(node), pos) -} - type FeatureMapEntry struct { lib string props []string diff --git a/internal/parser/parser.go b/internal/parser/parser.go index 65d907d2d6e..cad92636086 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -2034,19 +2034,19 @@ func (p *Parser) parseEnumDeclaration(pos int, hasJSDoc bool, modifiers *ast.Mod } func (p *Parser) parseModuleDeclaration(pos int, hasJSDoc bool, modifiers *ast.ModifierList) *ast.Statement { - keyword := ast.KindModuleKeyword if p.token == ast.KindGlobalKeyword { // global augmentation return p.parseAmbientExternalModuleDeclaration(pos, hasJSDoc, modifiers) } else if p.parseOptional(ast.KindNamespaceKeyword) { - keyword = ast.KindNamespaceKeyword + // namespace keyword always produces a namespace declaration } else { p.parseExpected(ast.KindModuleKeyword) if p.token == ast.KindStringLiteral { return p.parseAmbientExternalModuleDeclaration(pos, hasJSDoc, modifiers) } + // `module X` is treated as `namespace X` } - return p.parseModuleOrNamespaceDeclaration(pos, hasJSDoc, modifiers, false /*nested*/, keyword) + return p.parseModuleOrNamespaceDeclaration(pos, hasJSDoc, modifiers, false /*nested*/, ast.KindNamespaceKeyword) } func (p *Parser) parseAmbientExternalModuleDeclaration(pos int, hasJSDoc bool, modifiers *ast.ModifierList) *ast.Node { diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go index d72f43cbced..174fbf7347f 100644 --- a/internal/printer/printer_test.go +++ b/internal/printer/printer_test.go @@ -255,8 +255,8 @@ func TestEmit(t *testing.T) { {title: "EnumDeclaration#1", input: `enum a{}`, output: "enum a {\n}"}, {title: "EnumDeclaration#2", input: `enum a{b}`, output: "enum a {\n b\n}"}, {title: "EnumDeclaration#3", input: `enum a{b=c}`, output: "enum a {\n b = c\n}"}, - {title: "ModuleDeclaration#1", input: `module a{}`, output: "module a { }"}, - {title: "ModuleDeclaration#2", input: `module a.b{}`, output: "module a.b { }"}, + {title: "ModuleDeclaration#1", input: `module a{}`, output: "namespace a { }"}, + {title: "ModuleDeclaration#2", input: `module a.b{}`, output: "namespace a.b { }"}, {title: "ModuleDeclaration#3", input: `module "a";`, output: "module \"a\";"}, {title: "ModuleDeclaration#4", input: `module "a"{}`, output: "module \"a\" { }"}, {title: "ModuleDeclaration#5", input: `namespace a{}`, output: "namespace a { }"}, From e50c1d7d156f0a6904bf34362230edb05cdebed5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 07:48:29 +0000 Subject: [PATCH 3/5] Make module keyword produce parse error instead of silently normalizing - Parser emits parse error on each identifier name when `module` keyword is used for namespace declarations (matching TS behavior) - Dotted names like `module A.B {}` get errors on both `A` and `B` - AST still uses KindNamespaceKeyword for error recovery - Baselines now match TypeScript exactly (diff files deleted) Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com> --- internal/parser/parser.go | 15 +++-- internal/printer/printer_test.go | 2 - .../compiler/escapedIdentifiers.errors.txt | 5 +- .../escapedIdentifiers.errors.txt.diff | 22 ------- .../moduleKeywordDeprecated.errors.txt | 58 +++++++++++++++++ .../moduleKeywordDeprecated.errors.txt.diff | 62 ------------------- 6 files changed, 72 insertions(+), 92 deletions(-) delete mode 100644 testdata/baselines/reference/submodule/compiler/escapedIdentifiers.errors.txt.diff create mode 100644 testdata/baselines/reference/submodule/compiler/moduleKeywordDeprecated.errors.txt delete mode 100644 testdata/baselines/reference/submodule/compiler/moduleKeywordDeprecated.errors.txt.diff diff --git a/internal/parser/parser.go b/internal/parser/parser.go index cad92636086..2cd78f1d614 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -2039,14 +2039,15 @@ func (p *Parser) parseModuleDeclaration(pos int, hasJSDoc bool, modifiers *ast.M return p.parseAmbientExternalModuleDeclaration(pos, hasJSDoc, modifiers) } else if p.parseOptional(ast.KindNamespaceKeyword) { // namespace keyword always produces a namespace declaration + return p.parseModuleOrNamespaceDeclaration(pos, hasJSDoc, modifiers, false /*nested*/, false /*isIllegalModuleKeyword*/) } else { p.parseExpected(ast.KindModuleKeyword) if p.token == ast.KindStringLiteral { return p.parseAmbientExternalModuleDeclaration(pos, hasJSDoc, modifiers) } - // `module X` is treated as `namespace X` + // `module X {}` is illegal; use `namespace` instead + return p.parseModuleOrNamespaceDeclaration(pos, hasJSDoc, modifiers, false /*nested*/, true /*isIllegalModuleKeyword*/) } - return p.parseModuleOrNamespaceDeclaration(pos, hasJSDoc, modifiers, false /*nested*/, ast.KindNamespaceKeyword) } func (p *Parser) parseAmbientExternalModuleDeclaration(pos int, hasJSDoc bool, modifiers *ast.ModifierList) *ast.Node { @@ -2085,7 +2086,7 @@ func (p *Parser) parseModuleBlock() *ast.Node { return p.finishNode(p.factory.NewModuleBlock(statements), pos) } -func (p *Parser) parseModuleOrNamespaceDeclaration(pos int, hasJSDoc bool, modifiers *ast.ModifierList, nested bool, keyword ast.Kind) *ast.Node { +func (p *Parser) parseModuleOrNamespaceDeclaration(pos int, hasJSDoc bool, modifiers *ast.ModifierList, nested bool, isIllegalModuleKeyword bool) *ast.Node { saveHasAwaitIdentifier := p.statementHasAwaitIdentifier var name *ast.Node if nested { @@ -2093,17 +2094,21 @@ func (p *Parser) parseModuleOrNamespaceDeclaration(pos int, hasJSDoc bool, modif } else { name = p.parseIdentifier() } + if isIllegalModuleKeyword { + errorStart := scanner.SkipTrivia(p.sourceText, name.Pos()) + p.parseErrorAt(errorStart, name.End(), diagnostics.A_namespace_declaration_should_not_be_declared_using_the_module_keyword_Please_use_the_namespace_keyword_instead) + } var body *ast.Node if p.parseOptional(ast.KindDotToken) { implicitExport := p.factory.NewModifier(ast.KindExportKeyword) implicitExport.Loc = core.NewTextRange(p.nodePos(), p.nodePos()) implicitExport.Flags = ast.NodeFlagsReparsed implicitModifiers := p.newModifierList(implicitExport.Loc, p.nodeSlicePool.NewSlice1(implicitExport)) - body = p.parseModuleOrNamespaceDeclaration(p.nodePos(), false /*hasJSDoc*/, implicitModifiers, true /*nested*/, keyword) + body = p.parseModuleOrNamespaceDeclaration(p.nodePos(), false /*hasJSDoc*/, implicitModifiers, true /*nested*/, isIllegalModuleKeyword) } else { body = p.parseModuleBlock() } - result := p.finishNode(p.factory.NewModuleDeclaration(modifiers, keyword, name, body), pos) + result := p.finishNode(p.factory.NewModuleDeclaration(modifiers, ast.KindNamespaceKeyword, name, body), pos) p.withJSDoc(result, hasJSDoc) p.checkJSSyntax(result) p.statementHasAwaitIdentifier = saveHasAwaitIdentifier diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go index 174fbf7347f..4590fc1a22c 100644 --- a/internal/printer/printer_test.go +++ b/internal/printer/printer_test.go @@ -255,8 +255,6 @@ func TestEmit(t *testing.T) { {title: "EnumDeclaration#1", input: `enum a{}`, output: "enum a {\n}"}, {title: "EnumDeclaration#2", input: `enum a{b}`, output: "enum a {\n b\n}"}, {title: "EnumDeclaration#3", input: `enum a{b=c}`, output: "enum a {\n b = c\n}"}, - {title: "ModuleDeclaration#1", input: `module a{}`, output: "namespace a { }"}, - {title: "ModuleDeclaration#2", input: `module a.b{}`, output: "namespace a.b { }"}, {title: "ModuleDeclaration#3", input: `module "a";`, output: "module \"a\";"}, {title: "ModuleDeclaration#4", input: `module "a"{}`, output: "module \"a\" { }"}, {title: "ModuleDeclaration#5", input: `namespace a{}`, output: "namespace a { }"}, diff --git a/testdata/baselines/reference/submodule/compiler/escapedIdentifiers.errors.txt b/testdata/baselines/reference/submodule/compiler/escapedIdentifiers.errors.txt index c07e76a48e7..d8ab744fd24 100644 --- a/testdata/baselines/reference/submodule/compiler/escapedIdentifiers.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/escapedIdentifiers.errors.txt @@ -1,8 +1,9 @@ +escapedIdentifiers.ts(25,16): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. escapedIdentifiers.ts(37,12): error TS2564: Property 'foo1' has no initializer and is not definitely assigned in the constructor. escapedIdentifiers.ts(40,12): error TS2564: Property 'foo2' has no initializer and is not definitely assigned in the constructor. -==== escapedIdentifiers.ts (2 errors) ==== +==== escapedIdentifiers.ts (3 errors) ==== /* 0 .. \u0030 9 .. \u0039 @@ -28,6 +29,8 @@ escapedIdentifiers.ts(40,12): error TS2564: Property 'foo2' has no initializer a export var baz1: number; } declare module moduleType\u0032 { + ~~~~~~~~~~~~~~~~ +!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. export var baz2: number; } diff --git a/testdata/baselines/reference/submodule/compiler/escapedIdentifiers.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/escapedIdentifiers.errors.txt.diff deleted file mode 100644 index 557a1343d13..00000000000 --- a/testdata/baselines/reference/submodule/compiler/escapedIdentifiers.errors.txt.diff +++ /dev/null @@ -1,22 +0,0 @@ ---- old.escapedIdentifiers.errors.txt -+++ new.escapedIdentifiers.errors.txt -@@= skipped -0, +0 lines =@@ --escapedIdentifiers.ts(25,16): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. - escapedIdentifiers.ts(37,12): error TS2564: Property 'foo1' has no initializer and is not definitely assigned in the constructor. - escapedIdentifiers.ts(40,12): error TS2564: Property 'foo2' has no initializer and is not definitely assigned in the constructor. - - --==== escapedIdentifiers.ts (3 errors) ==== -+==== escapedIdentifiers.ts (2 errors) ==== - /* - 0 .. \u0030 - 9 .. \u0039 -@@= skipped -28, +27 lines =@@ - export var baz1: number; - } - declare module moduleType\u0032 { -- ~~~~~~~~~~~~~~~~ --!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. - export var baz2: number; - } - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/moduleKeywordDeprecated.errors.txt b/testdata/baselines/reference/submodule/compiler/moduleKeywordDeprecated.errors.txt new file mode 100644 index 00000000000..6f1a31c5eb0 --- /dev/null +++ b/testdata/baselines/reference/submodule/compiler/moduleKeywordDeprecated.errors.txt @@ -0,0 +1,58 @@ +decl.d.ts(1,16): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. +decl.d.ts(2,16): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. +decl.d.ts(2,20): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. +decl.d.ts(7,15): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. +decl.d.ts(8,15): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. +decl.d.ts(8,24): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. +foo.ts(2,8): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. +foo.ts(3,8): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. +foo.ts(3,12): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. +foo.ts(4,16): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. +foo.ts(5,16): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. +foo.ts(5,21): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + + +==== foo.ts (6 errors) ==== + // Error + module notok { } + ~~~~~ +!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + module not.ok { } + ~~~ +!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + ~~ +!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + declare module bad { } + ~~~ +!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + declare module also.bad { } + ~~~~ +!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + ~~~ +!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + + // Still the only way to do it + declare module "good" { } + +==== decl.d.ts (6 errors) ==== + declare module foo { } + ~~~ +!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + declare module foo.bar { } + ~~~ +!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + ~~~ +!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + + // Still the only way to do it + declare module "alsogood" { } + + export module exported { } + ~~~~~~~~ +!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + export module exported.sub { } + ~~~~~~~~ +!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + ~~~ +!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/moduleKeywordDeprecated.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/moduleKeywordDeprecated.errors.txt.diff deleted file mode 100644 index 0ac03eff1b8..00000000000 --- a/testdata/baselines/reference/submodule/compiler/moduleKeywordDeprecated.errors.txt.diff +++ /dev/null @@ -1,62 +0,0 @@ ---- old.moduleKeywordDeprecated.errors.txt -+++ new.moduleKeywordDeprecated.errors.txt -@@= skipped -0, +0 lines =@@ --decl.d.ts(1,16): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. --decl.d.ts(2,16): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. --decl.d.ts(2,20): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. --decl.d.ts(7,15): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. --decl.d.ts(8,15): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. --decl.d.ts(8,24): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. --foo.ts(2,8): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. --foo.ts(3,8): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. --foo.ts(3,12): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. --foo.ts(4,16): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. --foo.ts(5,16): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. --foo.ts(5,21): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. -- -- --==== foo.ts (6 errors) ==== -- // Error -- module notok { } -- ~~~~~ --!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. -- module not.ok { } -- ~~~ --!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. -- ~~ --!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. -- declare module bad { } -- ~~~ --!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. -- declare module also.bad { } -- ~~~~ --!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. -- ~~~ --!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. -- -- // Still the only way to do it -- declare module "good" { } -- --==== decl.d.ts (6 errors) ==== -- declare module foo { } -- ~~~ --!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. -- declare module foo.bar { } -- ~~~ --!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. -- ~~~ --!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. -- -- // Still the only way to do it -- declare module "alsogood" { } -- -- export module exported { } -- ~~~~~~~~ --!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. -- export module exported.sub { } -- ~~~~~~~~ --!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. -- ~~~ --!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. -- -+ \ No newline at end of file From 878236d6b533506114297647406efccdaebdd9ea Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Feb 2026 22:27:46 +0000 Subject: [PATCH 4/5] Skip duplicate errors on nested dotted module names Only report the module keyword error on the first component of dotted names (e.g., `module A.B {}` now only errors on `A`, not both `A` and `B`). The `nested` parameter already tracks this, so just add `!nested` to the error condition. Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com> --- internal/parser/parser.go | 2 +- .../moduleKeywordDeprecated.errors.txt | 16 +---- .../moduleKeywordDeprecated.errors.txt.diff | 63 +++++++++++++++++++ 3 files changed, 66 insertions(+), 15 deletions(-) create mode 100644 testdata/baselines/reference/submodule/compiler/moduleKeywordDeprecated.errors.txt.diff diff --git a/internal/parser/parser.go b/internal/parser/parser.go index 2cd78f1d614..4a812569b09 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -2094,7 +2094,7 @@ func (p *Parser) parseModuleOrNamespaceDeclaration(pos int, hasJSDoc bool, modif } else { name = p.parseIdentifier() } - if isIllegalModuleKeyword { + if isIllegalModuleKeyword && !nested { errorStart := scanner.SkipTrivia(p.sourceText, name.Pos()) p.parseErrorAt(errorStart, name.End(), diagnostics.A_namespace_declaration_should_not_be_declared_using_the_module_keyword_Please_use_the_namespace_keyword_instead) } diff --git a/testdata/baselines/reference/submodule/compiler/moduleKeywordDeprecated.errors.txt b/testdata/baselines/reference/submodule/compiler/moduleKeywordDeprecated.errors.txt index 6f1a31c5eb0..0097455e822 100644 --- a/testdata/baselines/reference/submodule/compiler/moduleKeywordDeprecated.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/moduleKeywordDeprecated.errors.txt @@ -1,26 +1,20 @@ decl.d.ts(1,16): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. decl.d.ts(2,16): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. -decl.d.ts(2,20): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. decl.d.ts(7,15): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. decl.d.ts(8,15): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. -decl.d.ts(8,24): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. foo.ts(2,8): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. foo.ts(3,8): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. -foo.ts(3,12): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. foo.ts(4,16): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. foo.ts(5,16): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. -foo.ts(5,21): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. -==== foo.ts (6 errors) ==== +==== foo.ts (4 errors) ==== // Error module notok { } ~~~~~ !!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. module not.ok { } ~~~ -!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. - ~~ !!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. declare module bad { } ~~~ @@ -28,21 +22,17 @@ foo.ts(5,21): error TS1540: A 'namespace' declaration should not be declared usi declare module also.bad { } ~~~~ !!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. - ~~~ -!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. // Still the only way to do it declare module "good" { } -==== decl.d.ts (6 errors) ==== +==== decl.d.ts (4 errors) ==== declare module foo { } ~~~ !!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. declare module foo.bar { } ~~~ !!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. - ~~~ -!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. // Still the only way to do it declare module "alsogood" { } @@ -53,6 +43,4 @@ foo.ts(5,21): error TS1540: A 'namespace' declaration should not be declared usi export module exported.sub { } ~~~~~~~~ !!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. - ~~~ -!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/moduleKeywordDeprecated.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/moduleKeywordDeprecated.errors.txt.diff new file mode 100644 index 00000000000..de16de510c3 --- /dev/null +++ b/testdata/baselines/reference/submodule/compiler/moduleKeywordDeprecated.errors.txt.diff @@ -0,0 +1,63 @@ +--- old.moduleKeywordDeprecated.errors.txt ++++ new.moduleKeywordDeprecated.errors.txt +@@= skipped -0, +0 lines =@@ + decl.d.ts(1,16): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + decl.d.ts(2,16): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. +-decl.d.ts(2,20): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + decl.d.ts(7,15): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + decl.d.ts(8,15): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. +-decl.d.ts(8,24): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + foo.ts(2,8): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + foo.ts(3,8): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. +-foo.ts(3,12): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + foo.ts(4,16): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + foo.ts(5,16): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. +-foo.ts(5,21): error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. +- +- +-==== foo.ts (6 errors) ==== ++ ++ ++==== foo.ts (4 errors) ==== + // Error + module notok { } + ~~~~~ +@@= skipped -19, +15 lines =@@ + module not.ok { } + ~~~ + !!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. +- ~~ +-!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + declare module bad { } + ~~~ + !!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + declare module also.bad { } + ~~~~ + !!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. +- ~~~ +-!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + + // Still the only way to do it + declare module "good" { } + +-==== decl.d.ts (6 errors) ==== ++==== decl.d.ts (4 errors) ==== + declare module foo { } + ~~~ + !!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + declare module foo.bar { } + ~~~ + !!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. +- ~~~ +-!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + + // Still the only way to do it + declare module "alsogood" { } +@@= skipped -32, +26 lines =@@ + !!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + export module exported.sub { } + ~~~~~~~~ +-!!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. +- ~~~ + !!! error TS1540: A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead. + \ No newline at end of file From 8088408acd2ac81a2be67390a6b55379884a2b48 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Feb 2026 23:38:25 +0000 Subject: [PATCH 5/5] Update local reachabilityChecks11 test to use namespace keyword The local test case at testdata/tests/cases/compiler/reachabilityChecks11.ts used `module` keyword for namespace declarations, which our parser now errors on. Updated to use `namespace` keyword to match the submodule version (which was already updated by TypeScript PR #62876). Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com> --- .../cases/compiler/reachabilityChecks11.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/testdata/tests/cases/compiler/reachabilityChecks11.ts b/testdata/tests/cases/compiler/reachabilityChecks11.ts index 81dbcf3c7ad..abcafb41133 100644 --- a/testdata/tests/cases/compiler/reachabilityChecks11.ts +++ b/testdata/tests/cases/compiler/reachabilityChecks11.ts @@ -4,33 +4,33 @@ // while (true); var x = 1; -module A { +namespace A { while (true); let x; } -module A1 { +namespace A1 { do {} while(true); - module A { + namespace A { interface F {} } } -module A2 { +namespace A2 { while (true); - module A { + namespace A { var x = 1; } } -module A3 { +namespace A3 { while (true); type T = string; } -module A4 { +namespace A4 { while (true); - module A { + namespace A { const enum E { X } } } @@ -51,9 +51,9 @@ function f2() { } } -module B { +namespace B { for (; ;); - module C { + namespace C { } }