Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
371cacd
fix (unfinished) TS6053 missing file diagnostics to match tsc (#2081)
Nov 14, 2025
3b00267
Merge branch 'main' into fix-missing-file-diagnostics
TranNhatHan Nov 14, 2025
67db554
Delete TestMissingReferenceFile test case
TranNhatHan Nov 15, 2025
5de90ce
Merge branch 'microsoft:main' into fix-missing-file-diagnostics
TranNhatHan Nov 15, 2025
5b87cc2
completely fix the missing error file not found bug
Nov 15, 2025
0b3f881
failed incremental test in scenario "when global file is added, the s…
Nov 16, 2025
b44a247
fix: attach missing-file diagnostics to the correct source file
Nov 16, 2025
b615125
fix: resolve golangci-lint errors
Nov 16, 2025
5bad47f
Merge branch 'microsoft:main' into fix-missing-file-diagnostics
TranNhatHan Nov 17, 2025
873b273
Merge branch 'main' into fix-missing-file-diagnostics
TranNhatHan Nov 17, 2025
77d30af
Merge branch 'main' into fix-missing-file-diagnostics
TranNhatHan Nov 17, 2025
ad50113
update code per maintainer suggestions
Nov 17, 2025
ea23f59
Merge branch 'main' into fix-missing-file-diagnostics
TranNhatHan Nov 17, 2025
0ed3489
reset the .golangci.yml as default
Nov 17, 2025
f46ccc9
reset the .golangci.yml as default
Nov 18, 2025
02696be
Merge branch 'main' into fix-missing-file-diagnostics
TranNhatHan Nov 19, 2025
87bd8d6
accept new baseline
Nov 19, 2025
aad5fc2
Revert "accept new baseline"
Nov 19, 2025
eadc7bf
update new baseline
Nov 19, 2025
1999a76
Revert "update new baseline"
Nov 19, 2025
1dddca1
failed tests
Nov 20, 2025
f4eddf6
failed incremental test
Nov 20, 2025
3ebb753
update new baseline
Nov 20, 2025
a8a4b3c
fix
Nov 20, 2025
5af31f1
Revert "failed incremental test"
Nov 20, 2025
c29d729
Revert "update new baseline"
Nov 20, 2025
aa2b4cf
fix
Nov 20, 2025
363bde5
keep fixing
Nov 20, 2025
4edbc11
Merge pull request #1 from TranNhatHan/fix-bug
TranNhatHan Nov 20, 2025
b0adcfe
Merge branch 'main' into fix-missing-file-diagnostics
TranNhatHan Nov 21, 2025
7e18c1f
raise error but change other behaviours
Nov 21, 2025
a6958e0
Merge branch 'fix-missing-file-diagnostics' of https://github.com/Tra…
Nov 21, 2025
8050037
fix bug
TranNhatHan Nov 23, 2025
86cb146
modifying
TranNhatHan Nov 23, 2025
cdceedd
Merge branch 'microsoft:main' into fix-missing-file-diagnostics
TranNhatHan Nov 23, 2025
1d00afc
update new baseline
Nov 23, 2025
70a11e1
fix bug futher
TranNhatHan Nov 23, 2025
e773ef6
Merge branch 'fix-missing-file-diagnostics' of https://github.com/Tra…
TranNhatHan Nov 23, 2025
19e5d81
fix for unsuported extension error
TranNhatHan Nov 23, 2025
0265230
undo unnecessary change
TranNhatHan Nov 23, 2025
69c62f5
undo unnecessary change
Nov 23, 2025
acb96cf
update new baseline
Nov 23, 2025
96d9254
undo unnescessary change
Nov 25, 2025
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
68 changes: 68 additions & 0 deletions internal/compiler/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,74 @@ func (p *Program) getSemanticDiagnosticsForFileNotFilter(ctx context.Context, so
}
diags := slices.Clip(sourceFile.BindDiagnostics())

supportedExtensions := tsoptions.GetSupportedExtensions(p.opts.Config.CompilerOptions(), nil)
supportedExtensionsWithJsonIfResolveJsonModule := tsoptions.GetSupportedExtensionsWithJsonIfResolveJsonModule(p.opts.Config.CompilerOptions(), supportedExtensions)

for _, ref := range sourceFile.ReferencedFiles {
fileName := ref.FileName
getSourceFile := func(fileName string) *ast.SourceFile {
resolvedPath := tspath.GetNormalizedAbsolutePath(fileName, tspath.GetDirectoryPath(sourceFile.FileName()))
canonicalPath := tspath.GetCanonicalFileName(resolvedPath, p.opts.Host.FS().UseCaseSensitiveFileNames())
return p.filesByPath[tspath.Path(canonicalPath)]
}

fail := func(diagnostic *diagnostics.Message, args ...string) {
argsAny := make([]any, len(args))
for i, v := range args {
argsAny[i] = v
}
diags = append(diags, ast.NewDiagnostic(
sourceFile,
ref.TextRange,
diagnostic,
argsAny...,
))
}

if tspath.HasExtension(fileName) {
canonicalFileName := tspath.GetCanonicalFileName(fileName, p.opts.Host.FS().UseCaseSensitiveFileNames())
if !core.Tristate.IsTrue(p.opts.Config.CompilerOptions().AllowNonTsExtensions) && !core.Some(core.Flatten(supportedExtensionsWithJsonIfResolveJsonModule), func(extension string) bool {
return tspath.FileExtensionIs(canonicalFileName, extension)
}) {
if tspath.HasJSFileExtension(canonicalFileName) {
fail(diagnostics.File_0_is_a_JavaScript_file_Did_you_mean_to_enable_the_allowJs_option, fileName)
} else {
fail(diagnostics.File_0_has_an_unsupported_extension_The_only_supported_extensions_are_1, fileName, "'"+strings.Join(core.Flatten(supportedExtensions), "', '")+"'")
}
continue
}

referencedFile := getSourceFile(fileName)
switch referencedFile {
case nil:
// !!! check for redirect
fail(diagnostics.File_0_not_found, fileName)
case sourceFile:
fail(diagnostics.A_file_cannot_have_a_reference_to_itself)
}
} else {
sourceFileNoExtension := core.Tristate.IsTrue(p.opts.Config.CompilerOptions().AllowNonTsExtensions) && getSourceFile(fileName) != nil
if sourceFileNoExtension {
continue
}

if core.Tristate.IsTrue(p.opts.Config.CompilerOptions().AllowNonTsExtensions) {
fail(diagnostics.File_0_not_found, fileName)
continue
}

// Only try adding extensions from the first supported group (which should be .ts/.tsx/.d.ts)
// supportedExtensions[0] corresponds to SupportedTSExtensions[0] in tspath
sourceFileWithAddedExtension := core.FirstNonNil(tspath.SupportedTSExtensions[0], func(extension string) *ast.SourceFile {
return getSourceFile(fileName + extension)
})

if sourceFileWithAddedExtension == nil {
fail(diagnostics.Could_not_resolve_the_path_0_with_the_extensions_Colon_1, fileName, "'"+strings.Join(core.Flatten(supportedExtensions), "', '")+"'")
}
}
}

// Ask for diags from all checkers; checking one file may add diagnostics to other files.
// These are deduplicated later.
checkerDiags := make([][]*ast.Diagnostic, p.checkerPool.Count())
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 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" />
~~~~~~~
!!! 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;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
file2.ts:1:22 - error TS6231: Could not resolve the path './file1' with the extensions: '.ts', '.tsx', '.d.ts', '.cts', '.d.cts', '.mts', '.d.mts'.

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 TS6231: Could not resolve the path './file1' with the extensions: '.ts', '.tsx', '.d.ts', '.cts', '.d.cts', '.mts', '.d.mts'.

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 TS6231: Could not resolve the path './file1' with the extensions: '.ts', '.tsx', '.d.ts', '.cts', '.d.cts', '.mts', '.d.mts'.
+
+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 TS6231: Could not resolve the path './file1' with the extensions: '.ts', '.tsx', '.d.ts', '.cts', '.d.cts', '.mts', '.d.mts'.

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 TS6231: Could not resolve the path './file1' with the extensions: '.ts', '.tsx', '.d.ts', '.cts', '.d.cts', '.mts', '.d.mts'.

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 TS6231: Could not resolve the path './file1' with the extensions: '.ts', '.tsx', '.d.ts', '.cts', '.d.cts', '.mts', '.d.mts'.

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 TS6231: Could not resolve the path './file1' with the extensions: '.ts', '.tsx', '.d.ts', '.cts', '.d.cts', '.mts', '.d.mts'.
+
+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 TS6231: Could not resolve the path './file1' with the extensions: '.ts', '.tsx', '.d.ts', '.cts', '.d.cts', '.mts', '.d.mts'.

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,14 @@
invalidTripleSlashReference.ts(1,22): error TS6053: File 'filedoesnotexist.ts' not found.
invalidTripleSlashReference.ts(2,22): error TS6053: File 'otherdoesnotexist.d.ts' not found.


==== invalidTripleSlashReference.ts (2 errors) ====
/// <reference path='filedoesnotexist.ts'/>
~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'filedoesnotexist.ts' not found.
/// <reference path='otherdoesnotexist.d.ts'/>
~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'otherdoesnotexist.d.ts' not found.

// this test doesn't actually give the errors you want due to the way the compiler reports errors
var x = 1;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
idx.test.ts(1,22): error TS6231: Could not resolve the path './idx' with the extensions: '.ts', '.tsx', '.d.ts', '.cts', '.d.cts', '.mts', '.d.mts'.


==== idx.test.ts (1 errors) ====
/// <reference path="./idx" />
~~~~~
!!! error TS6231: Could not resolve the path './idx' with the extensions: '.ts', '.tsx', '.d.ts', '.cts', '.d.cts', '.mts', '.d.mts'.

import moment = require("moment-timezone");

==== node_modules/moment/index.d.ts (0 errors) ====
declare function moment(): moment.Moment;
declare namespace moment {
interface Moment extends Object {
valueOf(): number;
}
}
export = moment;
==== node_modules/moment-timezone/index.d.ts (0 errors) ====
import * as moment from 'moment';
export = moment;
declare module "moment" {
interface Moment {
tz(): string;
}
}
==== idx.ts (0 errors) ====
import * as _moment from "moment";
declare module "moment" {
interface Moment {
strftime(pattern: string): string;
}
}
declare module "moment-timezone" {
interface Moment {
strftime(pattern: string): string;
}
}
Loading