Skip to content

Commit e11ee0f

Browse files
committed
Fixed a few of the code review suggestions
1 parent 16a8b3c commit e11ee0f

File tree

5 files changed

+25
-22
lines changed

5 files changed

+25
-22
lines changed

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module ts {
66
Identifier_expected: { code: 1003, category: DiagnosticCategory.Error, key: "Identifier expected." },
77
_0_expected: { code: 1005, category: DiagnosticCategory.Error, key: "'{0}' expected." },
88
Trailing_comma_not_allowed: { code: 1009, category: DiagnosticCategory.Error, key: "Trailing comma not allowed." },
9+
A_file_cannot_have_a_reference_to_itself: { code: 1006, category: DiagnosticCategory.Error, key: "A file cannot have a reference to itself." },
910
Asterisk_Slash_expected: { code: 1010, category: DiagnosticCategory.Error, key: "'*/' expected." },
1011
Unexpected_token: { code: 1012, category: DiagnosticCategory.Error, key: "Unexpected token." },
1112
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 {
340341
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}'." },
341342
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}'." },
342343
The_current_host_does_not_support_the_0_option: { code: 5001, category: DiagnosticCategory.Error, key: "The current host does not support the '{0}' option." },
343-
A_file_cannot_have_a_reference_to_itself: { code: 5006, category: DiagnosticCategory.Error, key: "A file cannot have a reference to itself." },
344344
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." },
345345
Cannot_read_file_0_Colon_1: { code: 5012, category: DiagnosticCategory.Error, key: "Cannot read file '{0}': {1}" },
346346
Unsupported_file_encoding: { code: 5013, category: DiagnosticCategory.Error, key: "Unsupported file encoding." },

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
"Trailing comma not allowed.": {
1515
"category": "Error",
1616
"code": 1009
17+
},
18+
"A file cannot have a reference to itself.": {
19+
"category": "Error",
20+
"code": 1006
1721
},
1822
"'*/' expected.": {
1923
"category": "Error",
@@ -1355,10 +1359,7 @@
13551359
"category": "Error",
13561360
"code": 5001
13571361
},
1358-
"A file cannot have a reference to itself.": {
1359-
"category": "Error",
1360-
"code": 5006
1361-
},
1362+
13621363
"Cannot find the common subdirectory path for the input files.": {
13631364
"category": "Error",
13641365
"code": 5009

src/compiler/parser.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3822,24 +3822,26 @@ module ts {
38223822
}
38233823
else {
38243824
var matchResult = fullTripleSlashReferencePathRegEx.exec(comment);
3825+
var start = range.pos;
3826+
var end = range.end;
3827+
var length = end - start;
38253828
if (!matchResult) {
3826-
var start = range.pos;
3827-
var length = range.end - start;
38283829
errorAtPos(start, length, Diagnostics.Invalid_reference_directive_syntax);
38293830
}
38303831
else {
3832+
var referenceFilename = matchResult[3];
38313833
var basePath = getDirectoryPath(file.filename);
3832-
var referenceFilename = normalizePath(combinePaths(basePath, matchResult[3]));
3833-
if (file.filename === referenceFilename) {
3834-
errorAtPos(range.pos, range.end - range.pos, Diagnostics.A_file_cannot_have_a_reference_to_itself);
3835-
}
3836-
else {
3837-
referencedFiles.push({
3838-
pos: range.pos,
3839-
end: range.end,
3840-
filename: matchResult[3]
3841-
});
3842-
}
3834+
var referenceFullPath = normalizePath(combinePaths(basePath, referenceFilename));
3835+
if (file.filename === referenceFullPath) {
3836+
errorAtPos(start, length, Diagnostics.A_file_cannot_have_a_reference_to_itself);
3837+
}
3838+
else {
3839+
referencedFiles.push({
3840+
pos: start,
3841+
end: end,
3842+
filename: referenceFilename
3843+
});
3844+
}
38433845
}
38443846
}
38453847
}

tests/baselines/reference/selfReferencingFile.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
tests/cases/compiler/selfReferencingFile.ts(1,1): error TS5006: A file cannot have a reference to itself.
1+
tests/cases/compiler/selfReferencingFile.ts(1,1): error TS1006: A file cannot have a reference to itself.
22

33

44
==== tests/cases/compiler/selfReferencingFile.ts (1 errors) ====
55
///<reference path='selfReferencingFile.ts'/>
66
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7-
!!! error TS5006: A file cannot have a reference to itself.
7+
!!! error TS1006: A file cannot have a reference to itself.
88

99
class selfReferencingFile {
1010

tests/baselines/reference/selfReferencingFile3.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
tests/cases/compiler/selfReferencingFile3.ts(1,1): error TS5006: A file cannot have a reference to itself.
1+
tests/cases/compiler/selfReferencingFile3.ts(1,1): error TS1006: A file cannot have a reference to itself.
22

33

44
==== tests/cases/compiler/selfReferencingFile3.ts (1 errors) ====
55
///<reference path='./selfReferencingFile3.ts'/>
66
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7-
!!! error TS5006: A file cannot have a reference to itself.
7+
!!! error TS1006: A file cannot have a reference to itself.
88

99
class selfReferencingFile3 {
1010

0 commit comments

Comments
 (0)