Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions internal/compiler/fileloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,17 @@ type fileLoader struct {
pathForLibFileResolutions collections.SyncMap[tspath.Path, *libResolution]
}

type missingFile struct {
path string
reason *FileIncludeReason
}

type processedFiles struct {
resolver *module.Resolver
files []*ast.SourceFile
filesByPath map[tspath.Path]*ast.SourceFile
projectReferenceFileMapper *projectReferenceFileMapper
missingFiles []string
missingFiles []missingFile
resolvedModules map[tspath.Path]module.ModeAwareCache[*module.ResolvedModule]
typeResolutionsInFile map[tspath.Path]module.ModeAwareCache[*module.ResolvedTypeReferenceDirective]
sourceFileMetaDatas map[tspath.Path]ast.SourceFileMetaData
Expand Down Expand Up @@ -136,7 +141,7 @@ func processAllProgramFiles(
totalFileCount := int(loader.totalFileCount.Load())
libFileCount := int(loader.libFileCount.Load())

var missingFiles []string
var missingFiles []missingFile
files := make([]*ast.SourceFile, 0, totalFileCount-libFileCount)
libFiles := make([]*ast.SourceFile, 0, totalFileCount) // totalFileCount here since we append files to it later to construct the final list

Expand Down Expand Up @@ -168,9 +173,13 @@ func processAllProgramFiles(
}
file := task.file
path := task.path

// !!! sheetal file preprocessing diagnostic explaining getSourceFileFromReferenceWorker
if file == nil {
// !!! sheetal file preprocessing diagnostic explaining getSourceFileFromReferenceWorker
missingFiles = append(missingFiles, task.normalizedFilePath)
missingFiles = append(missingFiles, missingFile{
path: task.normalizedFilePath,
reason: task.includeReason,
})
return
}

Expand Down
32 changes: 30 additions & 2 deletions internal/compiler/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func NewProgram(opts ProgramOptions) *Program {
p := &Program{opts: opts}
p.initCheckerPool()
p.processedFiles = processAllProgramFiles(p.opts, p.SingleThreaded())
p.addProgramDiagnostics()
p.verifyCompilerOptions()
return p
}
Expand Down Expand Up @@ -1222,6 +1223,33 @@ func (p *Program) getDiagnosticsHelper(ctx context.Context, sourceFile *ast.Sour
return SortAndDeduplicateDiagnostics(result)
}

func (p *Program) addProgramDiagnostics() {
for _, m := range p.missingFiles {
reason := m.reason
var location core.TextRange
var parent *ast.SourceFile
var ref *ast.FileReference

if data, ok := reason.data.(*referencedFileData); ok {
parent = p.filesByPath[data.file]
if parent != nil && data.index < len(parent.ReferencedFiles) {
ref = parent.ReferencedFiles[data.index]
location = ref.TextRange
}

}

diag := ast.NewDiagnostic(
parent,
location,
diagnostics.File_0_not_found,
m.path,
)

p.programDiagnostics = append(p.programDiagnostics, diag)
}
}

func (p *Program) LineCount() int {
var count int
for _, file := range p.files {
Expand Down Expand Up @@ -1553,8 +1581,8 @@ func (p *Program) GetIncludeReasons() map[tspath.Path][]*FileIncludeReason {

// Testing only
func (p *Program) IsMissingPath(path tspath.Path) bool {
return slices.ContainsFunc(p.missingFiles, func(missingPath string) bool {
return p.toPath(missingPath) == path
return slices.ContainsFunc(p.missingFiles, func(missingPath missingFile) bool {
return p.toPath(missingPath.path) == path
})
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declarationEmitInvalidReference.ts(1,22): error TS6053: File 'invalid.ts' not found.


==== declarationEmitInvalidReference.ts (1 errors) ====
/// <reference path="invalid.ts" />
~~~~~~~~~~
!!! error TS6053: File 'invalid.ts' not found.
var x = 0;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--- old.declarationEmitInvalidReference.errors.txt
+++ new.declarationEmitInvalidReference.errors.txt
@@= skipped -0, +0 lines =@@
-<no content>
+declarationEmitInvalidReference.ts(1,22): error TS6053: File 'invalid.ts' not found.
+
+
+==== declarationEmitInvalidReference.ts (1 errors) ====
+ /// <reference path="invalid.ts" />
+ ~~~~~~~~~~
+!!! error TS6053: File 'invalid.ts' not found.
+ var x = 0;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declarationEmitInvalidReference2.ts(1,22): error TS6053: File 'invalid.ts' not found.


==== declarationEmitInvalidReference2.ts (1 errors) ====
/// <reference path="invalid.ts" />
~~~~~~~~~~
!!! error TS6053: File 'invalid.ts' not found.
var x = 0;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declarationEmitInvalidReferenceAllowJs.ts(1,22): error TS6053: File 'invalid' not found.


==== declarationEmitInvalidReferenceAllowJs.ts (1 errors) ====
/// <reference path="invalid" />
~~~~~~~
!!! error TS6053: File 'invalid' not found.
var x = 0;

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
+++ new.declarationEmitInvalidReferenceAllowJs.errors.txt
@@= skipped -0, +0 lines =@@
-declarationEmitInvalidReferenceAllowJs.ts(1,22): error TS6231: Could not resolve the path 'invalid' with the extensions: '.ts', '.tsx', '.d.ts', '.js', '.jsx', '.cts', '.d.cts', '.cjs', '.mts', '.d.mts', '.mjs'.
-
-
-==== declarationEmitInvalidReferenceAllowJs.ts (1 errors) ====
- /// <reference path="invalid" />
- ~~~~~~~
+declarationEmitInvalidReferenceAllowJs.ts(1,22): error TS6053: File 'invalid' not found.


==== declarationEmitInvalidReferenceAllowJs.ts (1 errors) ====
/// <reference path="invalid" />
~~~~~~~
-!!! error TS6231: Could not resolve the path 'invalid' with the extensions: '.ts', '.tsx', '.d.ts', '.js', '.jsx', '.cts', '.d.cts', '.cjs', '.mts', '.d.mts', '.mjs'.
- var x = 0;
-
+<no content>
+!!! error TS6053: File 'invalid' not found.
var x = 0;
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
file2.ts:1:22 - error TS6053: File 'file1' not found.

1 /// <reference path="./file1" />
   ~~~~~~~

file2.ts:3:16 - error TS2664: Invalid module name in augmentation, module 'someMod' cannot be found.

3 declare module "someMod" {
   ~~~~~~~~~


==== file2.ts (1 errors) ====
==== file2.ts (2 errors) ====
/// <reference path="./file1" />
~~~~~~~
!!! error TS6053: File 'file1' not found.

declare module "someMod" {
~~~~~~~~~
Expand All @@ -26,5 +33,5 @@
duplicate3: () => string;
}
}
Found 1 error in file2.ts:3
Found 2 errors in the same file, starting at: file2.ts:1

Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,21 @@
-
-
-==== file2.ts (3 errors) ====
+file2.ts:1:22 - error TS6053: File 'file1' not found.
+
+1 /// <reference path="./file1" />
+   ~~~~~~~
+
+file2.ts:3:16 - error TS2664: Invalid module name in augmentation, module 'someMod' cannot be found.
+
+3 declare module "someMod" {
+   ~~~~~~~~~
+
+
+==== file2.ts (1 errors) ====
+==== file2.ts (2 errors) ====
/// <reference path="./file1" />
+ ~~~~~~~
+!!! error TS6053: File 'file1' not found.

declare module "someMod" {
+ ~~~~~~~~~
Expand Down Expand Up @@ -106,7 +113,7 @@
}
}
-Found 6 errors in 2 files.
+Found 1 error in file2.ts:3
+Found 2 errors in the same file, starting at: file2.ts:1

-Errors Files
- 3 file1.ts:3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
file2.ts:1:22 - error TS6053: File 'file1' not found.

1 /// <reference path="./file1" />
   ~~~~~~~

file2.ts:3:16 - error TS2664: Invalid module name in augmentation, module 'someMod' cannot be found.

3 declare module "someMod" {
   ~~~~~~~~~


==== file2.ts (1 errors) ====
==== file2.ts (2 errors) ====
/// <reference path="./file1" />
~~~~~~~
!!! error TS6053: File 'file1' not found.

declare module "someMod" {
~~~~~~~~~
Expand Down Expand Up @@ -38,5 +45,5 @@
duplicate9: () => string;
}
}
Found 1 error in file2.ts:3
Found 2 errors in the same file, starting at: file2.ts:1

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
-   ~~~~~~~
- Conflicts are in this file.
-file2.ts:3:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: duplicate1, duplicate2, duplicate3, duplicate4, duplicate5, duplicate6, duplicate7, duplicate8, duplicate9
+file2.ts:1:22 - error TS6053: File 'file1' not found.
+
+1 /// <reference path="./file1" />
+   ~~~~~~~
+
+file2.ts:3:16 - error TS2664: Invalid module name in augmentation, module 'someMod' cannot be found.

3 declare module "someMod" {
Expand All @@ -20,11 +25,16 @@
- 1 declare module "someMod" {
-   ~~~~~~~
- Conflicts are in this file.
-
-
-==== file2.ts (1 errors) ====
+   ~~~~~~~~~


==== file2.ts (1 errors) ====
+
+
+==== file2.ts (2 errors) ====
/// <reference path="./file1" />
+ ~~~~~~~
+!!! error TS6053: File 'file1' not found.

declare module "someMod" {
- ~~~~~~~
Expand All @@ -35,7 +45,7 @@
export interface TopLevel {
duplicate1(): number;
duplicate2(): number;
@@= skipped -38, +23 lines =@@
@@= skipped -38, +30 lines =@@
}
export {};

Expand All @@ -53,7 +63,7 @@
}
}
-Found 2 errors in 2 files.
+Found 1 error in file2.ts:3
+Found 2 errors in the same file, starting at: file2.ts:1

-Errors Files
- 1 file1.ts:1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
t.ts(1,22): error TS6053: File 'a' not found.
t.ts(2,22): error TS6053: File 'b' not found.
t.ts(3,22): error TS6053: File 'c' not found.


==== t.ts (3 errors) ====
/// <reference path="a"/>
~
!!! error TS6053: File 'a' not found.
/// <reference path="b"/>
~
!!! error TS6053: File 'b' not found.
/// <reference path="c"/>
~
!!! error TS6053: File 'c' not found.
var a = aa; // Check that a.ts is referenced
var b = bb; // Check that b.d.ts is referenced
var c = cc; // Check that c.ts has precedence over c.d.ts

==== a.ts (0 errors) ====
var aa = 1;

==== b.d.ts (0 errors) ====
declare var bb: number;

==== c.ts (0 errors) ====
var cc = 1;

==== c.d.ts (0 errors) ====
declare var xx: number;

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--- old.fileReferencesWithNoExtensions.errors.txt
+++ new.fileReferencesWithNoExtensions.errors.txt
@@= skipped -0, +0 lines =@@
-<no content>
+t.ts(1,22): error TS6053: File 'a' not found.
+t.ts(2,22): error TS6053: File 'b' not found.
+t.ts(3,22): error TS6053: File 'c' not found.
+
+
+==== t.ts (3 errors) ====
+ /// <reference path="a"/>
+ ~
+!!! error TS6053: File 'a' not found.
+ /// <reference path="b"/>
+ ~
+!!! error TS6053: File 'b' not found.
+ /// <reference path="c"/>
+ ~
+!!! error TS6053: File 'c' not found.
+ var a = aa; // Check that a.ts is referenced
+ var b = bb; // Check that b.d.ts is referenced
+ var c = cc; // Check that c.ts has precedence over c.d.ts
+
+==== a.ts (0 errors) ====
+ var aa = 1;
+
+==== b.d.ts (0 errors) ====
+ declare var bb: number;
+
+==== c.ts (0 errors) ====
+ var cc = 1;
+
+==== c.d.ts (0 errors) ====
+ declare var xx: number;
+
Loading