Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3580,24 +3580,31 @@ module ts {
return filter(errors, e => !e.file);
}

function addExtension(filename: string, extension: string): string {
return getBaseFilename(filename).indexOf(".") >= 0 ? filename : filename + extension;
function hasExtension(filename: string): boolean {
return getBaseFilename(filename).indexOf(".") >= 0;
}

function processRootFile(filename: string, isDefaultLib: boolean) {
processSourceFile(normalizePath(addExtension(filename, ".ts")), isDefaultLib);
processSourceFile(normalizePath(filename), isDefaultLib);
}

function processSourceFile(filename: string, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number) {
if (refEnd !== undefined && refPos !== undefined) {
var start = refPos;
var length = refEnd - refPos;
}
if (!fileExtensionIs(filename, ".ts")) {
errors.push(createFileDiagnostic(refFile, start, length, Diagnostics.File_0_must_have_extension_ts_or_d_ts, filename));
if (hasExtension(filename)) {
if (!fileExtensionIs(filename, ".ts")) {
errors.push(createFileDiagnostic(refFile, start, length, Diagnostics.File_0_must_have_extension_ts_or_d_ts, filename));
}
else if (!findSourceFile(filename, isDefaultLib, refFile, refPos, refEnd)) {
errors.push(createFileDiagnostic(refFile, start, length, Diagnostics.File_0_not_found, filename));
}
}
else if (!findSourceFile(filename, isDefaultLib, refFile, refPos, refEnd)) {
errors.push(createFileDiagnostic(refFile, start, length, Diagnostics.File_0_not_found, filename));
else {
if (!(findSourceFile(filename + ".ts", isDefaultLib, refFile, refPos, refEnd) || findSourceFile(filename + ".d.ts", isDefaultLib, refFile, refPos, refEnd))) {
errors.push(createFileDiagnostic(refFile, start, length, Diagnostics.File_0_not_found, filename + ".ts"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error message is a bit misleading since it says only about failed attempt to find .ts file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but honestly not worth it to add another error message.

}
}
}

Expand Down
19 changes: 19 additions & 0 deletions tests/cases/compiler/fileReferencesWithNoExtensions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @Filename: t.ts
/// <reference path="a"/>
/// <reference path="b"/>
/// <reference path="c"/>
var a = aa; // Check that a.ts is referenced
var b = bb; // Check that b.d.ts is referenced
var c = cc; // Check that c.ts has precedence over c.d.ts

// @Filename: a.ts
var aa = 1;

// @Filename: b.d.ts
declare var bb: number;

// @Filename: c.ts
var cc = 1;

// @Filename: c.d.ts
declare var xx: number;