Skip to content

Commit 3a60026

Browse files
Remove version comparison logic and fix diagnostic message ordering
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
1 parent dcfee6e commit 3a60026

File tree

2 files changed

+36
-47
lines changed

2 files changed

+36
-47
lines changed

src/compiler/checker.ts

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -48001,39 +48001,28 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4800148001
const pos = getNonModifierTokenPosOfNode(node);
4800248002
const span = getSpanOfTokenAtPosition(sourceFile, pos);
4800348003

48004-
// Check if we should generate an error (TS 6.0+) or suggestion (older versions)
48005-
const currentVersion = new Version(versionMajorMinor);
48006-
const errorVersion = new Version("6.0");
48007-
const shouldError = currentVersion.compareTo(errorVersion) >= Comparison.EqualTo;
48008-
48009-
// Check if ignoreDeprecations should suppress this error
48010-
let shouldSuppress = false;
48011-
if (shouldError && compilerOptions.ignoreDeprecations) {
48012-
// Only valid ignoreDeprecations values: "5.0" and "6.0"
48013-
if (compilerOptions.ignoreDeprecations === "6.0") {
48014-
shouldSuppress = true;
48015-
}
48016-
}
48017-
48018-
if (shouldError && !shouldSuppress) {
48019-
// In TypeScript 6.0+, this is an error unless suppressed by ignoreDeprecations
48020-
const errorDiagnostic = createFileDiagnostic(
48021-
sourceFile,
48022-
span.start,
48023-
span.length,
48024-
Diagnostics.The_module_keyword_is_not_allowed_for_namespace_declarations_Use_the_namespace_keyword_instead,
48025-
);
48026-
diagnostics.add(errorDiagnostic);
48027-
}
48028-
else {
48029-
// In older versions or when suppressed, keep as suggestion
48030-
const suggestionDiagnostic = createFileDiagnostic(
48031-
sourceFile,
48032-
span.start,
48033-
span.length,
48034-
Diagnostics.A_namespace_declaration_should_not_be_declared_using_the_module_keyword_Please_use_the_namespace_keyword_instead,
48035-
);
48036-
suggestionDiagnostics.add(suggestionDiagnostic);
48004+
// Check if ignoreDeprecations should suppress this error
48005+
const shouldSuppress = compilerOptions.ignoreDeprecations === "6.0";
48006+
48007+
if (!shouldSuppress) {
48008+
// Generate error for module keyword usage in namespace declarations
48009+
const errorDiagnostic = createFileDiagnostic(
48010+
sourceFile,
48011+
span.start,
48012+
span.length,
48013+
Diagnostics.The_module_keyword_is_not_allowed_for_namespace_declarations_Use_the_namespace_keyword_instead,
48014+
);
48015+
diagnostics.add(errorDiagnostic);
48016+
}
48017+
else {
48018+
// When suppressed by ignoreDeprecations, keep as suggestion
48019+
const suggestionDiagnostic = createFileDiagnostic(
48020+
sourceFile,
48021+
span.start,
48022+
span.length,
48023+
Diagnostics.A_namespace_declaration_should_not_be_declared_using_the_module_keyword_Please_use_the_namespace_keyword_instead,
48024+
);
48025+
suggestionDiagnostics.add(suggestionDiagnostic);
4803748026
}
4803848027
}
4803948028
}

src/compiler/diagnosticMessages.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,15 +1820,11 @@
18201820
"category": "Error",
18211821
"code": 1539
18221822
},
1823-
"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
1827-
},
1828-
"The 'module' keyword is not allowed for namespace declarations. Use the 'namespace' keyword instead.": {
1829-
"category": "Error",
1830-
"code": 1547
1831-
},
1823+
"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
1827+
},
18321828
"Type-only import of an ECMAScript module from a CommonJS module must have a 'resolution-mode' attribute.": {
18331829
"category": "Error",
18341830
"code": 1541
@@ -1849,11 +1845,15 @@
18491845
"category": "Error",
18501846
"code": 1545
18511847
},
1852-
"'await using' declarations are not allowed in ambient contexts.": {
1853-
"category": "Error",
1854-
"code": 1546
1855-
},
1856-
1848+
"'await using' declarations are not allowed in ambient contexts.": {
1849+
"category": "Error",
1850+
"code": 1546
1851+
},
1852+
"The 'module' keyword is not allowed for namespace declarations. Use the 'namespace' keyword instead.": {
1853+
"category": "Error",
1854+
"code": 1547
1855+
},
1856+
18571857
"The types of '{0}' are incompatible between these types.": {
18581858
"category": "Error",
18591859
"code": 2200

0 commit comments

Comments
 (0)