From 3a6002642feb405b172b058a65bba84b4fca0652 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 4 Sep 2025 15:45:51 +0000 Subject: [PATCH] Remove version comparison logic and fix diagnostic message ordering Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com> --- src/compiler/checker.ts | 55 +++++++++++----------------- src/compiler/diagnosticMessages.json | 28 +++++++------- 2 files changed, 36 insertions(+), 47 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7cedd0c48c7..c8115ead565 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -48001,39 +48001,28 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const pos = getNonModifierTokenPosOfNode(node); const span = getSpanOfTokenAtPosition(sourceFile, pos); - // Check if we should generate an error (TS 6.0+) or suggestion (older versions) - const currentVersion = new Version(versionMajorMinor); - const errorVersion = new Version("6.0"); - const shouldError = currentVersion.compareTo(errorVersion) >= Comparison.EqualTo; - - // Check if ignoreDeprecations should suppress this error - let shouldSuppress = false; - if (shouldError && compilerOptions.ignoreDeprecations) { - // Only valid ignoreDeprecations values: "5.0" and "6.0" - if (compilerOptions.ignoreDeprecations === "6.0") { - shouldSuppress = true; - } - } - - if (shouldError && !shouldSuppress) { - // In TypeScript 6.0+, this is an error unless suppressed by ignoreDeprecations - 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); - } - else { - // In older versions or when suppressed, 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); + // Check if ignoreDeprecations should suppress this error + const shouldSuppress = compilerOptions.ignoreDeprecations === "6.0"; + + if (!shouldSuppress) { + // 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); + } + else { + // 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); } } } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 7d6c8ba5ab3..f1ea9a7b064 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1820,15 +1820,11 @@ "category": "Error", "code": 1539 }, - "A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead.": { - "category": "Suggestion", - "code": 1540, - "reportsDeprecated": true - }, - "The 'module' keyword is not allowed for namespace declarations. Use the 'namespace' keyword instead.": { - "category": "Error", - "code": 1547 - }, + "A 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword instead.": { + "category": "Suggestion", + "code": 1540, + "reportsDeprecated": true + }, "Type-only import of an ECMAScript module from a CommonJS module must have a 'resolution-mode' attribute.": { "category": "Error", "code": 1541 @@ -1849,11 +1845,15 @@ "category": "Error", "code": 1545 }, - "'await using' declarations are not allowed in ambient contexts.": { - "category": "Error", - "code": 1546 - }, - + "'await using' declarations are not allowed in ambient contexts.": { + "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", "code": 2200