Skip to content

Commit a37106d

Browse files
committed
Merge pull request #748 from chrisbubernak/selfReferencingFileError
Fix issue #568 (no error for file self reference)
2 parents 10610bb + 3751b25 commit a37106d

11 files changed

+71
-6
lines changed

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module ts {
55
Unterminated_string_literal: { code: 1002, category: DiagnosticCategory.Error, key: "Unterminated string literal." },
66
Identifier_expected: { code: 1003, category: DiagnosticCategory.Error, key: "Identifier expected." },
77
_0_expected: { code: 1005, category: DiagnosticCategory.Error, key: "'{0}' expected." },
8+
A_file_cannot_have_a_reference_to_itself: { code: 1006, category: DiagnosticCategory.Error, key: "A file cannot have a reference to itself." },
89
Trailing_comma_not_allowed: { code: 1009, category: DiagnosticCategory.Error, key: "Trailing comma not allowed." },
910
Asterisk_Slash_expected: { code: 1010, category: DiagnosticCategory.Error, key: "'*/' expected." },
1011
Unexpected_token: { code: 1012, category: DiagnosticCategory.Error, key: "Unexpected token." },

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
"'{0}' expected.": {
1111
"category": "Error",
1212
"code": 1005
13+
},
14+
"A file cannot have a reference to itself.": {
15+
"category": "Error",
16+
"code": 1006
1317
},
1418
"Trailing comma not allowed.": {
1519
"category": "Error",
@@ -1355,6 +1359,7 @@
13551359
"category": "Error",
13561360
"code": 5001
13571361
},
1362+
13581363
"Cannot find the common subdirectory path for the input files.": {
13591364
"category": "Error",
13601365
"code": 5009

src/compiler/parser.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3831,15 +3831,17 @@ module ts {
38313831
}
38323832
else {
38333833
var matchResult = fullTripleSlashReferencePathRegEx.exec(comment);
3834+
var start = range.pos;
3835+
var end = range.end;
3836+
var length = end - start;
3837+
38343838
if (!matchResult) {
3835-
var start = range.pos;
3836-
var length = range.end - start;
38373839
errorAtPos(start, length, Diagnostics.Invalid_reference_directive_syntax);
38383840
}
38393841
else {
38403842
referencedFiles.push({
3841-
pos: range.pos,
3842-
end: range.end,
3843+
pos: start,
3844+
end: end,
38433845
filename: matchResult[3]
38443846
});
38453847
}
@@ -3956,6 +3958,9 @@ module ts {
39563958
else if (!findSourceFile(filename, isDefaultLib, refFile, refPos, refEnd)) {
39573959
diagnostic = Diagnostics.File_0_not_found;
39583960
}
3961+
else if (refFile && host.getCanonicalFileName(filename) === host.getCanonicalFileName(refFile.filename)) {
3962+
diagnostic = Diagnostics.A_file_cannot_have_a_reference_to_itself;
3963+
}
39593964
}
39603965
else {
39613966
if (!(findSourceFile(filename + ".ts", isDefaultLib, refFile, refPos, refEnd) || findSourceFile(filename + ".d.ts", isDefaultLib, refFile, refPos, refEnd))) {

tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/amd/visibilityOfTypeUsedAcrossModules2.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
main.ts(1,1): error TS1006: A file cannot have a reference to itself.
12
main.ts(2,1): error TS6053: File 'nonExistingFile1.ts' not found.
23
main.ts(3,1): error TS6053: File 'nonExistingFile2.ts' not found.
34

45

5-
==== main.ts (2 errors) ====
6+
==== main.ts (3 errors) ====
67
/// <reference path="main.ts" />
8+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9+
!!! error TS1006: A file cannot have a reference to itself.
710
/// <reference path="nonExistingFile1.ts" />
811
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
912
!!! error TS6053: File 'nonExistingFile1.ts' not found.

tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/node/visibilityOfTypeUsedAcrossModules2.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
main.ts(1,1): error TS1006: A file cannot have a reference to itself.
12
main.ts(2,1): error TS6053: File 'nonExistingFile1.ts' not found.
23
main.ts(3,1): error TS6053: File 'nonExistingFile2.ts' not found.
34

45

5-
==== main.ts (2 errors) ====
6+
==== main.ts (3 errors) ====
67
/// <reference path="main.ts" />
8+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9+
!!! error TS1006: A file cannot have a reference to itself.
710
/// <reference path="nonExistingFile1.ts" />
811
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
912
!!! error TS6053: File 'nonExistingFile1.ts' not found.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tests/cases/compiler/selfReferencingFile.ts(1,1): error TS1006: A file cannot have a reference to itself.
2+
3+
4+
==== tests/cases/compiler/selfReferencingFile.ts (1 errors) ====
5+
///<reference path='selfReferencingFile.ts'/>
6+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7+
!!! error TS1006: A file cannot have a reference to itself.
8+
9+
class selfReferencingFile {
10+
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tests/cases/compiler/selfReferencingFile2.ts(1,1): error TS6053: File 'tests/cases/selfReferencingFile2.ts' not found.
2+
3+
4+
==== tests/cases/compiler/selfReferencingFile2.ts (1 errors) ====
5+
///<reference path='../selfReferencingFile2.ts'/>
6+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7+
!!! error TS6053: File 'selfReferencingFile2.ts' not found.
8+
9+
class selfReferencingFile2 {
10+
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tests/cases/compiler/selfReferencingFile3.ts(1,1): error TS1006: A file cannot have a reference to itself.
2+
3+
4+
==== tests/cases/compiler/selfReferencingFile3.ts (1 errors) ====
5+
///<reference path='./selfReferencingFile3.ts'/>
6+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7+
!!! error TS1006: A file cannot have a reference to itself.
8+
9+
class selfReferencingFile3 {
10+
11+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
///<reference path='selfReferencingFile.ts'/>
2+
3+
class selfReferencingFile {
4+
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
///<reference path='../selfReferencingFile2.ts'/>
2+
3+
class selfReferencingFile2 {
4+
5+
}

0 commit comments

Comments
 (0)