Merge pull request #365 from Microsoft/extensionlessReferences

Support extensionless <reference> comments.
This commit is contained in:
Anders Hejlsberg 2014-08-05 15:02:03 -07:00
commit afeabe8100
2 changed files with 33 additions and 7 deletions

View file

@ -3580,12 +3580,12 @@ 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) {
@ -3593,11 +3593,18 @@ module ts {
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"));
}
}
}

View file

@ -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;