Skip to content

Commit afeabe8

Browse files
committed
Merge pull request #365 from Microsoft/extensionlessReferences
Support extensionless <reference> comments.
2 parents 97987b1 + a2a6b8a commit afeabe8

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

src/compiler/parser.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3580,24 +3580,31 @@ module ts {
35803580
return filter(errors, e => !e.file);
35813581
}
35823582

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

35873587
function processRootFile(filename: string, isDefaultLib: boolean) {
3588-
processSourceFile(normalizePath(addExtension(filename, ".ts")), isDefaultLib);
3588+
processSourceFile(normalizePath(filename), isDefaultLib);
35893589
}
35903590

35913591
function processSourceFile(filename: string, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number) {
35923592
if (refEnd !== undefined && refPos !== undefined) {
35933593
var start = refPos;
35943594
var length = refEnd - refPos;
35953595
}
3596-
if (!fileExtensionIs(filename, ".ts")) {
3597-
errors.push(createFileDiagnostic(refFile, start, length, Diagnostics.File_0_must_have_extension_ts_or_d_ts, filename));
3596+
if (hasExtension(filename)) {
3597+
if (!fileExtensionIs(filename, ".ts")) {
3598+
errors.push(createFileDiagnostic(refFile, start, length, Diagnostics.File_0_must_have_extension_ts_or_d_ts, filename));
3599+
}
3600+
else if (!findSourceFile(filename, isDefaultLib, refFile, refPos, refEnd)) {
3601+
errors.push(createFileDiagnostic(refFile, start, length, Diagnostics.File_0_not_found, filename));
3602+
}
35983603
}
3599-
else if (!findSourceFile(filename, isDefaultLib, refFile, refPos, refEnd)) {
3600-
errors.push(createFileDiagnostic(refFile, start, length, Diagnostics.File_0_not_found, filename));
3604+
else {
3605+
if (!(findSourceFile(filename + ".ts", isDefaultLib, refFile, refPos, refEnd) || findSourceFile(filename + ".d.ts", isDefaultLib, refFile, refPos, refEnd))) {
3606+
errors.push(createFileDiagnostic(refFile, start, length, Diagnostics.File_0_not_found, filename + ".ts"));
3607+
}
36013608
}
36023609
}
36033610

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// @Filename: t.ts
2+
/// <reference path="a"/>
3+
/// <reference path="b"/>
4+
/// <reference path="c"/>
5+
var a = aa; // Check that a.ts is referenced
6+
var b = bb; // Check that b.d.ts is referenced
7+
var c = cc; // Check that c.ts has precedence over c.d.ts
8+
9+
// @Filename: a.ts
10+
var aa = 1;
11+
12+
// @Filename: b.d.ts
13+
declare var bb: number;
14+
15+
// @Filename: c.ts
16+
var cc = 1;
17+
18+
// @Filename: c.d.ts
19+
declare var xx: number;

0 commit comments

Comments
 (0)