diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 0664b3483b8fa..8cd92ddd285cd 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1530,7 +1530,7 @@ namespace ts { function getPrependNodes() { return createPrependNodes( projectReferences, - (_ref, index) => resolvedProjectReferences![index]!.commandLine, + (_ref, index) => resolvedProjectReferences![index]?.commandLine, fileName => { const path = toPath(fileName); const sourceFile = getSourceFileByPath(path); diff --git a/src/testRunner/tsconfig.json b/src/testRunner/tsconfig.json index 8a0c0fbaf57b9..f17f10789f03b 100644 --- a/src/testRunner/tsconfig.json +++ b/src/testRunner/tsconfig.json @@ -130,6 +130,7 @@ "unittests/tsc/declarationEmit.ts", "unittests/tsc/incremental.ts", "unittests/tsc/listFilesOnly.ts", + "unittests/tsc/projectReferences.ts", "unittests/tsc/runWithoutArgs.ts", "unittests/tscWatch/consoleClearing.ts", "unittests/tscWatch/emit.ts", diff --git a/src/testRunner/unittests/tsc/projectReferences.ts b/src/testRunner/unittests/tsc/projectReferences.ts new file mode 100644 index 0000000000000..06e68018dd6ce --- /dev/null +++ b/src/testRunner/unittests/tsc/projectReferences.ts @@ -0,0 +1,21 @@ +namespace ts { + describe("unittests:: tsc:: projectReferences::", () => { + verifyTsc({ + scenario: "projectReferences", + subScenario: "when project contains invalid project reference", + fs: () => loadProjectFromFiles({ + "/src/project/src/main.ts": "export const x = 10;", + "/src/project/tsconfig.json": JSON.stringify({ + compilerOptions: { + module: "amd", + outFile: "theApp.js" + }, + references: [ + { path: "../Util/Dates" } + ] + }), + }), + commandLineArgs: ["--p", "src/project"], + }); + }); +} diff --git a/tests/baselines/reference/tsc/projectReferences/initial-build/when-project-contains-invalid-project-reference.js b/tests/baselines/reference/tsc/projectReferences/initial-build/when-project-contains-invalid-project-reference.js new file mode 100644 index 0000000000000..ab55d2a9e860d --- /dev/null +++ b/tests/baselines/reference/tsc/projectReferences/initial-build/when-project-contains-invalid-project-reference.js @@ -0,0 +1,46 @@ +Input:: +//// [/lib/lib.d.ts] +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } +interface ReadonlyArray {} +declare const console: { log(msg: any): void; }; + +//// [/src/project/src/main.ts] +export const x = 10; + +//// [/src/project/tsconfig.json] +{"compilerOptions":{"module":"amd","outFile":"theApp.js"},"references":[{"path":"../Util/Dates"}]} + + + +Output:: +/lib/tsc --p src/project +src/project/tsconfig.json:1:73 - error TS6053: File '/src/Util/Dates' not found. + +1 {"compilerOptions":{"module":"amd","outFile":"theApp.js"},"references":[{"path":"../Util/Dates"}]} +   ~~~~~~~~~~~~~~~~~~~~~~~~ + + +Found 1 error. + +exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated + + +//// [/src/project/theApp.js] +define("main", ["require", "exports"], function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.x = void 0; + exports.x = 10; +}); + +