Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
32 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
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
21 changes: 20 additions & 1 deletion internal/compiler/fileloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/microsoft/typescript-go/internal/ast"
"github.com/microsoft/typescript-go/internal/collections"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/diagnostics"
"github.com/microsoft/typescript-go/internal/module"
"github.com/microsoft/typescript-go/internal/tsoptions"
"github.com/microsoft/typescript-go/internal/tspath"
Expand Down Expand Up @@ -69,6 +70,7 @@ type processedFiles struct {
// if file was included using source file and its output is actually part of program
// this contains mapping from output to source file
outputFileToProjectReferenceSource map[tspath.Path]string
fileDiagnostics []*ast.Diagnostic
}

type jsxRuntimeImportSpecifier struct {
Expand All @@ -80,6 +82,7 @@ func processAllProgramFiles(
opts ProgramOptions,
singleThreaded bool,
) processedFiles {
var fileDiagnostics []*ast.Diagnostic
compilerOptions := opts.Config.CompilerOptions()
rootFiles := opts.Config.FileNames()
supportedExtensions := tsoptions.GetSupportedExtensions(compilerOptions, nil /*extraFileExtensions*/)
Expand Down Expand Up @@ -168,9 +171,24 @@ 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)

if task.includeReason != nil {
task.includeReason.diagOnce.Do(func() {
var parentFile *ast.SourceFile
d := ast.NewDiagnostic(
parentFile, // !!! unknown parent file
core.UndefinedTextRange(), // !!! unknown location
diagnostics.File_0_not_found,
task.normalizedFilePath,
)
task.includeReason.diag = d
fileDiagnostics = append(fileDiagnostics, d)
})
}
return
}

Expand Down Expand Up @@ -250,6 +268,7 @@ func processAllProgramFiles(
missingFiles: missingFiles,
includeProcessor: loader.includeProcessor,
outputFileToProjectReferenceSource: outputFileToProjectReferenceSource,
fileDiagnostics: fileDiagnostics,
}
}

Expand Down
1 change: 1 addition & 0 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.programDiagnostics = append(p.programDiagnostics, p.processedFiles.fileDiagnostics...)
p.verifyCompilerOptions()
return p
}
Expand Down
43 changes: 43 additions & 0 deletions internal/compiler/program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,46 @@ func BenchmarkNewProgram(b *testing.B) {
}
})
}

func TestMissingReferenceFile(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this; if you fixed the bug, the declarationEmitIndexTypeNotFound test should have been updated when you ran the tests.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have just fixed the bug, should i open a new pull request or just commit on this request?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just push to this one, please

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still an issue; the PR is not fixing the test I mentioned above

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the last commit, I only made changes to loaderfile.go and program.go. I had previously added a new test (TestMissingReferenceFile), but it has been removed following the your guidance. Please let me know if I have misunderstood your point.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the fix in this PR worked, then the test case Ryan was showing, declarationEmitIndexTypeNotFound, would fail and ask you to update the baselines, and likely other tests. The fact that this PR contains code but no test baseline changes means the fix is not working.

Are you testing this some other way?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, got it! so if the bug is fixed, the tests are expected to fail and I need to update the baseline, right?

Previously, I ran a test locally for debugging and compiled an erroneous .ts file to check whether the error matched what tsc would produce. After that, I ran go test, which failed. I then code again to pass the test but forgot to manually verify it again, so I just realized that my last commit didn’t actually solve the issue.

Now I have fixed the bug again and I’ve updated the baseline, but it resulted in 64 changes, and I’m not sure how to verify whether the updated baseline is correct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like an improvement with some regressions; if you view https://github.com/microsoft/typescript-go/pull/2096/files?file-filters%5B%5D=.go&file-filters%5B%5D=.diff (filtered to diffs), the goal would be to eliminate those by improving the fix.

t.Parallel()

if !bundled.Embedded {
t.Skip("bundled files are not embedded")
}

fs := vfstest.FromMap[any](nil, false /*useCaseSensitiveFileNames*/)
fs = bundled.WrapFS(fs)

// Write a test file that references a missing file
_ = fs.WriteFile("c:/dev/src/index.ts", `/// <reference path="missing.ts" />
const x = 42;
console.log(x);`, false)

compilerHost := compiler.NewCompilerHost("c:/dev/src", fs, bundled.LibPath(), nil, nil)

opts := core.CompilerOptions{Target: core.ScriptTargetESNext}

parsedConfig := &tsoptions.ParsedCommandLine{
ParsedConfig: &core.ParsedOptions{
FileNames: []string{"c:/dev/src/index.ts"},
CompilerOptions: &opts,
},
}

program := compiler.NewProgram(compiler.ProgramOptions{
Config: parsedConfig,
Host: compilerHost,
})

diagnostics := program.GetProgramDiagnostics()
found := false
for _, d := range diagnostics {
if d.Code() == 6053 {
found = true
break
}
}

assert.Assert(t, found, "Expected TS6053 diagnostic for missing reference file")
}
Loading