diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a3eedb29c61..9a210e21189 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3686,17 +3686,28 @@ module ts { var start = refPos; var length = refEnd - refPos; } + var diagnostic: DiagnosticMessage; if (hasExtension(filename)) { if (!fileExtensionIs(filename, ".ts")) { - errors.push(createFileDiagnostic(refFile, start, length, Diagnostics.File_0_must_have_extension_ts_or_d_ts, filename)); + diagnostic = Diagnostics.File_0_must_have_extension_ts_or_d_ts; } else if (!findSourceFile(filename, isDefaultLib, refFile, refPos, refEnd)) { - errors.push(createFileDiagnostic(refFile, start, length, Diagnostics.File_0_not_found, filename)); + diagnostic = Diagnostics.File_0_not_found; } } else { if (!(findSourceFile(filename + ".ts", isDefaultLib, refFile, refPos, refEnd) || findSourceFile(filename + ".d.ts", isDefaultLib, refFile, refPos, refEnd))) { - errors.push(createFileDiagnostic(refFile, start, length, Diagnostics.File_0_not_found, filename + ".ts")); + diagnostic = Diagnostics.File_0_not_found; + filename += ".ts"; + } + } + + if (diagnostic) { + if (refFile) { + errors.push(createFileDiagnostic(refFile, start, length, diagnostic, filename)); + } + else { + errors.push(createCompilerDiagnostic(diagnostic, filename)); } } } diff --git a/tests/baselines/reference/project/invalidRootFile/amd/invalidRootFile.errors.txt b/tests/baselines/reference/project/invalidRootFile/amd/invalidRootFile.errors.txt new file mode 100644 index 00000000000..b78b05f1b8f --- /dev/null +++ b/tests/baselines/reference/project/invalidRootFile/amd/invalidRootFile.errors.txt @@ -0,0 +1,8 @@ +error TS6053: File 'a.ts' not found. +error TS6053: File 'a.ts' not found. +error TS6054: File 'a.t' must have extension '.ts' or '.d.ts'. + + +!!! error TS6053: File 'a.ts' not found. +!!! error TS6053: File 'a.ts' not found. +!!! error TS6054: File 'a.t' must have extension '.ts' or '.d.ts'. \ No newline at end of file diff --git a/tests/baselines/reference/project/invalidRootFile/amd/invalidRootFile.json b/tests/baselines/reference/project/invalidRootFile/amd/invalidRootFile.json new file mode 100644 index 00000000000..2360a193650 --- /dev/null +++ b/tests/baselines/reference/project/invalidRootFile/amd/invalidRootFile.json @@ -0,0 +1,13 @@ +{ + "scenario": "InvalidRootFile", + "projectRoot": "tests/cases/projects/InvalidRootFile", + "inputFiles": [ + "a", + "a.t", + "a.ts" + ], + "resolvedInputFiles": [ + "lib.d.ts" + ], + "emittedFiles": [] +} \ No newline at end of file diff --git a/tests/baselines/reference/project/invalidRootFile/node/invalidRootFile.errors.txt b/tests/baselines/reference/project/invalidRootFile/node/invalidRootFile.errors.txt new file mode 100644 index 00000000000..b78b05f1b8f --- /dev/null +++ b/tests/baselines/reference/project/invalidRootFile/node/invalidRootFile.errors.txt @@ -0,0 +1,8 @@ +error TS6053: File 'a.ts' not found. +error TS6053: File 'a.ts' not found. +error TS6054: File 'a.t' must have extension '.ts' or '.d.ts'. + + +!!! error TS6053: File 'a.ts' not found. +!!! error TS6053: File 'a.ts' not found. +!!! error TS6054: File 'a.t' must have extension '.ts' or '.d.ts'. \ No newline at end of file diff --git a/tests/baselines/reference/project/invalidRootFile/node/invalidRootFile.json b/tests/baselines/reference/project/invalidRootFile/node/invalidRootFile.json new file mode 100644 index 00000000000..2360a193650 --- /dev/null +++ b/tests/baselines/reference/project/invalidRootFile/node/invalidRootFile.json @@ -0,0 +1,13 @@ +{ + "scenario": "InvalidRootFile", + "projectRoot": "tests/cases/projects/InvalidRootFile", + "inputFiles": [ + "a", + "a.t", + "a.ts" + ], + "resolvedInputFiles": [ + "lib.d.ts" + ], + "emittedFiles": [] +} \ No newline at end of file diff --git a/tests/cases/project/invalidRootFile.json b/tests/cases/project/invalidRootFile.json new file mode 100644 index 00000000000..d26ecf89e2b --- /dev/null +++ b/tests/cases/project/invalidRootFile.json @@ -0,0 +1,9 @@ +{ + "scenario": "InvalidRootFile", + "projectRoot": "tests/cases/projects/InvalidRootFile", + "inputFiles": [ + "a", + "a.t", + "a.ts" + ] +} \ No newline at end of file