Skip to content

Commit 16b933f

Browse files
Deprecate module syntax (#62876)
1 parent c84cb94 commit 16b933f

File tree

104 files changed

+487
-242
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+487
-242
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,6 @@ import {
347347
getNamespaceDeclarationNode,
348348
getNewTargetContainer,
349349
getNonAugmentationDeclaration,
350-
getNonModifierTokenPosOfNode,
351350
getNormalizedAbsolutePath,
352351
getObjectFlags,
353352
getOriginalNode,
@@ -48121,12 +48120,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4812148120
if (isIdentifier(node.name)) {
4812248121
checkCollisionsForDeclarationName(node, node.name);
4812348122
if (!(node.flags & (NodeFlags.Namespace | NodeFlags.GlobalAugmentation))) {
48124-
const sourceFile = getSourceFileOfNode(node);
48125-
const pos = getNonModifierTokenPosOfNode(node);
48126-
const span = getSpanOfTokenAtPosition(sourceFile, pos);
48127-
suggestionDiagnostics.add(
48128-
createFileDiagnostic(sourceFile, span.start, span.length, Diagnostics.A_namespace_declaration_should_not_be_declared_using_the_module_keyword_Please_use_the_namespace_keyword_instead),
48129-
);
48123+
error(node.name, Diagnostics.A_namespace_declaration_should_not_be_declared_using_the_module_keyword_Please_use_the_namespace_keyword_instead);
4813048124
}
4813148125
}
4813248126

src/compiler/diagnosticMessages.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,9 +1821,8 @@
18211821
"code": 1539
18221822
},
18231823
"A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead.": {
1824-
"category": "Suggestion",
1825-
"code": 1540,
1826-
"reportsDeprecated": true
1824+
"category": "Error",
1825+
"code": 1540
18271826
},
18281827
"Type-only import of an ECMAScript module from a CommonJS module must have a 'resolution-mode' attribute.": {
18291828
"category": "Error",

src/compiler/utilities.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,16 +1282,6 @@ export function getNonDecoratorTokenPosOfNode(node: Node, sourceFile?: SourceFil
12821282
return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, lastDecorator.end);
12831283
}
12841284

1285-
/** @internal */
1286-
export function getNonModifierTokenPosOfNode(node: Node, sourceFile?: SourceFileLike): number {
1287-
const lastModifier = !nodeIsMissing(node) && canHaveModifiers(node) && node.modifiers ? last(node.modifiers) : undefined;
1288-
if (!lastModifier) {
1289-
return getTokenPosOfNode(node, sourceFile);
1290-
}
1291-
1292-
return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, lastModifier.end);
1293-
}
1294-
12951285
/** @internal */
12961286
export function getSourceTextOfNodeFromSourceFile(sourceFile: SourceFile, node: Node, includeTrivia = false): string {
12971287
return getTextOfNodeFromSourceText(sourceFile.text, node, includeTrivia);

tests/baselines/reference/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName.ts(26,26): error
1414
}
1515
}
1616

17-
module A{
17+
namespace A{
1818
// expected error
1919
export class Point {
2020
~~~~~

tests/baselines/reference/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace A {
88
}
99
}
1010

11-
module A{
11+
namespace A{
1212
// expected error
1313
export class Point {
1414
origin: number;

tests/baselines/reference/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName.symbols

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ namespace A {
1515
}
1616
}
1717

18-
module A{
18+
namespace A{
1919
>A : Symbol(A, Decl(TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName.ts, 0, 0), Decl(TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName.ts, 5, 1))
2020

2121
// expected error
2222
export class Point {
23-
>Point : Symbol(Point, Decl(TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName.ts, 7, 9))
23+
>Point : Symbol(Point, Decl(TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName.ts, 7, 12))
2424

2525
origin: number;
2626
>origin : Symbol(Point.origin, Decl(TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName.ts, 9, 24))

tests/baselines/reference/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace A {
1919
}
2020
}
2121

22-
module A{
22+
namespace A{
2323
>A : typeof A
2424
> : ^^^^^^^^
2525

tests/baselines/reference/TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace A.B {
55
export var x: number;
66
}
77

8-
module A{
8+
namespace A{
99
namespace B {
1010
export var x: string;
1111
}

tests/baselines/reference/TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName.symbols

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ namespace A.B {
99
>x : Symbol(x, Decl(TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName.ts, 1, 14))
1010
}
1111

12-
module A{
12+
namespace A{
1313
>A : Symbol(A, Decl(TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName.ts, 0, 0), Decl(TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName.ts, 2, 1))
1414

1515
namespace B {
16-
>B : Symbol(B, Decl(TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName.ts, 4, 9))
16+
>B : Symbol(B, Decl(TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName.ts, 4, 12))
1717

1818
export var x: string;
1919
>x : Symbol(x, Decl(TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName.ts, 6, 18))

tests/baselines/reference/TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace A.B {
1212
> : ^^^^^^
1313
}
1414

15-
module A{
15+
namespace A{
1616
>A : typeof A
1717
> : ^^^^^^^^
1818

0 commit comments

Comments
 (0)