Skip to content

Commit 4105d32

Browse files
authored
Fix crash in reporting unresolved project reference as part of compilerOptions verification (#39095)
* Fix crash in reporting unresolved project reference as part of compilerOptions verification Fixes #38143 * Fix typo
1 parent 7611579 commit 4105d32

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,7 @@ namespace ts {
15301530
function getPrependNodes() {
15311531
return createPrependNodes(
15321532
projectReferences,
1533-
(_ref, index) => resolvedProjectReferences![index]!.commandLine,
1533+
(_ref, index) => resolvedProjectReferences![index]?.commandLine,
15341534
fileName => {
15351535
const path = toPath(fileName);
15361536
const sourceFile = getSourceFileByPath(path);

src/testRunner/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
"unittests/tsc/declarationEmit.ts",
131131
"unittests/tsc/incremental.ts",
132132
"unittests/tsc/listFilesOnly.ts",
133+
"unittests/tsc/projectReferences.ts",
133134
"unittests/tsc/runWithoutArgs.ts",
134135
"unittests/tscWatch/consoleClearing.ts",
135136
"unittests/tscWatch/emit.ts",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace ts {
2+
describe("unittests:: tsc:: projectReferences::", () => {
3+
verifyTsc({
4+
scenario: "projectReferences",
5+
subScenario: "when project contains invalid project reference",
6+
fs: () => loadProjectFromFiles({
7+
"/src/project/src/main.ts": "export const x = 10;",
8+
"/src/project/tsconfig.json": JSON.stringify({
9+
compilerOptions: {
10+
module: "amd",
11+
outFile: "theApp.js"
12+
},
13+
references: [
14+
{ path: "../Util/Dates" }
15+
]
16+
}),
17+
}),
18+
commandLineArgs: ["--p", "src/project"],
19+
});
20+
});
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Input::
2+
//// [/lib/lib.d.ts]
3+
/// <reference no-default-lib="true"/>
4+
interface Boolean {}
5+
interface Function {}
6+
interface CallableFunction {}
7+
interface NewableFunction {}
8+
interface IArguments {}
9+
interface Number { toExponential: any; }
10+
interface Object {}
11+
interface RegExp {}
12+
interface String { charAt: any; }
13+
interface Array<T> { length: number; [n: number]: T; }
14+
interface ReadonlyArray<T> {}
15+
declare const console: { log(msg: any): void; };
16+
17+
//// [/src/project/src/main.ts]
18+
export const x = 10;
19+
20+
//// [/src/project/tsconfig.json]
21+
{"compilerOptions":{"module":"amd","outFile":"theApp.js"},"references":[{"path":"../Util/Dates"}]}
22+
23+
24+
25+
Output::
26+
/lib/tsc --p src/project
27+
src/project/tsconfig.json:1:73 - error TS6053: File '/src/Util/Dates' not found.
28+
29+
1 {"compilerOptions":{"module":"amd","outFile":"theApp.js"},"references":[{"path":"../Util/Dates"}]}
30+
   ~~~~~~~~~~~~~~~~~~~~~~~~
31+
32+
33+
Found 1 error.
34+
35+
exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated
36+
37+
38+
//// [/src/project/theApp.js]
39+
define("main", ["require", "exports"], function (require, exports) {
40+
"use strict";
41+
exports.__esModule = true;
42+
exports.x = void 0;
43+
exports.x = 10;
44+
});
45+
46+

0 commit comments

Comments
 (0)