Skip to content
Draft
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
27 changes: 24 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47998,9 +47998,30 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const sourceFile = getSourceFileOfNode(node);
const pos = getNonModifierTokenPosOfNode(node);
const span = getSpanOfTokenAtPosition(sourceFile, pos);
suggestionDiagnostics.add(
createFileDiagnostic(sourceFile, span.start, span.length, Diagnostics.A_namespace_declaration_should_not_be_declared_using_the_module_keyword_Please_use_the_namespace_keyword_instead),
);

// Check if ignoreDeprecations should suppress this error
const shouldSuppress = compilerOptions.ignoreDeprecations === "6.0";

if (shouldSuppress) {
// When suppressed by ignoreDeprecations, keep as suggestion
const suggestionDiagnostic = createFileDiagnostic(
sourceFile,
span.start,
span.length,
Diagnostics.A_namespace_declaration_should_not_be_declared_using_the_module_keyword_Please_use_the_namespace_keyword_instead,
);
suggestionDiagnostics.add(suggestionDiagnostic);
}
else {
// Generate error for module keyword usage in namespace declarations
const errorDiagnostic = createFileDiagnostic(
sourceFile,
span.start,
span.length,
Diagnostics.The_module_keyword_is_not_allowed_for_namespace_declarations_Use_the_namespace_keyword_instead,
);
diagnostics.add(errorDiagnostic);
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1849,6 +1849,10 @@
"category": "Error",
"code": 1546
},
"The 'module' keyword is not allowed for namespace declarations. Use the 'namespace' keyword instead.": {
"category": "Error",
"code": 1547
},

"The types of '{0}' are incompatible between these types.": {
"category": "Error",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//// [tests/cases/conformance/internalModules/DeclarationMerging/AmbientModuleAndAmbientFunctionWithTheSameNameAndCommonRoot.ts] ////

//// [module.d.ts]
declare module Point {
declare namespace Point {
export var Origin: { x: number; y: number; }
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//// [tests/cases/conformance/internalModules/DeclarationMerging/AmbientModuleAndAmbientFunctionWithTheSameNameAndCommonRoot.ts] ////

=== module.d.ts ===
declare module Point {
declare namespace Point {
>Point : Symbol(Point, Decl(module.d.ts, 0, 0), Decl(function.d.ts, 0, 0))

export var Origin: { x: number; y: number; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//// [tests/cases/conformance/internalModules/DeclarationMerging/AmbientModuleAndAmbientFunctionWithTheSameNameAndCommonRoot.ts] ////

=== module.d.ts ===
declare module Point {
declare namespace Point {
>Point : typeof Point
> : ^^^^^^^^^^^^

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//// [tests/cases/conformance/internalModules/DeclarationMerging/AmbientModuleAndAmbientWithSameNameAndCommonRoot.ts] ////

//// [module.d.ts]
declare module A {
export module Point {
declare namespace A {
export namespace Point {
export var Origin: {
x: number;
y: number;
Expand All @@ -11,7 +11,7 @@ declare module A {
}

//// [class.d.ts]
declare module A {
declare namespace A {
export class Point {
constructor(x: number, y: number);
x: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//// [tests/cases/conformance/internalModules/DeclarationMerging/AmbientModuleAndAmbientWithSameNameAndCommonRoot.ts] ////

=== module.d.ts ===
declare module A {
declare namespace A {
>A : Symbol(A, Decl(module.d.ts, 0, 0), Decl(class.d.ts, 0, 0))

export module Point {
>Point : Symbol(Point, Decl(module.d.ts, 0, 18), Decl(class.d.ts, 0, 18))
export namespace Point {
>Point : Symbol(Point, Decl(module.d.ts, 0, 21), Decl(class.d.ts, 0, 21))

export var Origin: {
>Origin : Symbol(Origin, Decl(module.d.ts, 2, 18))
Expand All @@ -20,11 +20,11 @@ declare module A {
}

=== class.d.ts ===
declare module A {
declare namespace A {
>A : Symbol(A, Decl(module.d.ts, 0, 0), Decl(class.d.ts, 0, 0))

export class Point {
>Point : Symbol(Point, Decl(module.d.ts, 0, 18), Decl(class.d.ts, 0, 18))
>Point : Symbol(Point, Decl(module.d.ts, 0, 21), Decl(class.d.ts, 0, 21))

constructor(x: number, y: number);
>x : Symbol(x, Decl(class.d.ts, 2, 20))
Expand All @@ -47,14 +47,14 @@ var p: { x: number; y: number; }
var p = A.Point.Origin;
>p : Symbol(p, Decl(test.ts, 0, 3), Decl(test.ts, 1, 3), Decl(test.ts, 2, 3))
>A.Point.Origin : Symbol(A.Point.Origin, Decl(module.d.ts, 2, 18))
>A.Point : Symbol(A.Point, Decl(module.d.ts, 0, 18), Decl(class.d.ts, 0, 18))
>A.Point : Symbol(A.Point, Decl(module.d.ts, 0, 21), Decl(class.d.ts, 0, 21))
>A : Symbol(A, Decl(module.d.ts, 0, 0), Decl(class.d.ts, 0, 0))
>Point : Symbol(A.Point, Decl(module.d.ts, 0, 18), Decl(class.d.ts, 0, 18))
>Point : Symbol(A.Point, Decl(module.d.ts, 0, 21), Decl(class.d.ts, 0, 21))
>Origin : Symbol(A.Point.Origin, Decl(module.d.ts, 2, 18))

var p = new A.Point(0, 0); // unexpected error here, bug 840000
>p : Symbol(p, Decl(test.ts, 0, 3), Decl(test.ts, 1, 3), Decl(test.ts, 2, 3))
>A.Point : Symbol(A.Point, Decl(module.d.ts, 0, 18), Decl(class.d.ts, 0, 18))
>A.Point : Symbol(A.Point, Decl(module.d.ts, 0, 21), Decl(class.d.ts, 0, 21))
>A : Symbol(A, Decl(module.d.ts, 0, 0), Decl(class.d.ts, 0, 0))
>Point : Symbol(A.Point, Decl(module.d.ts, 0, 18), Decl(class.d.ts, 0, 18))
>Point : Symbol(A.Point, Decl(module.d.ts, 0, 21), Decl(class.d.ts, 0, 21))

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//// [tests/cases/conformance/internalModules/DeclarationMerging/AmbientModuleAndAmbientWithSameNameAndCommonRoot.ts] ////

=== module.d.ts ===
declare module A {
declare namespace A {
>A : typeof A
> : ^^^^^^^^

export module Point {
export namespace Point {
>Point : typeof Point
> : ^^^^^^^^^^^^

Expand All @@ -25,7 +25,7 @@ declare module A {
}

=== class.d.ts ===
declare module A {
declare namespace A {
>A : typeof A
> : ^^^^^^^^

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//// [tests/cases/conformance/internalModules/DeclarationMerging/AmbientModuleAndNonAmbientClassWithSameNameAndCommonRoot.ts] ////

//// [module.d.ts]
declare module A {
export module Point {
declare namespace A {
export namespace Point {
export var Origin: {
x: number;
y: number;
Expand All @@ -11,7 +11,7 @@ declare module A {
}

//// [classPoint.ts]
module A {
namespace A {
export class Point {
constructor(public x: number, public y: number) { }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//// [tests/cases/conformance/internalModules/DeclarationMerging/AmbientModuleAndNonAmbientClassWithSameNameAndCommonRoot.ts] ////

=== module.d.ts ===
declare module A {
declare namespace A {
>A : Symbol(A, Decl(module.d.ts, 0, 0), Decl(classPoint.ts, 0, 0))

export module Point {
>Point : Symbol(Point, Decl(module.d.ts, 0, 18), Decl(classPoint.ts, 0, 10))
export namespace Point {
>Point : Symbol(Point, Decl(module.d.ts, 0, 21), Decl(classPoint.ts, 0, 13))

export var Origin: {
>Origin : Symbol(Origin, Decl(module.d.ts, 2, 18))
Expand All @@ -20,11 +20,11 @@ declare module A {
}

=== classPoint.ts ===
module A {
namespace A {
>A : Symbol(A, Decl(module.d.ts, 0, 0), Decl(classPoint.ts, 0, 0))

export class Point {
>Point : Symbol(Point, Decl(module.d.ts, 0, 18), Decl(classPoint.ts, 0, 10))
>Point : Symbol(Point, Decl(module.d.ts, 0, 21), Decl(classPoint.ts, 0, 13))

constructor(public x: number, public y: number) { }
>x : Symbol(Point.x, Decl(classPoint.ts, 2, 20))
Expand All @@ -41,14 +41,14 @@ var p: { x: number; y: number; }
var p = A.Point.Origin;
>p : Symbol(p, Decl(test.ts, 0, 3), Decl(test.ts, 1, 3), Decl(test.ts, 2, 3))
>A.Point.Origin : Symbol(A.Point.Origin, Decl(module.d.ts, 2, 18))
>A.Point : Symbol(A.Point, Decl(module.d.ts, 0, 18), Decl(classPoint.ts, 0, 10))
>A.Point : Symbol(A.Point, Decl(module.d.ts, 0, 21), Decl(classPoint.ts, 0, 13))
>A : Symbol(A, Decl(module.d.ts, 0, 0), Decl(classPoint.ts, 0, 0))
>Point : Symbol(A.Point, Decl(module.d.ts, 0, 18), Decl(classPoint.ts, 0, 10))
>Point : Symbol(A.Point, Decl(module.d.ts, 0, 21), Decl(classPoint.ts, 0, 13))
>Origin : Symbol(A.Point.Origin, Decl(module.d.ts, 2, 18))

var p = new A.Point(0, 0); // unexpected error here, bug 840000
>p : Symbol(p, Decl(test.ts, 0, 3), Decl(test.ts, 1, 3), Decl(test.ts, 2, 3))
>A.Point : Symbol(A.Point, Decl(module.d.ts, 0, 18), Decl(classPoint.ts, 0, 10))
>A.Point : Symbol(A.Point, Decl(module.d.ts, 0, 21), Decl(classPoint.ts, 0, 13))
>A : Symbol(A, Decl(module.d.ts, 0, 0), Decl(classPoint.ts, 0, 0))
>Point : Symbol(A.Point, Decl(module.d.ts, 0, 18), Decl(classPoint.ts, 0, 10))
>Point : Symbol(A.Point, Decl(module.d.ts, 0, 21), Decl(classPoint.ts, 0, 13))

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//// [tests/cases/conformance/internalModules/DeclarationMerging/AmbientModuleAndNonAmbientClassWithSameNameAndCommonRoot.ts] ////

=== module.d.ts ===
declare module A {
declare namespace A {
>A : typeof A
> : ^^^^^^^^

export module Point {
export namespace Point {
>Point : typeof Point
> : ^^^^^^^^^^^^

Expand All @@ -25,7 +25,7 @@ declare module A {
}

=== classPoint.ts ===
module A {
namespace A {
>A : typeof A
> : ^^^^^^^^

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//// [tests/cases/conformance/internalModules/DeclarationMerging/AmbientModuleAndNonAmbientFunctionWithTheSameNameAndCommonRoot.ts] ////

//// [module.d.ts]
declare module Point {
declare namespace Point {
export var Origin: { x: number; y: number; }
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//// [tests/cases/conformance/internalModules/DeclarationMerging/AmbientModuleAndNonAmbientFunctionWithTheSameNameAndCommonRoot.ts] ////

=== module.d.ts ===
declare module Point {
declare namespace Point {
>Point : Symbol(Point, Decl(module.d.ts, 0, 0), Decl(function.ts, 0, 0))

export var Origin: { x: number; y: number; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//// [tests/cases/conformance/internalModules/DeclarationMerging/AmbientModuleAndNonAmbientFunctionWithTheSameNameAndCommonRoot.ts] ////

=== module.d.ts ===
declare module Point {
declare namespace Point {
>Point : typeof Point
> : ^^^^^^^^^^^^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts(46,15): err
value: T;
}

module clodule1 {
namespace clodule1 {
function f(x: T) { }
~
!!! error TS2304: Cannot find name 'T'.
Expand All @@ -26,7 +26,7 @@ ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts(46,15): err
value: T;
}

module clodule2 {
namespace clodule2 {
var x: T;
~
!!! error TS2304: Cannot find name 'T'.
Expand All @@ -45,7 +45,7 @@ ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts(46,15): err
value: T;
}

module clodule3 {
namespace clodule3 {
export var y = { id: T };
~
!!! error TS2304: Cannot find name 'T'.
Expand All @@ -57,7 +57,7 @@ ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts(46,15): err
value: T;
}

module clodule4 {
namespace clodule4 {
class D {
name: T;
~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class clodule1<T>{
value: T;
}

module clodule1 {
namespace clodule1 {
function f(x: T) { }
}

Expand All @@ -19,7 +19,7 @@ class clodule2<T>{
value: T;
}

module clodule2 {
namespace clodule2 {
var x: T;

class D<U extends T>{
Expand All @@ -34,7 +34,7 @@ class clodule3<T>{
value: T;
}

module clodule3 {
namespace clodule3 {
export var y = { id: T };
}

Expand All @@ -44,7 +44,7 @@ class clodule4<T>{
value: T;
}

module clodule4 {
namespace clodule4 {
class D {
name: T;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class clodule1<T>{
>T : Symbol(T, Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 2, 15))
}

module clodule1 {
namespace clodule1 {
>clodule1 : Symbol(clodule1, Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 0, 0), Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 6, 1))

function f(x: T) { }
>f : Symbol(f, Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 8, 17))
>f : Symbol(f, Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 8, 20))
>x : Symbol(x, Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 9, 15))
>T : Symbol(T)
}
Expand All @@ -36,7 +36,7 @@ class clodule2<T>{
>T : Symbol(T, Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 12, 15))
}

module clodule2 {
namespace clodule2 {
>clodule2 : Symbol(clodule2, Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 10, 1), Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 16, 1))

var x: T;
Expand Down Expand Up @@ -69,7 +69,7 @@ class clodule3<T>{
>T : Symbol(T, Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 27, 15))
}

module clodule3 {
namespace clodule3 {
>clodule3 : Symbol(clodule3, Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 25, 1), Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 31, 1))

export var y = { id: T };
Expand All @@ -89,11 +89,11 @@ class clodule4<T>{
>T : Symbol(T, Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 37, 15))
}

module clodule4 {
namespace clodule4 {
>clodule4 : Symbol(clodule4, Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 35, 1), Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 41, 1))

class D {
>D : Symbol(D, Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 43, 17))
>D : Symbol(D, Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 43, 20))

name: T;
>name : Symbol(D.name, Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 44, 13))
Expand Down
Loading