diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts
index ba6f742c4c1..e0b8099ef3c 100644
--- a/src/compiler/diagnosticInformationMap.generated.ts
+++ b/src/compiler/diagnosticInformationMap.generated.ts
@@ -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." },
diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json
index 0480cd3000c..1b89d2242c7 100644
--- a/src/compiler/diagnosticMessages.json
+++ b/src/compiler/diagnosticMessages.json
@@ -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
diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts
index fcc8c62ba16..6dd593c7fee 100644
--- a/src/compiler/parser.ts
+++ b/src/compiler/parser.ts
@@ -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))) {
diff --git a/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/amd/visibilityOfTypeUsedAcrossModules2.errors.txt b/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/amd/visibilityOfTypeUsedAcrossModules2.errors.txt
index 9bdeb723415..d5c992fff66 100644
--- a/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/amd/visibilityOfTypeUsedAcrossModules2.errors.txt
+++ b/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/amd/visibilityOfTypeUsedAcrossModules2.errors.txt
@@ -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) ====
///
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+!!! error TS1006: A file cannot have a reference to itself.
///
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'nonExistingFile1.ts' not found.
diff --git a/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/node/visibilityOfTypeUsedAcrossModules2.errors.txt b/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/node/visibilityOfTypeUsedAcrossModules2.errors.txt
index 9bdeb723415..d5c992fff66 100644
--- a/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/node/visibilityOfTypeUsedAcrossModules2.errors.txt
+++ b/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/node/visibilityOfTypeUsedAcrossModules2.errors.txt
@@ -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) ====
///
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+!!! error TS1006: A file cannot have a reference to itself.
///
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'nonExistingFile1.ts' not found.
diff --git a/tests/baselines/reference/selfReferencingFile.errors.txt b/tests/baselines/reference/selfReferencingFile.errors.txt
new file mode 100644
index 00000000000..727be1ea0b2
--- /dev/null
+++ b/tests/baselines/reference/selfReferencingFile.errors.txt
@@ -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) ====
+ ///
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+!!! error TS1006: A file cannot have a reference to itself.
+
+ class selfReferencingFile {
+
+ }
\ No newline at end of file
diff --git a/tests/baselines/reference/selfReferencingFile2.errors.txt b/tests/baselines/reference/selfReferencingFile2.errors.txt
new file mode 100644
index 00000000000..5bd2d75723a
--- /dev/null
+++ b/tests/baselines/reference/selfReferencingFile2.errors.txt
@@ -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) ====
+ ///
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+!!! error TS6053: File 'selfReferencingFile2.ts' not found.
+
+ class selfReferencingFile2 {
+
+ }
\ No newline at end of file
diff --git a/tests/baselines/reference/selfReferencingFile3.errors.txt b/tests/baselines/reference/selfReferencingFile3.errors.txt
new file mode 100644
index 00000000000..e6e8deb5d47
--- /dev/null
+++ b/tests/baselines/reference/selfReferencingFile3.errors.txt
@@ -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) ====
+ ///
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+!!! error TS1006: A file cannot have a reference to itself.
+
+ class selfReferencingFile3 {
+
+ }
\ No newline at end of file
diff --git a/tests/cases/compiler/selfReferencingFile.ts b/tests/cases/compiler/selfReferencingFile.ts
new file mode 100644
index 00000000000..cac46da2369
--- /dev/null
+++ b/tests/cases/compiler/selfReferencingFile.ts
@@ -0,0 +1,5 @@
+///
+
+class selfReferencingFile {
+
+}
\ No newline at end of file
diff --git a/tests/cases/compiler/selfReferencingFile2.ts b/tests/cases/compiler/selfReferencingFile2.ts
new file mode 100644
index 00000000000..c98e7a07735
--- /dev/null
+++ b/tests/cases/compiler/selfReferencingFile2.ts
@@ -0,0 +1,5 @@
+///
+
+class selfReferencingFile2 {
+
+}
\ No newline at end of file
diff --git a/tests/cases/compiler/selfReferencingFile3.ts b/tests/cases/compiler/selfReferencingFile3.ts
new file mode 100644
index 00000000000..4242d0b3633
--- /dev/null
+++ b/tests/cases/compiler/selfReferencingFile3.ts
@@ -0,0 +1,5 @@
+///
+
+class selfReferencingFile3 {
+
+}
\ No newline at end of file