Skip to content

Commit d145105

Browse files
authored
Do not create SourceFiles for non-existent files (#1148)
1 parent c202a92 commit d145105

File tree

52 files changed

+41
-222
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+41
-222
lines changed

internal/compiler/host.go

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

7676
func (h *compilerHost) GetSourceFile(fileName string, path tspath.Path, options *core.SourceFileAffectingCompilerOptions, metadata *ast.SourceFileMetaData) *ast.SourceFile {
77-
text, _ := h.FS().ReadFile(fileName)
77+
text, ok := h.FS().ReadFile(fileName)
78+
if !ok {
79+
return nil
80+
}
7881
if tspath.FileExtensionIs(fileName, tspath.ExtensionJson) {
7982
return parser.ParseJSONText(fileName, path, text)
8083
}

internal/compiler/program.go

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

266266
func canReplaceFileInProgram(file1 *ast.SourceFile, file2 *ast.SourceFile) bool {
267267
// TODO(jakebailey): metadata??
268-
return file1.FileName() == file2.FileName() &&
268+
return file2 != nil &&
269+
file1.FileName() == file2.FileName() &&
269270
file1.Path() == file2.Path() &&
270271
file1.LanguageVersion == file2.LanguageVersion &&
271272
file1.LanguageVariant == file2.LanguageVariant &&

internal/testutil/harnessutil/harnessutil.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,10 @@ func GetSourceFileCacheKey(
497497
}
498498

499499
func (h *cachedCompilerHost) GetSourceFile(fileName string, path tspath.Path, options *core.SourceFileAffectingCompilerOptions, metadata *ast.SourceFileMetaData) *ast.SourceFile {
500-
text, _ := h.FS().ReadFile(fileName)
500+
text, ok := h.FS().ReadFile(fileName)
501+
if !ok {
502+
return nil
503+
}
501504

502505
key := GetSourceFileCacheKey(
503506
fileName,

testdata/baselines/reference/submodule/compiler/declarationEmitInvalidReference.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
/// <reference path="invalid.ts" />
55
var x = 0;
66

7-
//// [invalid.js]
87
//// [declarationEmitInvalidReference.js]
98
/// <reference path="invalid.ts" />
109
var x = 0;
1110

1211

13-
//// [invalid.d.ts]
1412
//// [declarationEmitInvalidReference.d.ts]
1513
declare var x: number;

testdata/baselines/reference/submodule/compiler/declarationEmitInvalidReference.js.diff

Lines changed: 0 additions & 15 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/declarationEmitInvalidReference2.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
/// <reference path="invalid.ts" />
55
var x = 0;
66

7-
//// [invalid.js]
87
//// [declarationEmitInvalidReference2.js]
98
/// <reference path="invalid.ts" />
109
var x = 0;
1110

1211

13-
//// [invalid.d.ts]
1412
//// [declarationEmitInvalidReference2.d.ts]
1513
declare var x: number;

testdata/baselines/reference/submodule/compiler/declarationEmitInvalidReference2.js.diff

Lines changed: 0 additions & 15 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/duplicateIdentifierRelatedSpans6.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,3 @@ export {};
2525
"use strict";
2626
Object.defineProperty(exports, "__esModule", { value: true });
2727
/// <reference path="./file1" />
28-
//// [file1.js]

testdata/baselines/reference/submodule/compiler/duplicateIdentifierRelatedSpans6.js.diff

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@
99
"use strict";
1010
-/// <reference path="./file1" />
1111
Object.defineProperty(exports, "__esModule", { value: true });
12-
+/// <reference path="./file1" />
13-
+//// [file1.js]
12+
+/// <reference path="./file1" />

testdata/baselines/reference/submodule/compiler/duplicateIdentifierRelatedSpans7.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,3 @@ export {};
3737
"use strict";
3838
Object.defineProperty(exports, "__esModule", { value: true });
3939
/// <reference path="./file1" />
40-
//// [file1.js]

0 commit comments

Comments
 (0)