diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index ba6f742c4c1..10fa0e27b97 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -340,6 +340,7 @@ module ts { Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4077, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." }, Parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4078, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using private name '{1}'." }, The_current_host_does_not_support_the_0_option: { code: 5001, category: DiagnosticCategory.Error, key: "The current host does not support the '{0}' option." }, + A_file_cannot_have_a_reference_to_itself: { code: 5006, category: DiagnosticCategory.Error, key: "A file cannot have a reference to itself." }, Cannot_find_the_common_subdirectory_path_for_the_input_files: { code: 5009, category: DiagnosticCategory.Error, key: "Cannot find the common subdirectory path for the input files." }, Cannot_read_file_0_Colon_1: { code: 5012, category: DiagnosticCategory.Error, key: "Cannot read file '{0}': {1}" }, Unsupported_file_encoding: { code: 5013, category: DiagnosticCategory.Error, key: "Unsupported file encoding." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 0480cd3000c..146b4df0905 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1355,6 +1355,10 @@ "category": "Error", "code": 5001 }, + "A file cannot have a reference to itself.": { + "category": "Error", + "code": 5006 + }, "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 af1851d6a75..e7d6b32831e 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3828,11 +3828,18 @@ module ts { errorAtPos(start, length, Diagnostics.Invalid_reference_directive_syntax); } else { - referencedFiles.push({ - pos: range.pos, - end: range.end, - filename: matchResult[3] - }); + var basePath = getDirectoryPath(file.filename); + var referenceFilename = normalizePath(combinePaths(basePath, matchResult[3])); + if (file.filename === referenceFilename) { + errorAtPos(range.pos, range.end - range.pos, Diagnostics.A_file_cannot_have_a_reference_to_itself); + } + else { + referencedFiles.push({ + pos: range.pos, + end: range.end, + filename: matchResult[3] + }); + } } } } diff --git a/tests/baselines/reference/selfReferencingFile.errors.txt b/tests/baselines/reference/selfReferencingFile.errors.txt new file mode 100644 index 00000000000..0a72bdf5867 --- /dev/null +++ b/tests/baselines/reference/selfReferencingFile.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/selfReferencingFile.ts(1,1): error TS5006: A file cannot have a reference to itself. + + +==== tests/cases/compiler/selfReferencingFile.ts (1 errors) ==== + /// + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS5006: 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..84e3650de9e --- /dev/null +++ b/tests/baselines/reference/selfReferencingFile3.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/selfReferencingFile3.ts(1,1): error TS5006: A file cannot have a reference to itself. + + +==== tests/cases/compiler/selfReferencingFile3.ts (1 errors) ==== + /// + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS5006: 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