From cafa481843bcea80fb879754f3997322bf18db51 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 25 Sep 2014 08:44:46 -0700 Subject: [PATCH 01/10] Added error checking for references that reference the same file along with 3 tests, --- .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 ++++ src/compiler/parser.ts | 17 ++++++++++++----- .../reference/selfReferencingFile.errors.txt | 11 +++++++++++ .../reference/selfReferencingFile2.errors.txt | 11 +++++++++++ .../reference/selfReferencingFile3.errors.txt | 11 +++++++++++ tests/cases/compiler/selfReferencingFile.ts | 5 +++++ tests/cases/compiler/selfReferencingFile2.ts | 5 +++++ tests/cases/compiler/selfReferencingFile3.ts | 5 +++++ 9 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 tests/baselines/reference/selfReferencingFile.errors.txt create mode 100644 tests/baselines/reference/selfReferencingFile2.errors.txt create mode 100644 tests/baselines/reference/selfReferencingFile3.errors.txt create mode 100644 tests/cases/compiler/selfReferencingFile.ts create mode 100644 tests/cases/compiler/selfReferencingFile2.ts create mode 100644 tests/cases/compiler/selfReferencingFile3.ts 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 From 75e04f21e8870793b7d8fea6e9a23ebc2f69cffc Mon Sep 17 00:00:00 2001 From: Chris Bubernak Date: Thu, 25 Sep 2014 08:59:58 -0700 Subject: [PATCH 02/10] fixed some tabbing issues --- src/compiler/parser.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index e7d6b32831e..1aa9076671a 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3829,17 +3829,17 @@ module ts { } else { 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] - }); - } + 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] + }); + } } } } From ae17c357280d64f0a056a139da1232f8ddc1f1c0 Mon Sep 17 00:00:00 2001 From: ChrisBubernak Date: Thu, 25 Sep 2014 09:12:31 -0700 Subject: [PATCH 03/10] Added error checking for references that reference the same file along with 3 tests, --- .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 ++++ src/compiler/parser.ts | 17 ++++++++++++----- .../reference/selfReferencingFile.errors.txt | 11 +++++++++++ .../reference/selfReferencingFile2.errors.txt | 11 +++++++++++ .../reference/selfReferencingFile3.errors.txt | 11 +++++++++++ tests/cases/compiler/selfReferencingFile.ts | 5 +++++ tests/cases/compiler/selfReferencingFile2.ts | 5 +++++ tests/cases/compiler/selfReferencingFile3.ts | 5 +++++ 9 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 tests/baselines/reference/selfReferencingFile.errors.txt create mode 100644 tests/baselines/reference/selfReferencingFile2.errors.txt create mode 100644 tests/baselines/reference/selfReferencingFile3.errors.txt create mode 100644 tests/cases/compiler/selfReferencingFile.ts create mode 100644 tests/cases/compiler/selfReferencingFile2.ts create mode 100644 tests/cases/compiler/selfReferencingFile3.ts 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 From e11ee0f6cf7039e847237160738e5afff8759aa6 Mon Sep 17 00:00:00 2001 From: ChrisBubernak Date: Thu, 25 Sep 2014 13:02:37 -0700 Subject: [PATCH 04/10] Fixed a few of the code review suggestions --- .../diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 9 +++--- src/compiler/parser.ts | 28 ++++++++++--------- .../reference/selfReferencingFile.errors.txt | 4 +-- .../reference/selfReferencingFile3.errors.txt | 4 +-- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 10fa0e27b97..ebe8aa16f60 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -6,6 +6,7 @@ module ts { Identifier_expected: { code: 1003, category: DiagnosticCategory.Error, key: "Identifier expected." }, _0_expected: { code: 1005, category: DiagnosticCategory.Error, key: "'{0}' expected." }, Trailing_comma_not_allowed: { code: 1009, category: DiagnosticCategory.Error, key: "Trailing comma not allowed." }, + A_file_cannot_have_a_reference_to_itself: { code: 1006, category: DiagnosticCategory.Error, key: "A file cannot have a reference to itself." }, Asterisk_Slash_expected: { code: 1010, category: DiagnosticCategory.Error, key: "'*/' expected." }, Unexpected_token: { code: 1012, category: DiagnosticCategory.Error, key: "Unexpected token." }, Catch_clause_parameter_cannot_have_a_type_annotation: { code: 1013, category: DiagnosticCategory.Error, key: "Catch clause parameter cannot have a type annotation." }, @@ -340,7 +341,6 @@ 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 146b4df0905..7a395b071e5 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -14,6 +14,10 @@ "Trailing comma not allowed.": { "category": "Error", "code": 1009 + }, + "A file cannot have a reference to itself.": { + "category": "Error", + "code": 1006 }, "'*/' expected.": { "category": "Error", @@ -1355,10 +1359,7 @@ "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 e47311895dd..d393d43b8f4 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3822,24 +3822,26 @@ 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 { + var referenceFilename = 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] - }); - } + var referenceFullPath = normalizePath(combinePaths(basePath, referenceFilename)); + if (file.filename === referenceFullPath) { + errorAtPos(start, length, Diagnostics.A_file_cannot_have_a_reference_to_itself); + } + else { + referencedFiles.push({ + pos: start, + end: end, + filename: referenceFilename + }); + } } } } diff --git a/tests/baselines/reference/selfReferencingFile.errors.txt b/tests/baselines/reference/selfReferencingFile.errors.txt index 0a72bdf5867..727be1ea0b2 100644 --- a/tests/baselines/reference/selfReferencingFile.errors.txt +++ b/tests/baselines/reference/selfReferencingFile.errors.txt @@ -1,10 +1,10 @@ -tests/cases/compiler/selfReferencingFile.ts(1,1): error TS5006: A file cannot have a reference to itself. +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 TS5006: A file cannot have a reference to itself. +!!! error TS1006: A file cannot have a reference to itself. class selfReferencingFile { diff --git a/tests/baselines/reference/selfReferencingFile3.errors.txt b/tests/baselines/reference/selfReferencingFile3.errors.txt index 84e3650de9e..e6e8deb5d47 100644 --- a/tests/baselines/reference/selfReferencingFile3.errors.txt +++ b/tests/baselines/reference/selfReferencingFile3.errors.txt @@ -1,10 +1,10 @@ -tests/cases/compiler/selfReferencingFile3.ts(1,1): error TS5006: A file cannot have a reference to itself. +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 TS5006: A file cannot have a reference to itself. +!!! error TS1006: A file cannot have a reference to itself. class selfReferencingFile3 { From a12c35b69b8fdee1a38a28462c16654358efe5f9 Mon Sep 17 00:00:00 2001 From: ChrisBubernak Date: Thu, 25 Sep 2014 13:07:14 -0700 Subject: [PATCH 05/10] fixing formatting again... --- src/compiler/parser.ts | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index d393d43b8f4..32db284c7bf 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3822,26 +3822,27 @@ module ts { } else { var matchResult = fullTripleSlashReferencePathRegEx.exec(comment); - var start = range.pos; - var end = range.end; + var start = range.pos; + var end = range.end; var length = end - start; + if (!matchResult) { errorAtPos(start, length, Diagnostics.Invalid_reference_directive_syntax); } else { - var referenceFilename = matchResult[3]; + var referenceFilename = matchResult[3]; var basePath = getDirectoryPath(file.filename); var referenceFullPath = normalizePath(combinePaths(basePath, referenceFilename)); - if (file.filename === referenceFullPath) { - errorAtPos(start, length, Diagnostics.A_file_cannot_have_a_reference_to_itself); - } - else { - referencedFiles.push({ - pos: start, - end: end, - filename: referenceFilename - }); - } + if (file.filename === referenceFullPath) { + errorAtPos(start, length, Diagnostics.A_file_cannot_have_a_reference_to_itself); + } + else { + referencedFiles.push({ + pos: start, + end: end, + filename: referenceFilename + }); + } } } } From 93db897778e2d54aa82c33d720541cf25a459ed3 Mon Sep 17 00:00:00 2001 From: ChrisBubernak Date: Fri, 26 Sep 2014 07:47:44 -0700 Subject: [PATCH 06/10] Fixed some of the baselines, made file comparisons handle different casing, put diagnostic message in correct order --- src/compiler/diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 8 ++++---- src/compiler/parser.ts | 2 +- .../amd/visibilityOfTypeUsedAcrossModules2.errors.txt | 8 ++++++-- .../node/visibilityOfTypeUsedAcrossModules2.errors.txt | 8 ++++++-- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index ebe8aa16f60..e0b8099ef3c 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -5,8 +5,8 @@ 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." }, - Trailing_comma_not_allowed: { code: 1009, category: DiagnosticCategory.Error, key: "Trailing comma not allowed." }, 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." }, Catch_clause_parameter_cannot_have_a_type_annotation: { code: 1013, category: DiagnosticCategory.Error, key: "Catch clause parameter cannot have a type annotation." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 7a395b071e5..1b89d2242c7 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -10,15 +10,15 @@ "'{0}' expected.": { "category": "Error", "code": 1005 - }, - "Trailing comma not allowed.": { - "category": "Error", - "code": 1009 }, "A file cannot have a reference to itself.": { "category": "Error", "code": 1006 }, + "Trailing comma not allowed.": { + "category": "Error", + "code": 1009 + }, "'*/' expected.": { "category": "Error", "code": 1010 diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 32db284c7bf..15a55046db9 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3833,7 +3833,7 @@ module ts { var referenceFilename = matchResult[3]; var basePath = getDirectoryPath(file.filename); var referenceFullPath = normalizePath(combinePaths(basePath, referenceFilename)); - if (file.filename === referenceFullPath) { + if (file.filename.toLocaleLowerCase() === referenceFullPath.toLocaleLowerCase()) { errorAtPos(start, length, Diagnostics.A_file_cannot_have_a_reference_to_itself); } else { diff --git a/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/amd/visibilityOfTypeUsedAcrossModules2.errors.txt b/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/amd/visibilityOfTypeUsedAcrossModules2.errors.txt index 9bdeb723415..4a086fae46f 100644 --- a/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/amd/visibilityOfTypeUsedAcrossModules2.errors.txt +++ b/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/amd/visibilityOfTypeUsedAcrossModules2.errors.txt @@ -1,12 +1,16 @@ +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. /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS6053: File 'nonExistingFile2.ts' not found. \ No newline at end of file +!!! error TS6053: File 'nonExistingFile2.ts' not found. + \ No newline at end of file diff --git a/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/node/visibilityOfTypeUsedAcrossModules2.errors.txt b/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/node/visibilityOfTypeUsedAcrossModules2.errors.txt index 9bdeb723415..4a086fae46f 100644 --- a/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/node/visibilityOfTypeUsedAcrossModules2.errors.txt +++ b/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/node/visibilityOfTypeUsedAcrossModules2.errors.txt @@ -1,12 +1,16 @@ +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. /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS6053: File 'nonExistingFile2.ts' not found. \ No newline at end of file +!!! error TS6053: File 'nonExistingFile2.ts' not found. + \ No newline at end of file From 1b3da908de26d11b3caa844e8f5ba383871272e5 Mon Sep 17 00:00:00 2001 From: ChrisBubernak Date: Fri, 26 Sep 2014 09:33:06 -0700 Subject: [PATCH 07/10] fixing baseline --- .../amd/visibilityOfTypeUsedAcrossModules2.errors.txt | 3 +-- .../node/visibilityOfTypeUsedAcrossModules2.errors.txt | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/amd/visibilityOfTypeUsedAcrossModules2.errors.txt b/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/amd/visibilityOfTypeUsedAcrossModules2.errors.txt index 4a086fae46f..d5c992fff66 100644 --- a/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/amd/visibilityOfTypeUsedAcrossModules2.errors.txt +++ b/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/amd/visibilityOfTypeUsedAcrossModules2.errors.txt @@ -12,5 +12,4 @@ main.ts(3,1): error TS6053: File 'nonExistingFile2.ts' not found. !!! error TS6053: File 'nonExistingFile1.ts' not found. /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS6053: File 'nonExistingFile2.ts' not found. - \ No newline at end of file +!!! error TS6053: File 'nonExistingFile2.ts' not found. \ No newline at end of file diff --git a/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/node/visibilityOfTypeUsedAcrossModules2.errors.txt b/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/node/visibilityOfTypeUsedAcrossModules2.errors.txt index 4a086fae46f..d5c992fff66 100644 --- a/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/node/visibilityOfTypeUsedAcrossModules2.errors.txt +++ b/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/node/visibilityOfTypeUsedAcrossModules2.errors.txt @@ -12,5 +12,4 @@ main.ts(3,1): error TS6053: File 'nonExistingFile2.ts' not found. !!! error TS6053: File 'nonExistingFile1.ts' not found. /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS6053: File 'nonExistingFile2.ts' not found. - \ No newline at end of file +!!! error TS6053: File 'nonExistingFile2.ts' not found. \ No newline at end of file From 36b46291f264a65e44503546f14cb13d2d506d47 Mon Sep 17 00:00:00 2001 From: ChrisBubernak Date: Fri, 26 Sep 2014 09:54:32 -0700 Subject: [PATCH 08/10] still trying to get the indenting correct --- src/compiler/parser.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 15a55046db9..426fbe61d92 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3822,27 +3822,27 @@ module ts { } else { var matchResult = fullTripleSlashReferencePathRegEx.exec(comment); - var start = range.pos; - var end = range.end; + var start = range.pos; + var end = range.end; var length = end - start; - + if (!matchResult) { errorAtPos(start, length, Diagnostics.Invalid_reference_directive_syntax); } else { - var referenceFilename = matchResult[3]; + var referenceFilename = matchResult[3]; var basePath = getDirectoryPath(file.filename); var referenceFullPath = normalizePath(combinePaths(basePath, referenceFilename)); - if (file.filename.toLocaleLowerCase() === referenceFullPath.toLocaleLowerCase()) { - errorAtPos(start, length, Diagnostics.A_file_cannot_have_a_reference_to_itself); - } - else { - referencedFiles.push({ - pos: start, - end: end, - filename: referenceFilename - }); - } + if (file.filename.toLocaleLowerCase() === referenceFullPath.toLocaleLowerCase()) { + errorAtPos(start, length, Diagnostics.A_file_cannot_have_a_reference_to_itself); + } + else { + referencedFiles.push({ + pos: start, + end: end, + filename: referenceFilename + }); + } } } } From ba61c63a1af650c6013e99984bf0b30fbe6ecb10 Mon Sep 17 00:00:00 2001 From: ChrisBubernak Date: Mon, 29 Sep 2014 10:20:31 -0700 Subject: [PATCH 09/10] Moved logic to another location where host was in scope so we could call getCanonicalFileName --- src/compiler/parser.ts | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 426fbe61d92..7b43aaec665 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3825,24 +3825,16 @@ module ts { var start = range.pos; var end = range.end; var length = end - start; - + if (!matchResult) { errorAtPos(start, length, Diagnostics.Invalid_reference_directive_syntax); } else { - var referenceFilename = matchResult[3]; - var basePath = getDirectoryPath(file.filename); - var referenceFullPath = normalizePath(combinePaths(basePath, referenceFilename)); - if (file.filename.toLocaleLowerCase() === referenceFullPath.toLocaleLowerCase()) { - errorAtPos(start, length, Diagnostics.A_file_cannot_have_a_reference_to_itself); - } - else { - referencedFiles.push({ - pos: start, - end: end, - filename: referenceFilename - }); - } + referencedFiles.push({ + pos: start, + end: end, + filename: matchResult[3] + }); } } } @@ -3957,6 +3949,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))) { @@ -4015,7 +4010,7 @@ module ts { function processReferencedFiles(file: SourceFile, basePath: string) { forEach(file.referencedFiles, ref => { - processSourceFile(normalizePath(combinePaths(basePath, ref.filename)), /* isDefaultLib */ false, file, ref.pos, ref.end); + processSourceFile(normalizePath(combinePaths(basePath, ref.filename)), /* isDefaultLib */ false, file, ref.pos, ref.end); }); } From 3751b25dd202e165ec0d10b0539de341d6da1cb0 Mon Sep 17 00:00:00 2001 From: ChrisBubernak Date: Mon, 29 Sep 2014 10:23:01 -0700 Subject: [PATCH 10/10] Fixed indentation --- src/compiler/parser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 7b43aaec665..378d880bc37 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4010,7 +4010,7 @@ module ts { function processReferencedFiles(file: SourceFile, basePath: string) { forEach(file.referencedFiles, ref => { - processSourceFile(normalizePath(combinePaths(basePath, ref.filename)), /* isDefaultLib */ false, file, ref.pos, ref.end); + processSourceFile(normalizePath(combinePaths(basePath, ref.filename)), /* isDefaultLib */ false, file, ref.pos, ref.end); }); }