Skip to content

Commit 29a1bc0

Browse files
committed
Test output not found built error
1 parent ca72b95 commit 29a1bc0

File tree

4 files changed

+68
-2
lines changed

4 files changed

+68
-2
lines changed

internal/compiler/host.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ func (h *compilerHost) Trace(msg string) {
9191
}
9292

9393
func (h *compilerHost) GetSourceFile(fileName string, path tspath.Path, languageVersion core.ScriptTarget) *ast.SourceFile {
94-
text, _ := h.FS().ReadFile(fileName)
94+
text, ok := h.FS().ReadFile(fileName)
95+
if !ok {
96+
return nil
97+
}
9598
if tspath.FileExtensionIs(fileName, tspath.ExtensionJson) {
9699
return parser.ParseJSONText(fileName, path, text)
97100
}

internal/compiler/program.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ func (p *Program) initCheckerPool() {
244244
}
245245

246246
func canReplaceFileInProgram(file1 *ast.SourceFile, file2 *ast.SourceFile) bool {
247-
return file1.FileName() == file2.FileName() &&
247+
return file2 != nil &&
248+
file1.FileName() == file2.FileName() &&
248249
file1.Path() == file2.Path() &&
249250
file1.LanguageVersion == file2.LanguageVersion &&
250251
file1.LanguageVariant == file2.LanguageVariant &&

internal/execute/tscprojectreferences_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ func TestProjectReferences(t *testing.T) {
5151
"references": [
5252
{ "path": "../utils" },
5353
],
54+
}`,
55+
}, "/home/src/workspaces/solution"),
56+
commandLineArgs: []string{"--p", "project"},
57+
},
58+
{
59+
subScenario: "when project reference is not built",
60+
sys: newTestSys(FileMap{
61+
"/home/src/workspaces/solution/utils/index.ts": "export const x = 10;",
62+
"/home/src/workspaces/solution/utils/tsconfig.json": `{
63+
"compilerOptions": {
64+
"composite": true,
65+
},
66+
}`,
67+
"/home/src/workspaces/solution/project/index.ts": `import { x } from "../utils";`,
68+
"/home/src/workspaces/solution/project/tsconfig.json": `{
69+
"references": [
70+
{ "path": "../utils" },
71+
],
5472
}`,
5573
}, "/home/src/workspaces/solution"),
5674
commandLineArgs: []string{"--p", "project"},
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
currentDirectory::/home/src/workspaces/solution
3+
useCaseSensitiveFileNames::true
4+
Input::--p project
5+
//// [/home/src/workspaces/solution/project/index.ts] new file
6+
import { x } from "../utils";
7+
//// [/home/src/workspaces/solution/project/tsconfig.json] new file
8+
{
9+
"references": [
10+
{ "path": "../utils" },
11+
],
12+
}
13+
//// [/home/src/workspaces/solution/utils/index.ts] new file
14+
export const x = 10;
15+
//// [/home/src/workspaces/solution/utils/tsconfig.json] new file
16+
{
17+
"compilerOptions": {
18+
"composite": true,
19+
},
20+
}
21+
22+
ExitStatus:: 2
23+
24+
CompilerOptions::{
25+
"project": "/home/src/workspaces/solution/project"
26+
}
27+
Output::
28+
project/index.ts:1:19 - error TS6305: Output file '/home/src/workspaces/solution/utils/index.d.ts' has not been built from source file '/home/src/workspaces/solution/utils/index.ts'.
29+
30+
1 import { x } from "../utils";
31+
   ~~~~~~~~~~
32+
33+
34+
Found 1 error in project/index.ts:1
35+
36+
//// [/home/src/workspaces/solution/project/index.js] new file
37+
"use strict";
38+
Object.defineProperty(exports, "__esModule", { value: true });
39+
40+
//// [/home/src/workspaces/solution/project/index.ts] no change
41+
//// [/home/src/workspaces/solution/project/tsconfig.json] no change
42+
//// [/home/src/workspaces/solution/utils/index.ts] no change
43+
//// [/home/src/workspaces/solution/utils/tsconfig.json] no change
44+

0 commit comments

Comments
 (0)