Merge pull request #748 from chrisbubernak/selfReferencingFileError

Fix issue #568 (no error for file self reference)
This commit is contained in:
Mohamed Hegazy
2014-10-01 13:44:47 -07:00
11 changed files with 71 additions and 6 deletions

View File

@@ -5,6 +5,7 @@ module ts {
Unterminated_string_literal: { code: 1002, category: DiagnosticCategory.Error, key: "Unterminated string literal." },
Identifier_expected: { code: 1003, category: DiagnosticCategory.Error, key: "Identifier expected." },
_0_expected: { code: 1005, category: DiagnosticCategory.Error, key: "'{0}' expected." },
A_file_cannot_have_a_reference_to_itself: { code: 1006, category: DiagnosticCategory.Error, key: "A file cannot have a reference to itself." },
Trailing_comma_not_allowed: { code: 1009, category: DiagnosticCategory.Error, key: "Trailing comma not allowed." },
Asterisk_Slash_expected: { code: 1010, category: DiagnosticCategory.Error, key: "'*/' expected." },
Unexpected_token: { code: 1012, category: DiagnosticCategory.Error, key: "Unexpected token." },

View File

@@ -10,6 +10,10 @@
"'{0}' expected.": {
"category": "Error",
"code": 1005
},
"A file cannot have a reference to itself.": {
"category": "Error",
"code": 1006
},
"Trailing comma not allowed.": {
"category": "Error",
@@ -1355,6 +1359,7 @@
"category": "Error",
"code": 5001
},
"Cannot find the common subdirectory path for the input files.": {
"category": "Error",
"code": 5009

View File

@@ -3831,15 +3831,17 @@ module ts {
}
else {
var matchResult = fullTripleSlashReferencePathRegEx.exec(comment);
var start = range.pos;
var end = range.end;
var length = end - start;
if (!matchResult) {
var start = range.pos;
var length = range.end - start;
errorAtPos(start, length, Diagnostics.Invalid_reference_directive_syntax);
}
else {
referencedFiles.push({
pos: range.pos,
end: range.end,
pos: start,
end: end,
filename: matchResult[3]
});
}
@@ -3956,6 +3958,9 @@ module ts {
else if (!findSourceFile(filename, isDefaultLib, refFile, refPos, refEnd)) {
diagnostic = Diagnostics.File_0_not_found;
}
else if (refFile && host.getCanonicalFileName(filename) === host.getCanonicalFileName(refFile.filename)) {
diagnostic = Diagnostics.A_file_cannot_have_a_reference_to_itself;
}
}
else {
if (!(findSourceFile(filename + ".ts", isDefaultLib, refFile, refPos, refEnd) || findSourceFile(filename + ".d.ts", isDefaultLib, refFile, refPos, refEnd))) {

View File

@@ -1,9 +1,12 @@
main.ts(1,1): error TS1006: A file cannot have a reference to itself.
main.ts(2,1): error TS6053: File 'nonExistingFile1.ts' not found.
main.ts(3,1): error TS6053: File 'nonExistingFile2.ts' not found.
==== main.ts (2 errors) ====
==== main.ts (3 errors) ====
/// <reference path="main.ts" />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1006: A file cannot have a reference to itself.
/// <reference path="nonExistingFile1.ts" />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'nonExistingFile1.ts' not found.

View File

@@ -1,9 +1,12 @@
main.ts(1,1): error TS1006: A file cannot have a reference to itself.
main.ts(2,1): error TS6053: File 'nonExistingFile1.ts' not found.
main.ts(3,1): error TS6053: File 'nonExistingFile2.ts' not found.
==== main.ts (2 errors) ====
==== main.ts (3 errors) ====
/// <reference path="main.ts" />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1006: A file cannot have a reference to itself.
/// <reference path="nonExistingFile1.ts" />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'nonExistingFile1.ts' not found.

View File

@@ -0,0 +1,11 @@
tests/cases/compiler/selfReferencingFile.ts(1,1): error TS1006: A file cannot have a reference to itself.
==== tests/cases/compiler/selfReferencingFile.ts (1 errors) ====
///<reference path='selfReferencingFile.ts'/>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1006: A file cannot have a reference to itself.
class selfReferencingFile {
}

View File

@@ -0,0 +1,11 @@
tests/cases/compiler/selfReferencingFile2.ts(1,1): error TS6053: File 'tests/cases/selfReferencingFile2.ts' not found.
==== tests/cases/compiler/selfReferencingFile2.ts (1 errors) ====
///<reference path='../selfReferencingFile2.ts'/>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'selfReferencingFile2.ts' not found.
class selfReferencingFile2 {
}

View File

@@ -0,0 +1,11 @@
tests/cases/compiler/selfReferencingFile3.ts(1,1): error TS1006: A file cannot have a reference to itself.
==== tests/cases/compiler/selfReferencingFile3.ts (1 errors) ====
///<reference path='./selfReferencingFile3.ts'/>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1006: A file cannot have a reference to itself.
class selfReferencingFile3 {
}

View File

@@ -0,0 +1,5 @@
///<reference path='selfReferencingFile.ts'/>
class selfReferencingFile {
}

View File

@@ -0,0 +1,5 @@
///<reference path='../selfReferencingFile2.ts'/>
class selfReferencingFile2 {
}

View File

@@ -0,0 +1,5 @@
///<reference path='./selfReferencingFile3.ts'/>
class selfReferencingFile3 {
}