Skip to content

Commit 1993387

Browse files
committed
Update error message
1 parent cc41daa commit 1993387

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ module ts {
496496
Corrupted_locale_file_0: { code: 6051, category: DiagnosticCategory.Error, key: "Corrupted locale file {0}." },
497497
Raise_error_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: DiagnosticCategory.Message, key: "Raise error on expressions and declarations with an implied 'any' type." },
498498
File_0_not_found: { code: 6053, category: DiagnosticCategory.Error, key: "File '{0}' not found." },
499-
File_0_must_have_extension_ts_or_d_ts: { code: 6054, category: DiagnosticCategory.Error, key: "File '{0}' must have extension '.ts' or '.d.ts'." },
499+
File_0_has_unsupported_extension_The_only_supported_extensions_are_1: { code: 6054, category: DiagnosticCategory.Error, key: "File '{0}' has unsupported extension. The only supported extensions are {1}." },
500500
Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." },
501501
Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." },
502502
Preserve_new_lines_when_emitting_code: { code: 6057, category: DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." },

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1974,7 +1974,7 @@
19741974
"category": "Error",
19751975
"code": 6053
19761976
},
1977-
"File '{0}' must have extension '.ts' or '.d.ts'.": {
1977+
"File '{0}' has unsupported extension. The only supported extensions are {1}.": {
19781978
"category": "Error",
19791979
"code": 6054
19801980
},

src/compiler/program.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,38 +307,45 @@ module ts {
307307
function processSourceFile(fileName: string, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number) {
308308
let start: number;
309309
let length: number;
310+
let extensions: string;
311+
let diagnosticArgument: string[];
310312
if (refEnd !== undefined && refPos !== undefined) {
311313
start = refPos;
312314
length = refEnd - refPos;
313315
}
314316
let diagnostic: DiagnosticMessage;
315317
if (hasExtension(fileName)) {
316318
if (!options.allowNonTsExtensions && !forEach(supportedExtensions, extension => fileExtensionIs(host.getCanonicalFileName(fileName), extension))) {
317-
diagnostic = Diagnostics.File_0_must_have_extension_ts_or_d_ts;
319+
diagnostic = Diagnostics.File_0_has_unsupported_extension_The_only_supported_extensions_are_1;
320+
diagnosticArgument = [fileName, "'" + supportedExtensions.join("', '") + "'"];
318321
}
319322
else if (!findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) {
320323
diagnostic = Diagnostics.File_0_not_found;
324+
diagnosticArgument = [fileName];
321325
}
322326
else if (refFile && host.getCanonicalFileName(fileName) === host.getCanonicalFileName(refFile.fileName)) {
323327
diagnostic = Diagnostics.A_file_cannot_have_a_reference_to_itself;
328+
diagnosticArgument = [fileName];
324329
}
325330
}
326331
else {
327332
if (options.allowNonTsExtensions && !findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) {
328333
diagnostic = Diagnostics.File_0_not_found;
334+
diagnosticArgument = [fileName];
329335
}
330336
else if (!forEach(supportedExtensions, extension => findSourceFile(fileName + extension, isDefaultLib, refFile, refPos, refEnd))) {
331337
diagnostic = Diagnostics.File_0_not_found;
332338
fileName += ".ts";
339+
diagnosticArgument = [fileName];
333340
}
334341
}
335342

336343
if (diagnostic) {
337344
if (refFile) {
338-
diagnostics.add(createFileDiagnostic(refFile, start, length, diagnostic, fileName));
345+
diagnostics.add(createFileDiagnostic(refFile, start, length, diagnostic, ...diagnosticArgument));
339346
}
340347
else {
341-
diagnostics.add(createCompilerDiagnostic(diagnostic, fileName));
348+
diagnostics.add(createCompilerDiagnostic(diagnostic, ...diagnosticArgument));
342349
}
343350
}
344351
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
error TS6054: File 'a.t' must have extension '.ts' or '.d.ts'.
1+
error TS6054: File 'a.t' has unsupported extension. The only supported extensions are '.ts', '.d.ts'.
22
error TS6053: File 'a.ts' not found.
33

44

5-
!!! error TS6054: File 'a.t' must have extension '.ts' or '.d.ts'.
5+
!!! error TS6054: File 'a.t' has unsupported extension. The only supported extensions are '.ts', '.d.ts'.
66
!!! error TS6053: File 'a.ts' not found.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
error TS6054: File 'a.t' must have extension '.ts' or '.d.ts'.
1+
error TS6054: File 'a.t' has unsupported extension. The only supported extensions are '.ts', '.d.ts'.
22
error TS6053: File 'a.ts' not found.
33

44

5-
!!! error TS6054: File 'a.t' must have extension '.ts' or '.d.ts'.
5+
!!! error TS6054: File 'a.t' has unsupported extension. The only supported extensions are '.ts', '.d.ts'.
66
!!! error TS6053: File 'a.ts' not found.

0 commit comments

Comments
 (0)